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

It should bypass SiYuan's default pasting content handle logic when using Event Bus paste to hijack paste content #12429

Open
zxkmm opened this issue Sep 10, 2024 · 0 comments
Assignees

Comments

@zxkmm
Copy link
Contributor

zxkmm commented Sep 10, 2024

TLDR

事件总线paste在用event.preventDefault();拦截并用event.detail.resolve回传魔改后内容时候应该绕过思源本身的粘贴内容处理逻辑(例如绕过过滤出text/html里的代码文本)

Details

用如下代码拦截粘贴事件

this.eventBus.on("paste", this.handlePasteEvent);
  handlePasteEvent = (event: any) => {
    console.log("paste handler");
    event.preventDefault();
    const originalText = event.detail.textPlain.trim();
    console.log("originalText: ", originalText);
    const processedText =
      this.detectLanguageAndTransferToMarkdownCodeFormat(originalText);
    event.detail.resolve({
      textPlain: processedText,
    });
  };

如果剪贴板内容提供方只提供text/plain, 一切工作正常;
但是如果剪贴板内容提供方同时提供text/html和text/plain的话,思源会检测到text/html,自动用思源内部的逻辑处理text/html,最后给我从handlePasteEvent回传的按我需求魔改后的text/plain固执的加上思源预处理的上下文,(例如从IDE粘贴过来的内容,即使是我自己回传的text/plain,也会被思源加上md的代码块的三个反撇)。

Describe the candidate solution

No response

Other information

ref.
zxkmm/siyuan_auto_codeblock#3
zxkmm/siyuan_auto_codeblock#1

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

No branches or pull requests

2 participants