akiomik / akiomik/mado

MD037 does not see a pair of markers split by another inline

Aberta
#409 0 comentários 0 reações 0 responsáveis Ver no GitHub
bug
Linguagem predominante
Rust
Estrelas
409
Forks
12
Merge médio
5h 45min
PRs com merge (30d)
30

Descrição

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.

Guia de contribuição

Abrir o guia de contribuição

Direção de pesquisa

Start at the MD037 `check` implementation described in the issue, then run the four Markdown reproductions. Inspect how the AST text nodes are traversed around the code span, raw HTML inline, and link. Done means the first three violations are reported while the existing fourth-line behavior remains covered.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
markdown, rust
Domínio
tooling
Tipo de issue
Bug
Dificuldade
3/5
Tempo estimado
1-2 dias
Status de atividade
Ativa
Clareza
Razoavelmente clara
Facilidade para iniciantes
68/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.