Skip to content

Commit 7d29df9

Browse files
author
Yu
committed
šŸ› yzhang-gh#275, ignore # ... in code blocks
1 parent ecdacba commit 7d29df9

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

ā€Žsrc/toc.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,10 @@ function buildToc() {
223223
let toc;
224224
let editor = vscode.window.activeTextEditor;
225225
if (isMdEditor(editor)) {
226-
toc = editor.document.getText().split(/\r?\n/g)
227-
.filter(lineText => lineText.startsWith('#') && !lineText.toLowerCase().includes('<!-- omit in toc -->'))
226+
toc = editor.document.getText()
227+
.replace(/(^|\r?\n)```[\W\w]+?(```|$)/g, '') // Remove code blocks
228+
.split(/\r?\n/g)
229+
.filter(lineText => lineText.startsWith('#') && lineText.includes('# ') && !lineText.toLowerCase().includes('<!-- omit in toc -->'))
228230
.map(lineText => {
229231
let entry = {};
230232
let matches = /^(#+) (.*)/.exec(lineText);

0 commit comments

Comments
Ā (0)