UNPKG

@awesome-fe/translate

Version:
59 lines 3.06 kB
"use strict"; 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.hastToMastHandlers = void 0; var all = require("hast-util-to-mdast/lib/all"); var rehype_1 = require("../rehype"); function generateHtmlRaw(h, node) { var value = rehype_1.Rehype.stringify(node); return h(node, 'htmlRaw', { value: value }, []); } function generateClosingTag(h, node) { return h(node, 'htmlTag', { tagName: node.tagName, selfClosing: false, attributes: __assign(__assign({}, node.properties), ({})), }, all(h, node)); } exports.hastToMastHandlers = { em: function (h, node) { return h(node, 'emphasis', { marker: node.properties['nt__marker'] }, all(h, node)); }, strong: function (h, node) { return h(node, 'strong', { marker: node.properties['nt__marker'] }, all(h, node)); }, li: function (h, node) { return h(node, 'listItem', { marker: node.properties['nt__marker'] }, all(h, node)); }, 'live-example': function (h, node) { return generateHtmlRaw(h, node); }, 'code-tabs': function (h, node) { return generateHtmlRaw(h, node); }, 'code-example': function (h, node) { return generateHtmlRaw(h, node); }, 'code-examples': function (h, node) { return generateHtmlRaw(h, node); }, br: function (h, node) { return generateHtmlRaw(h, node); }, img: function (h, node) { return generateHtmlRaw(h, node); }, 'header': function (h, node) { return generateClosingTag(h, node); }, 'div': function (h, node) { return generateClosingTag(h, node); }, 'tag': function (h, node) { return h(node, 'html', { value: decodeURIComponent(node.properties.value) }, all(h, node)); }, 'html-raw': function (h, node) { return h(node, 'htmlRaw', { value: decodeURIComponent(node.properties.value) }, all(h, node)); }, 'original-id': function (h, node) { return h(node, 'originalId', { value: node.properties['value'] }, all(h, node)); }, 'comment': function (h, node) { return h(node, 'comment', { value: node.value }); }, a: function (h, node) { var href = node.properties['href']; var title = node.properties['title']; if (href === null || href === void 0 ? void 0 : href.startsWith('linkRef:')) { var 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: title }, all(h, node)); } else if (node.properties['name']) { return h(node, 'anchor', __assign({}, node.properties), all(h, node)); } }, }; //# sourceMappingURL=hast-to-mast-handlers.js.map