@awesome-fe/translate
Version:
Translation utils
49 lines • 2.51 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.hastToMastHandlers = void 0;
const all = require("hast-util-to-mdast/lib/all");
const rehype_1 = require("../rehype");
function generateHtmlRaw(h, node) {
const value = rehype_1.Rehype.stringify(node);
return h(node, 'htmlRaw', { value }, []);
}
function generateClosingTag(h, node) {
return h(node, 'htmlTag', {
tagName: node.tagName,
selfClosing: false,
attributes: { ...node.properties, ...({}) },
}, all(h, node));
}
exports.hastToMastHandlers = {
em: (h, node) => h(node, 'emphasis', { marker: node.properties['nt__marker'] }, all(h, node)),
strong: (h, node) => h(node, 'strong', { marker: node.properties['nt__marker'] }, all(h, node)),
li: (h, node) => h(node, 'listItem', { marker: node.properties['nt__marker'] }, all(h, node)),
'live-example': (h, node) => generateHtmlRaw(h, node),
'code-tabs': (h, node) => generateHtmlRaw(h, node),
'code-example': (h, node) => generateHtmlRaw(h, node),
'code-examples': (h, node) => generateHtmlRaw(h, node),
br: (h, node) => generateHtmlRaw(h, node),
img: (h, node) => generateHtmlRaw(h, node),
'header': (h, node) => generateClosingTag(h, node),
'div': (h, node) => generateClosingTag(h, node),
'tag': (h, node) => h(node, 'html', { value: decodeURIComponent(node.properties.value) }, all(h, node)),
'html-raw': (h, node) => h(node, 'htmlRaw', { value: decodeURIComponent(node.properties.value) }, all(h, node)),
'ng-inline-at': (h, node) => h(node, 'ngInlineAt', { name: node.properties['name'], value: node.properties['value'] }, all(h, node)),
'ng-doc-directive': (h, node) => h(node, 'ngDocDirective', { name: node.properties['name'], value: node.properties['value'] }, all(h, node)),
'comment': (h, node) => h(node, 'comment', { value: node.value }),
a: (h, node) => {
const href = node.properties['href'];
const title = node.properties['title'];
if (href?.startsWith('linkRef:')) {
const url = href.replace(/^linkRef:/, '');
return h(node, 'linkReference', { identifier: url, label: url }, all(h, node));
}
else if (href) {
return h(node, 'link', { url: href, title }, all(h, node));
}
else if (node.properties['name']) {
return h(node, 'anchor', { ...node.properties }, all(h, node));
}
},
};
//# sourceMappingURL=hast-to-mast-handlers.js.map