-
Notifications
You must be signed in to change notification settings - Fork 5
/
cjk.test.ts
64 lines (59 loc) · 2.87 KB
/
cjk.test.ts
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
import { describe, expect, it } from 'vitest'
import { fromMarkdown } from '../parse'
import { hastToHtml, mdToHast } from '../stringify'
import { STRONG_REGEXP, cjk, parseAndTransform } from '../cjk'
describe('strong', () => {
const render = (s: string) => hastToHtml(mdToHast(fromMarkdown(s, { mdastExtensions: [cjk()] }))!)
it('render strong', () => {
const list = [
[`**真,**她`, '<p><strong>真,</strong>她</p>'],
[`**真。**她`, '<p><strong>真。</strong>她</p>'],
[`**真、**她`, '<p><strong>真、</strong>她</p>'],
[`**真;**她`, '<p><strong>真;</strong>她</p>'],
[`**真:**她`, '<p><strong>真:</strong>她</p>'],
[`**真?**她`, '<p><strong>真?</strong>她</p>'],
[`**真!**她`, '<p><strong>真!</strong>她</p>'],
[`**真“**她`, '<p><strong>真“</strong>她</p>'],
[`**真”**她`, '<p><strong>真”</strong>她</p>'],
[`**真‘**她`, '<p><strong>真‘</strong>她</p>'],
[`**真’**她`, '<p><strong>真’</strong>她</p>'],
[`**真(**她`, '<p><strong>真(</strong>她</p>'],
[`**真)**她`, '<p><strong>真)</strong>她</p>'],
[`**真【**她`, '<p><strong>真【</strong>她</p>'],
[`**真】**她`, '<p><strong>真】</strong>她</p>'],
[`**真《**她`, '<p><strong>真《</strong>她</p>'],
[`**真》**她`, '<p><strong>真》</strong>她</p>'],
[`**真—**她`, '<p><strong>真—</strong>她</p>'],
[`**真~**她`, '<p><strong>真~</strong>她</p>'],
[`**真…**她`, '<p><strong>真…</strong>她</p>'],
[`**真·**她`, '<p><strong>真·</strong>她</p>'],
[`**真〃**她`, '<p><strong>真〃</strong>她</p>'],
[`**真-**她`, '<p><strong>真-</strong>她</p>'],
[`**真々**她`, '<p><strong>真々</strong>她</p>'],
[`**真**她`, '<p><strong>真</strong>她</p>'],
]
list.forEach((it) => {
expect(render(it[0])).eq(it[1])
})
})
it('Render multiple strong', () => {
expect(render('**真,**她**真**,她')).eq('<p><strong>真,</strong>她<strong>真</strong>,她</p>')
})
it('Render with escaped asterisks', () => {
expect(render(`\*\*真,\*\*她`)).eq('<p><strong>真,</strong>她</p>').not.eq('<p>**真,**她</p>')
})
})
it('clearStrongAfterSpace', () => {
const render = (s: string) => hastToHtml(mdToHast(fromMarkdown(s, { mdastExtensions: [cjk()] }))!)
expect(render('**真,** 她**真**,她')).eq('<p><strong>真,</strong>她<strong>真</strong>,她</p>')
})
it('parseAndTransform', () => {
expect(parseAndTransform('**真,**她', STRONG_REGEXP)).deep.eq([
{ match: true, value: '真,' },
{ match: false, value: '她' },
])
expect(parseAndTransform('**真,**她**真**,她', STRONG_REGEXP)).deep.eq([
{ match: true, value: '真,' },
{ match: false, value: '她**真**,她' },
])
})