Open jet10000 opened 4 years ago
If your intention is just to use just plain text content, which seems likely, then it is better to avoid the rendered content
completely in your rule. So your example would look like
turndownService.addRule('pre', {
filter: 'pre',
replacement: function (content, node) {
// Note this is not bulletproof, see below.
return '```\n' + node.textContent + '\n```'
}
});
To make it bulletproof, you need to deal with eventual fence string (```
), which may occur within <pre>
, and there are also a few considerations regarding leading and trailing newlines. All these things should now be covered in the standard fencedCodeBlock
rule: https://github.com/domchristie/turndown/blob/master/src/commonmark-rules.js#L111
TurndownService.prototype.escape
I add a rule for pre, how to avoid escape for pre?