andre-simon / highlight

Source code to formatted text converter
GNU General Public License v3.0
206 stars 58 forks source link

Feature request: possibility to paste into web WYSIWYG editors #32

Closed ferenczy closed 6 years ago

ferenczy commented 6 years ago

Sometimes, I need to paste a formatted source code in a browser (usually some WYSIWYG editor, for example on visualstudio.com). But when I copy the code as an HTML using Copy preview to clipboard in Highlight and paste it in the browser, it pastes the HTML source code instead of the formatted text. That's not so surprising. But it wold be good to have such possibility.

I would say that it should be enough to just add one more format when copying into the clipboard - HTML Format.

Currently, Highlight copies the following clipboard formats on Windows:

When I copy the formatted source code from some online code highlighter, I can paste it into a web WYSIWYG editor without any issues. The clipboard contains the following formats:

The Win API format ID for HTML Format is 49521.

Thank you.

andre-simon commented 6 years ago

The RTF output format adds a Rich Text MIME type to the clipboard format. Possibly the Visual Studio Online editor supports RTF. But I will also test the HTML MIME type. Which online highlighter was used for pasting working code?

ferenczy commented 6 years ago

I have tested it with the RTF output format but then it doesn't paste anything into the WYSIWYG editor.

  1. Pasted a piece of code into Highlight
  2. Selected RTF output format
  3. Clicked Copy preview to clipboard button
  4. Tried to paste into the WYSIWYG editor - nothing pasted (with the HTML output format it pastes an unformatted HTML code)

Regarding the online highlighter - probably any one, I have tested for example hilite.me.

andre-simon commented 6 years ago

The next release will contain an option to add HTML MIME type. This works when pasting code into a word processor like LibreOffice.

andre-simon commented 6 years ago

Done in v3.41. The new checkbox is located in HTML options -> Misc. Please reopen if it does not work for you.

ferenczy commented 6 years ago

Thank you Andre. It's working properly with MSIE now, I can paste a highlighted code with proper colors and background but it's not working with Vivaldi browser (it's based on Chrome), unfortunately. I'm not sure, what might be wrong here, it's not pasting anything.

Tested with the version 3.42.

andre-simon commented 6 years ago

I have tested this with HTML and several browsers. As there is no universal RichEdit web control each web application and browser may support different kinds of markup. Some will support HTML with inline CSS, without header and footer (ie html, head, title, body tags). Another option to play with is to toggle the enclosing pre tag. This applies to the GMail mail editor or the MS Team Services Wiki.

I think the MIME type is not relevant for browsers, this is being accepted by "old school" editors for RTF.

tajmone commented 6 years ago

Maybe Highlight's output HTML block could be copied to the clipboard as plain-text, which should pass any MIME-filtering, and then let the destination app backend to its filtering job (ie: remove unallowed tags, scripts, etc.)?

Either the destination app filters the submitted HTML contents or it would leave them as they are.

andre-simon commented 6 years ago

HTML as plain text is the default, the MIME option was added as "experiment". Only RTF is copied with a fix MIME type as there is no need for plain RTF.