Skip to content
This repository has been archived by the owner on May 27, 2021. It is now read-only.

Commit

Permalink
Merge pull request #44 from kondratyev-nv/fix_title_parsing
Browse files Browse the repository at this point in the history
Fix title parsing
  • Loading branch information
alanwalk committed Apr 9, 2018
2 parents 0f5d279 + c9cddf9 commit 1fc815e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const REGEXP_TOC_STOP = /\s*<!--(.*)\/TOC(.*)-->/gi;
const REGEXP_TOC_CONFIG = /\w+[:=][\w.]+/gi;
const REGEXP_TOC_CONFIG_ITEM = /(\w+)[:=]([\w.]+)/;
const REGEXP_MARKDOWN_ANCHOR = /^<a id="markdown-.+" name=".+"><\/a\>/;
const REGEXP_HEADER = /^(\#{1,6})\s*([.0-9]*)\s*(.+)/;
const REGEXP_HEADER = /^(\#{1,6})\s*(.+)/;
const REGEXP_CODE_BLOCK1 = /^```/;
const REGEXP_CODE_BLOCK2 = /^~~~/;
const REGEXP_ANCHOR = /\[.+\]\(#(.+)\)/
Expand Down Expand Up @@ -366,10 +366,11 @@ class MarkdownTocTools {
}

let title = lineText.substr(depth).trim();
let baseTitle = title.replace(/^(?:\d+\.)+/, "").trim(); // title without section number
title = title.replace(/\[(.+)]\([^)]*\)/gi, "$1"); // replace link
title = title.replace(/<!--.+-->/gi, ""); // replace comment
title = title.replace(/\#*_/gi, "").trim(); // replace special char

if (hashMap[title] == null) {
hashMap[title] = 0
} else {
Expand All @@ -385,7 +386,7 @@ class MarkdownTocTools {
range : new Range(index, 0, index, lineText.length),
header : headerResult[1],
orderedList : orderedListStr,
baseTitle : headerResult[3]
baseTitle : baseTitle
});
}
return headerList;
Expand Down

0 comments on commit 1fc815e

Please sign in to comment.