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

Improve Paste and Paste as plain text #8289

Closed
3 tasks done
xiaoheimissu opened this issue May 17, 2023 · 18 comments
Closed
3 tasks done

Improve Paste and Paste as plain text #8289

xiaoheimissu opened this issue May 17, 2023 · 18 comments
Assignees
Milestone

Comments

@xiaoheimissu
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Can the issue be reproduced with the default theme (daylight/midnight)?

  • I was able to reproduce the issue with the default theme

Could the issue be due to extensions?

  • I've ruled out the possibility that the extension is causing the problem.

Describe the problem

在2.8.6及以后的版本中,当复制文本时,文本中出现$^$^子序列,比如 下面这段话:

The kernel is not trivial. Let $d$ be the smallest positive integer in the kernel. Then $d$ is called the period of $a$. If $m$ is an integer such that $a^m=e$ then $m=d s$ for some integer $s$. We observe that the elements $e, a, \ldots, a^{d-1}$ are distinct. Indeed, if $a^r=a^s$ with $0 \leqq r, s \leqq d-1$, and say $r \leqq s$, then $a^{s-r}=$ $e$. Since $0 \leqq s-r<d$ we must have $s-r=0$. The cyclic subgroup generated by $a$ has order $d$.

如果将这段话从QQ或者其他聊天软件中粘贴,在Siyuan中会变成:
image

如果从GitHub上面直接复制粘贴为"文本",则没什么问题,但是如果先复制为"转义文本",再复制为"纯文本",也会出现问题:
image

但我个人认为无论是直接复制粘贴,还是先粘贴成转义文本再粘贴为纯文本,都应该是:
image

其实这不是一个很大的问题,但是使用AI时也会涉及到这个“复制粘贴”问题,比如我将上面那句话使用AI翻译:
image
会出现和上面类似的错误。

Expected result

希望可以自定义符号的优先级或者自定义屏蔽某些符号在文本中的作用(比如上标我一般是直接ctrl + h,从来没用过^,那么我希望可以屏蔽这个符号对于文本的作用)。

或者直接改进这个“复制粘贴”本身。

Screenshot or screen recording presentation

No response

Version environment

- Version: 2.8.6 and later
- Operating System: Windows 11 enterprise
- Browser (if used):

Log file

siyuan.log

More information

No response

@xiaoheimissu
Copy link
Author

testing.txt
测试文本

@zxhd863943427
Copy link
Contributor

图片

无法复现你的结果。

@zxhd863943427
Copy link
Contributor

先转义后粘贴也不行
图片

@zxhd863943427
Copy link
Contributor

另外好像github也没法渲染你粘贴上去的东西。
图片

@xiaoheimissu
Copy link
Author

我的意思是说先粘贴为”转义文本“,再粘贴为”纯文本“,或者是直接从聊天软件中复制粘贴这段,你可以先将txt中内容发给你的一个好友,然后将消息复制粘贴到思源。

这个问题导致了从gpt发过来的信息中出现了上面的序列,也无法正确渲染。

@zxhd863943427
Copy link
Contributor

我的意思就是,先粘贴为”转义文本“,再粘贴为”纯文本“,不能复现你的结果。

不过从QQ发送的信息里复制倒是能复现,我猜测是QQ自带了一些转义字符。

但是从QQ发送的信息里复制,先粘贴为”转义文本“,再粘贴为”纯文本“,也能恢复正常。

@zxhd863943427
Copy link
Contributor

错了,我刚刚发现,先粘贴为”转义文本“,再“直接粘贴”才不会出现问题,粘贴为“纯文本”确实会出现。

@xiaoheimissu
Copy link
Author

是的,有时候直接粘贴为"纯文本"也会出现,txt中的文字是规范的latex或者markdown语法,按理说应该先渲染公式。

@zxhd863943427
Copy link
Contributor

zxhd863943427 commented May 17, 2023

不过,我认为对粘贴纯文本的处理是合理的,这不是错误,因为纯文本大概不包含数学公式,$会被过滤掉,这是有意为之。

粘贴以下这个例子足以说明。

The kernel is not trivial. Let $d$

@zxhd863943427
Copy link
Contributor

zxhd863943427 commented May 17, 2023

不过,这个解析确实出现了错误,体现在缺失了部分字符。

图片

@xiaoheimissu
Copy link
Author

是这样的,对于纯文本这样是合理的,而且这个问题并不严重,有办法解决,只要换一种粘贴方法即可(因为两种方法总有一种是正确的,当一种错误时换一种即可)。
但是当涉及到AI时,因为AI的回复中如果包含类似的内容,可能会产生不能解决的错误。
image

@xiaoheimissu
Copy link
Author

比如将上面的话翻译成简体中文,出于这个问题,它直接截断了

@zxhd863943427
Copy link
Contributor

这个需要去检查一下chatgpt的返回,因为它不一定就是写正确的……

@xiaoheimissu
Copy link
Author

是的,chatgpt不一定是正确的,而且每次返回的结果也不相同。但是你会发现这个和您上面图片中的不一致是一样的。
image
您上面的结果:
image
这一定程度上可以说明这两个结果应该有共同的原因。

@xiaoheimissu
Copy link
Author

当然其实我也不认为这个复制粘贴是一个错误,因为要平衡好各种类型的文本是一种比较困难的事情,如果是化学工作者它可能下标使用比较多,他可能希望 "_" 有最高的优先级 。因为我是数学工作者我数学公式用得就比较多,我”$“符号用得比较多,因此是否可以有一个可设置符号优先级,或者可以选择屏蔽掉某些符号的作用。比如,此处我希望屏蔽"^"符号。

@88250
Copy link
Member

88250 commented May 17, 2023

分析了下目前情况:

对于 粘贴为纯文本 目前的实现是将行级元素中的内容作为文本进行粘贴,丢掉标记符。但是带来的问题就是会导致内容本身自带的潜在标记符会参与后续解析,比如 foo $bar^2$ baz^3 粘贴为纯文本的过程是:

  1. 去掉标记符 foo bar^2 baz^3
  2. 后续解析 foo bar <sup>2 baz</sup>3

对于上述例子中截断解析的问题也是由于这个原因造成的,内容中带有 &lt; 后形成了 HTML 标签 <d,导致后续解析异常,内容被截断。

总的来说,对于 粘贴为纯文本 的设计意图是将行级元素内容提取,将这些内容作为普通文本插入,实现上没有考虑到内容自身需要转义以避免后续解析出现问题。

这个稍后我们会进一步确认,感谢两位反馈。

@88250 88250 self-assigned this May 17, 2023
@88250 88250 modified the milestones: 2.8.10, 2.8.9 May 17, 2023
@88250 88250 changed the title Bug of copy and past Improve Paste and Paste As Plain Text May 17, 2023
@88250 88250 changed the title Improve Paste and Paste As Plain Text Improve Paste and Paste as plain text May 17, 2023
@88250 88250 closed this as completed May 17, 2023
@88250
Copy link
Member

88250 commented May 17, 2023

v2.8.9-dev1 做了改进,各位有空的话帮忙测试,谢谢。

@xiaoheimissu
Copy link
Author

感谢D大的回复,后续版本都会参与测试。

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

No branches or pull requests

3 participants