mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-09-30 09:01:30 +08:00
26 lines
755 B
JavaScript
26 lines
755 B
JavaScript
![]() |
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'
|
||
|
)
|
||
|
}
|
||
|
})
|
||
|
}
|