turndown
turndown copied to clipboard
limiting the markdown syntax
right now I only want to support a minimal set of markdown rules (emphasis, lists and links).
I am not sure that I properly understood the approach I should take here.
would this require https://github.com/domchristie/turndown/issues/206 ?
ok this is my workaround to reduce the common markdown syntax
const keepKeys = [
1, // new line
4, // list
5, // list element
9, // links
10, // links
11, // emphasis
12, // emphasis
14, // images
];
turndownService.rules.array = turndownService.rules.array.filter((value, key) => keepKeys.includes(key));
Rather than digging into the internals, you may wish to try adding a custom rule to handle everything other than your subset. For example, something like:
turndownService.addRule({
filter: function (node) {
var subset = ['BR', 'UL', 'OL', 'LI', 'A', 'EM', 'IMG']
return !subset.includes(node.nodeName)
},
replacement: function (content, node) {
return node.outerHTML
}
})
hmm .. not managing to get this to work.
one small issue is easy to fix. the rule needs a string parameter.
but I then struggle to both ensure that the common rules for the tags I want are applied and that all the unwanted stuff like <meta>
is stripped and other tags just the text is extracted.
I do realize that messing with internals like this isn't the way to go. would you be willing to accept a PR that allows me to either:
-
removeRule('identedCodeBlock')
-
filterRules(['linebreak', 'list', 'listItem])
- optionally pass in the "common rules"