This repository was archived by the owner on Nov 18, 2022. It is now read-only.
forked from quantizor/markdown-to-jsx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatchHtmlBlock.spec.js
114 lines (102 loc) · 2.7 KB
/
matchHtmlBlock.spec.js
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import { matchHtmlBlock } from './index'
import fs from 'fs'
describe('matchHtmlBlock', () => {
it('matches a single div', () => {
const source = '<div></div>'
const capture = matchHtmlBlock(source)
expect(capture).toEqual([
'<div></div>',
'div',
'',
''
])
});
it('matches a single div with attributes', () => {
const source = '<div class="foo"></div>'
const capture = matchHtmlBlock(source)
expect(capture).toEqual([
'<div class="foo"></div>',
'div',
'class="foo"',
''
])
});
it('matches a single div with children', () => {
const source = '<div class="foo">foo</div>'
const capture = matchHtmlBlock(source)
expect(capture).toEqual([
'<div class="foo">foo</div>',
'div',
'class="foo"',
'foo'
])
});
it('matches nested divs', () => {
const source = '<div><div><div>foo</div></div></div>'
const capture = matchHtmlBlock(source)
expect(capture).toEqual([
'<div><div><div>foo</div></div></div>',
'div',
'',
'<div><div>foo</div></div>'
])
});
it('handles void elements', () => {
const source = '<div><br>foo<br></div>'
const capture = matchHtmlBlock(source)
expect(capture).toEqual([
'<div><br>foo<br></div>',
'div',
'',
'<br>foo<br>'
])
});
it('handles self-closing tags', () => {
const source = '<div><br />and <img src="foo" /></div>'
const capture = matchHtmlBlock(source)
expect(capture).toEqual([
'<div><br />and <img src="foo" /></div>',
'div',
'',
'<br />and <img src="foo" />'
])
});
it('return null for autolink tags', () => {
const source = `
**autolink** style
<https://google.com>
`
const capture = matchHtmlBlock(source)
expect(capture).toEqual(null)
});
it('handles svgs', () => {
const source = fs.readFileSync(__dirname + '/docs/images/logo.svg', 'utf8')
const capture = matchHtmlBlock(source)
expect(capture).toEqual([
source,
'svg',
'width="246" height="369" xmlns="http://www.w3.org/2000/svg"',
source.replace(/<svg[^>]*>(.+)<\/svg>/, '$1'),
])
});
it('is case-insensitive', () => {
const source = '<Foo>bar</Foo>'
const capture = matchHtmlBlock(source)
expect(capture).toEqual([
'<Foo>bar</Foo>',
'Foo',
'',
'bar',
])
});
it('does not match self-closing tags', () => {
const source = '<Inner children="bah" />'
const capture = matchHtmlBlock(source)
expect(capture).toBeNull()
});
it('does not match just an open tag', () => {
const source = '<div>'
const capture = matchHtmlBlock(source)
expect(capture).toBeNull()
});
});