1
0
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:
Henry Heino 2023-07-23 07:59:24 -07:00 committed by GitHub
parent 1c1d20f82c
commit e47985c101
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 11 deletions

View File

@ -1 +1 @@
   **A test...** Test
   **A test...** Test

View File

@ -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'
}
}

View File

@ -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
)
}