Skip to content

Commit 4f0b316

Browse files
committed
test: add test for parseHeaders
1 parent ec330f0 commit 4f0b316

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

lib/util/parseHeaders.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const removeMarkdownToken = str => String(str)
1818
.replace(/(\\)(\*|_|`)/g, '$2') // remove escape char '\'
1919

2020
exports.removeTailHtml = (str) => {
21-
return String(str).replace(/<.*>\s*$/g, '')
21+
return String(str).replace(/\s*?<.*>\s*$/g, '')
2222
}
2323

2424
// only remove some md tokens.

test/util/parseHeaders.spec.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import {
2+
parseHeaders,
3+
removeTailHtml
4+
} from '@/util/parseHeaders'
5+
6+
describe('parseHeaders', () => {
7+
test('should unescape html', () => {
8+
const input = '&lt;div&gt;'
9+
expect(parseHeaders(input)).toBe('<div>')
10+
})
11+
12+
test('should remove markdown tokens correctly', () => {
13+
const asserts = {
14+
// #238
15+
'[vue](vuejs.org)': 'vue',
16+
'`vue`': 'vue',
17+
'*vue*': 'vue',
18+
'**vue**': 'vue',
19+
'***vue***': 'vue',
20+
'_vue_': 'vue',
21+
'\\_vue\\_': '_vue_',
22+
'\\*vue\\*': '*vue*',
23+
24+
// #564 For multiple markdown tokens
25+
'`a` and `b`': 'a and b',
26+
'***bold and italic***': 'bold and italic',
27+
'**bold** and *italic*': 'bold and italic'
28+
}
29+
Object.keys(asserts).forEach(input => {
30+
expect(parseHeaders(input)).toBe(asserts[input])
31+
})
32+
})
33+
34+
test('should remove tail html correctly', () => {
35+
expect(removeTailHtml('# H1 <div></div>>')).toBe('# H1')
36+
})
37+
})

0 commit comments

Comments
 (0)