Skip to content

Commit

Permalink
Fix the SyntaxError with document.querySelector() when id start with …
Browse files Browse the repository at this point in the history
…a digit

See http://calixe.fr/global_id.html for a demo:

* html works well with such id
* querySelector() thow a SyntaxError
  • Loading branch information
electrolinux committed Mar 10, 2023
1 parent bc32933 commit f9f507a
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/runtime/markdown-parser/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ export default function (this: any, _options: MarkdownOptions) {
}

// Remove double dashes and trailing dash from heading ids
// Insert underscore if id start with a digit
if (node.tagName?.startsWith('h') && node.properties.id) {
node.properties.id = node.properties.id
.replace(/-+/g, '-')
.replace(/-$/, '')
.replace(/^-/, '')
.replace(/^(\d)/, '_$1')
}

/**
Expand Down

0 comments on commit f9f507a

Please sign in to comment.