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
10 changes: 8 additions & 2 deletions .github/actions/prose-gate/prose_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"(?<!\\)\|")
Comment thread
ptr727 marked this conversation as resolved.
Resolved
# A word-joining character before the repeat keeps "either/or or" from reading as a doubled word.
DUPWORD = re.compile(r"(?<![\w/-])(\w+)\s+\1\b", re.IGNORECASE)
# A step marker is a label on the sentence that follows, so its dot terminates nothing.
Expand Down Expand Up @@ -1097,10 +1098,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 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):
cells = line.strip().strip("|").split("|") if line.lstrip().startswith("|") else [line]
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(";")
Expand Down
2 changes: 1 addition & 1 deletion scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. 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.

Expand Down
11 changes: 10 additions & 1 deletion tests/test_prose_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,8 +641,17 @@ 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:
"""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"}))

def test_an_escaped_pipe_in_a_blockquoted_row_stays_inside_its_cell(self) -> None:
self.assertEqual(
["semicolon"], self.kinds("| S1 | it runs; it gates | D1, D2 |\n", {"semicolon"})
[], self.kinds("> | x | red, green \\| blue; cyan; teal |\n", {"semicolon"})
)

def test_a_bullet_label_colon_does_not_announce_a_list(self) -> None:
Expand Down
Loading