Skip to content

Commit

Permalink
Use preRenderNode in panel span heading plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
ang-zeyu committed May 28, 2020
1 parent f74f118 commit 96a2aa6
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions src/plugins/default/markbind-plugin-shorthandSyntax.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
const cheerio = module.parent.require('cheerio');

// Convert panel headings: <span heading>
function convertPanelHeadings($) {
$('panel>span[heading]').each((i, element) => {
$(element).attr('slot', 'header');
$(element).addClass('card-title');
$(element).removeAttr('heading');
});
}

/**
* Converts shorthand syntax to proper Markbind syntax
* @param content of the page
*/
module.exports = {
postRender: (content) => {
const $ = cheerio.load(content, { xmlMode: false });
convertPanelHeadings($);
return $.html();
preRenderNode: (node) => {
if (node.name === 'panel' && node.children) {
node.children.forEach((n) => {
if (n.name === 'span' && n.attribs.heading !== undefined) {
n.attribs.slot = 'header';
n.attribs.class = n.attribs.class ? `${n.attribs.class} card-title` : 'card-title';
delete n.attribs.heading;
}
});
}

return node;
},
};

0 comments on commit 96a2aa6

Please sign in to comment.