diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
index f0f6744c6000..a5237219b347 100644
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -1403,7 +1403,20 @@ multilineTableHeader headless = try $ do
-- ending with a footer (dashed line followed by blank line).
gridTable :: PandocMonad m
=> MarkdownParser m (F TableComponents)
-gridTable = gridTableWith' NormalizeHeader parseBlocks
+gridTable = try $ do
+ -- Like other block-level constructs, a grid table may be indented by
+ -- up to three spaces. The underlying grid-table parser expects the
+ -- table to begin at the left margin, so strip a uniform indentation
+ -- from every line before handing it off.
+ indent <- T.length <$> lookAhead nonindentSpaces
+ if indent == 0
+ then gridTableWith' NormalizeHeader parseBlocks
+ else do
+ let gridLine = try $ count indent (char ' ')
+ *> lookAhead (oneOf "+|")
+ *> anyLineNewline
+ rawTable <- T.concat <$> many1 gridLine
+ parseFromString' (gridTableWith' NormalizeHeader parseBlocks) rawTable
pipeBreak :: PandocMonad m => MarkdownParser m ([Alignment], [Int])
pipeBreak = try $ do
diff --git a/test/command/grid-table-indented.md b/test/command/grid-table-indented.md
new file mode 100644
index 000000000000..cf6f24c07610
--- /dev/null
+++ b/test/command/grid-table-indented.md
@@ -0,0 +1,65 @@
+Like other block-level constructs, grid tables may be indented by up to
+three spaces and are still recognized as tables.
+
+```
+% pandoc -f markdown -t html
+ +---+---+
+ | a | b |
+ +===+===+
+ | 1 | 2 |
+ +---+---+
+^D
+
+
+
+
+
+
+
+| a |
+b |
+
+
+
+
+| 1 |
+2 |
+
+
+
+```
+
+A headerless indented grid table is recognized too.
+
+```
+% pandoc -f markdown -t html
+ +------+------+
+ | foo | bar |
+ +------+------+
+^D
+
+
+
+
+
+
+
+| foo |
+bar |
+
+
+
+```
+
+A grid table indented four spaces is a code block, not a table.
+
+```
+% pandoc -f markdown -t html
+ +---+---+
+ | a | b |
+ +---+---+
+^D
++---+---+
+| a | b |
++---+---+
+```