Paste Auto-updating snippets from other drafts

I’m not sure if this is already a feature but here’s my idea:

Type in a syntax of something like:


Then Drafts will, behind the scenes, fetch the text from that unique draft and paste it into that draft. And if you make any changes to that unique draft it will auto-update the text of every draft that has that syntax pasted in it. So for example, you could:

  1. Make one note with very reusable text.
  2. Make 10 other notes that have the code syntax to auto paste from that 1st note.
  3. Then if you need to make a change to the 1st note’s reusable text, simply change the 1st note and it will auto-update the text in every note that has the code syntax in it.

I hope that explanation is clear enough.

A few questions about how you envisage this:

How would you deal with the positioning of the pulled in text? Presumably, immediately below?

What if you edit that pulled in text in the non-prime version and then update the prime version? What should Drafts do, simply reinsert? Overwrite everything below? Should it warn you somehow?

I’m wondering if it would need to be a delimited range instead to accommodate that sort of scenario better?

How often would updates occur and what would happen to modification timestamps?

  1. The pulled in text would simply replace the code. For example:

    …some text…
    …some text…

would render in the preview window as:

...some text...
...some text...
  1. I don’t know what prime version means. Sorry. I guess you’re talking about how Drafts has the ability to save multiple versions of the same draft. I suppose the best implementation would be to have the UUID code default to the latest version, But if you want to specify a particular version then the syntax could include extra info to specify version number or version time code.

  2. Sorry I don’t know what delimited range means?

  3. I would think that updates would occur at runtime. Meaning that Drafts wouldn’t actually update anything until you actually open that drafts preview pane. When you open the preview pane (or export the HTML) then Drafts would read the code, lookup the draft that corresponds to the UUID, fetch the text, and then paste it in place of the code.

If Drafts detects a change in the text, while you’re looking at the Preview window, then Drafts would update the Preview window.

Aha - you didn’t mention anything in your first post about previews. It sounded like you wanted it updating the actual raw content of the draft.

You can do that using the wiki-style links and a few actions.

Greg’s Transclude > Preview action does this, and my Exploded Markdown Preview in the Thoughtasylum action group also caters to this or example.

Shame. I thought this was heading more in the direction of suggesting “include” blocks that would render in the editor, rather than preview… :wink:

1 Like

That was what I thought from the initial post.

Any opinion on whether includes might ever be possible? I appreciate the ability to transclude in previews, but since Drafts’ UI places primary focus on the editor, being able to “include” other drafts would be useful, even if non-prime rendered blocks weren’t editable outside of their prime/source drafts…

(Not to hijack the OP’s thread!)

1 Like

Actually yeah, include blocks would be really cool.

Ok, I’m trying to wrap my head around Wiki-Style links and the full power of them. Thanks @sylumer for all those action suggestions. I tried them and they don’t seem to work, but I’m sure there’s something that I’m not understanding correctly.

EDIT: Figured it out. My mac was still on Drafts 19, so it didn’t support wiki-style links yet.

Based on what we thought this was initially about, and my suggestions, I thought what the hey, let’s try it. I’ve come up with something that isn’t perfect. There’s a small amount of manual effort involved, but it feels workable.

The latest version of the ThoughtAsylum Action Group has a section (currently at the bottom of the list), called Draft Embedding. It includes three actions.

  1. TAD-Embed a Draft

    • Create a refreshable embed block in a draft that includes another draft’s content.
  2. TAD-Refresh Embeds of this Drafts

    • Searches all other non-trashed drafts for an embed block for the current draft and refreshes them to include the current content of the draft.
  3. TAD-Refresh Embeds in this Draft

    • Refreshes the content of all embed blocks in the current draft.

Let me explain a little further what happens.

The first action is used to make an initial insertion of two placeholder markers, and the current content of another draft. The placeholders are written as HTML comment, so they won’t appear in Markdown/HTML rendered previews. The comments also contain UUID based wiki links to let the other actions know which draft to reference as the content source, and give you an easy way to navigate directly to it.

A block looks something like this:

Some content in the original draft

<!-- EMBED : [[u:10715A17-F4CB-4B29-B780-103568651D42]] -->

Content here is taken from another draft.
It isn't updated automatically, but we can use some other actions to force a refresh.

<!-- [[u:10715A17-F4CB-4B29-B780-103568651D42]] : EMBED -->

Some more content in the original draft

The second and third actions carry out refreshes, but from opposite directions.

The second action would be run when your source draft is loaded in the drafts editor. It searches through all of your non-trashed drafts and finds any embeds for the current draft. For each one it finds, it refreshes the content of this source draft into that draft.

The third action would be run when you are in a draft containing one or more embeds and you want to ensure that they have the latest content. The action scans the draft for all embed blocks. For each of the blocks it refreshes it, fetching the current content from its source draft.

Without being able to hook this into any sort of version saving event in Drafts, this was the best option I could come up with.

Hopefully folks will find some use in it.

1 Like

As ever, you’re a boon. Many thanks, @sylumer.