Skip to content

Commit

Permalink
Merge pull request pulldown-cmark#653 from raphlinus/paragraphs-befor…
Browse files Browse the repository at this point in the history
…e-tables

fix: tables can interrupt paragraphs
  • Loading branch information
Martin1887 authored May 28, 2023
2 parents cd20ed8 + a83cf96 commit 4921c42
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/firstpass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,22 @@ impl<'a, 'b> FirstPass<'a, 'b> {
return LoopInstruction::BreakAtWith(ix, None);
}

// If tables are not enabled yet and the next char is a pipe,
// and there was content before then a table begins here but
// there was content before the table:
// ```
// Hello
// | a | b | c |
// ```
if TableParseMode::Scan == mode
&& bytes.len() > (ix + 1)
&& bytes[ix + 1] == b'|'
&& begin_text < ix
&& pipes == 0
{
return LoopInstruction::BreakAtWith(ix, None);
}

let mut i = ix;
let eol_bytes = scan_eol(&bytes[ix..]).unwrap();
if mode == TableParseMode::Scan && pipes > 0 {
Expand Down
27 changes: 27 additions & 0 deletions tests/suite/gfm_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,30 @@ fn gfm_table_test_8() {

test_markdown_html(original, expected, false, false);
}

#[test]
fn gfm_table_test_9() {
let original = r##"Hello World
| abc | def |
| --- | --- |
| bar | baz |
"##;
let expected = r##"<p>Hello World</p>
<table>
<thead>
<tr>
<th>abc</th>
<th>def</th>
</tr>
</thead>
<tbody>
<tr>
<td>bar</td>
<td>baz</td>
</tr>
</tbody>
</table>
"##;

test_markdown_html(original, expected, false, false);
}
25 changes: 25 additions & 0 deletions third_party/GitHub/gfm_table.txt
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,28 @@ If there are no rows in the body, no `<tbody>` is generated in HTML output:
</thead>
</table>
````````````````````````````````

Tables can interrupt paragraphs:

```````````````````````````````` example
Hello World
| abc | def |
| --- | --- |
| bar | baz |
.
<p>Hello World</p>
<table>
<thead>
<tr>
<th>abc</th>
<th>def</th>
</tr>
</thead>
<tbody>
<tr>
<td>bar</td>
<td>baz</td>
</tr>
</tbody>
</table>
````````````````````````````````

0 comments on commit 4921c42

Please sign in to comment.