forked from marktext/marktext
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmarkdown-basic.spec.js
More file actions
104 lines (96 loc) · 3.49 KB
/
markdown-basic.spec.js
File metadata and controls
104 lines (96 loc) · 3.49 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
92
93
94
95
96
97
98
99
100
101
102
103
104
import ContentState from '../../../src/muya/lib/contentState'
import EventCenter from '../../../src/muya/lib/eventHandler/event'
import ExportMarkdown from '../../../src/muya/lib/utils/exportMarkdown'
import { MUYA_DEFAULT_OPTION } from '../../../src/muya/lib/config'
import * as templates from '../markdown'
const defaultOptions = { endOfLine: 'lf' }
const defaultOptionsCrlf = Object.assign({}, defaultOptions, { endOfLine: 'crlf' })
const createMuyaContext = options => {
const ctx = {}
ctx.options = Object.assign({}, MUYA_DEFAULT_OPTION, options)
ctx.eventCenter = new EventCenter()
ctx.contentState = new ContentState(ctx, ctx.options)
return ctx
}
// ----------------------------------------------------------------------------
// Muya parser (Markdown to HTML to Markdown)
//
const verifyMarkdown = (markdown, options) => {
const ctx = createMuyaContext(options)
ctx.contentState.importMarkdown(markdown)
const blocks = ctx.contentState.getBlocks()
const exportedMarkdown = new ExportMarkdown(blocks).generate()
// FIXME: We always need to add a new line at the end of the document. Add a option to disable the new line.
// Muya always use LF line endings.
expect(exportedMarkdown).to.equal(markdown)
}
describe('Muya parser', () => {
it('Basic Text Formatting', () => {
verifyMarkdown(templates.BasicTextFormattingTemplate(), defaultOptions)
})
it('Blockquotes', () => {
verifyMarkdown(templates.BlockquotesTemplate(), defaultOptions)
})
it('Code Blocks', () => {
verifyMarkdown(templates.CodeBlocksTemplate(), defaultOptions)
})
it('Escapes', () => {
verifyMarkdown(templates.EscapesTemplate(), defaultOptions)
})
it('Headings', () => {
verifyMarkdown(templates.HeadingsTemplate(), defaultOptions)
})
it('Images', () => {
verifyMarkdown(templates.ImagesTemplate(), defaultOptions)
})
it('Links', () => {
verifyMarkdown(templates.LinksTemplate(), defaultOptions)
})
it('Lists', () => {
verifyMarkdown(templates.ListsTemplate(), defaultOptions)
})
it('GFM - Basic Text Formatting', () => {
verifyMarkdown(templates.GfmBasicTextFormattingTemplate(), defaultOptions)
})
it('GFM - Lists', () => {
verifyMarkdown(templates.GfmListsTemplate(), defaultOptions)
})
it('GFM - Tables', () => {
verifyMarkdown(templates.GfmTablesTemplate(), defaultOptions)
})
})
describe('Muya parser (CRLF)', () => {
it('Basic Text Formatting', () => {
verifyMarkdown(templates.BasicTextFormattingTemplate(), defaultOptionsCrlf)
})
it('Blockquotes', () => {
verifyMarkdown(templates.BlockquotesTemplate(), defaultOptionsCrlf)
})
it('Code Blocks', () => {
verifyMarkdown(templates.CodeBlocksTemplate(), defaultOptionsCrlf)
})
it('Escapes', () => {
verifyMarkdown(templates.EscapesTemplate(), defaultOptionsCrlf)
})
it('Headings', () => {
verifyMarkdown(templates.HeadingsTemplate(), defaultOptionsCrlf)
})
it('Images', () => {
verifyMarkdown(templates.ImagesTemplate(), defaultOptionsCrlf)
})
it('Links', () => {
verifyMarkdown(templates.LinksTemplate(), defaultOptionsCrlf)
})
it('Lists', () => {
verifyMarkdown(templates.ListsTemplate(), defaultOptionsCrlf)
})
it('GFM - Basic Text Formatting', () => {
verifyMarkdown(templates.GfmBasicTextFormattingTemplate(), defaultOptionsCrlf)
})
it('GFM - Lists', () => {
verifyMarkdown(templates.GfmListsTemplate(), defaultOptionsCrlf)
})
it('GFM - Tables', () => {
verifyMarkdown(templates.GfmTablesTemplate(), defaultOptionsCrlf)
})
})