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 #6055: Preserve empty newlines created by pressing Enter repeatedly in the rich text editor #8549

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,3 @@
<p>Paragraphs with a single nonbreaking space should be preserved:</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
@@ -0,0 +1,5 @@
Paragraphs with a single nonbreaking space should be preserved:

&nbsp;

&nbsp;
Expand Up @@ -91,7 +91,7 @@ let dispatchDidUpdateIID_: any = null;
let changeId_ = 1;

const TinyMCE = (props: NoteBodyEditorProps, ref: any) => {
const [editor, setEditor] = useState(null);
const [editor, setEditor] = useState<Editor|null>(null);
const [scriptLoaded, setScriptLoaded] = useState(false);
const [editorReady, setEditorReady] = useState(false);
const [draggingStarted, setDraggingStarted] = useState(false);
Expand Down Expand Up @@ -578,7 +578,12 @@ const TinyMCE = (props: NoteBodyEditorProps, ref: any) => {
icons_url: 'gui/NoteEditor/NoteBody/TinyMCE/icons.js',
plugins: 'noneditable link joplinLists hr searchreplace codesample table',
noneditable_noneditable_class: 'joplin-editable', // Can be a regex too
valid_elements: '*[*]', // We already filter in sanitize_html

// #p: Pad empty paragraphs with &nbsp; to prevent them from being removed.
// *[*]: Allow all elements and attributes -- we already filter in sanitize_html
// See https://www.tiny.cloud/docs/configure/content-filtering/#controlcharacters
valid_elements: '#p,*[*]',

menubar: false,
relative_urls: false,
branding: false,
Expand Down
8 changes: 7 additions & 1 deletion packages/turndown/src/commonmark-rules.js
@@ -1,4 +1,4 @@
import { repeat, isCodeBlockSpecialCase1, isCodeBlockSpecialCase2, isCodeBlock, getStyleProp, htmlEscapeLeadingNonbreakingSpace } from './utilities'
import { repeat, isCodeBlockSpecialCase1, isCodeBlockSpecialCase2, isCodeBlock, getStyleProp } from './utilities'
const Entities = require('html-entities').AllHtmlEntities;
const htmlentities = (new Entities()).encode;

Expand Down Expand Up @@ -32,6 +32,12 @@ rules.paragraph = {
const leadingNonbreakingSpace = /^\u{00A0}/ug;
content = content.replace(leadingNonbreakingSpace, '&nbsp;');

// Paragraphs that are truly empty (not even containing nonbreaking spaces)
// take up by default no space. Output nothing.
if (content === '') {
return '';
}

return '\n\n' + content + '\n\n'
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/turndown/src/utilities.js
Expand Up @@ -53,7 +53,7 @@ export function hasVoid (node) {

var meaningfulWhenBlankElements = [
'A', 'TABLE', 'THEAD', 'TBODY', 'TFOOT', 'TH', 'TD', 'IFRAME', 'SCRIPT',
'AUDIO', 'VIDEO'
'AUDIO', 'VIDEO', 'P'
]

export function isMeaningfulWhenBlank (node) {
Expand Down