forked from get-alex/alex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
50 lines (41 loc) · 1.01 KB
/
index.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
'use strict'
var VFile = require('vfile')
var unified = require('unified')
var markdown = require('remark-parse')
var frontmatter = require('remark-frontmatter')
var english = require('retext-english')
var equality = require('retext-equality')
var profanities = require('retext-profanities')
var remark2retext = require('remark-retext')
var sort = require('vfile-sort')
var filter = require('./filter')
module.exports = alex
alex.text = noMarkdown
alex.markdown = alex
var text = unified()
.use(english)
.use(equality)
.use(profanities)
// Alex’s core.
function core(value, processor) {
var file = new VFile(value)
var tree = processor.parse(file)
processor.runSync(tree, file)
sort(file)
return file
}
// Alex.
function alex(value, allow) {
return core(
value,
unified()
.use(markdown)
.use(frontmatter, ['yaml', 'toml'])
.use(remark2retext, text)
.use(filter, {allow: allow})
)
}
// Alex, without the markdown.
function noMarkdown(value) {
return core(value, text)
}