@diplodoc/transform
Version:
A simple transformer of text in YFM (Yandex Flavored Markdown) to HTML
45 lines • 2.13 kB
JavaScript
;
const utils_1 = require("../utils");
const constant_1 = require("./constant");
const inlineCode = (md, options) => {
const lang = options.lang;
md.renderer.rules.code_inline = function (tokens, idx) {
var _a, _b;
const id = (0, utils_1.generateID)();
const description = (_a = constant_1.LANG_TOKEN_DESCRIPTION[lang]) !== null && _a !== void 0 ? _a : constant_1.LANG_TOKEN_DESCRIPTION.en;
const label = (_b = constant_1.LANG_TOKEN_LABEL[lang]) !== null && _b !== void 0 ? _b : constant_1.LANG_TOKEN_LABEL.en;
return `<code class="yfm-clipboard-inline-code" role="button" aria-label="${label}" aria-description="${description}" tabindex='0' id="${id}">${tokens[idx].content}</code>`;
};
md.core.ruler.after('inline', 'tooltip_code_inline', (state) => {
var _a;
const tokens = state.tokens;
for (let i = 0; i !== tokens.length; i++) {
const token = tokens[i];
if (token.type !== 'inline') {
continue;
}
if (!token.children || token.children.every((e) => e.type !== 'code_inline')) {
continue;
}
const child = token.children.find((e) => e.type === 'code_inline');
if (!child) {
return;
}
const dialog = new state.Token('tooltip_open', 'div', 1);
dialog.attrSet('class', 'yfm inline_code_tooltip');
dialog.attrSet('id', `tooltip_inline_clipboard_dialog`);
dialog.attrSet('role', 'dialog');
dialog.attrSet('aria-live', 'polite');
dialog.attrSet('aria-modal', 'true');
tokens.push(dialog);
const text = new state.Token('text', '', 0);
text.content = (_a = constant_1.LANG_TOKEN[lang]) !== null && _a !== void 0 ? _a : constant_1.LANG_TOKEN.en;
tokens.push(text);
const closeDialog = new state.Token('tooltip_close', 'div', -1);
tokens.push(closeDialog);
break;
}
});
};
module.exports = inlineCode;
//# sourceMappingURL=index.js.map