@awesome-fe/translate
Version:
Translation utils
176 lines • 7.2 kB
JavaScript
;
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.adoc = void 0;
var core_1 = require("@asciidoctor/core");
var adoc;
(function (adoc) {
var doc = (0, core_1.default)();
function isParagraph(node) {
return (node === null || node === void 0 ? void 0 : node.getNodeName()) === 'paragraph';
}
adoc.isParagraph = isParagraph;
function isSection(node) {
return (node === null || node === void 0 ? void 0 : node.getNodeName()) === 'section';
}
adoc.isSection = isSection;
function isDocument(node) {
return (node === null || node === void 0 ? void 0 : node.getNodeName()) === 'document' || node.getNodeName() === 'embedded';
}
adoc.isDocument = isDocument;
function isAbstractBlock(node) {
return node.isBlock();
}
adoc.isAbstractBlock = isAbstractBlock;
function isInline(node) {
return node.isInline();
}
adoc.isInline = isInline;
function isIndexTerm(node) {
return (node === null || node === void 0 ? void 0 : node.getNodeName()) === 'inline_indexterm';
}
adoc.isIndexTerm = isIndexTerm;
function isList(node) {
return (node === null || node === void 0 ? void 0 : node.getNodeName()) === 'ulist' || node.getNodeName() === 'olist';
}
adoc.isList = isList;
function isDescriptionList(node) {
return (node === null || node === void 0 ? void 0 : node.getNodeName()) === 'dlist';
}
adoc.isDescriptionList = isDescriptionList;
function isListItem(node) {
return (node === null || node === void 0 ? void 0 : node.getNodeName()) === 'list_item';
}
adoc.isListItem = isListItem;
function setSubstitutionMode(doc, mode) {
var consts = doc.Substitutors.$$const;
var result = __assign({}, consts);
consts.BASIC_SUBS = mode.BASIC_SUBS;
consts.HEADER_SUBS = mode.HEADER_SUBS;
consts.NORMAL_SUBS = mode.NORMAL_SUBS;
consts.REFTEXT_SUBS = mode.REFTEXT_SUBS;
consts.VERBATIM_SUBS = mode.VERBATIM_SUBS;
return result;
}
adoc.setSubstitutionMode = setSubstitutionMode;
function setSubstitutionsForAdoc(doc) {
setSubstitutionMode(doc, {
BASIC_SUBS: [],
HEADER_SUBS: [],
NORMAL_SUBS: [],
REFTEXT_SUBS: [],
VERBATIM_SUBS: ['callouts'],
});
}
adoc.setSubstitutionsForAdoc = setSubstitutionsForAdoc;
function setSubstitutionsForDefaultHtml(doc) {
setSubstitutionMode(doc, {
BASIC_SUBS: ['specialcharacters'],
HEADER_SUBS: ['specialcharacters', 'attributes'],
NORMAL_SUBS: ['specialcharacters', 'quotes', 'attributes', 'replacements', 'macros', 'post_replacements'],
REFTEXT_SUBS: ['specialcharacters', 'quotes', 'replacements'],
VERBATIM_SUBS: ['specialcharacters', 'callouts'],
});
}
adoc.setSubstitutionsForDefaultHtml = setSubstitutionsForDefaultHtml;
function setSubstitutionsForTranslatableHtml(doc) {
setSubstitutionMode(doc, {
BASIC_SUBS: ['specialcharacters'],
HEADER_SUBS: ['specialcharacters', 'attributes'],
NORMAL_SUBS: ['specialcharacters', 'quotes', 'attributes', 'macros'],
REFTEXT_SUBS: ['specialcharacters', 'quotes'],
VERBATIM_SUBS: ['specialcharacters', 'callouts'],
});
}
adoc.setSubstitutionsForTranslatableHtml = setSubstitutionsForTranslatableHtml;
function isBlockImage(node) {
return (node === null || node === void 0 ? void 0 : node.getNodeName()) === 'image';
}
adoc.isBlockImage = isBlockImage;
function isBlockResource(node) {
return (node === null || node === void 0 ? void 0 : node.getNodeName()) === 'video' || node.getNodeName() === 'audio';
}
adoc.isBlockResource = isBlockResource;
function isAdmonition(node) {
return (node === null || node === void 0 ? void 0 : node.getNodeName()) === 'admonition';
}
adoc.isAdmonition = isAdmonition;
function isExample(node) {
return (node === null || node === void 0 ? void 0 : node.getNodeName()) === 'example';
}
adoc.isExample = isExample;
function isQuote(node) {
return (node === null || node === void 0 ? void 0 : node.getNodeName()) === 'quote';
}
adoc.isQuote = isQuote;
function isTable(node) {
return (node === null || node === void 0 ? void 0 : node.getNodeName()) === 'table';
}
adoc.isTable = isTable;
function isSidebar(node) {
return (node === null || node === void 0 ? void 0 : node.getNodeName()) === 'sidebar';
}
adoc.isSidebar = isSidebar;
function isVerse(node) {
return (node === null || node === void 0 ? void 0 : node.getNodeName()) === 'verse';
}
adoc.isVerse = isVerse;
function isListing(node) {
return (node === null || node === void 0 ? void 0 : node.getNodeName()) === 'listing';
}
adoc.isListing = isListing;
function hasLines(node) {
return 'lines' in node;
}
adoc.hasLines = hasLines;
function escapeDirectives(content) {
return content
.replace(/^\[(.*)indent=("?)(\d+)("?)(.*)]$/gm, '[$1rawIndent=$2$3$4$5]')
.replace(/^((?:ifdef|ifndef|ifeval|endif)::\[.*])$/gm, '`begin-directive:[$1]end-directive`')
.replace(/^(include::.*?])$/gm, '`begin-directive:[$1]end-directive`')
.replace(/^(\/\/ *(?:tag|end)::.*?])$/gm, '`begin-directive:[$1]end-directive`');
}
adoc.escapeDirectives = escapeDirectives;
function unescapeDirectives(content) {
return content
.replace(/^\[(.*)rawIndent=("?)(\d+)("?)(.*)]$/gm, '[$1indent=$2$3$4$5]')
.replace(/^`begin-directive:\[(.*?)]end-directive`$/gm, '$1')
.replace(/^Unresolved directive in .* - (.*)$/gm, '$1');
}
adoc.unescapeDirectives = unescapeDirectives;
function createBlock(parent, context) {
return doc.Block.create(parent, context);
}
adoc.createBlock = createBlock;
function createInline(parent, context) {
return doc.Inline.create(parent, context);
}
adoc.createInline = createInline;
function createNode(parent, context) {
if (context === 'document' || context === 'embedded' || !context) {
return parent;
}
if (context.startsWith('inline_')) {
return createInline(parent, context);
}
else {
var child = createBlock(parent, context);
if (!adoc.isDocument(child)) {
parent.append(child);
}
return child;
}
}
adoc.createNode = createNode;
})(adoc = exports.adoc || (exports.adoc = {}));
//# sourceMappingURL=adoc.js.map