Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/Text/Pandoc/Readers/Markdown.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
65 changes: 65 additions & 0 deletions test/command/grid-table-indented.md
Original file line number Diff line number Diff line change
@@ -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
<table style="width:11%;">
<colgroup>
<col style="width: 5%" />
<col style="width: 5%" />
</colgroup>
<thead>
<tr>
<th>a</th>
<th>b</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>2</td>
</tr>
</tbody>
</table>
```

A headerless indented grid table is recognized too.

```
% pandoc -f markdown -t html
+------+------+
| foo | bar |
+------+------+
^D
<table style="width:19%;">
<colgroup>
<col style="width: 9%" />
<col style="width: 9%" />
</colgroup>
<tbody>
<tr>
<td>foo</td>
<td>bar</td>
</tr>
</tbody>
</table>
```

A grid table indented four spaces is a code block, not a table.

```
% pandoc -f markdown -t html
+---+---+
| a | b |
+---+---+
^D
<pre><code>+---+---+
| a | b |
+---+---+</code></pre>
```