-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgfm.js
More file actions
54 lines (45 loc) · 1.39 KB
/
gfm.js
File metadata and controls
54 lines (45 loc) · 1.39 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
'use strict'
// const assert = require('assert')
const zmd = require('../zmd')
const fs = require('fs')
const path = require('path')
// function read(name) {
// return fs.readFileSync(path.join(__dirname, name)).toString()
// }
function write(filepath, content) {
fs.writeFileSync(path.join(__dirname, filepath), content)
}
const gfm = require('../spec/gfm.json')
const result = []
gfm.forEach(item => {
try {
item.zzmd = zmd(item.markdown, {
xhtml: true,
headerIds: false,
autourl: item.section === 'Autolinks (extension)',
encodeURI: true,
ignoreBlankLine: false
})
if (item.html.indexOf('\t') > -1) {
item._html = item.html.replace(/\t/g, ' ')
}
if (/&(?:#(?:\d+)|(?:#[xX][0-9a-fA-F]+))/.test(item.zzmd)) {
item._zzmd = item.zzmd.replace(/&#(\d+|[xX][0-9a-fA-F]+);?/g, function (_, n) {
return n.charAt(0).toLowerCase() === 'x' ?
String.fromCharCode(parseInt(n.substring(1), 16)) :
String.fromCharCode(+n)
})
}
if (item.section === 'Task list items (extension)') {
item._zzmd = (item._zzmd || item.zzmd)
.replace(/ class="task-list-item"/g, '')
.replace(/"checkbox" \/>/g, '"checkbox">')
}
} catch (error) {
item.error = true
item.zzmd = error.message
console.log(error, item)
}
result.push(item)
})
write('gfm.json', JSON.stringify(result, null, ' '))