-
Notifications
You must be signed in to change notification settings - Fork 13
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
feat (core): added support for an empty string #505
base: main
Are you sure you want to change the base?
Conversation
Preview is ready. |
I propose incorporating this functionality into the markup mode.
|
src/markup/commands/emptyRow.ts
Outdated
export const insertEmptyRow: StateCommand = ({state, dispatch}) => { | ||
const trSpec = state.changeByRange((range) => { | ||
const lineFrom = state.doc.lineAt(range.from); | ||
|
||
return { | ||
changes: [{from: lineFrom.from, insert: str}], | ||
range: EditorSelection.range( | ||
range.anchor + str.length, | ||
range.head + str.length, | ||
range.goalColumn, | ||
range.bidiLevel ?? undefined, | ||
), | ||
}; | ||
}); | ||
|
||
dispatch(state.update(trSpec)); | ||
return true; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can use replaceOrInsertAfter
helper, like in insertHRule
command
src/bundle/types.ts
Outdated
@@ -28,6 +28,7 @@ export type ParseInsertedUrlAsImage = (text: string) => {imageUrl: string; title | |||
|
|||
export type MarkdownEditorMdOptions = { | |||
html?: boolean; | |||
allowEmptyRows?: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We thought about naming. Let's choose a more accurate name - preserveEmptyRows
src/bundle/Editor.ts
Outdated
yfmLangOptions: {languageData: this.#markupConfig.languageData}, | ||
yfmLangOptions: { | ||
languageData: this.#markupConfig.languageData, | ||
allowEmptyRows: this.#mdOptions.allowEmptyRows, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why inside yfmLangOptions
?
src/markup/commands/helpers.ts
Outdated
const insert = state.lineBreak.repeat(2) + markup + state.lineBreak.repeat(2); | ||
let breaksAfter = 2; | ||
|
||
if (shouldGetBreaks) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use from emptyRows
src/markup/codemirror/yfm.ts
Outdated
@@ -64,23 +60,6 @@ const MarkedExtension = mdInlineFactory({ | |||
tag: customTags.marked, | |||
}); | |||
|
|||
export type YfmNoteType = 'info' | 'tip' | 'warning' | 'alert'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return plz
state.closeBlock(node); | ||
toMd: (state, node, parent) => { | ||
if (opts.allowEmptyRows && !node.content.size) { | ||
const isParentEmpty = parent.content.size / parent.content.childCount === 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add comment plz
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are nodes (for example, iframe) that contain size === 1, we suggest changing the logic to bypass the nodes
src/bundle/useMarkdownEditor.ts
Outdated
@@ -82,6 +89,7 @@ export function useMarkdownEditor<T extends object = {}>( | |||
html: md.html ?? props.allowHTML, | |||
linkify: md.linkify ?? props.linkify, | |||
linkifyTlds: md.linkifyTlds ?? props.linkifyTlds, | |||
pmTransformers: pmTransformers, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pmTransformers,
const transformers = []; | ||
|
||
if (emptyRowTransformer) { | ||
transformers.push(transformEmptyParagraph); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add today: add a new method to the ExtensionBuilder
@@ -77,6 +77,7 @@ export type PlaygroundProps = { | |||
allowHTML?: boolean; | |||
settingsVisible?: boolean; | |||
initialEditor?: MarkdownEditorMode; | |||
preserveEmptyRows?: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add preserveEmptyRows to the following line in Playground.tsx to enable rerendering in the demo.
@@ -90,7 +93,7 @@ export class WysiwygEditor implements CommonEditor, ActionStorage { | |||
actions, | |||
} = ExtensionsManager.process(extensions, { | |||
// "breaks" option only affects the renderer, but not the parser | |||
mdOpts: {html: allowHTML, linkify, breaks: true, preset: mdPreset}, | |||
mdOpts: {pmTransformers, html: allowHTML, linkify, breaks: true, preset: mdPreset}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mdOpts
– its about markdown-it options. pmTransformers
– he's not one of them. put pmTransformers
similarly as linkifyTlds
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename file to emptyRowTransformer.ts
or something similar name
yfmLangOptions: {languageData: this.#markupConfig.languageData}, | ||
yfmLangOptions: { | ||
languageData: getAutocompleteConfig({ | ||
preserveEmptyRows: this.#mdOptions.preserveEmptyRows, | ||
}), | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should concat languageData config from this.#markupConfig.languageData
and result of call getAutocompleteConfig()
together
breaks?: boolean; | ||
linkify?: boolean; | ||
linkifyTlds?: string | string[]; | ||
pmTransformers?: TransformFn[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this field not needed anymore?
@@ -39,9 +41,11 @@ export type WysiwygPlaceholderOptions = { | |||
|
|||
export type MarkdownEditorMdOptions = { | |||
html?: boolean; | |||
preserveEmptyRows?: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this setting to experiment options
Adds support for empty strings through the flag "allowEmptyString".
There are 2 implementation options:
In the end, I want to leave it
, but maybe there will be ideas for the second option