浏览代码

Merge pull request #25 from ian-r-rose/dont-add-code-fence-headers

Don't parse code blocks in markdown for headers.
Ian Rose 6 年之前
父节点
当前提交
c7b8ae6a85
共有 1 个文件被更改,包括 9 次插入0 次删除
  1. 9 0
      packages/toc/src/generators.ts

+ 9 - 0
packages/toc/src/generators.ts

@@ -244,9 +244,18 @@ namespace Private {
     const lines = text.split('\n');
     let headings: IHeading[] = [];
 
+    let inCodeBlock = false;
     // Iterate over the lines to get the header level and
     // the text for the line.
     lines.forEach((line, idx) => {
+      // Don't check for markdown headings if we
+      // are in a code block (demarkated by backticks.
+      if (line.indexOf('```') === 0) {
+        inCodeBlock = !inCodeBlock;
+      }
+      if (inCodeBlock) {
+        return;
+      }
       // Make an onClick handler for this line.
       const onClick = onClickFactory(idx);