From 2081b1526b4e89a5933e95b74ea96c10452026a8 Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Fri, 30 Oct 2026 03:51:04 -0700 Subject: [PATCH 1/4] Read Table Cells From the Parser in the Semicolon Rule The semicolon rule split a table row on every pipe, so an escaped pipe cut its cell in two. It now judges the cells markdown-it-py yields, the same cells the sentence-length rule reads, and skips the raw row lines those cells came from. Closes on promotion: #3655 Co-Authored-By: Claude Opus 5.5 --- .github/actions/prose-gate/prose_lint.py | 37 ++++++++++++++---------- tests/test_prose_lint.py | 15 +++++++++- 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/.github/actions/prose-gate/prose_lint.py b/.github/actions/prose-gate/prose_lint.py index 4217e3a0b..fd82f1b26 100755 --- a/.github/actions/prose-gate/prose_lint.py +++ b/.github/actions/prose-gate/prose_lint.py @@ -489,7 +489,7 @@ class Unit(NamedTuple): """A run of text one kind of rule reads. `source` is every line, and `prose` and `code` the unfenced ones. `paragraph` is a Markdown - sentence block. `comment`, `doc`, and `markup` are runs of adjacent comment lines, `doc` a + sentence block, and `cell` one table cell as the parser splits its row. `comment`, `doc`, and `markup` are runs of adjacent comment lines, `doc` a documentation comment and `markup` a Markdown HTML one. `docstring` opens at `column`. """ @@ -849,7 +849,7 @@ def front_matter_end(lines: list[str]) -> int: MARKDOWN = MarkdownIt("commonmark").enable("table") HTML = BASE["languages"]["markup"] TAG = re.compile(r"<[^<>]*>") -BLOCK_PARENTS = (["paragraph_open"], ["th_open"], ["td_open"]) +BLOCK_PARENTS = {"paragraph_open": "paragraph", "th_open": "cell", "td_open": "cell"} def extract_markdown(lines: list[str]) -> Extracted: @@ -881,11 +881,10 @@ def extract_markdown(lines: list[str]) -> Extracted: paragraphs.append(Unit("paragraph", (Line(n, span),))) elif tok.type == "inline": markup += inline_comments(tok, lines) - if parents[-1:] in BLOCK_PARENTS and "blockquote_open" not in parents: + kind = BLOCK_PARENTS.get(parents[-1] if parents else "") + if kind and "blockquote_open" not in parents: spans = enumerate(tok.content.split("\n")) - paragraphs.append( - Unit("paragraph", tuple(Line(first + i, s.strip()) for i, s in spans)) - ) + paragraphs.append(Unit(kind, tuple(Line(first + i, s.strip()) for i, s in spans))) skip = frozenset(code) units = [ Unit("source", tuple(Line(n, t) for n, t in enumerate(lines, 1))), @@ -966,6 +965,7 @@ class Context(NamedTuple): language: dict[str, Any] config: Config allowed: set[int] | None = None + rows: frozenset[int] = frozenset() # The one sentence boundary every reader shares, a terminator that no initial or abbreviation ends. @@ -1097,12 +1097,15 @@ def rule_charset(unit: Unit, ctx: Context) -> list[Finding]: def rule_semicolon(unit: Unit, ctx: Context) -> list[Finding]: - """A Markdown semicolon, unless its sentence is a list carrying a comma that needs one.""" + """A Markdown semicolon, unless its sentence is a list carrying a comma that needs one. + + A table row is judged a parsed cell at a time, so an escaped pipe stays inside its cell. + """ out: list[Finding] = [] for n, _txt, line in prose_lines(unit): - cells = line.strip().strip("|").split("|") if line.lstrip().startswith("|") else [line] - pieces = (s for cell in cells for s in SENTENCE_BREAK.split(LABEL_COLON.sub("", cell))) - for sentence in (s for s in pieces if s.strip()): + if unit.kind == "prose" and n in ctx.rows: + continue + for sentence in (s for s in SENTENCE_BREAK.split(LABEL_COLON.sub("", line)) if s.strip()): head, _, tail = sentence.partition(";") listish = sentence.count(";") > 1 or ( LABELED_ITEM.match(LIST_MARKER.sub("", head, count=1)) is not None @@ -1682,7 +1685,7 @@ def docstring_sentences(unit: Unit, ctx: Context) -> list[Finding]: def rule_sentence_length(unit: Unit, ctx: Context) -> list[Finding]: """A sentence over the word cap, in a Markdown block, a comment run, or a docstring.""" - if unit.kind == "paragraph": + if unit.kind in ("paragraph", "cell"): return over_cap( [(line.number, strip_list_marker(line.text)) for line in unit.lines], ctx.allowed ) @@ -1700,12 +1703,15 @@ def rule_sentence_length(unit: Unit, ctx: Context) -> list[Finding]: "comment-case": (rule_comment_wrap, frozenset({"comment", "markup"})), "comment-added": (rule_comment_added, frozenset({"comment"})), "issue-ref": (rule_issue_ref, frozenset({"prose", "comment", "doc", "docstring"})), - "sentence-length": (rule_sentence_length, frozenset({"paragraph", "comment", "docstring"})), + "sentence-length": ( + rule_sentence_length, + frozenset({"paragraph", "cell", "comment", "docstring"}), + ), "home-path": (rule_home_path, frozenset({"source"})), "charset": (rule_charset, frozenset({"prose", "code"})), "charset-unknown": (rule_charset, frozenset({"prose", "code"})), "dead-path": (rule_dead_path, frozenset({"prose"})), - "semicolon": (rule_semicolon, frozenset({"prose"})), + "semicolon": (rule_semicolon, frozenset({"prose", "cell"})), "dash": (rule_dash, frozenset({"prose"})), "dupword": (rule_dupword, frozenset({"prose", "comment"})), "spelling": (rule_spelling, frozenset({"prose", "comment"})), @@ -1736,13 +1742,14 @@ def check_file( bom = chr(0xFEFF) text = decoded.removeprefix(bom) out = [f for f in charset_findings(1, bom) if f[1] in rules] if text != decoded else [] - lex = any(RULE_TABLE[r][1] - {"source", "prose", "code"} for r in rules) + lex = any(RULE_TABLE[r][1] - {"source", "prose", "code", "cell"} for r in rules) units, fenced, read_plain = extract(path, text, lex) if read_plain and plain is not None: plain.append(path) lexer = lexer_name(path, text.split("\n", 1)[0].rstrip("\r")) config = config_for(str(root) if root else None) - ctx = Context(path, root, fenced, language_of(lexer) or {}, config, allowed) + rows = frozenset(line.number for u in units if u.kind == "cell" for line in u.lines) + ctx = Context(path, root, fenced, language_of(lexer) or {}, config, allowed, rows) passes: dict[Rule, set[str]] = {} for name in RULE_TABLE: if name in rules: diff --git a/tests/test_prose_lint.py b/tests/test_prose_lint.py index 1c1e6f989..38edd3cb6 100755 --- a/tests/test_prose_lint.py +++ b/tests/test_prose_lint.py @@ -641,10 +641,23 @@ def test_a_list_whose_commas_fall_in_a_later_item_keeps_its_semicolons(self) -> def test_a_table_row_judges_each_cell_alone(self) -> None: """A row is a record of fields, so one column's comma cannot excuse another's semicolon.""" + table = "| A | B | C |\n| --- | --- | --- |\n| S1 | it runs; it gates | D1, D2 |\n" + self.assertEqual(["semicolon"], self.kinds(table, {"semicolon"})) + + def test_an_escaped_pipe_stays_inside_its_cell(self) -> None: + """The cell is the parser's, so a comma before an escaped pipe still excuses the list.""" + table = "| A | B |\n| --- | --- |\n| x | red, green \\| blue; cyan; teal |\n" + self.assertEqual([], self.kinds(table, {"semicolon"})) + + def test_a_header_cell_is_judged_like_a_body_cell(self) -> None: self.assertEqual( - ["semicolon"], self.kinds("| S1 | it runs; it gates | D1, D2 |\n", {"semicolon"}) + ["semicolon"], self.kinds("| it runs; it gates |\n| --- |\n", {"semicolon"}) ) + def test_a_piped_line_that_is_no_table_is_judged_whole(self) -> None: + """Without a delimiter row there are no cells, so the comma in one span excuses the list.""" + self.assertEqual([], self.kinds("| a, b | c; d; e |\n", {"semicolon"})) + def test_a_bullet_label_colon_does_not_announce_a_list(self) -> None: """`- **Label**:` opens the bullet, the same construct the label dash is exempted for.""" self.assertEqual( From 9c815bfa8fdc498d6ede534548adb91743cde84b Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Fri, 30 Oct 2026 03:51:44 -0700 Subject: [PATCH 2/4] Say the Semicolon Rule Reads the Parser's Table Cells Co-Authored-By: Claude Opus 5.5 --- scripts/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/README.md b/scripts/README.md index f06bc41ea..83d69dc6d 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -89,7 +89,7 @@ A double-quoted span in Markdown is treated as a quotation and not scanned for p The `semicolon` and `dash` rules ban a construction rather than a detectable subset of it. Each therefore flags by default, and the exceptions are the ones the rule names. The exceptions for the dash are a compound word, a leading list marker, a range, and the `- **Label** - explanation` separator that opens a governed bullet. The exception for a semicolon is one inside a list that already carries commas. Where such a list is joined by a single semicolon, each of its two items carries a label. -**The semicolon rule reads the list where it lives.** The comma qualifies the list as a whole rather than one separator's position. An enumeration whose commas fall in a later item therefore keeps every semicolon it carries. Reading it positionally split one series in two. That reading flagged the openers of the same list it then exempted the tail of. That would have restructured the enumerated guarantees the exemption exists to protect. A Markdown table row is judged one cell at a time. This is because a row is a record of fields, and a comma in one column cannot excuse a semicolon in another. A bullet's `**Label**:` is dropped before the line is read, because it opens the bullet rather than announcing a list. The `**Label**:` is the same construct the label dash is exempted for. The colon is written inside the emphasis as often as outside it, so `**Label:**` is dropped on the same grounds. Matching only one spelling left the other announcing a list it never announced. +**The semicolon rule reads the list where it lives.** The comma qualifies the list as a whole rather than one separator's position. An enumeration whose commas fall in a later item therefore keeps every semicolon it carries. Reading it positionally split one series in two. That reading flagged the openers of the same list it then exempted the tail of. That would have restructured the enumerated guarantees the exemption exists to protect. A Markdown table row is judged one cell at a time. This is because a row is a record of fields, and a comma in one column cannot excuse a semicolon in another. The cells are the ones markdown-it-py splits the row into, the same cells the `sentence-length` rule reads. So an escaped pipe stays inside its cell, and a line holding pipes outside any table is read whole. A bullet's `**Label**:` is dropped before the line is read, because it opens the bullet rather than announcing a list. The `**Label**:` is the same construct the label dash is exempted for. The colon is written inside the emphasis as often as outside it, so `**Label:**` is dropped on the same grounds. Matching only one spelling left the other announcing a list it never announced. **The sentence is the unit the exemption is judged on, because that is where a list lives.** The whole bullet decided it once. A colon anywhere before the first semicolon therefore marked the bullet a list and exempted every semicolon after it. That held however plainly one joined two independent clauses. The colon and the semicolon did not have to be near each other or related at all. Measured over this repo when it was fixed, the exemption was covering 62 spans holding 120 semicolons across 9 files. The rule reported none of them, so the gate read as clean over the docs it exists to check. Scoping it to the sentence reported 43 further semicolons and silenced none, with a 44th from dropping the other spelling of the label colon. The sentence boundary is the run-on rule's. So an initial or an abbreviation ends nothing, and a terminator closing inside emphasis or a bracket (`.**`, `.)`) still ends a sentence. A lone semicolon separates a list only where the items on both sides of it open with a label, as in `Inputs: a, b; outputs: c`. No structure tells an explanatory colon from a list colon. A colon and a comma alone once exempted the one semicolon joining two clauses after them. A sentence with two or more semicolons and a comma stays a series whatever colon it holds. From ebfbab84da7a7ee9f8959c3550425aec444124c6 Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Fri, 30 Oct 2026 03:58:49 -0700 Subject: [PATCH 3/4] Split a Table Row Only at an Unescaped Pipe Reading the parser's cell tokens dropped text the row split used to judge, a blockquoted table's rows and any cell past the header's width. Keep the row split, and end a cell only where markdown-it-py ends one, at a pipe no backslash escapes. Co-Authored-By: Claude Opus 5.5 --- .github/actions/prose-gate/prose_lint.py | 37 ++++++++++++------------ scripts/README.md | 2 +- tests/test_prose_lint.py | 10 ++----- 3 files changed, 22 insertions(+), 27 deletions(-) diff --git a/.github/actions/prose-gate/prose_lint.py b/.github/actions/prose-gate/prose_lint.py index fd82f1b26..da787f387 100755 --- a/.github/actions/prose-gate/prose_lint.py +++ b/.github/actions/prose-gate/prose_lint.py @@ -489,7 +489,7 @@ class Unit(NamedTuple): """A run of text one kind of rule reads. `source` is every line, and `prose` and `code` the unfenced ones. `paragraph` is a Markdown - sentence block, and `cell` one table cell as the parser splits its row. `comment`, `doc`, and `markup` are runs of adjacent comment lines, `doc` a + sentence block. `comment`, `doc`, and `markup` are runs of adjacent comment lines, `doc` a documentation comment and `markup` a Markdown HTML one. `docstring` opens at `column`. """ @@ -849,7 +849,7 @@ def front_matter_end(lines: list[str]) -> int: MARKDOWN = MarkdownIt("commonmark").enable("table") HTML = BASE["languages"]["markup"] TAG = re.compile(r"<[^<>]*>") -BLOCK_PARENTS = {"paragraph_open": "paragraph", "th_open": "cell", "td_open": "cell"} +BLOCK_PARENTS = (["paragraph_open"], ["th_open"], ["td_open"]) def extract_markdown(lines: list[str]) -> Extracted: @@ -881,10 +881,11 @@ def extract_markdown(lines: list[str]) -> Extracted: paragraphs.append(Unit("paragraph", (Line(n, span),))) elif tok.type == "inline": markup += inline_comments(tok, lines) - kind = BLOCK_PARENTS.get(parents[-1] if parents else "") - if kind and "blockquote_open" not in parents: + if parents[-1:] in BLOCK_PARENTS and "blockquote_open" not in parents: spans = enumerate(tok.content.split("\n")) - paragraphs.append(Unit(kind, tuple(Line(first + i, s.strip()) for i, s in spans))) + paragraphs.append( + Unit("paragraph", tuple(Line(first + i, s.strip()) for i, s in spans)) + ) skip = frozenset(code) units = [ Unit("source", tuple(Line(n, t) for n, t in enumerate(lines, 1))), @@ -965,7 +966,6 @@ class Context(NamedTuple): language: dict[str, Any] config: Config allowed: set[int] | None = None - rows: frozenset[int] = frozenset() # The one sentence boundary every reader shares, a terminator that no initial or abbreviation ends. @@ -996,6 +996,7 @@ class Context(NamedTuple): LABEL_WORD = r"[\w`]+(?:[./-][\w`]+)*" LABELED_ITEM = re.compile(rf"^\s*[*_]*{LABEL_WORD}(?:\s+{LABEL_WORD}){{0,2}}[*_]*:[*_]*(?:\s|$)") LIST_MARKER = re.compile(rf"^\s*{LIST_MARKER_TOKEN}\s") +CELL_BREAK = re.compile(r"(? list[Finding]: def rule_semicolon(unit: Unit, ctx: Context) -> list[Finding]: """A Markdown semicolon, unless its sentence is a list carrying a comma that needs one. - A table row is judged a parsed cell at a time, so an escaped pipe stays inside its cell. + A table row is read a cell at a time, split where markdown-it-py splits one, at a pipe no + backslash escapes. """ out: list[Finding] = [] for n, _txt, line in prose_lines(unit): - if unit.kind == "prose" and n in ctx.rows: - continue - for sentence in (s for s in SENTENCE_BREAK.split(LABEL_COLON.sub("", line)) if s.strip()): + row = line.lstrip().startswith("|") + cells = CELL_BREAK.split(line.strip().strip("|")) if row else [line] + pieces = (s for cell in cells for s in SENTENCE_BREAK.split(LABEL_COLON.sub("", cell))) + for sentence in (s for s in pieces if s.strip()): head, _, tail = sentence.partition(";") listish = sentence.count(";") > 1 or ( LABELED_ITEM.match(LIST_MARKER.sub("", head, count=1)) is not None @@ -1685,7 +1688,7 @@ def docstring_sentences(unit: Unit, ctx: Context) -> list[Finding]: def rule_sentence_length(unit: Unit, ctx: Context) -> list[Finding]: """A sentence over the word cap, in a Markdown block, a comment run, or a docstring.""" - if unit.kind in ("paragraph", "cell"): + if unit.kind == "paragraph": return over_cap( [(line.number, strip_list_marker(line.text)) for line in unit.lines], ctx.allowed ) @@ -1703,15 +1706,12 @@ def rule_sentence_length(unit: Unit, ctx: Context) -> list[Finding]: "comment-case": (rule_comment_wrap, frozenset({"comment", "markup"})), "comment-added": (rule_comment_added, frozenset({"comment"})), "issue-ref": (rule_issue_ref, frozenset({"prose", "comment", "doc", "docstring"})), - "sentence-length": ( - rule_sentence_length, - frozenset({"paragraph", "cell", "comment", "docstring"}), - ), + "sentence-length": (rule_sentence_length, frozenset({"paragraph", "comment", "docstring"})), "home-path": (rule_home_path, frozenset({"source"})), "charset": (rule_charset, frozenset({"prose", "code"})), "charset-unknown": (rule_charset, frozenset({"prose", "code"})), "dead-path": (rule_dead_path, frozenset({"prose"})), - "semicolon": (rule_semicolon, frozenset({"prose", "cell"})), + "semicolon": (rule_semicolon, frozenset({"prose"})), "dash": (rule_dash, frozenset({"prose"})), "dupword": (rule_dupword, frozenset({"prose", "comment"})), "spelling": (rule_spelling, frozenset({"prose", "comment"})), @@ -1742,14 +1742,13 @@ def check_file( bom = chr(0xFEFF) text = decoded.removeprefix(bom) out = [f for f in charset_findings(1, bom) if f[1] in rules] if text != decoded else [] - lex = any(RULE_TABLE[r][1] - {"source", "prose", "code", "cell"} for r in rules) + lex = any(RULE_TABLE[r][1] - {"source", "prose", "code"} for r in rules) units, fenced, read_plain = extract(path, text, lex) if read_plain and plain is not None: plain.append(path) lexer = lexer_name(path, text.split("\n", 1)[0].rstrip("\r")) config = config_for(str(root) if root else None) - rows = frozenset(line.number for u in units if u.kind == "cell" for line in u.lines) - ctx = Context(path, root, fenced, language_of(lexer) or {}, config, allowed, rows) + ctx = Context(path, root, fenced, language_of(lexer) or {}, config, allowed) passes: dict[Rule, set[str]] = {} for name in RULE_TABLE: if name in rules: diff --git a/scripts/README.md b/scripts/README.md index 83d69dc6d..14d1e1e14 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -89,7 +89,7 @@ A double-quoted span in Markdown is treated as a quotation and not scanned for p The `semicolon` and `dash` rules ban a construction rather than a detectable subset of it. Each therefore flags by default, and the exceptions are the ones the rule names. The exceptions for the dash are a compound word, a leading list marker, a range, and the `- **Label** - explanation` separator that opens a governed bullet. The exception for a semicolon is one inside a list that already carries commas. Where such a list is joined by a single semicolon, each of its two items carries a label. -**The semicolon rule reads the list where it lives.** The comma qualifies the list as a whole rather than one separator's position. An enumeration whose commas fall in a later item therefore keeps every semicolon it carries. Reading it positionally split one series in two. That reading flagged the openers of the same list it then exempted the tail of. That would have restructured the enumerated guarantees the exemption exists to protect. A Markdown table row is judged one cell at a time. This is because a row is a record of fields, and a comma in one column cannot excuse a semicolon in another. The cells are the ones markdown-it-py splits the row into, the same cells the `sentence-length` rule reads. So an escaped pipe stays inside its cell, and a line holding pipes outside any table is read whole. A bullet's `**Label**:` is dropped before the line is read, because it opens the bullet rather than announcing a list. The `**Label**:` is the same construct the label dash is exempted for. The colon is written inside the emphasis as often as outside it, so `**Label:**` is dropped on the same grounds. Matching only one spelling left the other announcing a list it never announced. +**The semicolon rule reads the list where it lives.** The comma qualifies the list as a whole rather than one separator's position. An enumeration whose commas fall in a later item therefore keeps every semicolon it carries. Reading it positionally split one series in two. That reading flagged the openers of the same list it then exempted the tail of. That would have restructured the enumerated guarantees the exemption exists to protect. A Markdown table row is judged one cell at a time. This is because a row is a record of fields, and a comma in one column cannot excuse a semicolon in another. A cell ends where markdown-it-py ends one, at a pipe no backslash escapes, so an escaped pipe stays inside its cell. A bullet's `**Label**:` is dropped before the line is read, because it opens the bullet rather than announcing a list. The `**Label**:` is the same construct the label dash is exempted for. The colon is written inside the emphasis as often as outside it, so `**Label:**` is dropped on the same grounds. Matching only one spelling left the other announcing a list it never announced. **The sentence is the unit the exemption is judged on, because that is where a list lives.** The whole bullet decided it once. A colon anywhere before the first semicolon therefore marked the bullet a list and exempted every semicolon after it. That held however plainly one joined two independent clauses. The colon and the semicolon did not have to be near each other or related at all. Measured over this repo when it was fixed, the exemption was covering 62 spans holding 120 semicolons across 9 files. The rule reported none of them, so the gate read as clean over the docs it exists to check. Scoping it to the sentence reported 43 further semicolons and silenced none, with a 44th from dropping the other spelling of the label colon. The sentence boundary is the run-on rule's. So an initial or an abbreviation ends nothing, and a terminator closing inside emphasis or a bracket (`.**`, `.)`) still ends a sentence. A lone semicolon separates a list only where the items on both sides of it open with a label, as in `Inputs: a, b; outputs: c`. No structure tells an explanatory colon from a list colon. A colon and a comma alone once exempted the one semicolon joining two clauses after them. A sentence with two or more semicolons and a comma stays a series whatever colon it holds. diff --git a/tests/test_prose_lint.py b/tests/test_prose_lint.py index 38edd3cb6..48ac41ce7 100755 --- a/tests/test_prose_lint.py +++ b/tests/test_prose_lint.py @@ -645,19 +645,15 @@ def test_a_table_row_judges_each_cell_alone(self) -> None: self.assertEqual(["semicolon"], self.kinds(table, {"semicolon"})) def test_an_escaped_pipe_stays_inside_its_cell(self) -> None: - """The cell is the parser's, so a comma before an escaped pipe still excuses the list.""" + """The row splits where the parser splits it, so the comma still excuses the list.""" table = "| A | B |\n| --- | --- |\n| x | red, green \\| blue; cyan; teal |\n" self.assertEqual([], self.kinds(table, {"semicolon"})) - def test_a_header_cell_is_judged_like_a_body_cell(self) -> None: + def test_an_escaped_pipe_in_a_blockquoted_row_stays_inside_its_cell(self) -> None: self.assertEqual( - ["semicolon"], self.kinds("| it runs; it gates |\n| --- |\n", {"semicolon"}) + [], self.kinds("> | x | red, green \\| blue; cyan; teal |\n", {"semicolon"}) ) - def test_a_piped_line_that_is_no_table_is_judged_whole(self) -> None: - """Without a delimiter row there are no cells, so the comma in one span excuses the list.""" - self.assertEqual([], self.kinds("| a, b | c; d; e |\n", {"semicolon"})) - def test_a_bullet_label_colon_does_not_announce_a_list(self) -> None: """`- **Label**:` opens the bullet, the same construct the label dash is exempted for.""" self.assertEqual( From 221e158825e0dcb921b3abcfd4260573e98b2095 Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Fri, 30 Oct 2026 04:01:30 -0700 Subject: [PATCH 4/4] Say Only the Escape Rule Matches markdown-it-py Co-Authored-By: Claude Opus 5.5 --- .github/actions/prose-gate/prose_lint.py | 4 ++-- scripts/README.md | 2 +- tests/test_prose_lint.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/actions/prose-gate/prose_lint.py b/.github/actions/prose-gate/prose_lint.py index da787f387..0df5130ba 100755 --- a/.github/actions/prose-gate/prose_lint.py +++ b/.github/actions/prose-gate/prose_lint.py @@ -1100,8 +1100,8 @@ def rule_charset(unit: Unit, ctx: Context) -> list[Finding]: def rule_semicolon(unit: Unit, ctx: Context) -> list[Finding]: """A Markdown semicolon, unless its sentence is a list carrying a comma that needs one. - A table row is read a cell at a time, split where markdown-it-py splits one, at a pipe no - backslash escapes. + A table row is read a cell at a time. A cell ends at a pipe no backslash escapes, which is how + markdown-it-py reads an escaped pipe. """ out: list[Finding] = [] for n, _txt, line in prose_lines(unit): diff --git a/scripts/README.md b/scripts/README.md index 14d1e1e14..e8953905c 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -89,7 +89,7 @@ A double-quoted span in Markdown is treated as a quotation and not scanned for p The `semicolon` and `dash` rules ban a construction rather than a detectable subset of it. Each therefore flags by default, and the exceptions are the ones the rule names. The exceptions for the dash are a compound word, a leading list marker, a range, and the `- **Label** - explanation` separator that opens a governed bullet. The exception for a semicolon is one inside a list that already carries commas. Where such a list is joined by a single semicolon, each of its two items carries a label. -**The semicolon rule reads the list where it lives.** The comma qualifies the list as a whole rather than one separator's position. An enumeration whose commas fall in a later item therefore keeps every semicolon it carries. Reading it positionally split one series in two. That reading flagged the openers of the same list it then exempted the tail of. That would have restructured the enumerated guarantees the exemption exists to protect. A Markdown table row is judged one cell at a time. This is because a row is a record of fields, and a comma in one column cannot excuse a semicolon in another. A cell ends where markdown-it-py ends one, at a pipe no backslash escapes, so an escaped pipe stays inside its cell. A bullet's `**Label**:` is dropped before the line is read, because it opens the bullet rather than announcing a list. The `**Label**:` is the same construct the label dash is exempted for. The colon is written inside the emphasis as often as outside it, so `**Label:**` is dropped on the same grounds. Matching only one spelling left the other announcing a list it never announced. +**The semicolon rule reads the list where it lives.** The comma qualifies the list as a whole rather than one separator's position. An enumeration whose commas fall in a later item therefore keeps every semicolon it carries. Reading it positionally split one series in two. That reading flagged the openers of the same list it then exempted the tail of. That would have restructured the enumerated guarantees the exemption exists to protect. A Markdown table row is judged one cell at a time. This is because a row is a record of fields, and a comma in one column cannot excuse a semicolon in another. A cell ends at a pipe no backslash escapes, which is how markdown-it-py reads an escaped pipe, so the escaped pipe stays inside its cell. A bullet's `**Label**:` is dropped before the line is read, because it opens the bullet rather than announcing a list. The `**Label**:` is the same construct the label dash is exempted for. The colon is written inside the emphasis as often as outside it, so `**Label:**` is dropped on the same grounds. Matching only one spelling left the other announcing a list it never announced. **The sentence is the unit the exemption is judged on, because that is where a list lives.** The whole bullet decided it once. A colon anywhere before the first semicolon therefore marked the bullet a list and exempted every semicolon after it. That held however plainly one joined two independent clauses. The colon and the semicolon did not have to be near each other or related at all. Measured over this repo when it was fixed, the exemption was covering 62 spans holding 120 semicolons across 9 files. The rule reported none of them, so the gate read as clean over the docs it exists to check. Scoping it to the sentence reported 43 further semicolons and silenced none, with a 44th from dropping the other spelling of the label colon. The sentence boundary is the run-on rule's. So an initial or an abbreviation ends nothing, and a terminator closing inside emphasis or a bracket (`.**`, `.)`) still ends a sentence. A lone semicolon separates a list only where the items on both sides of it open with a label, as in `Inputs: a, b; outputs: c`. No structure tells an explanatory colon from a list colon. A colon and a comma alone once exempted the one semicolon joining two clauses after them. A sentence with two or more semicolons and a comma stays a series whatever colon it holds. diff --git a/tests/test_prose_lint.py b/tests/test_prose_lint.py index 48ac41ce7..7b960684f 100755 --- a/tests/test_prose_lint.py +++ b/tests/test_prose_lint.py @@ -645,7 +645,7 @@ def test_a_table_row_judges_each_cell_alone(self) -> None: self.assertEqual(["semicolon"], self.kinds(table, {"semicolon"})) def test_an_escaped_pipe_stays_inside_its_cell(self) -> None: - """The row splits where the parser splits it, so the comma still excuses the list.""" + """An escaped pipe ends no cell, as in the parser, so the comma still excuses the list.""" table = "| A | B |\n| --- | --- |\n| x | red, green \\| blue; cyan; teal |\n" self.assertEqual([], self.kinds(table, {"semicolon"}))