Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/core/markdown/MarkdownSerializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/extensions/markdown/Breaks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/extensions/yfm/Checkbox/CheckboxSpecs/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ export const serializerTokens: Record<CheckboxNode, SerializerNodeToken> = {
state.write('[ ] ');
}

state.renderInline(node);
state.renderCheckbox(node);
},
};
2 changes: 1 addition & 1 deletion src/extensions/yfm/Checkbox/index.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.g-md-checkbox {
display: flex;
align-items: center;
align-items: start;

&__label {
display: inline-block;
Expand Down
1 change: 0 additions & 1 deletion src/extensions/yfm/Checkbox/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,4 @@ export const keymapPlugin = () =>
keymap({
Enter: splitCheckbox(),
Backspace: removeCheckbox,
'Shift-Enter': splitCheckbox(true),
});