world/book/node_modules/honkit/lib/models/templateShortcut.js
2025-05-12 05:38:44 +09:00

66 lines
1.8 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 immutable_1 = __importDefault(require("immutable"));
/*
A TemplateShortcut is defined in plugin's template blocks
to replace content with a templating block using delimiters.
*/
class TemplateShortcut extends immutable_1.default.Record({
// List of parser names accepting this shortcut
parsers: immutable_1.default.Map(),
start: String(),
end: String(),
startTag: String(),
endTag: String()
}, "TemplateShortcut") {
getStart() {
return this.get("start");
}
getEnd() {
return this.get("end");
}
getStartTag() {
return this.get("startTag");
}
getEndTag() {
return this.get("endTag");
}
getParsers() {
return this.get("parsers");
}
/**
Test if this shortcut accept a parser
@param {Parsers|String} parser
@return {boolean}
*/
acceptParser(parser) {
if (typeof parser !== "string") {
parser = parser.getName();
}
const parserNames = this.get("parsers");
return parserNames.includes(parser);
}
/**
Create a shortcut for a block
@param {TemplateBlock} block
@param {Map} details
@return {TemplateShortcut}
*/
static createForBlock(block, details) {
details = immutable_1.default.fromJS(details);
return new TemplateShortcut({
parsers: details.get("parsers"),
start: details.get("start"),
end: details.get("end"),
startTag: block.getName(),
endTag: block.getEndTag()
});
}
}
exports.default = TemplateShortcut;