Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Markdown: highlight bold-italics#3152

Open
code-with-rashid wants to merge 1 commit into
pygments:masterfrom
code-with-rashid:markdown-bold-italics
Open

Markdown: highlight bold-italics#3152
code-with-rashid wants to merge 1 commit into
pygments:masterfrom
code-with-rashid:markdown-bold-italics

Conversation

@code-with-rashid

Copy link
Copy Markdown

The MarkdownLexer highlights **bold** and *italic* spans, but the combined bold-italics form ***bold italics*** (and ___bold italics___) was not recognized and fell through to plain Text:

>>> from pygments.lexers.markup import MarkdownLexer
>>> [(str(t), v) for t, v in MarkdownLexer().get_tokens('***bold italics***') if v.strip()]
[('Token.Text', '***bold'), ('Token.Text', 'italics***')]

Pygments already has a dedicated Generic.EmphStrong token for exactly this case, so this adds two inline rules that emit it. They are placed before the existing **/__ bold rules so the triple markers aren't partially consumed.

After:

>>> [(str(t), v) for t, v in MarkdownLexer().get_tokens('***bold italics***') if v.strip()]
[('Token.Generic.EmphStrong', '***bold italics***')]

Existing **bold**, __bold__, *italic*, _italic_ and the snake***case***word non-emphasis behavior are unchanged.

Tests

Extended tests/examplefiles/md/example.md with bold-italics lines (both the emphasized form and the snake***case***word non-match) and regenerated the golden output. pytest tests/examplefiles/md/ tests/test_basic_api.py passes (2446 passed, 8 skipped).

Closes #3067

The MarkdownLexer handled **bold** and *italic* spans but not the
combined ***bold italics*** (and ___bold italics___) form, which fell
through to plain text. Emit the existing Generic.EmphStrong token for
these spans, matching them before the bold rules so the triple markers
are not partially consumed.

Closes pygments#3067
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.

Pygments MarkdownLexer does not handle bold-italics

1 participant