-
Notifications
You must be signed in to change notification settings - Fork 10.3k
/
index.js
92 lines (81 loc) · 2.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
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
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
const Remark = require(`remark`);
const toHAST = require(`mdast-util-to-hast`);
const hastToHTML = require(`hast-util-to-html`);
const cheerio = require(`cheerio`);
const plugin = require(`../`);
const remark = new Remark().data(`settings`, {
commonmark: true,
footnotes: true,
pedantic: true
});
const run =
/*#__PURE__*/
function () {
var _ref = (0, _asyncToGenerator2.default)(function* (content) {
const markdownAST = remark.parse(content);
yield plugin({
markdownAST
});
const htmlAst = toHAST(markdownAST, {
allowDangerousHTML: true
});
const html = hastToHTML(htmlAst, {
allowDangerousHTML: true
});
return html;
});
return function run(_x) {
return _ref.apply(this, arguments);
};
}();
describe(`handles valid graph languages`, () => {
it(`dot`,
/*#__PURE__*/
(0, _asyncToGenerator2.default)(function* () {
const test = yield run(`
\`\`\`dot
digraph graphname {
a -> b;
b -> c;
a -> c;
}
\`\`\``);
const $ = cheerio.load(test);
expect($(`svg`).length).toBe(1);
expect($(`pre`).length).toBe(0);
expect($(`code`).length).toBe(0);
}));
it(`circo`,
/*#__PURE__*/
(0, _asyncToGenerator2.default)(function* () {
const test = yield run(`
\`\`\`circo
digraph graphname {
a -> b;
b -> c;
a -> c;
}
\`\`\``);
const $ = cheerio.load(test);
expect($(`svg`).length).toBe(1);
expect($(`pre`).length).toBe(0);
expect($(`code`).length).toBe(0);
}));
it(`unknown graph lang`,
/*#__PURE__*/
(0, _asyncToGenerator2.default)(function* () {
const test = yield run(`
\`\`\`pieh-format
digraph graphname {
a :heart: b;
}
\`\`\``);
const $ = cheerio.load(test);
expect($(`svg`).length).toBe(0);
expect($(`pre`).length).toBe(1);
expect($(`code`).length).toBe(1);
}));
});