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

Autoformat should not take effect within code blocks #3814

Open
tomdyqin opened this issue Nov 27, 2024 · 1 comment
Open

Autoformat should not take effect within code blocks #3814

tomdyqin opened this issue Nov 27, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@tomdyqin
Copy link
Contributor

Description

Autoformat should not take effect within code blocks

Reproduction URL

No response

Reproduction steps

1. Go to 'playground'
2. Click on ' '
3. Input '# '
4. See '#' will remove, becase the markdown autoformat is take effect

Plate version

39.2.15

Slate React version

0.110.3

Screenshots

No response

Logs

No response

Browsers

No response

@tomdyqin tomdyqin added the bug Something isn't working label Nov 27, 2024
@tomdyqin
Copy link
Contributor Author

tomdyqin commented Nov 27, 2024

  // plate/packages/autoformat/src/lib/withAutoformat.ts
  editor.insertText = (text) => {
    if (!isCollapsed(editor.selection)) return insertText(text);

    if (getCodeLineEntry(editor)) return insertText(text); // I'm not sure if adding this processing here is too much

    for (const rule of getOptions().rules!) {
      const { insertTrigger, mode = 'text', query } = rule;

      if (query && !query(editor as any, { ...rule, text })) continue;

      const autoformatter: Record<typeof mode, any> = {
        block: autoformatBlock,
        mark: autoformatMark,
        text: autoformatText,
      };

      if (
        autoformatter[mode]?.(editor, {
          ...(rule as any),
          text,
        })
      ) {
        return insertTrigger && insertText(text);
      }
    }

    insertText(text);
  };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant