mirror of
https://github.com/zadam/trilium.git
synced 2025-11-03 20:06:08 +01:00
Add 'packages/turndown-plugin-gfm/' from commit '0f43299c17108e9508e7e6237369e86f504ea60a'
git-subtree-dir: packages/turndown-plugin-gfm git-subtree-mainline:ebebdd0b07git-subtree-split:0f43299c17
This commit is contained in:
25
packages/turndown-plugin-gfm/src/highlighted-code-block.js
Normal file
25
packages/turndown-plugin-gfm/src/highlighted-code-block.js
Normal file
@@ -0,0 +1,25 @@
|
||||
var highlightRegExp = /highlight-(?:text|source)-([a-z0-9]+)/
|
||||
|
||||
export default function highlightedCodeBlock (turndownService) {
|
||||
turndownService.addRule('highlightedCodeBlock', {
|
||||
filter: function (node) {
|
||||
var firstChild = node.firstChild
|
||||
return (
|
||||
node.nodeName === 'DIV' &&
|
||||
highlightRegExp.test(node.className) &&
|
||||
firstChild &&
|
||||
firstChild.nodeName === 'PRE'
|
||||
)
|
||||
},
|
||||
replacement: function (content, node, options) {
|
||||
var className = node.className || ''
|
||||
var language = (className.match(highlightRegExp) || [null, ''])[1]
|
||||
|
||||
return (
|
||||
'\n\n' + options.fence + language + '\n' +
|
||||
node.firstChild.textContent +
|
||||
'\n' + options.fence + '\n\n'
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user