Diffs on versions

Could diffs be added to Versions, so I can see where content was lost, like it seems to have been twice today

(I don’t want to do any more log dumps and analysis – I know sync is as good as it can be on iCloud)

I haven’t done any deletes today (17:34 drop to 19202c), and I’ve pulled more than 300c of content out of versions that wasn’t in the latest, so the 19654c wasn’t just a late true-up

Diffs (with copy of deletions) would help make the occasional hiccups pretty easy to recover from

1 Like

There is the Diff action by @jsamlarose that I would typically refer people to.

I haven’t used it in a while, and today when I tried it on a test draft I created, instead of outputting <del> and <ins> tags for the output in the body of the HTML, it is outputting HTML comments for me. I did a very quick check and it looks like the Markdown to HTML rendering is affecting it.

<!-- PRE-RENDER -->
<del>Abc
</del><ins>Ab

</ins><ins>Def
</ins>


<!-- POST-RENDER -->

<p><!-- raw HTML omitted -->Abc
<!-- raw HTML omitted --><!-- raw HTML omitted -->Ab</p>
<p><!-- raw HTML omitted --><!-- raw HTML omitted -->Def
<!-- raw HTML omitted --></p>

I generated the above by adding in some extra lines of script at the end of the script actionand running against a simple test draft:

strPreRender = myDiff.replace(/\t/g, '&emsp;') //Store this
myDiff = mmd.render(myDiff.replace(/\t/g, '&emsp;'));

app.setClipboard("<!-- PRE-RENDER -->\n" + strPreRender + "\n\n\n<!-- POST-RENDER -->\n\n" + myDiff); //Put the pre and post render content on the clipboard
draft.setTemplateTag("myDiff",myDiff)

I also tried setting the tags as <span> with a class attribute and modifing the CSS, but the same ommission message appeared.

I’m testing against a beta version v38.1 (257), but given the recent changes around the Markdown rendering, I’m wondering if that’s what might be at play here.

I can see in the docs that the processHTML property for MultiMarkdown should be defaulting to true. I tried explicitly setting it in case that was the cause, but unfortunately it made no difference.

@jsamlarose & @agiletortoise can you reproduce and/or shed any insight on the behaviour? Is the Markdown rendering forcing an ignore of HTML in Markdown, or is something else at play?

1 Like

<del and <ins> are considers unsafe tags. For that to work, you would need to have “processHTML” off for MultiMarkdown, or “safe tags” off and “unsafe tags” on for GitHub Markdown. With those settings it should allow those tags.

This action is explicitly using the GitHubMarkdown processor, try adding:

var mmd = GitHubMarkdown.create(); // existing
// add
mmd.safe = false
mmd.unsafe = true
// END add
2 Likes

To follow up on the original question, it wouldn’t be too hard to write an action that wrote out a couple of version’s contents to files and opened them in a proper diffing tool. That might be the best route.

2 Likes

Actions are fine, just logging a feature request

While I’m here, a quick question – does Drafts at all try to do a merge on a version conflict?

After putting a couple paragraphs back, an almost full duplicate of an old version appeared at an odd place about 100c from the top (only 85% of it, and def in a place I wouldn’t have been pasting) – I’m actually in favor of something like this, just curious

Only after seeing your suggested settings @agiletortoise did I go back and check the Markdown object being used in the original action. The use of mmd as the variable name had made me think the flavour of Markdown being used was MultiMarkdown. Didn’t even occur to me it could have been GFM.

Thanks for this fix, and thank you @sylumer for bringing this up. I’d noted elsewhere that a couple of my HTML based actions weren’t outputting as they had in the past, but I haven’t had the headspace to figure out why.

I’ve just posted an updated diff action (DIFF | Drafts Directory); for some reason I didn’t have the option to post an update on the original. Also shared the MGCL version I’ve been using that makes it easier (for me) to determine which version I want to compare with the current draft (DIFF and restore versions (MGCL) | Drafts Directory). Glad to have it working again.

3 Likes

Cheers @jsamlarose, just fired this up tonight, great stuff :beer:

The MGCL version is nice – for longer drafts it’s hard to tell versions, so tried something simpler, a “compare 2” checkbox prompt version of your original action DIFF2 | Drafts Directory

1 Like