telesoho / vscode-markdown-paste-image

Smartly paste for Markdown.
MIT License
135 stars 41 forks source link

HTML conversion is not working 未能将HTML tag转换为Markdown #44

Closed JeffersonQin closed 2 years ago

JeffersonQin commented 3 years ago

插件版本:v0.13.3

复制内容:

image

输出:

image

telesoho commented 3 years ago

@JeffersonQin 转换HTML tag为Markdown的功能没问题呀,你发的图里也没包含html tag。

JeffersonQin commented 3 years ago

嘶.... 我是复制的浏览器的内容,理论上剪切板中应该包含HTML tag的(Windows下测试的)

JeffersonQin commented 3 years ago

我举个例子: 下图是我复制的内容:

image

下图是剪切板的输出:

image

命令:

Get-Clipboard -TextFormatType Html
telesoho commented 3 years ago

由于我不用Windows和Mac,目前只完成了Linux中把HTML转换为Markdown的功能。我曾经尝试过在Windows中使用powershell去获取剪贴板中的内容,但是当时windows中有一个bug,如果剪贴板内容中有中文或日文字符时,将剪贴板中的文本转换为UTF编码会出现非法字符,导致无法取出正确的剪贴板内容,所以就放弃了。

目前如果在windows下想使用HTML转换为Markdown的功能,可以通过直接拷贝HTML的代码,然后用插件粘贴到markdown里,插件会判断粘贴的文本中是否带有html的tag的标记,如果有它就会尝试转换。

JeffersonQin commented 3 years ago

我找到解决办法了。这两天正好在写WPF,之前也接触过Clipboard类,可以用类似的办法:即,WPF (.NET) 封装好的函数来调Clipboard

代码:

Add-Type -Assembly PresentationCore
[Windows.Clipboard]::GetData([Windows.DataFormats]::Html)

image

Reference:

JeffersonQin commented 3 years ago

您这边不方便用win对吧,这个反正也不急,我过两天有时间研究一下写一下,提个PR上了,到时候麻烦您看一下

telesoho commented 3 years ago

@JeffersonQin 太感谢了!!!

lukebrowell commented 3 years ago

Would you consider making the extension handle more complex paste-types (regardless of platform/language/localisation), so as to meet with the reporting user's expectations?

Have a look at how clipboard2markdown works.

Complex Clipboard type handling code

A more detailed explanation of how it works

I'd raise a PR with some nice recursion to handle inlining images from within Web-page copies, but I'm maxed-out at work at the moment.

telesoho commented 2 years ago

@lukebrowell This extension also use to-markdown lib to convert html to markdown too, but it only work on Linux. Vscode is not a web browser, it seem does not support document.addEventListener API, so it is a troublesome thing to get complex clipboard type in vscode.