Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improper linking of headings that have part of text enclosed within "<>" #1076

Closed
yash-chowdhary opened this issue Mar 2, 2020 · 1 comment · Fixed by #1089
Closed

Improper linking of headings that have part of text enclosed within "<>" #1076

yash-chowdhary opened this issue Mar 2, 2020 · 1 comment · Fixed by #1089

Comments

@yash-chowdhary
Copy link
Contributor

yash-chowdhary commented Mar 2, 2020

Tell us about your environment

  • MarkBind Version: 2.11.0

What did you do? Please include the actual source code causing the issue.
There are instances where part of the header text that is enclosed within "<>".
Referring to such headings using hrefs is not straightforward.
For example, the heading -

Specifying Variables in an <include>

will have to be linked using the following href - #specifying-variables-in-an-and-lt-include-and-gt

What did you expect to happen?
The href should be #specifying-variables-in-an-include

What actually happened? Please include the actual, raw output.
The href was #specifying-variables-in-an-and-lt-include-and-gt, as the string passed as input to slugify is Specifying variables in an &lt; include &gt;

There are a couple of instances in the user guide where linking such headers is broken (this is the correct link).

Suggested Fix(es)
For this particular case, I have tried removing the "[-]?and-lt" and "[-]?and-gt" substrings from the slugified text like so -

headerId = headerId.replace(/[-]?and-lt/g, '');
headerId = headerId.replace(/[-]?and-gt/g, '');
@ang-zeyu
Copy link
Contributor

ang-zeyu commented Mar 2, 2020

We can use the custom replacements option here https://www.npmjs.com/package/@sindresorhus/slugify for a slightly easier fix.
e.g. ['and lt', ''], ['and gt', ''] for customReplacements

The slugify package actually erases < and > by default.
The issue here is that markdown-it escapes < and > into &lt/gt; before it is passed to htmlparser2, which slugify converts to and-lt/and-gt.

The first h1 here is from a markdown heading, the second from a normal <h1> tag
mdvsnormal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants