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

ir模式获取选中的markdown原文 #1495

Closed
FantasticPornTaiQiang opened this issue Nov 7, 2023 · 1 comment
Closed

ir模式获取选中的markdown原文 #1495

FantasticPornTaiQiang opened this issue Nov 7, 2023 · 1 comment

Comments

@FantasticPornTaiQiang
Copy link

问题描述

ir模式下:

根据文档,选中一段selection,vditor实例有insert/update/deleteValue等方法可以操作选区文本,唯独没有根据选区获取markdown原文的方法

只有getValue方法获取整个文档的markdown原文,或者getSelection方法获取选区的innerText(非markdown原文)。

自答

想了一下,vditor在复制粘贴时,可以粘贴出与原文一模一样的内容,因而按理说markdown原文应该是存在的、可以被获取到的。因此,利用模拟复制操作,执行document.exec('copy')复制,然后用clipboard.readText()就可以读到markdown原文了。但感觉这算是一种投机的方式。

提问

不知道有没有其他直接能够获取选区markdown原文的正常方法?

@Vanessa219
Copy link
Owner

试一下获取后使用 html2md

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