Skip to content

Commit

Permalink
Desktop: Fixes laurent22#6055: Preserve empty newlines created by pre…
Browse files Browse the repository at this point in the history
…ssing Enter repeatedly in the rich text editor (laurent22#8549)
  • Loading branch information
personalizedrefrigerator authored and laurent22 committed Jul 28, 2023
1 parent cb0b802 commit 0f062bf
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
@@ -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

0 comments on commit 0f062bf

Please sign in to comment.