blob: 7425f65e0e04fc05077c68203d3d0e3c422cd42e (
plain)
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 { State } = require('markup-it');
const AsciidoctorJS = require('asciidoctor.js');
const asciidoc = require('markup-it/lib/asciidoc');
const asciidocjs = AsciidoctorJS();
const FILE_EXTENSIONS = [
'.adoc',
'.asciidoc'
];
/**
* Render a document as text.
* @param {Document} document
* @return {String} text
*/
function toText(document) {
const state = State.create(asciidoc);
return state.serializeDocument(document);
}
/**
* Parse asciidoc into a document.
* @param {String} text
* @return {Document} document
*/
function toDocument(text) {
const state = State.create(asciidoc);
return state.deserializeToDocument(text);
}
/**
* Render asciidoc to HTML.
* @param {String} text
* @return {String} html
*/
function toHTML(text) {
return asciidocjs.convert(text, {
attributes: 'showtitle'
});
}
/**
* Prepare a document for parsing
* @param {String} text
* @return {String} text
*/
function prepare(text) {
return text;
}
/**
* Render asciidoc to inline HTML.
* @param {String} text
* @return {String} html
*/
function toInlineHTML(text) {
return asciidocjs.convert(text, {
doctype: 'inline',
attributes: 'showtitle'
});
}
module.exports = {
name: 'asciidoc',
FILE_EXTENSIONS,
prepare,
toDocument,
toText,
toHTML,
toInlineHTML
};
|