Skip to content

Commit

Permalink
Desktop: Fix laurent22#5626: when clipper, keep code in multiline and…
Browse files Browse the repository at this point in the history
… delete code number lines
  • Loading branch information
wljince007 committed Mar 18, 2024
1 parent e727504 commit 031c040
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions packages/turndown/src/commonmark-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,20 +474,9 @@ rules.code = {
}

content = content.replace(/\r?\n|\r/g, '\n')
// if code is multiline and in isCodeBlock, just return it, isCodeBlock well add fence(default is ```)
// if code is multiline but not in isCodeBlock, add fence(default is ```)
if (content.indexOf('\n') != -1){
if (node.parentNode && isCodeBlock(node.parentNode)) {
return content
}else {
var className = node.className || ''
var language = (className.match(/language-(\S+)/) || [null, ''])[1]
return (
'\n\n' + options.fence + language + '\n' +
code.replace(/\n$/, '') +
'\n' + options.fence + '\n\n'
)
}
// if code is multiline and in codeBlock, just return it, codeBlock well add fence(default is ```)
if (content.indexOf('\n') != -1 && node.parentNode && isCodeBlock(node.parentNode)){
return content
}

content = content.replace(/\r?\n|\r/g, '')
Expand Down

0 comments on commit 031c040

Please sign in to comment.