Skip to content

Commit

Permalink
Fix special characters causing weird escape sequences
Browse files Browse the repository at this point in the history
  • Loading branch information
oprypin committed May 15, 2021
1 parent 505b182 commit 740bb2a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
7 changes: 6 additions & 1 deletion mkdocs_literate_nav/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import markdown
import markdown.extensions
import markdown.postprocessors
import markdown.preprocessors
import markdown.treeprocessors
import mkdocs.utils
Expand All @@ -17,6 +18,8 @@
log = logging.getLogger(f"mkdocs.plugins.{__name__}")
log.addFilter(mkdocs.utils.warning_filter)

_unescape = markdown.postprocessors.UnescapePostprocessor().run


NavItem = Dict[Optional[str], Union[str, Any]]
Nav = List[NavItem]
Expand Down Expand Up @@ -69,6 +72,8 @@ def nav(self) -> Optional[etree.Element]:
return None

def extendMarkdown(self, md):
md.inlinePatterns.deregister("html", strict=False)
md.inlinePatterns.deregister("entity", strict=False)
md.preprocessors.register(_Preprocessor(md), _NAME, 25)
self._treeprocessor = _Treeprocessor(md)
md.treeprocessors.register(self._treeprocessor, _NAME, 19)
Expand Down Expand Up @@ -149,7 +154,7 @@ def make_nav(
out_item = get_nav_for_roots((abs_link, *roots))
except RecursionError as e:
log.warning(f"{e} ({link!r})")
out_title = "".join(child.itertext())
out_title = _unescape("".join(child.itertext()))
child = next(children)
if child.tag in _LIST_TAGS:
out_item = make_nav(child, get_nav_for_roots, globber, roots, seen_items, out_item)
Expand Down
2 changes: 1 addition & 1 deletion tests/markdown_to_nav/test_fancy_link.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ navs:
* [Item **1**](item1.md)
* [Item 2](item2.md)
2. Section 2
* [Item](section2/item.md)
* [`Item`](section2/item.md)
output:
- Section 1:
- Item 1: item1.md
Expand Down
13 changes: 13 additions & 0 deletions tests/markdown_to_nav/test_special_chars.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
navs:
/: |
* [a&b](a.md)
* [a&b](b.md)
* [a&b](c.md)
* [\__init__](d.md)
* [\`hi`](e.md)
output:
- a&b: a.md
- a&b: b.md
- a&b: c.md
- __init__: d.md
- '`hi`': e.md

0 comments on commit 740bb2a

Please sign in to comment.