From 3c3b94947602c6757748924cbda666039a043440 Mon Sep 17 00:00:00 2001 From: Andrei Alexandrescu Date: Wed, 16 Oct 2024 16:45:21 -0400 Subject: [PATCH 1/2] Create a filter that allows &sbr; as a soft break, useful for breaking up inline code --- md/pandoc.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/md/pandoc.py b/md/pandoc.py index 2cca07e2..388ad8e7 100755 --- a/md/pandoc.py +++ b/md/pandoc.py @@ -5,6 +5,7 @@ import subprocess # import pygraphviz import hashlib +from panflute import toJSONFilter, RawInline def h1hr(elem, doc): """ @@ -110,8 +111,21 @@ def std(elem, doc): return pf.Div(pf.BlockQuote(elem), classes=["std"]) +def soft_break(elem, doc): + if isinstance(elem, pf.Str): + if '&sbr;' in elem.text: + # Replace all instances of '&cacados;' with the desired HTML span + replaced_text = elem.text.replace( + '&sbr;', + '''­''' + ) + # Return the replaced text as RawInline HTML + return pf.RawInline(replaced_text, format='html') + # If no replacement is needed, return None to keep the original element + return None + if __name__ == '__main__': # pf.run_filters([h1hr, bq, graphviz, mermaid, op]) - pf.run_filters([h1hr, bq, std, mermaid, op]) + pf.run_filters([h1hr, bq, std, mermaid, op, soft_break]) # pf.run_filters([h1hr, bq, op]) From 3d8db8ed550bb7f1b87f3149ab98a3902049a968 Mon Sep 17 00:00:00 2001 From: Andrei Alexandrescu Date: Thu, 9 Jan 2025 14:17:21 -0500 Subject: [PATCH 2/2] --amend --- md/pandoc.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/md/pandoc.py b/md/pandoc.py index 388ad8e7..d24cbed1 100755 --- a/md/pandoc.py +++ b/md/pandoc.py @@ -114,7 +114,8 @@ def std(elem, doc): def soft_break(elem, doc): if isinstance(elem, pf.Str): if '&sbr;' in elem.text: - # Replace all instances of '&cacados;' with the desired HTML span + # Replace all instances of '&sbr;' with a soft break without spacing or hyphenation + # (akin to a zero-width space) replaced_text = elem.text.replace( '&sbr;', '''­'''