Transclude record to outline

In the outline-like environment of Connected Text, one can re-use blocks of text from other sections of the Wiki by transcluding them (something that a new web app recently recreated). With DEVONthink being highly scriptable as it is, I thought this ought to be possible over here as well. This is my attempt not to recreate those tools, but to explore and see what would be possible working with this amazing tool that we have available.

I decided to keep the standard MMD transclusion/placeholder marks, but I am not absolutely sure this is the best way to go. What this script will do is to take whatever is between {{ and .md}}, perform a search for it, copy the text, and bring it back placing it between html <details> tags. It will then comment out the transclusion placeholder using <!-- --> and insert a link to the original file along with a delimiter at the bottom.

If the transcluded text contains other placeholders, it will look for them as well and perform the changes again. A limitation so far is this: if the text contains, instead of other placeholders, text that was already transcluded from elsewhere, then it will work fine the first time. But it won’t be able to keep updating the final text with the script. This is due to the positioning of the delimiter. You can always revert back to the placeholders without the text and perform the process again. (It is best to try it out and see for yourself this happening than to understand it in written form).

Some examples of what the script will do:


The idea is that you can navigate the document, open a block to edit as much as you want, and then see it automatically updated.

There are a few optional parameters, such as:

  • Randomize footnote numbering - useful if you are using footnotes since the numbering could coincide.
  • Partial Transclusion - The syntax is {{## SectionWithHashtags|Record.md}}. This is still very experimental.
  • Clean MMD header - This will allow only the text to be taken over. You can adapt the handler in the bottom of the script to your particular needs.
  • Last Modification Date - This will add the last modification date to the bottom.
  • To top - This will add a html link <a href="#top">[To top]</a> next to the modification date. You would need, then, to create an anchor at the top to allow navigation inside document.
  • Name between brackets - This is for avoiding the auto wiki link to render improperly when it is between html tags, namely, <summary>.
  • Backlinks - This should be off at the moment. It will work with an accompanying script that collects occurrences of the name & aliases of the record and stores it in a custom metadata field (I am still working on it trying to make it work a bit faster).


The script is available here. And the CSS trickery for the outline to look better is here.

Before playing around with the script, remember that CHANGES MADE BY SCRIPTS CANNOT BE REVERSED. So, test it on dummy files and do not use it AT ALL on file of which you have no backup.

3 Likes