mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
remove heading sequence in header ID
This commit is contained in:
parent
09bb1566b1
commit
0735764a34
@ -317,7 +317,10 @@ class MarkdownIt extends VxWorker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
generateHeaderId(p_headerIds, p_str) {
|
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 id = idBase;
|
||||||
let idx = 1;
|
let idx = 1;
|
||||||
while (p_headerIds.has(id)) {
|
while (p_headerIds.has(id)) {
|
||||||
|
@ -46,7 +46,7 @@ class NodeLineMapper {
|
|||||||
this.headingNodes = this.container.querySelectorAll("h1, h2, h3, h4, h5, h6");
|
this.headingNodes = this.container.querySelectorAll("h1, h2, h3, h4, h5, h6");
|
||||||
let headings = [];
|
let headings = [];
|
||||||
let needSectionNumber = window.vxOptions.sectionNumberEnabled;
|
let needSectionNumber = window.vxOptions.sectionNumberEnabled;
|
||||||
let regExp = /^\d(?:\.\d)*\.? /;
|
let regExp = Utils.headingSequenceRegExp();
|
||||||
for (let i = 0; i < this.headingNodes.length; ++i) {
|
for (let i = 0; i < this.headingNodes.length; ++i) {
|
||||||
let node = this.headingNodes[i];
|
let node = this.headingNodes[i];
|
||||||
let headingContent = this.getHeadingContent(node);
|
let headingContent = this.getHeadingContent(node);
|
||||||
|
@ -109,4 +109,8 @@ class Utils {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static headingSequenceRegExp() {
|
||||||
|
return /^\d(?:\.\d)*\.? /;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user