forked from github.com/GenderDysphoria.fyi
Moved new build process out of gulp folder
This commit is contained in:
46
build/lib/markdown-token-filter.js
Normal file
46
build/lib/markdown-token-filter.js
Normal file
@@ -0,0 +1,46 @@
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user