Skip to content

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

Closed
@jcayzac

Description

@jcayzac

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions