Skip to content
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

End of table (e.g. </tr></table>) does not get generated. #3

Open
iliatimofeev opened this issue Jul 12, 2018 · 3 comments · May be fixed by #7
Open

End of table (e.g. </tr></table>) does not get generated. #3

iliatimofeev opened this issue Jul 12, 2018 · 3 comments · May be fixed by #7
Assignees

Comments

@iliatimofeev
Copy link

import CommonMarkExtensions.tables
display(HTML( CommonMarkExtensions.tables.commonmark("""
|  Col     | Header 2 |
| -------- | -------- |
| Cells    | **can**  |
| `have`   | inlines. |

# Second table

|  Col2    | Header 3 |
| -------- | -------- |
| Cells    | **can**  |
| `have`   | inlines. |

""") ))
Col Header 2
Cells can
have inlines.
# Second table
Col2 Header 3
Cells can
have inlines.
@gregelin gregelin changed the title Don't end table block End of table (e.g. </tr></table>) does not get generated. Jul 13, 2018
@gregelin
Copy link

@iliatimofeev Thanks. I've verified the issue.

hughdavenport added a commit to hughdavenport/CommonMark-py-Extensions that referenced this issue Nov 26, 2020
Also fixes GovReady#3.

Checks whether the next nonspace is None which means that it is a blank line.

Alters the test case to fit in with the Google Flavoured Markdown (GFM) spec.
@hughdavenport hughdavenport linked a pull request Nov 26, 2020 that will close this issue
@hughdavenport
Copy link
Contributor

Workaround for this, until PR#7 gets merged.

import commonmark_extensions.tables
import commonmark.blocks

def check_commonmark_tables_bug3():

    class TableWaitingForBug3(commonmark_extensions.tables.Table):
        @staticmethod
        def continue_(parser=None, container=None):
            ln = parser.current_line
            if not parser.indented and commonmark.blocks.peek(ln, parser.next_nonspace) == "|":
                parser.advance_next_nonspace()
                parser.advance_offset(1, False)
            elif not parser.indented and commonmark.blocks.peek(ln, parser.next_nonspace) not in ("", ">", "`", None):
                pass
            else:
                return 1
            return 0

    parser = commonmark_extensions.tables.ParserWithTables()
    renderer = commonmark_extensions.tables.RendererWithTables()
    example_202 = """| abc | def |
| --- | --- |
| bar | baz |
bar

bar"""
    example_202_expected = """<table>
<thead>
<tr>
<th>abc</th>
<th>def</th>
</tr>
</thead>
<tbody>
<tr>
<td>bar</td>
<td>baz</td>
</tr>
<tr>
<td>bar</td>
<td></td>
</tr>
</tbody>
</table>

<p>bar</p>"""
    if renderer.render(parser.parse(example_202)) != example_202_expected:
        commonmark.blocks.Table = TableWaitingForBug3

    return commonmark.blocks.Table

I have the above saved in monkey_patches.py, then in my main script I have:

import commonmark
import monkey_patches
commonmark.blocks.Table = monkey_patches.check_commonmark_tables_bug3()

This is basically grabbing the patched file from d5b8845, and using that if the test for this bug fails.

Hopefully someone finds this useful in their codebase :)

@hughdavenport
Copy link
Contributor

Workaround if you are now using Python3.9 with commonmark 0.9.1 until #7 and #8 is merged. This is mostly the same as above, but checks whether the parser has a blocks dict (this is introduced in commonmark 0.9.1) and ensures that it is using the correct table class.

import commonmark_extensions.tables
import commonmark.blocks

def check_commonmark_tables_bug3():

    class TableWaitingForBug3(commonmark_extensions.tables.Table):
        @staticmethod
        def continue_(parser=None, container=None):
            ln = parser.current_line
            if not parser.indented and commonmark.blocks.peek(ln, parser.next_nonspace) == "|":
                parser.advance_next_nonspace()
                parser.advance_offset(1, False)
            elif not parser.indented and commonmark.blocks.peek(ln, parser.next_nonspace) not in ("", ">", "`", None):
                pass
            else:
                return 1
            return 0

    parser = commonmark_extensions.tables.ParserWithTables()
    bug4 = hasattr(parser. 'blocks') and 'table' not in parser.blocks
    if bug4:
        parser.blocks['table'] = commonmark.blocks.Table
    renderer = commonmark_extensions.tables.RendererWithTables()
    example_202 = """| abc | def |
| --- | --- |
| bar | baz |
bar

bar"""
    example_202_expected = """<table>
<thead>
<tr>
<th>abc</th>
<th>def</th>
</tr>
</thead>
<tbody>
<tr>
<td>bar</td>
<td>baz</td>
</tr>
<tr>
<td>bar</td>
<td></td>
</tr>
</tbody>
</table>

<p>bar</p>"""
    if renderer.render(parser.parse(example_202)) != example_202_expected:
        commonmark.blocks.Table = TableWaitingForBug3
        if bug4:
            parser.blocks['table'] = commonmark.blocks.Table

    return commonmark.blocks.Table

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants