-
-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: Rework autorefs replacement to not re-parse the final HTML
Define a "transport representation" for autorefs: <span data-mkdocstrings-identifier="SomeIdentifier">SomeHTML</span> First a native Markdown extension translates from the usual `[SomeMarkdown][SomeIdentifier]` to the above, and then the post-process replacement mechanism (which is kept in the same place as before) doesn't need to be so careful and complicated, it just indiscriminately replaces such exact strings. This is a very big boost in performance and I think is more future-proof. Other mkdocstrings handlers are also free to use this mechanism: define whatever syntax for autorefs that they need and then insert this exact HTML themselves, for the postprocessing to pick up later. It used to be possible to insert the square-brackets Markdown before, but that was very fragile. Issue #187: #187 PR #188: #188
- Loading branch information
Showing
7 changed files
with
156 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
""" | ||
Link to [something.Else][]. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,29 @@ | ||
"""Tests for the extension module.""" | ||
|
||
from markdown import Markdown | ||
|
||
from mkdocstrings.extension import MkdocstringsExtension | ||
|
||
_DEFAULT_CONFIG = { | ||
"theme_name": "material", | ||
"mdx": [], | ||
"mdx_configs": {}, | ||
"mkdocstrings": {"default_handler": "python", "custom_templates": None, "watch": [], "handlers": {}}, | ||
} | ||
|
||
|
||
def test_render_html_escaped_sequences(): | ||
"""Assert HTML-escaped sequences are correctly parsed as XML.""" | ||
config = { | ||
"theme_name": "material", | ||
"mdx": [], | ||
"mdx_configs": {}, | ||
"mkdocstrings": {"default_handler": "python", "custom_templates": None, "watch": [], "handlers": {}}, | ||
} | ||
md = Markdown(extensions=[MkdocstringsExtension(config)]) | ||
md = Markdown(extensions=[MkdocstringsExtension(_DEFAULT_CONFIG)]) | ||
md.convert("::: tests.fixtures.html_escaped_sequences") | ||
|
||
|
||
def test_reference_inside_autodoc(): | ||
config = dict(_DEFAULT_CONFIG) | ||
ext = MkdocstringsExtension(config) | ||
config["mdx"].append(ext) | ||
|
||
md = Markdown(extensions=[ext]) | ||
|
||
output = md.convert("::: tests.fixtures.cross_reference") | ||
snippet = 'Link to <span data-mkdocstrings-identifier="something.Else">something.Else</span>.' | ||
assert snippet in output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters