|
1 | 1 | const markdownParser = require("./markdown-parser"); |
2 | 2 |
|
3 | 3 | describe("markdownParser", () => { |
4 | | - test("it can find level 1 headings", () => { |
5 | | - const markdown = "# Test"; |
6 | | - const astNode = markdownParser.getAstNodeFromMarkdown(markdown); |
7 | | - const level1Heading = markdownParser.getFirstLevel1HeadingChild(astNode); |
| 4 | + describe("getFirstLevel1HeadingChild", () => { |
| 5 | + test("it can find level 1 headings", () => { |
| 6 | + const markdown = "# Test"; |
| 7 | + const astNode = markdownParser.getAstNodeFromMarkdown(markdown); |
| 8 | + const level1Heading = markdownParser.getFirstLevel1HeadingChild(astNode); |
8 | 9 |
|
9 | | - expect(markdownParser.getStartIndex(level1Heading)).toBe(0); |
10 | | - expect(markdownParser.getEndIndex(level1Heading)).toBe(6); |
| 10 | + expect(markdownParser.getStartIndex(level1Heading)).toBe(0); |
| 11 | + expect(markdownParser.getEndIndex(level1Heading)).toBe(6); |
| 12 | + }); |
| 13 | + |
| 14 | + test("it ignores level 2 headings", () => { |
| 15 | + const markdown = "## Test"; |
| 16 | + const astNode = markdownParser.getAstNodeFromMarkdown(markdown); |
| 17 | + expect(markdownParser.getFirstLevel1HeadingChild(astNode)).toBeUndefined(); |
| 18 | + }); |
11 | 19 | }); |
12 | 20 |
|
13 | | - test("it can find HTML comments", () => { |
14 | | - const markdown = "# Test\n<!-- this was a test -->"; |
15 | | - const astNode = markdownParser.getAstNodeFromMarkdown(markdown); |
| 21 | + describe("getFirstHtmlChildWithValue", () => { |
| 22 | + test("it can find HTML comments", () => { |
| 23 | + const markdown = "# Test\n<!-- this was a test -->"; |
| 24 | + const astNode = markdownParser.getAstNodeFromMarkdown(markdown); |
| 25 | + |
| 26 | + const htmlComment = markdownParser.getFirstHtmlChildWithValue( |
| 27 | + "<!-- this was a test -->", |
| 28 | + astNode |
| 29 | + ); |
| 30 | + |
| 31 | + expect(markdownParser.getStartIndex(htmlComment)).toBe(7); |
| 32 | + expect(markdownParser.getEndIndex(htmlComment)).toBe(31); |
| 33 | + }); |
16 | 34 |
|
17 | | - const htmlComment = markdownParser.getFirstHtmlChildWithValue( |
18 | | - "<!-- this was a test -->", |
19 | | - astNode |
20 | | - ); |
| 35 | + test("it ignores HTML inside source code blocks", () => { |
| 36 | + const markdown = "# Test\n```\n<!-- this was a test -->\n```"; |
| 37 | + const astNode = markdownParser.getAstNodeFromMarkdown(markdown); |
21 | 38 |
|
22 | | - expect(markdownParser.getStartIndex(htmlComment)).toBe(7); |
23 | | - expect(markdownParser.getEndIndex(htmlComment)).toBe(31); |
| 39 | + expect( |
| 40 | + markdownParser.getFirstHtmlChildWithValue("<!-- this was a test -->", astNode) |
| 41 | + ).toBeUndefined(); |
| 42 | + }); |
24 | 43 | }); |
25 | 44 |
|
26 | 45 | describe("hasLinkDescendant", () => { |
|
0 commit comments