Skip to content

Commit f26afeb

Browse files
authored
Merge pull request #399 from xxyzz/table_cell
`||` inside table should be parsed as one cell
2 parents 12626d6 + a33e7f2 commit f26afeb

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

src/wikitextprocessor/parser.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,11 +1655,13 @@ def double_vbar_fn(ctx: "Wtp", token: str) -> None:
16551655
return
16561656

16571657
# If it is at the beginning of a line, interpret it as starting a new
1658-
# cell, without any HTML attributes. We do this by emitting two individual
1659-
# vbars.
1658+
# cell, without any HTML attributes. We do this by emitting one vbar.
16601659
if ctx.beginning_of_line and ctx.begline_enabled:
1661-
vbar_fn(ctx, "|")
1662-
vbar_fn(ctx, "|")
1660+
if _parser_have(ctx, NodeKind.TABLE):
1661+
vbar_fn(ctx, "|")
1662+
else:
1663+
vbar_fn(ctx, "|")
1664+
vbar_fn(ctx, "|")
16631665
return
16641666

16651667
while True:
@@ -2397,7 +2399,7 @@ def process_text(ctx: "Wtp", text: str) -> None:
23972399
hline_fn(ctx, token)
23982400
elif re.match(list_prefix_re, token):
23992401
list_fn(ctx, token)
2400-
elif token.startswith("https://") or token.startswith("http://"):
2402+
elif token.startswith(("https://", "http://")):
24012403
url_fn(ctx, token)
24022404
elif (
24032405
len(token) == 1

tests/test_parser.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2058,7 +2058,17 @@ def test_table_hdr_vbar_vbar(self):
20582058
self.assertEqual(b.kind, NodeKind.TABLE_HEADER_CELL)
20592059

20602060
def test_table_hdr4(self):
2061-
tree = self.parse("test", "{|\n! Hdr\n||bar\n| |baz\n| zap\n|}")
2061+
# en edition page "山歩き", Template:ja-suru
2062+
# fr edition page "amare", Template:es-verbe-flexion
2063+
tree = self.parse(
2064+
"test",
2065+
"""{|
2066+
! Hdr
2067+
||bar
2068+
| |baz
2069+
| zap
2070+
|}""",
2071+
)
20622072
self.assertEqual(self.ctx.errors, [])
20632073
self.assertEqual(self.ctx.warnings, [])
20642074
self.assertEqual(self.ctx.debugs, [])
@@ -2068,18 +2078,27 @@ def test_table_hdr4(self):
20682078
self.assertEqual(len(t.children), 1)
20692079
row = t.children[0]
20702080
self.assertEqual(row.kind, NodeKind.TABLE_ROW)
2071-
self.assertEqual(len(row.children), 5)
2081+
self.assertEqual(len(row.children), 4)
20722082
for c, kind in zip(
20732083
row.children,
20742084
[
20752085
NodeKind.TABLE_HEADER_CELL,
20762086
NodeKind.TABLE_CELL,
20772087
NodeKind.TABLE_CELL,
20782088
NodeKind.TABLE_CELL,
2079-
NodeKind.TABLE_CELL,
20802089
],
20812090
):
20822091
self.assertEqual(c.kind, kind)
2092+
tree = self.parse(
2093+
"test",
2094+
"""{|
2095+
||bar
2096+
| |baz
2097+
| zap
2098+
|}""",
2099+
)
2100+
row = tree.children[0].children[0]
2101+
self.assertEqual(len(row.children), 3)
20832102

20842103
def test_table_bang1(self):
20852104
# Testing that the single exclamation mark in the middle of a table

0 commit comments

Comments
 (0)