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

#50 is incomplete, slugs are still broken when headings contain html #1442

Closed
jcayzac opened this issue Dec 9, 2020 · 1 comment · Fixed by #1443
Closed

#50 is incomplete, slugs are still broken when headings contain html #1442

jcayzac opened this issue Dec 9, 2020 · 1 comment · Fixed by #1443

Comments

@jcayzac
Copy link

jcayzac commented Dec 9, 2020

Bug Report

#50 only fixes a corner case of #49 and has a few problems:

  • It uses a greedy regex.
  • It stops when it finds a digit in a tag (why?).

What is current behaviour

## Bla bla bla <svg aria-label="broken" class="broken" viewPort="0 0 1 1"><circle cx="0.5" cy="0.5"/></svg>

## Another <span style="font-size: 1.2em" class="foo bar baz">broken <span class="aaa">example</span></span>

…produces the slugs:

  • bla-bla-bla-svg-aria-labelbroken-classbroken-viewport0-0-1-1circle-cx05-cy05.
  • another-span-stylefont-size-12em-classfoo-bar-bazbroken-example

What is the expected behaviour

The slugs should ignore the html tags, and be:

  • bla-bla-bla
  • another-broken-example

Proposed fix

In src/core/render/slugify.js:

  let slug = str
    .trim()
    .replace(/[A-Z]+/g, lower)
-   .replace(/<[^>\d]+>/g, '')
+   .replace(/<[^>]+?>/g, '')
    .replace(re, '')
    .replace(/\s/g, '-')
    .replace(/-+/g, '-')
    .replace(/^(\d)/, '_$1');

Other relevant information

  • Your OS: macOS Catalina
  • Node.js version: 14
  • Browser version: Chrome 83
  • Docsify version: master
  • Docsify plugins: none
@sy-records
Copy link
Member

Nice patch. Thank you for your feedback.

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

Successfully merging a pull request may close this issue.

2 participants