Jump to content

Quick way to format text that is a code snippet?


Recommended Posts

  • 5 months later...
  • 1 year later...

You can format your code with an online tool like this one: http://tohtml.com/ and then copy and paste into evernote.

 

Cool - thanks for the tip.

 

  • CAVEAT, as of Evernote 6.0.6 for the Mac  Copying a formatted snippet created at http://tohtml.com/ into Evernote then produces garbled results (line breaks are replaced with spaces) when later copying from Evernote elsewhere (such as into a plain-text editor).
    • Workaround: If the selection in Evernote contains at least 1 line OUTSIDE of the originally pasted code snippet, copying works fine.
    • Upshot: You can't (easily) copy parts of such code snippets elsewhere.

I don't know the reason - it may be specific to the HTML generated by http://tohtml.com/.

 

[Edit: clarification added after feedback from @jefito]

Link to comment
  • Level 5*

 

You can format your code with an online tool like this one: http://tohtml.com/ and then copy and paste into evernote.

 

Cool - thanks for the tip.

 

  • CAVEAT, as of Evernote 6.0.6: Copying a formatted snippet into Evernote then produces garbled results (line breaks are replaced with spaces) when later copying from Evernote elsewhere (such as into a plain-text editor).
    • Workaround: If the selection in Evernote contains at least 1 line OUTSIDE of the originally pasted code snippet, copying works fine.
    • Upshot: You can't (easily) copy parts of such code snippets elsewhere.

 

This does not hold true for all Evernote clients and most likely also depends on the source of the snippet.

 

For example, with the current Evernote Windows client (5.8.4.xxx), snippets from Visual Studio are put on the clipboard in Rich Text Format with syntax highlighting and Unicode. Evernote recognizes Rich Text and renders it pretty faithfully (font sizes don't always seem to quite match up), whereas NotePad++ only puts plain text formats on the clipboard, so no syntax highlighting is transferred, and the result is rendered in your default font in Evernote. In both cases, line breaks are honored.

Link to comment

 

Thanks - I've since clarified that I was talking about the Mac client and made it clearer that I was talking about snippets from http://tohtml.com/.

 

Good to hear that it works well on Windows, but just to clarify: does it work OK when you copy a previously pasted RTF snippet back out of Evernote? The Mac / http://tohtml.com/ issue isn't one of faithful rendering, it's a problem of copying the snippet out of Evernote elsewhere later.

Link to comment
  • Level 5*

Seeing as how this is a general topic, it's good to clarify your platform, and also whatever other software you're using in the chain. I don't know how the Mac clipboard works (if that's what they even call it), or how Evernote for Mac works in this respect.

 

In the Windows Evernote client, I find that the snippet that I pasted from Visual Studio, when copied in Evernote, is put on the clipboard in several text formats, HTML, and Evernote's own ENML format. Everntoe doesn't store RTF, though it can interpret it and convert it to its own internal format (ENML, essentially). Depending on where you put it, it will be handled differently, as that's dictated by the formats that the target program can handle. It came in fine into Visual Studio, which I assume just read one of the text formats available, and did its syntax highlighting. Ditto for the NotePad++ text snippet.

 

There's no guarantee of round-tripping in and outr of Evernote, because Evernote concerts anything that comes in into its own HTML-ish format. When it goes out,that's the basis...

Link to comment

Thanks for the useful background info about formats.

 

Understood re round-tripping, but in the case at hand the round-trip (even to plain text) is fundamentally broken (newlines replaced with spaces).

 

The problem does appear to relate to the HTML created by http://tohtml.com/, and I've let the maintainers know, but here's what makes me think the problem is on the Evernote side:

 

  • Copying the same HTML to TextEdit (a text editor that comes with OS X) and then from there back elsewhere (whether to plain text or not) works correctly.
  • In Evernote, including just one line *outside* the pasted snippet when copying back out makes the problem go away.

One thing that is unusual about the HTML created: The newlines in the formatted code are represented as *literal* newlines, not as markup.

 

(Re clipboard terminology: I think that "clipboard" is the term used these days on the Mac too, though you can find references (even in the names of CLIs) to "pasteboard" on occasion, due to OS X's NeXTSTEP heritage).

 

Seeing as how this is a general topic, it's good to clarify your platform, and also whatever other software you're using in the chain. I don't know how the Mac clipboard works (if that's what they even call it), or how Evernote for Mac works in this respect.

 

In the Windows Evernote client, I find that the snippet that I pasted from Visual Studio, when copied in Evernote, is put on the clipboard in several text formats, HTML, and Evernote's own ENML format. Everntoe doesn't store RTF, though it can interpret it and convert it to its own internal format (ENML, essentially). Depending on where you put it, it will be handled differently, as that's dictated by the formats that the target program can handle. It came in fine into Visual Studio, which I assume just read one of the text formats available, and did its syntax highlighting. Ditto for the NotePad++ text snippet.

 

There's no guarantee of round-tripping in and outr of Evernote, because Evernote concerts anything that comes in into its own HTML-ish format. When it goes out,that's the basis...

Link to comment
  • Level 5*

I think that Evernote uses div's to delineate text lines in its markup. If HTML with newlines and no divs comes in to Evernote, it's most likely interpreted as generic HTML; no line breaks. TextEdit may interpret the same thing differently. I've pretty much exhausted all I know about this stuff at this point, though. Happy spelunking!!

Link to comment

I think that Evernote uses div's to delineate text lines in its markup. If HTML with newlines and no divs comes in to Evernote, it's most likely interpreted as generic HTML; no line breaks. TextEdit may interpret the same thing differently. I've pretty much exhausted all I know about this stuff at this point, though. Happy spelunking!!

 

Thanks again.

 

One for the road: Evernote clearly recognizes these line breaks when *rendering* - everything *looks* as expected. The line breaks only disappear on *copying* (and can be made to reappear with my expand-the-selection-beyond-the-snippet trick).

Link to comment
  • Level 5*

Thanks - I've since clarified that I was talking about the Mac client and made it clearer that I was talking about snippets from http://tohtml.com/.

 

With respect to EN Mac, I have found that pasting formatted code from AppleScript editor into an EN Note initially looks great, maintaining all fonts, colors, and indents.

 

Unfortunately, once I click to another Note, and then back the one with AppleScript, the indents are removed.

Why would this be?

Link to comment
  • 4 weeks later...
  • 2 months later...
  • 1 month later...

i need that feature ASAP. Please add it to evernote soon :(

 

all the workarounds are not worth the time :(

 

I love and use Evernote a lot.

but it's just too tedious to make a note

with code snippet on Evernote.

 

for now I use Quiver

that has a dedicated "code cell" within it

(with line number, syntax highlight, etc)

 

it'll be great if Evernote can add a feature like this.

Link to comment
  • 6 months later...
  • 2 weeks later...
On 2016/2/1 at 0:49 PM, The Dev said:

Great solution! I find, however, pasting to evernote windows will make it FORCE CLOSE. Maybe the style code contained is parsed by evernote abnormally?
like this gif demonstrated (4mb): Animation.gif

 

and another fantastic way, like this post said, using "copy as rtf" feature of sublime text/notepad++/ultraedit, to paste code with style, also have an problem.
Evernote will add extra spaces, like this gif demonstrated (900K): Animation1.gif

 

really hope there's a better way.

Link to comment
  • 1 month later...
On 2/1/2016 at 11:36 AM, Metrodon said:

Code blocks in the latest Mac beta apparently

I just accidentally did this in Evernote on Mac v6.6 (453323). I typed ``` then hit enter and it gave me this:

Training_Plan_—_Evernote_Basic.png

I was then able to type code into the box. Note, it seems if you're font is already set to a monospace font it won't work, it also won't work if you type it while indented more than one level in a bullet. I haven't figured out how to specify code highlighting or anything.

I had a hard time finding anything official that mentioned this update. After looking for a while, I found this post that introduces it as a beta feature in v6.5 for Mac: 

Even though I have v6.6 for Mac, I can't find a post that announces its release or gives more clarifying details as to how the feature works. UPDATE: I'm keeping that line even though the post DOES exist, it just seems that searching the forums kind of sucks. Google found it for me, though: 

But again, no mention of the feature or how to use it. I'm happy that Evernote is going in this direction and I have high hopes it will keep getting better. What it needs now is code highlighting and it would also be great to enable in-line code snippets with single back tick, like in markdown, even if it was only an option you had to enable in preferences/settings.

Also, it looks like this is coming in Evernote for Windows v6, which is in beta right now: 

 

 

Link to comment
  • 1 month later...
  • 7 months later...
  • 5 months later...
  • 3 months later...
  • 2 months later...
  • Level 5

@Shubham Aggarwal This is actually my fault! I was doing some work cleaning up/merging some older posts and I believe that particular one may have been removed. (I'm currently searching for it, but it may not be possible to get it back.) @GrumpyMonkey Any chance you'd be gracious enough to provide some insight if you still recall?

 

 

Link to comment
  • 4 weeks later...
  • 1 month later...
  • Level 5*
On 4/16/2018 at 4:10 PM, julen said:

I cannot see ant reasonable justification why this feature is implemented in Windows but not on Mac.

If you are referring to the code block, it is working fine for me, running Evernote 6.11.1 (455059) on macOS 10.12.6:

5ad67af0de2ae_2018-04-17_17-52-12(2).png.23159f05d3f35fe430f09a2951d04fb5.png

Link to comment
  • 5 months later...

It is really sad evernote desktop application does not handle code well. The code block removes identation and tries to keep the color from the IDE marking, but the palet is all wrong so it uglifies everything.

A simple markdown solution from ``` or something custom doesn't look like a hard thing to add. Also, it just adds injury that the forum has this feature. 

Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...