Repository navigation
Conversation
|
Have you measured perf on running span gamut on each header? Plus this would break any existing hrefs if they were recompiled with this code |
|
Perf: the span gamut doesn't run an extra time.
Existing hrefs: ids stay the same for plain headers and for emphasis, code spans and entities ( If that's a concern, the new behaviour could sit behind a |
|
@Crozzers Tell me more on your backwards compat concern. You're worried that someone who previously rendered header IDs and then put them online and shared links would have invalid links if they went and re-rendered this and published the page again? |
|
Yeah that's pretty much it. I seem to remember previous changes having to be adapted around that compatibility concern. Could wrap it behind an option on the extra as suggested, although not sure about the name Then maybe at some point in the far future a 3.0.0 release can make this the default |
Changing every header id by default would break existing links to them,
so header-ids keeps building ids from the markdown source unless
{"strip-syntax": True} is set. The issue trentm#192 cases now set the option,
and *_default copies of them pin the unchanged default ids.
|
Makes sense. Done in e698958: the new behaviour is behind
I've updated the description to match. Happy to rename the option if you'd prefer something else. |
This fixes #192 behind an opt-in option, as discussed in the review. The default ids are unchanged.
With the
header-idsextra, a markdown header's id is slugified from the raw markdown source, so link URLs, image paths and emphasis markers end up in the id. With the newstrip-syntaxoption,extras={"header-ids": {"strip-syntax": True}}, the id is made from the rendered header instead:strip-syntax# [Inline link](https://github.com)inline-linkhttpsgithubcominline-link# [Reference link][ref]reference-linkrefreference-link#  Imagelogologopng-imageimage# <span>Inline</span> HTMLspaninlinespan-htmlinline-html# __Strong__ and _em___strong__-and-_em_strong-and-emHow it works with the option set:
_h_subbuilds the id from the rendered header, with tags stripped. The safe mode handling from Fix sanitized HTML leaking into header ids in safe mode #739 is kept: HTML spans are unhashed (to their sanitized form) before the id is built. In escape mode the escaped tags are visible text, so they still count towards the id.idattribute, and_do_footnote_markerlater failed with aValueError. Footnoted headers keep the id they have by default (# Header with a footnote[^1]->header-with-a-footnote1).# <sometext>) has no visible text, so it gets the same fallback id as other headers with no word characters (-1).Without the option, nothing changes:
header_id_from_text, the mixed-mode HTML headers and every default id are as on master. The module docstring describes the option, and the CHANGES entry is reworded to say it adds the option.Tests:
header_ids_issue192(the headers above, plus a code span that keeps its underscores) andheader_ids_footnote_ref(footnote refs in headers, which covers theValueErrorabove) now setstrip-syntax. Withlib/markdown2.pyfrom master, both fail on the ids.header_ids_issue192_defaultandheader_ids_footnote_ref_defaultrender the same inputs without the option. Their expected HTML was generated with master'smarkdown2.py, so they pin the default ids.Run on this head with the system Python 3.9.6:
cd test && python test.py -- -knownfailure(280 tests, OK; the pygments, wavedrom, latex2mathml and emoji tests were skipped because those modules aren't installed in that Python), andpython test/test_redos.py(10 tests, OK). The first version of this PR was also run on Python 3.12 with those modules installed. Not run on this head: pycodestyle (not installed here), the other Python versions, and the Windows and Linux CI jobs.