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

feat (core): added support for an empty string #505

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

PMAWorks
Copy link
Contributor

Adds support for empty strings through the flag "allowEmptyString".

There are 2 implementation options:

  1. Through token parsing and map comparison
  2. Through the insert  

In the end, I want to leave it  , but maybe there will be ideas for the second option

@gravity-ui-bot
Copy link
Contributor

Preview is ready.

@makhnatkin
Copy link
Collaborator

I propose incorporating this functionality into the markup mode.

  1. Implement auto-completion software and provide additional auto-completion features.
  2. Assign a keyboard shortcut.

Comment on lines 5 to 22
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;
};
Copy link
Member

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

@@ -28,6 +28,7 @@ export type ParseInsertedUrlAsImage = (text: string) => {imageUrl: string; title

export type MarkdownEditorMdOptions = {
html?: boolean;
allowEmptyRows?: boolean;
Copy link
Collaborator

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

yfmLangOptions: {languageData: this.#markupConfig.languageData},
yfmLangOptions: {
languageData: this.#markupConfig.languageData,
allowEmptyRows: this.#mdOptions.allowEmptyRows,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why inside yfmLangOptions?

const insert = state.lineBreak.repeat(2) + markup + state.lineBreak.repeat(2);
let breaksAfter = 2;

if (shouldGetBreaks) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use from emptyRows

@@ -64,23 +60,6 @@ const MarkedExtension = mdInlineFactory({
tag: customTags.marked,
});

export type YfmNoteType = 'info' | 'tip' | 'warning' | 'alert';
Copy link
Collaborator

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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add comment plz

Copy link
Collaborator

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

@@ -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,
Copy link
Collaborator

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);
Copy link
Collaborator

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;
Copy link
Collaborator

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},
Copy link
Member

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

Copy link
Member

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

Comment on lines -282 to +288
yfmLangOptions: {languageData: this.#markupConfig.languageData},
yfmLangOptions: {
languageData: getAutocompleteConfig({
preserveEmptyRows: this.#mdOptions.preserveEmptyRows,
}),
},
Copy link
Member

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[];
Copy link
Member

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;
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants