sublime-evernote icon indicating copy to clipboard operation
sublime-evernote copied to clipboard

Feature: Leverage ExportHtml package for syntax highlighting

Open GrantGatchel opened this issue 10 years ago • 5 comments

Before finding this plugin, my workflow was to use @facelessuser's package ExportHtml to create the highlighting for my browser, then copy/paste the page into Evernote (since web-clipping doesn't work on local files).

I love this package, but I prefer the configurability and product of ExportHtml. Is there any way to make use of the ExportHtml package or commands to create the ENML content for the notes?

GrantGatchel avatar Jul 25 '14 13:07 GrantGatchel

Hi thanks for the feedback! can you elaborate on what's exactly the set of features that ExportHtml have and we do not support?

bordaigorl avatar Jul 25 '14 13:07 bordaigorl

It allows using either the native syntax highlighting definitions for the file type. You can also specify one specifically for exporting in case you prefer a dark theme in the editor but want to use a lighter theme for sharing or printing.

GrantGatchel avatar Jul 25 '14 14:07 GrantGatchel

So, if I understand correctly, you are not happy with the syntax highlighting provided by the Evernote plugin? This plugin uses Pygments to highlight source code (both in markdown raw blocks and in the clip to evernote command). If you are not happy with the theme you can use another one of the ones provided by pygments or even write your own. Generating the coloring from your ST theme is complicated, as witnessed by the complex design of ExportHtml. Reusing ExportHtml as it is is out of question for the moment as the plugin makes use of many features which are not supported by Evernote (javascript for example) so we cannot just get the html from ExportHtml and place it in the note's contents. Stripping the offending parts as a post-processing step seems very error prone and fragile (could break after a new release of ExportHtml) plus I really do not know enough about the ExportHtml plugin to know if it's possible to extract a plain HTML (no <style> no <script> no id= no class=) directly from its guts.

So, I am afraid, the answer is this will most likely never happen. But I am not opposing to it in principle, if there's somebody with enough knowledge of ExportHtml and time willing to contribute I would gladly review PRs based on this.

bordaigorl avatar Jul 25 '14 14:07 bordaigorl

I don't know much about the specifics of this plugin, and because of that, I neither encourage or discourage using ExportHtml with it, but I will just explain some things about ExportHtml for people.

  • ExportHtml was designed for two purposes:
    1. I wanted to paste HTML into emails and bbcode into forums that support it.
    2. I like using ExportHtml to paste code in slideshows.
    3. The last because I was having fun (which is why it also has silly features like annotations and color filters etc.).

Technically Pygments can be used for these purposes as well, I just liked the more in depth syntax highlighting you get from Sublime syntaxes and the massive amounts of available syntaxes (though I have written simple lexers for Pygments when needed at times as well).

Pygments is a fantastic option for embedding code in web pages, and I use it as well if I am placing code in an actual web page. I usually feel if you are pasting code into web pages, Pygments is nice, light, and frankly a better way to go.

Hypothetically Modifying ExportHtml

  • I believe all javascript can be removed by sending in the argument "toolbar": []. The javascript was just there for the toolbar providing accessibility. Oh, and don't use annotations as that adds some associated javascript. But no real modifications would be needed for this, just proper usage.
  • The current implementation of ExportHtml does embed all the styling in the tags. Originally, I placed all the styling in the CSS header, but since my main objective was to paste this in emails from my webbrowser, it was critical to move the styling out of the CSS header and into the actual tag's style attributes so they would copy and paste. This is also why I went through the trouble of placing all the code in a table instead of the more sane approach of just using spans; I needed the line to wrap okay with the gutter, and I needed backgrounds to look good in emails.
  • Yes it could probably be relatively easy to strip out ids, classes, styles, and even script tags if needed after the fact, but then you don't have the highlighting. To style it, you will need to use classes and CSS in the header or style attributes. This is no different than how Pygments does it, so I don't completely understand why all would be need to be stripped out (but again, I am not familiar with this plugin). I probably will not budge on moving the CSS to the header unless I had a way to process the HTML into a format I could paste into an email. Possibly an option to process the HTML with premailer would be sufficient https://github.com/peterbe/premailer.

Anyways, I am flexible on some things because I realize I am not the only one who uses ExportHtml, but I may not be so flexible if the modifications cripple my real world use cases. And I would probably require any changes to be made via a pull request as I am probably not interested in spending time to refactor for a use case I don't use.

On a plus side @bordaigorl, I will probably check out your plugin because it does look interesting. Anyways, hopefully I provided some insight.

facelessuser avatar Jul 25 '14 16:07 facelessuser

I just did a test.

  1. ExportHTML -> Sublime View - Color (without the "color_scheme" set to use the current highlighting).
  2. Edited the output to remove everything, leaving only the contents of the <pre class="code_page"> node
  3. stripped all "class" and "id" attributes
  4. Evernote: Send to Evernote as new note

When I find some time, I'll see about forking these projects and trying a few things

GrantGatchel avatar Jun 23 '15 14:06 GrantGatchel