Skip to content

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

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 <svgaria-label="broken"class="broken"viewPort="0 0 1 1"><circlecx="0.5"cy="0.5"/></svg>## Another <spanstyle="font-size: 1.2em"class="foo bar baz">broken <spanclass="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

Activity

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

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