remove heading sequence in header ID

This commit is contained in:
Le Tan 2020-12-22 19:54:25 +08:00
parent 09bb1566b1
commit 0735764a34
3 changed files with 9 additions and 2 deletions

View File

@ -317,7 +317,10 @@ class MarkdownIt extends VxWorker {
}
generateHeaderId(p_headerIds, p_str) {
let idBase = p_str.replace(/\s/g, '-').toLowerCase();
// Remove leading heading sequence.
let regExp = Utils.headingSequenceRegExp();
let idBase = p_str.replace(regExp, '');
idBase = idBase.replace(/\s/g, '-').toLowerCase();
let id = idBase;
let idx = 1;
while (p_headerIds.has(id)) {

View File

@ -46,7 +46,7 @@ class NodeLineMapper {
this.headingNodes = this.container.querySelectorAll("h1, h2, h3, h4, h5, h6");
let headings = [];
let needSectionNumber = window.vxOptions.sectionNumberEnabled;
let regExp = /^\d(?:\.\d)*\.? /;
let regExp = Utils.headingSequenceRegExp();
for (let i = 0; i < this.headingNodes.length; ++i) {
let node = this.headingNodes[i];
let headingContent = this.getHeadingContent(node);

View File

@ -109,4 +109,8 @@ class Utils {
}
return true;
}
static headingSequenceRegExp() {
return /^\d(?:\.\d)*\.? /;
}
}