Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/wikitextprocessor/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1571,8 +1571,15 @@ def table_row_fn(ctx: "Wtp", token: str) -> None:
return text_fn(ctx, token)

if not (ctx.beginning_of_line or ctx.wsp_beginning_of_line):
vbar_fn(ctx, "|")
return text_fn(ctx, "-")
node = ctx.parser_stack[-1]
# ignore "|-" token before first row and not at line beginning
if node.kind == NodeKind.TABLE and not node.contain_node(
NodeKind.TABLE_ROW
):
return
else:
vbar_fn(ctx, "|")
return text_fn(ctx, "-")

close_begline_lists(ctx)
table_check_attrs(ctx)
Expand Down
16 changes: 16 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3394,6 +3394,22 @@ def test_newline_in_ref(self):
url_node.largs, [["http://purl.uni-rostock.de/demel/d00649426"]]
)

def test_incorrt_row_separator(self):
# tatuylonen/wiktextract#1509
self.ctx.start_page("αζωικός")
root = self.ctx.parse("""{| class="wikitable"|-
! Header A
|-
| row 1 A
|}""")
table = root.children[0]
first_row = table.children[0]
self.assertEqual(first_row.kind, NodeKind.TABLE_ROW)
self.assertEqual(len(first_row.children), 1)
header = first_row.children[0]
self.assertEqual(header.kind, NodeKind.TABLE_HEADER_CELL)
self.assertEqual(header.children, [" Header A\n"])


# XXX implement <nowiki/> marking for links, templates
# - https://en.wikipedia.org/wiki/Help:Wikitext#Nowiki
Expand Down