diff --git a/src/core/markdown/MarkdownSerializer.js b/src/core/markdown/MarkdownSerializer.js index f2063a7a..6af6fe0f 100644 --- a/src/core/markdown/MarkdownSerializer.js +++ b/src/core/markdown/MarkdownSerializer.js @@ -315,6 +315,28 @@ export class MarkdownSerializerState { this.inTightList = prevTight; } + renderCheckbox(node){ + let canSetBreak = false + node.forEach((child, _, i) => { + + if(child.type.name === "soft_break" || (child.type.name === 'text' && child.text === String.fromCharCode(160))){ + if(canSetBreak){ + const delim = i === 0 ? '' : '  ' + this.flushClose(1); + this.wrapBlock(delim, null, node, () => {}); + return + } + canSetBreak = true + return + } + + canSetBreak = false + const delim = i === 0 ? '' : ' ' + this.flushClose(1); + this.wrapBlock(delim, null, node, () => this.render(child, node, i)); + }); + } + // :: (string, ?bool) → string // Escape the given string so that it can safely appear in Markdown // content. If `startOfLine` is true, also escape characters that diff --git a/src/extensions/markdown/Breaks/index.ts b/src/extensions/markdown/Breaks/index.ts index 7b043271..cb0e5de9 100644 --- a/src/extensions/markdown/Breaks/index.ts +++ b/src/extensions/markdown/Breaks/index.ts @@ -7,6 +7,7 @@ import {logger} from '../../../logger'; import {isMac} from '../../../utils/platform'; import {isTextSelection} from '../../../utils/selection'; import {pType} from '../../base/BaseSchema/BaseSchemaSpecs'; +import {checkboxLabelType} from '../../yfm/Checkbox/CheckboxSpecs/const'; import {BreaksSpecs, BreaksSpecsOptions, hbType, sbType} from './BreaksSpecs'; @@ -55,7 +56,8 @@ const addBr = (br: NodeType) => !isTextSelection(sel) || !sel.empty || // breaks can only be in the paragraph - sel.$cursor?.parent.type !== pType(schema) + (sel.$cursor?.parent.type !== pType(schema) && + sel.$cursor?.parent.type !== checkboxLabelType(schema)) ) return false; diff --git a/src/extensions/yfm/Checkbox/CheckboxSpecs/serializer.ts b/src/extensions/yfm/Checkbox/CheckboxSpecs/serializer.ts index b43ef871..543dcb44 100644 --- a/src/extensions/yfm/Checkbox/CheckboxSpecs/serializer.ts +++ b/src/extensions/yfm/Checkbox/CheckboxSpecs/serializer.ts @@ -24,6 +24,6 @@ export const serializerTokens: Record = { state.write('[ ] '); } - state.renderInline(node); + state.renderCheckbox(node); }, }; diff --git a/src/extensions/yfm/Checkbox/index.scss b/src/extensions/yfm/Checkbox/index.scss index 861c1768..9daec1b9 100644 --- a/src/extensions/yfm/Checkbox/index.scss +++ b/src/extensions/yfm/Checkbox/index.scss @@ -1,6 +1,6 @@ .g-md-checkbox { display: flex; - align-items: center; + align-items: start; &__label { display: inline-block; diff --git a/src/extensions/yfm/Checkbox/plugin.ts b/src/extensions/yfm/Checkbox/plugin.ts index 123ca170..82485a37 100644 --- a/src/extensions/yfm/Checkbox/plugin.ts +++ b/src/extensions/yfm/Checkbox/plugin.ts @@ -94,5 +94,4 @@ export const keymapPlugin = () => keymap({ Enter: splitCheckbox(), Backspace: removeCheckbox, - 'Shift-Enter': splitCheckbox(true), });