diff --git a/src/wikitextprocessor/parser.py b/src/wikitextprocessor/parser.py index af966fc4..69361533 100644 --- a/src/wikitextprocessor/parser.py +++ b/src/wikitextprocessor/parser.py @@ -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) diff --git a/tests/test_parser.py b/tests/test_parser.py index 7d0a6873..49489953 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -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 marking for links, templates # - https://en.wikipedia.org/wiki/Help:Wikitext#Nowiki