UNPKG

markugen

Version:

Markdown to HTML/PDF static site generation tool

54 lines (53 loc) 2.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.tabsDirective = void 0; const html_entities_1 = require("html-entities"); exports.tabsDirective = { level: 'container', marker: ':::', renderer: tabs, }; function tabs(token) { if (token.meta.name === 'tabs') { // nothing to render if (!token.tokens) return ''; const tabs = []; let current = undefined; for (const child of token.tokens) { // start a new tab if (child.raw.startsWith('::tab')) { const ctoken = child; current = { name: `tab-${tabs.length + 1}`, label: ctoken.text, content: '', active: tabs.length === 0, }; tabs.push(current); } // else append to the current tab's content else if (current) current.content += this.parser.parse([child]); } // create the main tabs first let html = '<div class="markugen-tabs-container markugen-not-printable">\n<div class="markugen-tabs-labels">\n'; // add the labels for (const tab of tabs) html += `<div name="${tab.name}" class="markugen-tab-label${tab.active ? ' active' : ''}">${(0, html_entities_1.encode)(tab.label)}</div>\n`; html += '</div>\n<div class="markugen-tabs">\n'; // add the content for (const tab of tabs) html += `<div name="${tab.name}" class="markugen-tab${tab.active ? '' : ' markugen-hidden'}">\n${tab.content}</div>\n`; html += '</div>\n</div>\n'; // create the printable tabs next for (const tab of tabs) { html += `<div name="${tab.name}" class="markugen-tabs-container markugen-printable">\n` + `<div name="${tab.name}" class="markugen-tab-label">${(0, html_entities_1.encode)(tab.label)}</div>\n` + `<div name="${tab.name}" class="markugen-tab">\n${tab.content}</div>\n` + '</div>\n'; } return html; } return false; }