-
-
Notifications
You must be signed in to change notification settings - Fork 372
Expand file tree
/
Copy pathmarkdown-link-reference-definitions.test.ts
More file actions
91 lines (74 loc) · 2.43 KB
/
Copy pathmarkdown-link-reference-definitions.test.ts
File metadata and controls
91 lines (74 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import assert from 'node:assert/strict'
import { parseSiteMarkdown } from '../src/utils/markdown'
const markdownCases = [
{
name: 'single-quoted title',
markdown: "[//]: # 'SomeLabel'\n\nVisible content.",
referenceMarkdown:
"[example]: https://example.com 'Example title'\n\n[Example][example]",
title: 'Example title',
},
{
name: 'double-quoted title',
markdown: '[//]: # "SomeLabel"\n\nVisible content.',
referenceMarkdown:
'[example]: https://example.com "Example title"\n\n[Example][example]',
title: 'Example title',
},
{
name: 'parenthesized title',
markdown: '[//]: # (SomeLabel)\n\nVisible content.',
referenceMarkdown:
'[example]: https://example.com (Example title)\n\n[Example][example]',
title: 'Example title',
},
]
for (const testCase of markdownCases) {
const document = parseSiteMarkdown(testCase.markdown)
assert.equal(
document.children.length,
1,
`${testCase.name} reference definition is not rendered`,
)
const paragraph = document.children[0]
assert.equal(paragraph?.type, 'paragraph', `${testCase.name} content remains`)
if (paragraph?.type !== 'paragraph') {
throw new Error(`${testCase.name} did not produce a paragraph`)
}
assert.deepEqual(
paragraph.children,
[{ type: 'text', value: 'Visible content.' }],
`${testCase.name} visible paragraph is preserved`,
)
const referenceDocument = parseSiteMarkdown(testCase.referenceMarkdown)
const referenceParagraph = referenceDocument.children[0]
assert.equal(
referenceParagraph?.type,
'paragraph',
`${testCase.name} reference link paragraph is parsed`,
)
if (referenceParagraph?.type !== 'paragraph') {
throw new Error(`${testCase.name} did not produce a reference paragraph`)
}
const link = referenceParagraph.children[0]
assert.equal(link?.type, 'link', `${testCase.name} reference link resolves`)
if (link?.type !== 'link') {
throw new Error(`${testCase.name} did not produce a reference link`)
}
assert.equal(
link.href,
'https://example.com',
`${testCase.name} reference link href is preserved`,
)
assert.equal(
link.title,
testCase.title,
`${testCase.name} reference link title is preserved`,
)
assert.deepEqual(
link.children,
[{ type: 'text', value: 'Example' }],
`${testCase.name} reference link label is preserved`,
)
}
console.log('markdown link reference definition tests passed')