Placeholder variables for text snippets in markdown
Asked Answered
F

3

6

I'm trying to write a markdown document that contains something like a centrally specified placeholder variable which allows to propagate a certain text snippet to different locations of the document, e.g.

placeholder = markdown files
This is my text about %placeholder%. %placeholder% should be used by everyone.    

Unfortunately, after some research, I did not found a way to realize this behavior.

I'm aware of the reference-style links functionality of markdown. However, from my point of view, it does not seem to solve exactly the issue I'm facing. Further, https://www.brianchildress.co/variables-in-markdown/ described an approach that perfectly fits to my question. However, the variable random value of the provided demo code is not replaced in the text.

I would be glad for any suggestions or at least the hint that the requested feature is not available.

Fleabane answered 15/2, 2021 at 7:27 Comment(0)
F
6

That blog post is simply wrong. Reference-style links aren't variables, and they don't behave as described there.

One of Markdown's guiding principles is that files should be readable in their source form:

Readability, however, is emphasized above all else. A Markdown-formatted document should be publishable as-is, as plain text, without looking like it’s been marked up with tags or formatting instructions.

Placeholders conflict with that principle and are not included in Markdown.

Foochow answered 15/2, 2021 at 14:4 Comment(0)
E
2

This answer to a similar question easily creates the required behavior using CSS pseudo-elements in HTML-based markdown applications without any add-ons or complicated coding, but degrades the readability of the source form. So, as Chris pointed out, it also goes against Markdown guiding principles.

It might be possible to create a Markdown add-on for variables that satisfies the guidelines. Such a plugin would would occasionally make sense in some templates:

  • For example in legal documents sometimes a similar thing is done this way: Oolong Johnson (hereinafter "Client") and then, in the document, only Client is written everywhere instead of writing out the whole name. This preserves the readability, but readers have to do the substitutions in their heads.

  • An add-on could do these substitutions. A readable definition and placeholder could be something like [Client]-is: Oolong Johnson and [Client]. At render the definition would be hidden and every occurrence of [Client] would be replaced with Oolong Johnson.

This would be as readable as legal documents, which is not great but does the trick, and would work similarly to reference-style links.

Enzymology answered 31/1, 2024 at 9:59 Comment(2)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Rating
This is the sole answer on the entire internet which actually provides this functionality. Many thanks.Synsepalous
S
0

Setting a JavaScript variable:

<script type="application/javascript">
    variable_name = "value"
</script>

allows you to reuse those variables elsewhere:

<script type="application/javascript">
    title = "Document Title"
</script>

# **<script>document.write(title)</script>**

The content of <script>document.write(title)</script> is a document outlining blah blah blah (see? it works in a body context, too).

This works in code-insiders-1.88.0-1710157206.el8.

Synsepalous answered 25/3, 2024 at 23:39 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.