Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Desktop: Fixes #8530: Rich text editor: Use fewer  s in markdown while still preserving initial paragraph indentation #8529

Merged
@@ -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)
Comment on lines -225 to -227
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replaceNonbreakingSpaces was not present in upstream turndown and was added by #8468. It is no longer used and has thus been removed.

whitespace.leading +
rule.replacement(content, node, this.options) +
whitespace.trailing
)
}

Expand Down