diff --git a/docs/users/changelog.md b/docs/users/changelog.md index 0faac615..60e6281c 100644 --- a/docs/users/changelog.md +++ b/docs/users/changelog.md @@ -18,6 +18,9 @@ Note that there is currently no guarantee for a stable Markdown formatting style - Fixed - Read UTF-8 from standard input on all systems. Thank you, [Christopher Prohm](https://github.com/chmp), for the PR. + - No longer error on emphasis whose content is a whitespace character + reference (e.g. `* *`). The boundary whitespace is now kept in + character reference form so the emphasis markers remain functional. ## 0.7.22 diff --git a/src/mdformat/renderer/_context.py b/src/mdformat/renderer/_context.py index 238dd07d..3fc18022 100644 --- a/src/mdformat/renderer/_context.py +++ b/src/mdformat/renderer/_context.py @@ -289,12 +289,22 @@ def link(node: RenderTreeNode, context: RenderContext) -> str: def em(node: RenderTreeNode, context: RenderContext) -> str: text = make_render_children(separator="")(node, context) + # Emphasis can not begin or end in Unicode whitespace, so if it does + # (e.g. the whitespace came from a character reference like ` `), + # re-decimalify the boundary whitespace to keep the markers functional. + text = decimalify_leading(codepoints.UNICODE_WHITESPACE, text) + text = decimalify_trailing(codepoints.UNICODE_WHITESPACE, text) indicator = node.markup return indicator + text + indicator def strong(node: RenderTreeNode, context: RenderContext) -> str: text = make_render_children(separator="")(node, context) + # Emphasis can not begin or end in Unicode whitespace, so if it does + # (e.g. the whitespace came from a character reference like ` `), + # re-decimalify the boundary whitespace to keep the markers functional. + text = decimalify_leading(codepoints.UNICODE_WHITESPACE, text) + text = decimalify_trailing(codepoints.UNICODE_WHITESPACE, text) indicator = node.markup return indicator + text + indicator diff --git a/tests/data/default_style.md b/tests/data/default_style.md index 7f1d4538..10ece4db 100644 --- a/tests/data/default_style.md +++ b/tests/data/default_style.md @@ -530,3 +530,17 @@ Reduce to a space here. Reduce to a space here. . + +emphasis around whitespace character reference (issue 492) +. +* * +. +* * +. + +strong emphasis around named whitespace character reference +. +** ** +. +** ** +.