Skip to content

Commit

Permalink
Desktop: Fixes #8530: Rich text editor: Use fewer  s in markdo…
Browse files Browse the repository at this point in the history
…wn while still preserving initial paragraph indentation (#8529)
  • Loading branch information
personalizedrefrigerator committed Jul 23, 2023
1 parent 1c1d20f commit e47985c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
@@ -1 +1 @@
   **A test...** Test
   **A test...** Test
9 changes: 8 additions & 1 deletion packages/turndown/src/commonmark-rules.js
@@ -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;

Expand All @@ -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'
}
}
Expand Down
12 changes: 3 additions & 9 deletions packages/turndown/src/turndown.js
Expand Up @@ -36,7 +36,6 @@ export default function TurndownService (options) {
linkReferenceStyle: 'full',
anchorNames: [],
br: ' ',
nonbreakingSpace: ' ',
disableEscapeContent: false,
preformattedCode: false,
blankReplacement: function (content, node) {
Expand Down Expand Up @@ -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
)
}

Expand Down

0 comments on commit e47985c

Please sign in to comment.