This repository was archived by the owner on May 12, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathbfm.test.js
More file actions
72 lines (59 loc) · 1.91 KB
/
Copy pathbfm.test.js
File metadata and controls
72 lines (59 loc) · 1.91 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
const fs = require('fs')
const path = require('path')
const vm = require('vm')
const CodeMirror = require('codemirror')
require('codemirror/addon/runmode/runmode')
require('codemirror/addon/mode/overlay')
require('codemirror/mode/meta')
require('codemirror/mode/xml/xml')
require('codemirror/mode/markdown/markdown')
require('codemirror/mode/yaml/yaml')
require('codemirror/mode/gfm/gfm')
require('codemirror/mode/yaml-frontmatter/yaml-frontmatter')
function loadBrowserScript(relativePath) {
const filename = path.join(__dirname, '..', '..', relativePath)
const code = fs.readFileSync(filename, 'utf8')
vm.runInNewContext(
code,
{
CodeMirror,
console
},
{ filename }
)
}
loadBrowserScript('extra_scripts/codemirror/mode/bfm/bfm.js')
function runBfm(markdown) {
const tokens = []
CodeMirror.runMode(markdown, 'text/x-bfm', (token, style, line, start) => {
if (token !== '\n') {
tokens.push({ token, style, line, start })
}
})
return tokens
}
function nonWhitespaceTokens(tokens, line, minStart) {
return tokens.filter(
token =>
token.line === line && token.start >= minStart && token.token.trim()
)
}
function expectTokensToUseStyle(tokens, style) {
expect(tokens.length).toBeGreaterThan(0)
tokens.forEach(token => {
expect(token.style).toBe(style)
})
}
it('styles the first definition-list bullet like following bullets', () => {
const tokens = runBfm('Term\n: - first\n - second\n')
expectTokensToUseStyle(nonWhitespaceTokens(tokens, 1, 2), 'variable-2')
expectTokensToUseStyle(nonWhitespaceTokens(tokens, 2, 2), 'variable-2')
})
it('does not style plain definition text as a list', () => {
const tokens = runBfm('Term\n: plain definition\n')
const definitionTokens = nonWhitespaceTokens(tokens, 1, 0)
expect(definitionTokens.length).toBeGreaterThan(0)
definitionTokens.forEach(token => {
expect(token.style).not.toBe('variable-2')
})
})