-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.js
More file actions
33 lines (25 loc) · 1005 Bytes
/
index.js
File metadata and controls
33 lines (25 loc) · 1005 Bytes
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
"use strict";
const loaderUtils = require("loader-utils"),
assign = require("object-assign"),
asciidoctor = require('asciidoctor.js')(),
path = require('path');
// default option
const defaultOptions = {
safe: 'unsafe',
sourceHighlighter: 'highlightjs'
};
module.exports = function (content) {
// merge params and default config
const query = loaderUtils.parseQuery(this.query),
options = assign({}, defaultOptions, query, this.options["asciidoctorLoader"]),
includeRegExp = new RegExp(/^include::(.*)\[\]/, 'm');
let includePath,
includeFileName;
while (includeRegExp.test(content)) {
includeFileName = content.match(includeRegExp)[1];
includePath = path.join(`${this.context}/${includeFileName}`);
content = content.replace(includeRegExp, "++++\n${require("+includeFileName+"')}\n++++");
}
this.cacheable();
return asciidoctor.Asciidoctor(true).$convert(content, asciidoctor.Opal.hash(options));
};