61 lines
2.2 KiB
JavaScript
61 lines
2.2 KiB
JavaScript
"use strict";
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.default = exports.loadHtml = void 0;
|
|
exports.createParser = createParser;
|
|
const lodash_1 = __importDefault(require("lodash"));
|
|
const totext_1 = __importDefault(require("./totext"));
|
|
// import
|
|
const summary_1 = __importDefault(require("./summary"));
|
|
const glossary_1 = __importDefault(require("./glossary"));
|
|
const langs_1 = __importDefault(require("./langs"));
|
|
const readme_1 = __importDefault(require("./readme"));
|
|
const page_1 = __importDefault(require("./page"));
|
|
const htmlParser = {
|
|
summary: summary_1.default,
|
|
glossary: glossary_1.default,
|
|
langs: langs_1.default,
|
|
readme: readme_1.default,
|
|
page: page_1.default
|
|
};
|
|
/**
|
|
* Utility for loading HTML content
|
|
*/
|
|
var dom_1 = require("./dom");
|
|
Object.defineProperty(exports, "loadHtml", { enumerable: true, get: function () { return dom_1.loadHtml; } });
|
|
// Compose a function with a transform function for the first argument only
|
|
function compose(toHTML, fn) {
|
|
return function (content, options) {
|
|
// e.g. convert asciidoc to html
|
|
const html = toHTML(content, options);
|
|
return fn.call(this, html);
|
|
};
|
|
}
|
|
// Create a HonKit parser from an HTML converter
|
|
function createParser(toHTML, toText = undefined) {
|
|
if (typeof toHTML === "function") {
|
|
toHTML = {
|
|
inline: toHTML,
|
|
block: toHTML
|
|
};
|
|
}
|
|
const parser = {
|
|
summary: compose(toHTML.block, htmlParser.summary),
|
|
glossary: compose(toHTML.block, htmlParser.glossary),
|
|
langs: compose(toHTML.block, htmlParser.langs),
|
|
readme: compose(toHTML.block, htmlParser.readme),
|
|
page: compose(toHTML.block, htmlParser.page),
|
|
inline: compose(toHTML.inline, htmlParser.page)
|
|
};
|
|
// @ts-expect-error
|
|
const _toText = new totext_1.default(toText);
|
|
parser.summary.toText = _toText.summary;
|
|
parser.langs.toText = _toText.langs;
|
|
parser.glossary.toText = _toText.glossary;
|
|
return parser;
|
|
}
|
|
const defaultParser = createParser(lodash_1.default.identity);
|
|
exports.default = defaultParser;
|