Skip to content

Comments

fix: handle nested emphasis in triple-char closers#355

Merged
kjk merged 1 commit intogomarkdown:masterfrom
vnykmshr:fix-279-nested-emphasis
Feb 17, 2026
Merged

fix: handle nested emphasis in triple-char closers#355
kjk merged 1 commit intogomarkdown:masterfrom
vnykmshr:fix-279-nested-emphasis

Conversation

@vnykmshr
Copy link
Contributor

helperDoubleEmphasis consumes *** as **, leaving the inner * unpaired. Fix shifts the content boundary to include it when the last * in content is an unmatched opener. hasTrailingEmphOpener checks only the last * -- checking earlier ones would flag balanced pairs incorrectly. This is a targeted fix for the **bold *ital*** pattern, not a full overhaul of emphasis delimiter handling. Babelmark confirms the expected output: https://babelmark.github.io/?text=**bold+*ital***

4 tests: unclosed inner emph, balanced inner (regression guard), reversed nesting, no inner star. go test ./... passes.

Fixes #279

When input like `**bold *ital***` is parsed, the `***` closing
delimiter is consumed as `**` by helperDoubleEmphasis, leaving the
inner `*ital` without a closing `*`. This produces incorrect output:
`<strong>bold *ital</strong>*` instead of
`<strong>bold <em>ital</em></strong>`.

When the closing delimiter is `***` and the content contains a
trailing unclosed emphasis opener, shift the content boundary to
include one extra `*` so the inner emphasis can pair correctly.

The hasTrailingEmphOpener helper checks only the last `*` in the
content to avoid false positives on balanced pairs like `*ital*`.

Fixes gomarkdown#279
@kjk kjk merged commit 37c66b8 into gomarkdown:master Feb 17, 2026
1 check passed
@kjk
Copy link
Contributor

kjk commented Feb 17, 2026

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parsing error when parsing nested bold+ital

2 participants