|
| 1 | +'use strict' |
| 2 | + |
| 3 | +const test = require('tape') |
| 4 | + |
| 5 | +test('anchorMarkdownHeadings', (t) => { |
| 6 | + const anchorMarkdownHeadings = require('../../scripts/plugins/anchor-markdown-headings') |
| 7 | + |
| 8 | + t.test('correctly pharses markdown heading without links', (t) => { |
| 9 | + const text = 'Simple title' |
| 10 | + const level = 1 |
| 11 | + const raw = 'Simple title' |
| 12 | + const output = anchorMarkdownHeadings(text, level, raw) |
| 13 | + const expected = '<h1>Simple title<a name="simple-title" class="anchor" ' + |
| 14 | + 'href="#simple-title"></a></h1>' |
| 15 | + |
| 16 | + t.equal(output, expected) |
| 17 | + t.end() |
| 18 | + }) |
| 19 | + |
| 20 | + t.test('correctly pharses markdown heading with a single link', (t) => { |
| 21 | + const text = 'Title with <a href="#">link</a>' |
| 22 | + const level = 3 |
| 23 | + const raw = 'Title with [link](#)' |
| 24 | + const output = anchorMarkdownHeadings(text, level, raw) |
| 25 | + const expected = '<h3>Title with <a href="#">link</a>' + |
| 26 | + '<a name="title-with-link" class="anchor" href="#title-with-link"></a></h3>' |
| 27 | + |
| 28 | + t.equal(output, expected) |
| 29 | + t.end() |
| 30 | + }) |
| 31 | + |
| 32 | + t.test('correctly pharses markdown heading with multiple links', (t) => { |
| 33 | + const text = 'a <a href="b">b</a> c<a href="d">d</a>e' |
| 34 | + const level = 2 |
| 35 | + const raw = 'a [b](b) c[d](d)e' |
| 36 | + const output = anchorMarkdownHeadings(text, level, raw) |
| 37 | + const expected = '<h2>a <a href="b">b</a> c<a href="d">d</a>e' + |
| 38 | + '<a name="a-b-cde" class="anchor" href="#a-b-cde"></a></h2>' |
| 39 | + |
| 40 | + t.equal(output, expected) |
| 41 | + t.end() |
| 42 | + }) |
| 43 | + |
| 44 | + t.test('makes pretty slugs', (t) => { |
| 45 | + const text = '$$$ WIN BIG! $$$' |
| 46 | + const level = 4 |
| 47 | + const raw = '$$$ WIN BIG! $$$' |
| 48 | + const output = anchorMarkdownHeadings(text, level, raw) |
| 49 | + const expected = '<h4>$$$ WIN BIG! $$$' + |
| 50 | + '<a name="win-big" class="anchor" href="#win-big"></a></h4>' |
| 51 | + |
| 52 | + t.equal(output, expected) |
| 53 | + t.end() |
| 54 | + }) |
| 55 | + |
| 56 | + t.end() |
| 57 | +}) |
0 commit comments