mirror of
https://github.com/laurent22/joplin.git
synced 2025-01-11 18:24:43 +02:00
Desktop: Fixes #8530: Rich text editor: Use fewer
s in markdown while still preserving initial paragraph indentation (#8529)
This commit is contained in:
parent
1c1d20f82c
commit
e47985c101
@ -1 +1 @@
|
||||
**A test...** Test
|
||||
**A test...** Test
|
@ -1,4 +1,4 @@
|
||||
import { repeat, isCodeBlockSpecialCase1, isCodeBlockSpecialCase2, isCodeBlock, getStyleProp } from './utilities'
|
||||
import { repeat, isCodeBlockSpecialCase1, isCodeBlockSpecialCase2, isCodeBlock, getStyleProp, htmlEscapeLeadingNonbreakingSpace } from './utilities'
|
||||
const Entities = require('html-entities').AllHtmlEntities;
|
||||
const htmlentities = (new Entities()).encode;
|
||||
|
||||
@ -25,6 +25,13 @@ rules.paragraph = {
|
||||
filter: 'p',
|
||||
|
||||
replacement: function (content) {
|
||||
// If the line starts with a nonbreaking space, replace it. By default, the
|
||||
// markdown renderer removes leading non-HTML-escaped nonbreaking spaces. However,
|
||||
// because the space is nonbreaking, we want to keep it.
|
||||
// \u00A0 is a nonbreaking space.
|
||||
const leadingNonbreakingSpace = /^\u{00A0}/ug;
|
||||
content = content.replace(leadingNonbreakingSpace, ' ');
|
||||
|
||||
return '\n\n' + content + '\n\n'
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,6 @@ export default function TurndownService (options) {
|
||||
linkReferenceStyle: 'full',
|
||||
anchorNames: [],
|
||||
br: ' ',
|
||||
nonbreakingSpace: ' ',
|
||||
disableEscapeContent: false,
|
||||
preformattedCode: false,
|
||||
blankReplacement: function (content, node) {
|
||||
@ -216,15 +215,10 @@ function replacementForNode (node) {
|
||||
var whitespace = node.flankingWhitespace
|
||||
if (whitespace.leading || whitespace.trailing) content = content.trim()
|
||||
|
||||
const replaceNonbreakingSpaces = space => {
|
||||
// \u{00A0} is a nonbreaking space
|
||||
return space.replace(/\u{00A0}/ug, this.options.nonbreakingSpace);
|
||||
};
|
||||
|
||||
return (
|
||||
replaceNonbreakingSpaces(whitespace.leading) +
|
||||
replaceNonbreakingSpaces(rule.replacement(content, node, this.options)) +
|
||||
replaceNonbreakingSpaces(whitespace.trailing)
|
||||
whitespace.leading +
|
||||
rule.replacement(content, node, this.options) +
|
||||
whitespace.trailing
|
||||
)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user