Markdown to Evernote / ENML conversion

Hey guys,

I love to create notes in Drafts with markdown.
To “archive” or share them I want to use evernote.
Unitl now I just use an action which creates a note with converting the template [[draft]] via output format markdown and the [[safe_title]] for the note.

Its working but in evernote the formatting is not looking very good. E.g. the vertical Space between headlines and bullet lists and so on. I didn’t found any solution within evernote to change this in the note manually… Using HTML conversion of the draft and afterwards creating a note in evernote with ENML output format has the same result.

So I wanted to ask of anyone has a better action to parse markdown notes into evernote.
I havent found anything like a javascript converter from markdown to ENML, thats why I’m asking…

I’m noticing an issue with Evernote not showing markdown code blocks. The ENML template output throws an error when I set it, does Evernote support ENML now?

ENML is “Evernote Markup Language”.

Perhaps you could share details of your error and a test case to produce it?

I don’t think Evernote has any support for the <pre> and <code> tags, which are what is output by a Markdown code block. Those tags are permitted in ENML, but I think they are just ignored in Evernote’s own apps and I don’t know of any way to actually generate them in their apps.

Might get some insight from the ENML reference if you are actually trying to generate the raw ENML.

That fits with my experience
a. Using the ENML template returns error every time
b. The docs refer to <code> and yet it is not recognized
I wonder if ENML is deprecated those docs are old.

ENML is definitely not deprecated. If you are getting an error using ENML format, it’s likely you are sending invalid ENML. It is a XML format and Evernote strongly validates every incoming note. The Text and Markdown formats let Drafts take care of that for you, but if you use ENML, you need to be absolutely sure your template output fully valid ENML - including entity encoding, matching open/close tags, only tags that are valid in ENML, etc.

So Drafts 4 has an option for an xhtml parameter Drafts 4 Templates with this format

By default, HTML5 compliant HTML is generated, but if you include the xhtml parameter, like %%xhtml|…%%, XHTML will be output.

Now I know Drafts 5 drops this because I tried but it is also not in the documentation

So how do I get ‘valid xhtml’ in Drafts 5?

For the most part MultiMarkdown already produces valid XHTML, but there are input texts that can produce tags that are not valid.

It would be helpful if you provided sample actions you are using. Also, affected by text used as input? What is in the action log as an error?

Using the ENML template type is really not recommended unless you have a very advanced requirement. It’s very error prone since the validation is so strict.

Not sure I can give you the level of detail you require I am at my Mac, but here is the protocol I followed.

  1. duplicated an existing action that sends markdown to Evernote, action imported from Drafts 4 seems vanilla to me uses the default Evernote action
  2. change the template to ENML and save the action
  3. action runs action log shows invalid ENML

Specimen text, let me see if I can avoid the formatting

# Example with code block

for (i=1;i++;i<10)

Some text

Well, minimally, that will not produce valid ENML, because the < needs to be entified to &lt;.

It would also not produce the results you want. There would be no line breaks (because you would need to insert paragraph or <br/> tags), etc.

Evernote just doesn’t think in plain text. You have to turn it into ENML (basically HTML).

Just to be clear I showed you standard markdown there were no HTML tags in the sample text. So do you expect me to write a script to do this?

If you are following on email you will miss my intent I was correcting for the forum markup.

So one of the things I tried was using the %%[[draft]]%% template and adding opening and closing tags <en-note>. It didn’t work so I thought I would bring it to your attention because I tried everything I could think of.

I’m still not sure what you are trying to accomplish, or how it would affect rendering on the Evernote side.

If you use “Markdown” as the type, you are telling Drafts the output of the template is Markdown, and it will run it through your default Markdown engine to convert it to HTML - including doing things like handling HTML entities. That is going to generate <p> tags for blocks, <ul> tags around lists, etc., wrap that in the proper en-note information and upload it to Evernote.

You could script the generation of those HTML tags to manually create ENML output in the template, the Evernote as Todos is an example of doing this - but the result in Evernote would be the same. You still have to have a <p> tag to get a paragraph, and there is no way to influence the way that will be spaced in Evernote - they don’t support HTML styling or CSS to influence the layout.

No I am going down a rabbit hole here what I am trying to accomplish is to recognise the code block and you answered that above, it’s not possible.

Using the ENML with %%[[draft]]%% is entirely equivalent to the standard markdown action and has identical results, I see that now. There doesn’t seem any need for me to continue down this path. I do think the documentation page on the Evernote site hasn’t been updated recently.

For reference if you type three back ticks and press return the Evernote app will create a code block. This is fine as a manual procedure but I wanted to use it in Drafts.

Out of curiosity, I enabled the back tick option in Evernote’s advanced editing settings and exported the ENML.

Original Note

Exported ENML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
 <!DOCTYPE en-note SYSTEM "">
 <en-note><div><br/></div><div><br/></div><div style="box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902);-en-codeblock:true;"><div>Xxx</div><div>Yyy</div><div><span style="font-size: 12px; font-family: Monaco;">Zzz</span></div></div><div><br/></div></en-note>

It looks like Evernote is applying some styling rather than a true HTML compliant rendering of a code block.

Maybe you could reproduce the format with a template in Drafts and push it as HTML to Evernote?

That’s interesting I was wondering if you could do that. However a bit too much for me right now still slightly baffled by some of these replies.

I think I will leave this here I did try some scripting but got bogged down with regex couldn’t even get a string replace to work with all the escaping etc.

But this seems to be the minimal ENML to get the right results using the Evernote action.

<h1>Example with code block</h1>
<pre style="-en-codeblock:true;"><code>for (i=1;i&lt;10;i++)
<p>Some text</p>

I built an action for this :slight_smile: Save to Evernote (Full Formatting)