showdownjs / showdown

A bidirectional Markdown to HTML to Markdown converter written in Javascript
http://www.showdownjs.com/
MIT License
14.19k stars 1.56k forks source link

Footnote Above Table Causes Table Not to Render #929

Open shawnfunke opened 2 years ago

shawnfunke commented 2 years ago

Summary

Whenever there is a footnote used above a table it will not be rendered correctly. As a workaround a comment can be placed before the actual table.

Example

Footnote [^1]

[^1]: https://example.com

| C1  | C2  |
| --- | --- |
| k1  | v2  |
<p>Footnote <a href="https://example.com">^1</a></p>
<p>C1  | C2  | --- | --- |
| k1  | v2  |</p>

Workaround

Footnote [^1]

[^1]: https://example.com

<!-- comment -->

| C1  | C2  |
| --- | --- |
| k1  | v2  |
<p>Footnote <a href="https://example.com">^1</a></p>
<!-- comment -->
<table>
<thead>
<tr>
<th>C1</th>
<th>C2</th>
</tr>
</thead>
<tbody>
<tr>
<td>k1</td>
<td>v2</td>
</tr>
</tbody>
</table>
shawnfunke commented 2 years ago

What I found so far is that the issue comes from the makehtml.stripLinkDefinitions sub-parser ^1.

For the input of the example it matches C1 | C2 as a title and tries to put it back ^2. So it combines blankLines + title, which is \n and C1 | C2, which then results in the table being broken.