-
-
Notifications
You must be signed in to change notification settings - Fork 246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Markdown tables inside of ordered lists don't get parsed #158
Comments
@supersam654 That is designed on purpose, if you think you need this feature, you can subclass |
@lepture could you please expand a little more on why it was designed this way? |
@lepture I tried to subclass #! /usr/bin/env python3
from mistune import BlockLexer, Markdown
class WebteamBlockLexer(BlockLexer):
list_rules = (
'newline', 'block_code', 'fences', 'lheading', 'hrule',
'block_quote', 'list_block', 'block_html', 'text',
'table', 'nptable',
)
parse_markdown = Markdown(
parse_block_html=True, parse_inline_html=True,
block=WebteamBlockLexer()
)
md_text = """
| Title |
| ----- |
| Value |
1. List item 1
| Title |
| ----- |
| Value |
2. List item 2
"""
print(parse_markdown(md_text)) But it didn't work, giving the following output: <table>
<thead><tr>
<th>Title</th>
</tr>
</thead>
<tbody>
<tr>
<td>Value</td>
</tr>
</tbody>
</table>
<ol>
<li><p>List item 1</p>
<p>| Title |
| ----- |
| Value |</p>
</li>
<li><p>List item 2</p>
</li>
</ol> @lepture would you be able to help me understand where I went wrong? |
Okay, I worked it out - the order in that list matters. So So, for posterity, here's a working example of how to support tables in lists: from mistune import BlockLexer, Markdown
class MyBlockLexer(BlockLexer):
list_rules = (
'newline', 'block_code', 'fences', 'lheading', 'hrule',
'block_quote', 'list_block', 'table', 'block_html', 'text',
)
parse_markdown = Markdown(block=MyBlockLexer())
print(
parse_markdown("""
1. List item 1
| Title |
| ----- |
| Value |
2. List item 2
""")
) Which outputs: <ol>
<li><p>List item 1</p>
<table>
<thead><tr>
<th>Title</th>
</tr>
</thead>
<tbody>
<tr>
<td>Value</td>
</tr>
</tbody>
</table>
</li>
<li><p>List item 2</p>
</li>
</ol> |
Did you manage to get the same thing to work with I'm currently trying, but subclassing UPDATE: It does work, and it is even easier than subclassing markdown = mistune.create_markdown(...)
# or markdown = mistune.Markdown(...)
markdown.block.list_rules += ['table', 'nptable'] Tested with |
When I nest a table inside of an ordered list (so the list numbers continue), the table doesn't get parsed into HTML.
Prints
even though I was expecting an HTML table inside of the list.
The text was updated successfully, but these errors were encountered: