|
1 | 1 | import test from 'ava' |
2 | 2 |
|
3 | | -import { extractLinks, extractLinksFromFile } from '../index' |
| 3 | +import { extractLinks, extractAnchors, extractLinksFromFile } from '../index' |
4 | 4 |
|
5 | 5 | const dedent = (s: string) => s.replace('\n ', '') |
6 | 6 |
|
@@ -154,3 +154,34 @@ test('extractLinksFromFile: invalid notebook (bad schema)', async (t) => { |
154 | 154 | 'Could not read "__test__/fixtures/invalid-notebook-schema.ipynb": missing field `source` at line 10 column 5', |
155 | 155 | ) |
156 | 156 | }) |
| 157 | + |
| 158 | +test('extractAnchors: no anchors', (t) => { |
| 159 | + t.deepEqual(extractAnchors(''), []) |
| 160 | +}) |
| 161 | + |
| 162 | +test('extractAnchors: simple heading', (t) => { |
| 163 | + t.deepEqual(extractAnchors('# My heading'), ['#my-heading']) |
| 164 | +}) |
| 165 | + |
| 166 | +test('extractAnchors: duplicate headings', (t) => { |
| 167 | + t.deepEqual( |
| 168 | + extractAnchors('# My heading\n\n## My heading\n\n### My heading').sort(), |
| 169 | + ['#my-heading', '#my-heading-1', '#my-heading-2'].sort(), |
| 170 | + ) |
| 171 | +}) |
| 172 | + |
| 173 | +test('extractAnchors: markdown in headings', (t) => { |
| 174 | + t.deepEqual(extractAnchors('# My **heading**'), ['#my-**heading**']) |
| 175 | +}) |
| 176 | + |
| 177 | +test('extractAnchors: forbidden characters', (t) => { |
| 178 | + t.deepEqual(extractAnchors('## A heading with crazy punctuation.,;:!?`\()"\\'), ['#a-heading-with-crazy-punctuation']) |
| 179 | +}) |
| 180 | + |
| 181 | +test('extractAnchors: id tags', (t) => { |
| 182 | + t.deepEqual(extractAnchors('<id="thing">'), ['#thing']) |
| 183 | +}) |
| 184 | + |
| 185 | +test('extractAnchors: duplicate id tags', (t) => { |
| 186 | + t.deepEqual(extractAnchors('<id="thing">\n\n<id="thing">'), ['#thing']) |
| 187 | +}) |
0 commit comments