Reusable text in Markdown

Does anyone know if the markdown editor in DT will correctly render reusable text?

There is an example for r-markdown at the site link below, but I’ve not been able to reproduce the results in DT. Thank you kindly for helpful feedback.

Have you looked at multimarkdown transclusion? You can incorporate another markdown file with {{file_name.md}}.

2 Likes

Thank you saltlane. That works. Is it possible to be more granular within a file (i.e. pick out a specific line.) and avoid having a large number of different files for each piece of reusable text?

DEVONthink uses MultiMarkdown, which has a transclusion feature like saltlane mentions.

R Markdown is a package for R, which is a programming language that seems to be popular in data science. It uses markdown for basic text formatting, but it does a whole lot more, like execute inline code. Looks cool, but pretty niche—and you need to set up a specific environment to use it.

R FAQ: 2.1 What is R?:

R is a system for statistical computation and graphics. It consists of a language plus a run-time environment with graphics, a debugger, access to certain system functions, and the ability to run programs stored in script files.

How It Works | R Markdown from RStudio:

When you run render, R Markdown feeds the .Rmd file to knitr, which executes all of the code chunks and creates a new markdown (.md) document which includes the code and its output.

The markdown file generated by knitr is then processed by pandoc which is responsible for creating the finished format.

This may sound complicated, but R Markdown makes it extremely simple by encapsulating all of the above processing into a single render function.

No wonder it doesn’t work in DEVONthink.

2 Likes

It’s much easier to help if you give concrete examples of what you’d like to do.

You can’t transclude only part of a document. Nested transclusion should be possible, i.e. transcluding a document that itself contains transcluded documents.

You can also use MultiMarkdown metadata headers for placeholders, which is very useful. Set a key: value in the header, and put ‌[%key] wherever you need it in the body text. The placeholder is then substituted on render/export.

Depending on your use case markdown might work for you, but there might be better tools.

4 Likes

Transclusion is only for a whole document. However, you could create markdown ‘snippets’ and use a free tool like Xmenu to access them?

Thank you troejgaard. That worked perfectly. I help coach at an MMA gym and the various drills have equipment, etc. that is needed. Instead of retyping all of that for each drill in a catalog document, having a reference collection for the drills such that I could simply enter the reference variable and have the equipment list appear is what I was trying to accomplish. Now if we change equipment, I only need to change the list once and it will save a tremendous amount of typing.

I’m curious. Do you know if there are any limitations on how many key values you can create?

Glad it was useful!

I didn’t expect MMA coaching :smiley: Peoples use cases are so different, it’s always fascinating to see.

Your description helps a bit, but I still can’t picture exactly what you want. It would be best if you could share some example document(s). What text would you like to reuse where?

Do you want to reuse individual drills in
a) an overview document/catalog containing all drills?
b) different sets/combinations of drills?
– Or do you also want to reuse text inside individual drills?

It sounds like transclusion could work great, but you didn’t seem satisfied with that. Why doesn’t it work to create a document for each drill, and transclude that where needed?

Actually, do you need a change in one document to cascade through other documents, or do you just want to save some typing? Maybe a text expander makes just as much sense.

Do you know if there are any limitations on how many key values you can create?

I haven’t pushed MMD metadata variables very far, so I don’t know if there is an upper limit to how many it’s feasible to use in a document. However, it’s worth noting they don’t work when you transclude documents. At least that’s what I found from a little testing.

Let me get a quality example document together and I’ll share it here. Your point on transclusion for full drills is well made. For an overall catalog of drills that makes great sense.

For some drills I use a concept from dry fire practice in competitive shooting (IDPS / USPSA) called a “par time.” So, if I’ve got a fighter I’m helping prepare in fight camp, I’ll keep a list of “par times” for them to escape from various bad positions, their best time for holding a good position, or how long it takes them to execute on a piece of their fight plan.

So, as a fighter improves, finding and correctly updating all of those times in various locations of a long document is begging for pain. Hence my question and now use of metadata headers.

Thank you again troejgaard.

Let me amend that. I haven’t really experimented with combining transclusion and metadata variables before. Earlier I just tried transcluding a bunch of documents which all had their own metadata headers and placeholders. That didn’t work.

But it actually can work, with some limitations. When you transclude a document, the metadata header is discarded. So…

  • If a document uses metadata variables from it’s own header, they don’t work when transcluded into another document.
  • But metadata variables & placeholders still work in the containing document.
  • The cool part: If you use a [%key] in the transcluded document… And keep key: value in the header of the containing document… It works! Even through multiple layers of nested transclusion.

I wasn’t aware of these details. It opens up some possibilities I hadn’t thought of.

For example, you can make a “Training Status” document for every athlete you coach. In the metadata header you put variables for the “par time” for different drills. (You can create a template for this, so you only need to fill out the values.)

athlete name:		Name
partime drill1:		mm:ss
partime drill2:		mm:ss
partime drill3:		mm:ss

You can then use the variables in drill documents, and they work when transcluded in the “Training Status” document.

### Drill 1

Par time: [%partime drill1]

|---|
Duration | mm:ss
Skill level | Beginner
Targets | Strength/Endurance/Technique/…

#### Equipment:
- Item 1
- Item 2
- …

#### Description
Description of the drill.

(I just used some varied syntax for example’s sake.)

It might also make sense to keep a log of different times in one or more separate files. Maybe a sheet, or a proper spreadsheet if you want to plot trends an such. You can use item links to quickly open them.

1 Like

athlete name: Name
partime drill1: mm:ss
partime drill2: mm:ss
partime drill3: mm:ss

The flaw I see with this approach is the metadata has to match the transcluded drill.

Drill 1: Karate Chops partime drill1
Drill 2: High Kicks partime drill2
Drill 3: Leg Sweeps partime drill3

If Johnny is only concentrating on drill 3, merely transcluding drill 3 would require knowing what metadata name was used in it. Following suit, but using a bit more “connected” metadata names, perhaps …

2 Likes

Those were just placeholders of course, perhaps too generic :laughing: I assumed you would use names/abbreviations of actual drills so you can remember them.

I would probably shorten “par time” to “pt” and give more length to the drill name: pt legsweep, pt highkick, pt kchop. Use names that makes sense to you. Maybe even the full drill name. If you use templates you won’t need to type it out that often and can prioritise legibility.

Seems to me TextExpander, Typinator, or text expansion on Alfred/Keyboard Maestro are purpose-made for that use case.

2 Likes