Publish from Tinderbox to DEVONthink

I decided to do some tests using different version of Tinderbox (see table below) and different versions of the Publish to Devonthink file (see also table below).

For each test, I did:

  • A clean install of Tinderbox (delete cache…)
  • Download the original file from the GitHub page

Then I repeated this sequence:

  • Create a Note called “Note A” with the content “This is note A”
  • Create a Note called “Note B” with the content “This is note B”
  • Add the prototype p_DEVONITEM to both
  • Run the stamp to export the notes to DT
  • Observe the behaviour: Are the notes created in DT? Do I get back the url from DT?
  • Create a Note called “Note C” with the content “This is note C” and a zip link at the end to Note A
  • Add the prototype p_DEVONITEM
  • Run the stamp to export the notes to DT

Here is the result of those tests:

Tinderbox version Publish version Export Note A & B Export Note C TB crashes?
8.7.1 (b467) 0.4.1 Works Works No
8.7.1 (b467) 0.5.1 Works Works No
8.8.0 (b479) 0.4.1 Nothing happen Nothing happen No
8.8.0 (b479) 0.5.1 Nothing happen Nothing happen No
8.8.1 (b482) 0.4.1 Nothing happen Nothing happen No
8.8.1 (b482) 0.5.1 Nothing happen Nothing happen No

I think the issue lies in the HTML code produced.

Here is the content of the attribute DTExportSource for Note C from Tinderbox 8.7.1 (b467) and file 0.5.1:

<!DOCTYPE html>
<html>
<head>
	<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">
	<title>Note C</title>
</head>
<body>

<h1>Note C</h1>
<p>This is note C</p>

<p><a href=\"x-devonthink-item://939D01FF-7219-4AE7-AA6C-AC459FEAE6D4\">Note A</a></p>

</body>
</html>

Here is the content of the attribute DTExportSource for Note C from Tinderbox 8.8.1 (b482) and file 0.5.1:

<!DOCTYPE html>
<html>
<head>
	<meta http-equiv=\\\\\\"content-type\\\\\\" content=\\\\\\"text/html; charset=utf-8\\\\\\">
	<title>Note C</title>
</head>
<body>

<h1>Note C</h1>
<p>This is Note C</p>

<p><a href=\\\\\\"Note_A.html\\\\\\">Note A</a></p>

</body>
</html>

Note here all the extra backslash.

In the temple Sectional HTML page, Removing the line:

<meta http-equiv="content-type" content="text/html; charset=utf-8">

The note A and B (that contain no link) are exported to DT.
Note C not because of there are still too many backslashes in the <a> tag.

The file used being exactly the same between the version of Tinderbox, I think the issue is within Tinderbox and something has changed between 8.7.x and 8.8.x.

OK, the source tracks to this line in action in action code note “Publish single note to DEVONthink”:

$DTExportSource = $Text.replace('\"', '\\~~TB_DOUBLE_QUOTE~~\"').replace('~~TB_DOUBLE_QUOTE~~', '');

After checking a host of things it wasn’t, it looks to be a change in .replace()'s handling of it replacement string, i.e. the latter parameter.

Test (in v8.8.1) with a $Text of:

This is a " test.

The aim is to insert a literal backslash before any double quotes. If I use:

$Text("other") = $Text.replace('"','\"');

I get the $Text in note “other” to be:

This is a =" test.

But if I try to escape the backslash in the action:

$Text("other") = $Text.replace('"','\\"');

There is no output. But, using:

$Text("other") = $Text.replace('\"', '\\~~TB_DOUBLE_QUOTE~~\"').replace('~~TB_DOUBLE_QUOTE~~', ''); 

I get:

This is a \\" test.

Go figure! As @eastgate notes, there have been changes to .replace and I guess they have messed up the way backslashes are interpreted in the replacement string input to the function. In short, 1 backslash in the replace string escapes the character after it, using two 9or more consecutive backslashes in the replacement string produce no—or incorrect output.

FWIW, Tinderbox action code has always had a problem trying to escape quote characters, which presumably explains the double .replace() call in the original action. Now, where did that last hour go?

The double replace thing is a workaround for some peculiar behavior I found with replace, possibly the thing that was recently updated. I’ll see if I can accomplish the same thing without it, but am going to wait for @eastgate to weigh in first.

I’m stumped too.

The issue is still there with Tinderbox 8.9.

However I was able to solve the problem by changing in the action “Publish single note to DEVONthink”, the following code:

$DTExportSource = theExport.replace('\"', '\\~~TB_DOUBLE_QUOTE~~\"').replace('~~TB_DOUBLE_QUOTE~~', '');

by:

$DTExportSource = theExport.replace('(\w+)="([a-zA-Z0-9;\s\/\-=\._\:]+)"','$1=\\"$2\\"');

Now everything work as intended on my side, including when there is a link between notes.

Attached is the new version of Pat’s template (I named it 0.5.2 as it is built upon 0.5.1).
publish-tinderbox-to-devonthink-0.5.2.tbx (197.1 KB)

1 Like

It looks like the bottom of the heap here is finding a way for actions to escape single/double straight quotes. In noting that I’m sure that’s way less simple than my opening sentence makes it seem!

@Julien very cool, thanks for doing that

It’s my sincere hope that the interest in this tool will encourage @eastgate and DEVONtech to devise an official solution :wink:

@pat, you’re welcome.
Your template was one of the reason I decided to purchase Tinderbox, as I love the idea to consume my notes in DEVONthink To Go on my iPad and iPhone.

An official solution would be awesome.
I would not mind having just a one-way flow from Tinderbox to DT (we kinda of have the other way around directly). Of course 2-way sync would be even better.

1 Like

I’m still having issues - not a coder, so it’s probably my inability to grasp the issue.

The 0.5.2 file works just fine.

However, if I copy a note from my old file the stamp will not work for this new note. I’ve tried a combination of prototypes, including unlink the prototype and save in the old doc then paste into new and assign new prototype.

I’ve also tried creating a new note and simply pasting the contents of the old note in the file. This also does not work.

My old note has an embedded JPEG. Is the " " around the image source in the HTML part of the problem?

Hi,
Could you copy the content of the attribute DTExportTBView?
I have not tried with images and it may be possible that the regex I used in the replace function is not catching properly the image tag.

1 Like

The attribute DTBExportTBView simply has a value of outline.

I’m not sure if there is any more to it than that

My bad, I meant DTExportSource

I will try to have a look at it tomorrow if you can give me an example of the problematic behaviour.

1 Like

Zettelkasten 3.1.tbx (326.0 KB)

Attached is my test file, a couple of notes at root level

1 Like

One issue was because there were quotes in the notes titles and in the text of the notes.

I have added another regex in the “Publish single note to DEVONthink” but also in the AppleScript. Now it works.

Only the note with the image does not work. It gets exported to DT but empty (DTExportSource is empty). I don’t know why yet. I suspect Tinderbox does some transformation with the image, but get blocked because the double quote are already escaped by the regex in “Publish single note to DEVONthink”. Not sure if this makes sense when I write it :slight_smile:

I will update Pat’s template later today, but here is your file with the changes:
Zettelkasten 3.1-3.tbx (319.4 KB)

Let me know if it works.

1 Like

Here is the updated template:
publish-tinderbox-to-devonthink-0.5.3.tbx (204.3 KB)

@pat,
Please let me know if you prefer that I rename the template or the numbering system, I don’t want to highjack your work :slight_smile:

1 Like

I exported the note with the image to HMTL (using the export menu). The thing is the image is not inlined in the HTML but exported as a separate file. Unless I’m wrong I don’t think this is possible to export a Note with an image to DEVONThink.
Have you managed before to export a Note with an image to DT?

Side question for the audience, is it possible to ask Tinderbox to inline an image (converting it to base64) within an action?

Not at present, without recourse to AppleScript.

It works better now. I can use the STAMPS function to post legacy notes to Devonthink.

As noted, it does not publish images, however that is not a dealbreaker to me.

However, it also does not publish HTML links to external sources.

A simpler work-around for me at the moment is to export the entire Tinderbox file as HTML in a directory on iCloud. Then I have Devonthink index that directory. This preserves all links as well as embedded images. There is an annoyance - on the iPad you have to download both the source and target files in order for the hyperlink to work.

If I understand correctly the image in $Text is stored as base64. Is there a way to retrieve this as string in an action?

Not at present. If you’ve got a use case that will help people visualize and analyze their notes, send it to bernstein@eastgate.com.