Explorar el Código

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

Don't parse code blocks in markdown for headers.
Ian Rose hace 6 años
padre
commit
c7b8ae6a85
Se han modificado 1 ficheros con 9 adiciones y 0 borrados
  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);