Jump to content

Paste ENML from another Windows application


Recommended Posts

I've written a C# application which places ENML on the Windows clipboard so that to-do items with checkboxes can be pasted into an existing note. However, Evernote refuses to paste the ENML. It appears that Evernote requires a "Cookie" value that it generated on its own. If there's some way around this, I'd love to know.

When the Windows clipboard has content copied from within Evernote, the clipboard includes a data object with the format type "ENML Format". For example, if I copy "Chirp Chirp" from a note within Evernote for Windows, I see the following data on the clipboard, associated with the "ENML Format":

<en-clipboard Cookie="6479053"><en-note>Chirp Chirp</en-note></en-clipboard>

Where did that "Cookie" value come from? I've tried leaving it out, and Evernote refuses to paste. I've also tried reusing a value that was generated by Evernote, and that actually works... until I exit and restart Evernote. I could require the user to copy something from Evernote and then click a button in my application that captures the "Cookie" value that Evernote placed on the clipboard, so that it can be reused when pasting my content into Evernote, but that's obviously not a reasonable approach.

I checked the ENML DTD, and there's no mention of the "en-clipboard" element. This is specific to clipboard data, and I can't find any documentation on what it is and how to avoid it or generate a valid "Cookie" value.

I also posted this question on Stack Overflow.

Am I doing something wrong? I can't just paste HTML into Evernote, because there's no way to represent Evernote's checkboxes in HTML. I'm happy to use ENML... but I need a way to get Evernote to accept it. Thanks in advance for your help!

Link to comment

As a workaround, I was able to paste HTML into Evernote and have it convert brackets into checkboxes, using the same span style I was using in ENML. While I would prefer to find a way to paste proper ENML into Evernote from another Windows application, this gets me what I need right now.

Here's what the span style looks like, with an unchecked checkbox:

<div><span style="-en-todo:true;">[]</span>Daily To-Do Item</div>

I went into a little more detail on Stack Overflow. But I'm still hoping to crack the mystery of the "Cookie" attribute in Evernote's ENML clipboard payload.

Link to comment

Hi @hij

Well done teaching yourself ENML! I've never messed around with the ENML format myself. But, from using EN, I would guess that pasting ENML into a EN note requires some form of authentication, while pasting HTML (or text, or any non-ENML content) into a note piggybacks on the permission that the app receiving the paste (e.g. EN for Win) already has. If so, you would get the cookie from a browser session that is logged in to www.evernote.com, or possibly, from the EN for Windows client, or from the EN "Clip to Evernote" extension in your browser. I don't know how to access those values using C#, but perhaps you do? I imagine you'll have to deal with safe code vs. unsafe code, application boundaries, and other tricky stuff, in order to get your C# app to query a browser or another windows app for the cookie. Perhaps it might be easier to have your app create it's own https connection to EN, store your login credentials, and get a cookie that way?

Back when I did C# programming in 2008, I found MSDN Magazine, https://msdn.microsoft.com/en-us/magazine/ to be VERY helpful with these sorts of issues. Virtually all their articles come with sample code.

Maybe when you get it working you'll post more about what you learned?

Good luck!

Link to comment
  • Level 5*
21 hours ago, John in Michigan USA said:

Well done teaching yourself ENML!

Handy Evernote-written reference here: https://dev.evernote.com/doc/articles/enml.php. It's mostly an HTML subset (or more precisely, XHTML), with some Evernote-specific additions.

The <en-clipboard> element isn't part of the above; so it's hard to tell if it's a Windows-only thing,, at least for me, since I don't use Mac  It's probably not part of ENML, since it's used by the application only for clipboard stuff. Not sure why it's needed (since on Windows, it's recognizable as an ENML clip in the clipboard),  unless maybe the cookie is being used to identify the logged-in account (you can have more than one open at a time -- I'll need to test this at home) it comes from for some reason; even so I'm not sure what that would matter.

Link to comment

That makes sense. Thanks! But... I've experimented with pasting ENML that was identical to ENML placed on the clipboard by Evernote -- except that I left out the "Cookie" attribute. Even simple examples were rejected by Evernote. If validation is the cause of this rejection, is there any way I can find why the ENML is not passing validation? Should I be validating against the DTD?

Link to comment
  • Level 5*

Another thought: are you adding the clip as "ENML Format"? You might want to look at , e.g., https://docs.microsoft.com/en-us/windows/desktop/api/Winuser/nf-winuser-, though I'm not sure that's the issue, but I expect that Evernote will prefer ENML Format over others that are also on the clipboard. It is curious that they need to also validate a cookie; maybe it allows them to assume that the clip is valid ENML, and is safe to paste into a note, maybe???

Link to comment
31 minutes ago, jefito said:

Another thought: are you adding the clip as "ENML Format"?

That would be key. Different formats on the clipboard are handled differently. Just pasting ENML as text is not going to work.

  • Like 1
Link to comment

Yes, I specified in the original post that I'm setting the format to "ENML Format". And this actually works if I inject a "Cookie" value that I picked off the clipboard from a copy action that was initiated in Evernote.

It occurred to me that there might be some helpful info in Evernote's "Activity Log" (accessible via the Help menu)... and there is!

This is the error I see when I attempt to paste ENML that has no "Cookie" value specified:

15:09:47 [ERROR  ] [15544] [14384] Could not paste ENML: validation failed.
15:09:47 [ERROR  ] [15544] [14384] Validation failed: no DTD found !

I realized that I had not specified a DTD within my XML. (When Evernote places ENML on the clipboard, it doesn't include the standard XML headers... which makes sense, since it sees the Cookie and concludes that the ENML does not need to be validated. As a result, I had assumed that I didn't need to specify a DTD, either.)

When I added the xml and DOCTYPE headers, the errors went away... but pasting still does nothing. Here's the ENML I'm using for testing purposes:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">
<en-note>Hello world</en-note>

I found that I had to remove the <en-clipboard> element, or else I would still get the "no DTD found" error... which makes sense, since <en-clipboard> is not defined in the DTD.

I added code to locally validate my ENML against the DTD, and it passes validation. @dconnet - Any recommendations on next steps?

Link to comment

I suspect we've never even considered users trying to use this as a clipboard format since it's really intended for internal purposes... First, the root element must be "en-clipboard" or we ignore it. I'd have to actually trace into the code to see how validation is expected to work...

  • Thanks 1
Link to comment

Thanks for the quick response. Since I'm able to paste to-do checkboxes using HTML and the span stlye that I borrowed from an ENML sample...

<span style="-en-todo:true;">[]</span>

... there's no urgency on my part to get support for pasting ENML from another Windows application. I was pursuing it more as a matter of general interest, because I've found it valuable to be able to generate formatted text in another application and paste it into my notes, and being able to do so with ENML would open up a full set of possibilities.

Since the <en-clipboard> element is expected as the root element, and ENML pasted without the Cookie attribute is expected to conform to the DTD -- which is not included in the ENML DTD -- I think there's a catch-22 here. Evernote for Windows would probably have to be modified to accept a DTD-conformant ENML document from the "ENML Format" clipboard payload when the root element is not <en-clipboard>. Since there appears to be very little demand for this, I would 100% support treating this as a very low priority feature request.

Link to comment
  • 8 months later...

Hi,I have this question too.

I'm going to edit evernote notes quickly, which need to paste ENML source code to evernote so that i can control the content.

however, the evernote reject the copy, 

<en-clipboard Cookie="3311036"><en-note><h1>1223311133331111222212233111333311112222</h1></en-note></en-clipboard>

even I copy the content from evernote firstly, and then rewrite the content to ENML Format. after ctrl v, noting happened.

 

Did you deal out this problem? 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...