Files
gdb.lgbtqi.app/build/lib/markdown-token-filter.js
Bill Garrett 2f90e668cd Migrate to Node 16 (#118)
* Node 16: fix build dependencies

* Node 16: fix Bootstrap dependency problem

* Node 16: fix error in HTML writer

* Node 16: move await to proper place (h/t alliejones)
2023-01-02 14:03:02 -08:00

47 lines
863 B
JavaScript

const { flatten } = require('lodash');
module.exports = exports = function (md) {
md.core.ruler.push(
'modify-token',
(state) => {
state.tokens = flatten(state.tokens.map(descend).filter(Boolean));
return false;
}
);
};
function descend (token) {
switch (token.type) {
case 'link_open':
case 'link_close':
case 'html_block':
return false;
case 'heading_open':
token.type = 'paragraph_open';
token.tag = 'p';
token.markup = '';
return token;
case 'heading_close':
token.type = 'paragraph_close';
token.tag = 'p';
token.markup = '';
return token;
case 'image':
case 'container':
return token.children;
default:
if (token.children && token.children.length) {
token.children = flatten(token.children.map(descend).filter(Boolean));
}
return token;
}
}