Created
February 4, 2023 20:35
-
-
Save marshyon/ee87895d9a6edfab668a4b1f457e80e7 to your computer and use it in GitHub Desktop.
parsing markdown with html tables that have 'spanning rows' - otherwise not possible with plain markdown
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const tableMarkdown = ` | |
# Table | |
<table> | |
<tr> | |
<td>One</td> | |
<td>Two</td> | |
</tr> | |
<tr> | |
<td colspan="2">Three</td> | |
</tr> | |
</table> | |
and this should be just plain old text | |
> but this should be a blockquote | |
** and this should be bold ** | |
* and this should be italic * | |
# and this should be a heading | |
[and this should be a link](https://www.google.com) | |
and this should be a list | |
- one | |
- two | |
- three | |
and this should be a numbered list | |
1. one | |
2. two | |
3. three | |
` | |
marked = require('marked') | |
marked.parse(tableMarkdown) | |
// output | |
marked.setOptions({ | |
pedantic: false, | |
gfm: true, | |
breaks: false, | |
sanitize: false, | |
smartypants: false, | |
xhtml: false | |
}); | |
const html = marked.parse(tableMarkdown) | |
console.log(html) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1 id="table">Table</h1> | |
<table> | |
<tr> | |
<td>One</td> | |
<td>Two</td> | |
</tr> | |
<tr> | |
<td colspan="2">Three</td> | |
</tr> | |
</table> | |
<p>and this should be just plain old text</p> | |
<blockquote> | |
<p>but this should be a blockquote</p> | |
</blockquote> | |
<p>** and this should be bold **</p> | |
<ul> | |
<li>and this should be italic *</li> | |
</ul> | |
<h1 id="and-this-should-be-a-heading">and this should be a heading</h1> | |
<p><a href="https://www.google.com">and this should be a link</a></p> | |
<p>and this should be a list</p> | |
<ul> | |
<li>one</li> | |
<li>two</li> | |
<li>three</li> | |
</ul> | |
<p>and this should be a numbered list</p> | |
<ol> | |
<li>one</li> | |
<li>two</li> | |
<li>three</li> | |
</ol> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment