-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.js
More file actions
45 lines (42 loc) · 1.33 KB
/
index.js
File metadata and controls
45 lines (42 loc) · 1.33 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
import bbob from "@bbob/core";
import { render } from "@bbob/html";
import { lineBreakPlugin } from "./plugins/lineBreak";
import { preserveWhitespace } from "./plugins/preserveWhitespace";
import { removeEmptyLinePlugin } from "./plugins/removeEmptyLinesInAttr";
import { availableTags, preset, preventParsing } from "./preset";
import { postprocess } from "./utils/postprocess";
import { preprocessRaw } from "./utils/preprocess";
const options = {
onlyAllowTags: [...availableTags],
caseFreeTags: true,
contextFreeTags: preventParsing, // prevent parsing of children
enableEscapeTags: true,
onError: (err) => {
if (options.previewing) {
// eslint-disable-next-line no-console
console.warn(err.message, err.lineNumber, err.columnNumber);
}
},
};
const presetTags = preset();
export const RpNBBCode = (code, opts) => {
const plugins = [presetTags];
if (opts.preserveWhitespace) {
plugins.push(preserveWhitespace());
}
plugins.push(lineBreakPlugin(), removeEmptyLinePlugin);
const [preprocessed, preprocessedData] = preprocessRaw(code);
return bbob(plugins).process(preprocessed, {
render,
...options,
data: {
...preprocessedData,
raw: preprocessed,
previewing: opts.previewing,
fonts: new Set(),
styles: [],
bbscripts: [],
},
});
};
export { postprocess };