Skip to content

🐛 fix(markdown): write non-ASCII options as given - #2239

Merged
gaborbernat merged 3 commits into
tox-dev:mainfrom
gaborbernat:fix/markdown-bullet-codepoints
Nov 16, 2026
Merged

gaborbernat merged 3 commits into
tox-dev:mainfrom
gaborbernat:fix/markdown-bullet-codepoints

Conversation

@gaborbernat

Copy link
Copy Markdown
Member

Non-ASCII list bullets came out as mojibake. Markdown(lists=Markdown.Lists(bullets="•")) rendered each item as â a with a stray byte on the continuation line, so Markdown exported with a typographic bullet was unreadable. Once this merges, configured bullets, emphasis wrappers and PlainText's cell separator and default image alt are written as given. Fixes #2238.

The bullet was written one byte at a time

The bullet was read by byte index into the configured UTF-8 string and written as one code point per byte, so a three-byte bullet became three characters. The same byte-indexed bullet was used for every nested list. Bullets now step through the configured string by code point, and the list marker is written as the code point it names.

The emphasis checks compared bytes with characters

The output is held as code points, but the check that decides whether an emphasis wrapper needs its raw HTML fallback compared the first byte of the wrapper with the output character. Two wrappers that share a lead byte, such as « and », were then treated as one delimiter and fell back to <em>. The wrapper checks now compare the first code point and count code points, and the same decoding covers PlainText's table_cell_separator and default_image_alt.

Behavior changes

ASCII configuration produces the same output as before. A non-ASCII wrapper that used to fall back to raw HTML because of a shared lead byte now keeps its own delimiter. No new errors are raised.

Option strings arrive as UTF-8, but the list bullet was taken one byte
at a time and each byte was written as its own character, so a bullet
of "•" came out as "â" followed by a stray byte. The emphasis checks
compared the first byte of a configured wrapper with the output
character before it, so two wrappers that share a lead byte were
treated as one delimiter and fell back to raw HTML.

Bullets now cycle by code point, and the wrapper checks compare code
points. PlainText's table cell separator and default image alt decode
their UTF-8 the same way.

Fixes tox-dev#2238
@gaborbernat gaborbernat added the bug Something isn't working label Nov 16, 2026
@gaborbernat
gaborbernat merged commit d5619d9 into tox-dev:main Nov 16, 2026
7 of 9 checks passed
@codspeed

codspeed Bot commented Nov 16, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 582 untouched benchmarks
⏩ 89 skipped benchmarks1


Comparing gaborbernat:fix/markdown-bullet-codepoints (999db61) with main (7e6d0f9)

Open in CodSpeed

Footnotes

  1. 89 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

gaborbernat added a commit that referenced this pull request Nov 16, 2026
Markdown export of a list whose bullet is the default `-` got slower
after #2239. The bullet is now found by walking the configured bullet
string for every list item, and that walk costs more than the bullet
itself when the string is one character long. This change returns
one-character bullets directly, so list-heavy exports are back to their
earlier cost. Multi-character bullet strings keep the walk.

### Performance

Callgrind instructions per call on the Markdown list row, merge commit
d5619d9 against this branch: 610,824 before, 607,584 after (−0.53%).
The parent of that merge measured 608,034, so the list row is now below
its pre-merge cost. The emphasis row moved from 408,516 to 408,514. The
untouched rewrite control row moved from 3,922 to 3,857.

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

to_markdown() and to_text() write non-ASCII options as mojibake

1 participant