64 lines
2.6 KiB
JavaScript
64 lines
2.6 KiB
JavaScript
"use strict";
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const modifiers_1 = __importDefault(require("./modifiers"));
|
|
const resolveFileToURL_1 = __importDefault(require("./helper/resolveFileToURL"));
|
|
const api_1 = __importDefault(require("../api"));
|
|
const plugins_1 = __importDefault(require("../plugins"));
|
|
const promise_1 = __importDefault(require("../utils/promise"));
|
|
const defaultBlocks_1 = __importDefault(require("../constants/defaultBlocks"));
|
|
const fileToOutput_1 = __importDefault(require("./helper/fileToOutput"));
|
|
const CODEBLOCK = "code";
|
|
/**
|
|
* Return default modifier to prepare a page for
|
|
* rendering.
|
|
*
|
|
* @return {Array<Modifier>}
|
|
*/
|
|
function getModifiers(output, page) {
|
|
const book = output.getBook();
|
|
const plugins = output.getPlugins();
|
|
const glossary = book.getGlossary();
|
|
const file = page.getFile();
|
|
// Glossary entries
|
|
const entries = glossary.getEntries();
|
|
const glossaryFile = glossary.getFile();
|
|
const glossaryFilename = (0, fileToOutput_1.default)(output, glossaryFile.getPath());
|
|
// Current file path
|
|
const currentFilePath = file.getPath();
|
|
// Get TemplateBlock for highlighting
|
|
const blocks = plugins_1.default.listBlocks(plugins);
|
|
const code = blocks.get(CODEBLOCK) || defaultBlocks_1.default.get(CODEBLOCK);
|
|
// Current context
|
|
const context = api_1.default.encodeGlobal(output);
|
|
return [
|
|
// Normalize IDs on headings
|
|
modifiers_1.default.addHeadingId,
|
|
// Annotate text with glossary entries
|
|
modifiers_1.default.annotateText.bind(null, entries, glossaryFilename),
|
|
// Resolve images
|
|
modifiers_1.default.resolveImages.bind(null, currentFilePath),
|
|
// Resolve links (.md -> .html)
|
|
modifiers_1.default.resolveLinks.bind(null, currentFilePath, resolveFileToURL_1.default.bind(null, output)),
|
|
// Highlight code blocks using "code" block
|
|
modifiers_1.default.highlightCode.bind(null, (lang, source) => {
|
|
return (0, promise_1.default)(code.applyBlock({
|
|
body: source,
|
|
kwargs: {
|
|
language: lang
|
|
}
|
|
}, context)).then((result) => {
|
|
if (result.html === false) {
|
|
return { text: result.body };
|
|
}
|
|
else {
|
|
return { html: result.body };
|
|
}
|
|
});
|
|
})
|
|
];
|
|
}
|
|
exports.default = getModifiers;
|