-
Notifications
You must be signed in to change notification settings - Fork 4
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
Fix tests #7
base: master
Are you sure you want to change the base?
Fix tests #7
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,8 @@ def table(parser, container): | |
parser.advance_offset(1, False) | ||
parser.close_unmatched_blocks() | ||
parser.add_child('table', parser.next_nonspace) | ||
return 1 | ||
parser.tip.string_content = '|' | ||
return 2 | ||
return 0 | ||
|
||
|
||
|
@@ -43,7 +44,8 @@ def continue_(parser=None, container=None): | |
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 ("", ">", "`"): | ||
container.string_content += "|" | ||
elif not parser.indented and commonmark.blocks.peek(ln, parser.next_nonspace) not in ("", ">", "`", None): | ||
pass | ||
else: | ||
return 1 | ||
|
@@ -60,6 +62,7 @@ def finalize(parser=None, block=None): | |
table = [[""]] | ||
escape = False | ||
newrowbars = False | ||
ignore_pipe = True | ||
for c in block.string_content.rstrip(): | ||
# \-escaping | ||
if escape: | ||
|
@@ -71,6 +74,9 @@ def finalize(parser=None, block=None): | |
# New cell is begun by a bar. Right-strip the cell we're | ||
# ending. | ||
elif c == "|": | ||
if ignore_pipe: | ||
ignore_pipe = False | ||
continue | ||
table[-1][-1] = table[-1][-1].rstrip() | ||
table[-1].append("") | ||
|
||
|
@@ -80,6 +86,8 @@ def finalize(parser=None, block=None): | |
elif c == "\n": | ||
if table[-1][-1].strip() == "": table[-1].pop(-1) | ||
table.append([""]) | ||
ignore_pipe = True | ||
continue | ||
|
||
# Ignore space at start of cell. An escaped space | ||
# can force a space. | ||
|
@@ -90,6 +98,8 @@ def finalize(parser=None, block=None): | |
else: | ||
table[-1][-1] += c | ||
|
||
ignore_pipe = False | ||
|
||
# Remove the last cell if it's empty since it's caused | ||
# by the final pipe at the end of the last line. | ||
if table[-1][-1].strip() == "": | ||
|
@@ -107,6 +117,9 @@ def finalize(parser=None, block=None): | |
if len(list(filter(lambda cell : not re.match(r"[-=:]+$", cell), row))) == 0: | ||
# This row has cells of just dahses. | ||
if len(table_parts) == 1: | ||
if len(row) != len(table_parts[0][0]): | ||
block.t = 'paragraph' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned in commit message, this doesn't actually change the Python type of the block, but it does produce the right output on rendering so likely doesn't matter. |
||
return | ||
# The first time, we shift to the tbody. | ||
table_parts.append([]) | ||
|
||
|
@@ -138,6 +151,10 @@ def finalize(parser=None, block=None): | |
# Fill in empty rows if fewer than the header. | ||
if len(table_parts) > 1 and len(table_parts[0][0]) > len(table_parts[-1][-1]): | ||
table_parts[-1][-1].extend( ["" for _ in range(len(table_parts[0][0]) - len(table_parts[-1][-1])) ] ) | ||
|
||
# Remove excess cells if more than number of columns | ||
if len(table_parts) > 1 and len(table_parts[0][0]) < len(table_parts[-1][-1]): | ||
table_parts[-1][-1] = table_parts[-1][-1][:len(table_parts[0][0])] | ||
|
||
else: | ||
# Multline mode. Merge this row with the previous one. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,6 +121,8 @@ def test_break2(self): | |
"""| abc | def | | ||
| --- | --- | | ||
| bar | baz | | ||
bar | ||
|
||
bar""", | ||
|
||
"""<table> | ||
|
@@ -141,6 +143,7 @@ def test_break2(self): | |
</tr> | ||
</tbody> | ||
</table> | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This differs slightly from the spec, but doesn't actually change the visual output of the html (as blank lines aren't treated specially). If you are bothered by this, let me know and I can try work out why the new line appears and whether we can avoid it. |
||
<p>bar</p>""") | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning 2 makes it a leaf node, which in practice means that it doesn't slurp up whitespace after the
|
, meaning the pipe can be added back simply.