asciidoctor-intellij-plugin icon indicating copy to clipboard operation
asciidoctor-intellij-plugin copied to clipboard

Convert on paste

Open bodiam opened this issue 8 years ago • 13 comments

Find out if it's possible to convert Markdown or HTML to AsciiDoc on paste.

bodiam avatar Jul 22 '15 21:07 bodiam

:+1:

mojavelinux avatar Jul 22 '15 21:07 mojavelinux

That sounds nice, but I am not really sure what exactly you have in mind. Do you think about a 'special' command paste md to ad, or do you think we could detect that automatically and plug into the existing 'paste' action?

I think the later would be better if it could be implemented properly. But what if I want to paste a piece of code literally that includes md or html?

fwilhe avatar Oct 28 '15 13:10 fwilhe

The idea was to autodetect. With HTML, it's quite easy, but with markdown a little bit trickier. I thought it would be a nice feature, not very useful, just nice to build.

bodiam avatar Oct 28 '15 20:10 bodiam

Any formatted text in the clipboard seems to be available also as HTML.

With #1074 in place, the plugin now downloads Pandoc on demand for conversion of HTML to AsciiDoc.

The class AsciiDocPasteProvider already hooks into the paste provider, and could take the HTML out of the clipboard.

The class CreateDocxAction already shows how to call Pandoc that could do the conversion.

With that, a lot of building blocks are already in place. I'd be happy to lend a hand to anyone who wants to give it a try.

ahus1 avatar Jun 26 '22 10:06 ahus1

I have never used Pandoc to convert directly from HTML to AsciiDoc, but you would have to look at the quality of the conversion. I have mainly used Pandoc to convert from AsciiDoc to docx.

So far, my idea has always been to use a web clipper that saves the content as Markdown, and then use kramdoc to create adoc from it if needed. This works quite well so far.

One would have to imagine then probably in such a way that there is for HTML files in the context menu a point, which converts with Pandoc into AsciiDoc? Like now from AsciiDoc to docx?

And on Markdown files there could be a menu item to convert to AsciiDoc with kramdoc?

Since I have little experience with Java myself, I can't get involved there practically, unfortunately.

aisbergde avatar Sep 24 '22 19:09 aisbergde

@aisbergde - there is already the option in the plugin to convert a Markdown file to an AsciiDoc file. It is available from the context menu when you right-click into an markdown file.

image

Maybe that can be a workaround. At the moment it uses a different library than Kramdown, see #257.

Once the "convert on paste" is implemented, I imagine it to work as follows: (1) Copy the contents of a web page to the clipboard, then (2) paste the contents from the clipboard in an existing AsciiDoc file. As part of the second step the plugin would call the HTML-to-AsciiDoc conversion.

Even if you don't participate in the Java development, maybe you can help testing it.

ahus1 avatar Sep 24 '22 19:09 ahus1

Very happy to help with testing!

I am not clear about the first step: "Copy the contents of a web page to the clipboard".

This would require the content to be copied as HTML, right? But if you just copy, then you get what you see, not the HTML content? Or would that be an extra menu item?

I think this would be a good extension for the already existing plugin https://github.com/asciidoctor/asciidoctor-browser-extension There this would fit somehow well in terms of content. Maybe it should be suggested in this extension?

This could also be discussed further in the Zulip chat.

aisbergde avatar Sep 25 '22 17:09 aisbergde

Copy the contents of a web page to the clipboard

AFAIK most of the time when a user copies formatted text to the clipboard, that content is then available as HTML to the application where it is being pasted to. So the standard "copy to clipboard" for example from MS Word or a web browser could enable the IntelliJ plugin to convert the contents on paste to AsciiDoc using pandoc or any other mechanism that is capable to convert HTML to AsciiDoc.

ahus1 avatar Sep 25 '22 17:09 ahus1

With pre-release 0.37.51 there is now a version that allows pasting formatted text. As usual: The pre-release of the plugin is available from GitHub releases and the IntelliJ AsciiDoc EAP repository.

There's a new toolbar icon image. The first time it is pressed, it will download the Pandoc binary. It will take the formatted clipboard contents (that actually arrive as HTML), and convert it using Pandoc.

It works with copy-and-paste from rendered GitHub content, and you can copy also things from the Markdown preview in IntelliJ. I was also able to copy formatted content form a Word document and it got converted.

The standard Ctrl+V is still using the standard paste of non-formatted text. To change the standard paste, go to the plugin's settings and enable it (see picture below). I might enable it by default later once I'm confident that it works good in all scenarios ... still uses will be surprised when they trigger a download when pasting formatted content for the first time.

The conversion is done by Pandoc, so I don't have control over the conversion itself. For any problem that turns up in the conversion, we can discuss it here and then create an issue "upstream" in the Pandoc project.

Please give it a try and leave some feedback here so I know if something needs to be changed.

Eventually it could work also to convert Markdown content, unfortunately I haven't yet figured out how to auto-detect this

paste-formatted-text

image

ahus1 avatar Oct 02 '22 10:10 ahus1

I realize that you need both: normal paste, and converted paste. If the data is always converted, you have to post-process it. And you need to be able to decide when to insert the content converted.

Ideas for this:

  • different shortcuts for the two different actions
  • or "normal" insertion by default, and with the second shortcut an action menu is opened, which then allows different insertion options.

aisbergde avatar Oct 08 '22 11:10 aisbergde

Thank you for the feedback and testing this functionality!

IntelliJ already has a shortcut "Past as plain text", on Windows with the shortcut Alt+Ctrl+Shift+V. If you enabled the past with conversion in the plugin's settings, you can still use this shortcut to paste as plain text. If you find this shortcut to difficult, you can change it in the IDE's settings in section "Keymap".

If you choose not to enable the checkbox in the plugin's settings, you can use the icon with the mouse in the menu bar to paste formatted text when needed. In IDE's settings in section "Keymap" you can add a shortcut of your personal choice for that menu item. I wouldn't add a default shortcut to this, as shortcuts are a scarce resource in IntelliJ.

Please let me know which one you prefer. I'll add that information the the plugin's help after your feedback.

ahus1 avatar Oct 08 '22 11:10 ahus1

Thanks for the hints! I will test what works better: normal Past as default and using the icons for special Past seems very reasonable and intuitive to me. Because you can also use the icons to insert images and save a copy.

aisbergde avatar Oct 08 '22 13:10 aisbergde

This convert on paste is a really great idea!

The functionality was tested with a few iterations, each time "simplifying" the Word document. The following notes are more perhaps to do with Pandoc and the input file than the plugin.

  • Bullets were not converted, requiring search and repace
  • Headings had markdown link syntax eg == [#_Toc118247047]##[#_Toc1415457835]#Summary#
  • Code blocks were not transferred (Some success by indenting each code line one characer before conversion)
  • Tables: 3 column table prefixed by [cols=",,",]
  • Admonitions, eg NOTE: note text, were not converted to admonitions.

A cleaner AsciiDoc result was obtained by:

  1. converting the file to markdown first: Tools > Markdown converter > Import word document
  2. converting the markdown to AsciiDoc: Right click > Refactor > To AsciiDoc

Thanks for a really good evolving plugin!

sturtison avatar Jun 13 '23 20:06 sturtison