Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ python:
sphinx:
builder: html
fail_on_warning: true
configuration: docs/source/conf.py
15 changes: 15 additions & 0 deletions rst_to_myst/mdformat_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,19 @@ def _directive_render(node: RenderTreeNode, context: RenderContext) -> str:
return f"{fence_str}{{{name}}}{info_str}\n{option_block}{code_block}{fence_str}"


def _strip_nuls_in_tokens(tokens: list[Token]):
"""Recursively remove NUL padding (\x00) from token contents."""
if not tokens:
return
for token in tokens:
if isinstance(getattr(token, "content", None), str) and "\x00" in token.content:
# Docutils table parser may insert '\x00' for East Asian double-width padding.
# These must never reach mdformat/commonmark renderers.
token.content = token.content.replace("\x00", "")
if getattr(token, "children", None):
_strip_nuls_in_tokens(token.children)


class AdditionalRenderers:
RENDERERS = {
"unprocessed": _unprocessed_render,
Expand Down Expand Up @@ -134,6 +147,8 @@ def from_tokens(
warning_handler.setLevel(logging.WARNING)
LOGGER.addHandler(warning_handler)
try:
_strip_nuls_in_tokens(output.tokens)

# mdformat outputs only used reference definitions during 'finalize'
# instead we want to output all parsed reference definitions
text = md_renderer.render(output.tokens, options, output.env, finalize=False)
Expand Down