MD037 does not see a pair of markers split by another inline
- Vorherrschende Sprache
- Rust
- Sterne
- 407
- Forks
- 12
- Ø Merge
- 5 Std. 45 Min.
- Gemergte PRs (30 T.)
- 30
Beschreibung
MD037 searches one text node at a time, so it sees a pair of emphasis markers
only when both were written into the same one. Anything `CommonMark` parses as
an inline of its own splits the text around it into two nodes, and a marker on
either side of that inline is then a marker the rule never sees beside its
partner.
## Reproduction
```markdown
x ** `c` ** y
x **
** y
x ** [a](b) ** y
x ** b ** y
```
Only the fourth line is reported. The first three are the same violation with a
code span, a raw HTML inline and a link written between the markers — the spaces
inside the markers are exactly as visible in the output — and each is parsed as
```
Text("x ** ") Code/HtmlInline/Link Text(" ** y")
```
so neither node holds both markers and the regex matches in neither.
## Cause
`check` walks the text nodes and runs the regex over each on its own:
```rust
for node in doc.ast.descendants() {
let NodeValue::Text(literal) = &data.value else { continue };
...
let Some(m) = RE.find(&text) else { continue };
```
The regex wants `marker`, content, `marker` in one string. A text node is
whatever ran between two inlines, so that string is only the whole of an
emphasis span when nothing else was written inside it.
## Not the same as #406
#406 was the column a match is reported at, and #407 fixed that by measuring the
line rather than the string `CommonMark` resolved the escapes out of. This is a
match that is never made, and no column arithmetic reaches it.
It is worth saying where the two met, since #407's changelog entry could be read
as covering this. Before #407 the rule read an escaped `*` or `_` as a marker,
and a line with one on each side of an inline was sometimes reported for that
reason — the escaped marker pairing with a real one inside a single node, which
is a match on text that is not emphasis at all. Those reports are gone, and a
handful of them were on lines that do have spaced emphasis in them, split across
an inline like the ones above. The lines were never reported for the emphasis
they have; they were reported for emphasis they do not, and this issue is why
the right report is not there in its place.
Beitragsleitfaden
Bewertung
Dieses Issue wurde noch nicht bewertet.