Stream: helpdesk (published)

Topic: Markdown: Format interpolated string as literal


view this post on Zulip Adrian Hill (Mar 02 2022 at 14:51):

Is there any way to format an interpolated string as a literal such that it looks like code when displaying the Markdown string?

Some failed attempts:

julia> x = 5
5

julia> display(md"""Test: `$x`""")
  Test: $x

julia> display(md"""Test: $(join(["`", x, "`"]))""")  # doesn't render literal
  Test: `5`

view this post on Zulip Fredrik Ekre (Mar 02 2022 at 14:58):

Interpolation into md-strings doesn't work in all contexts, as you have noticed, but you can create the string first, and then Markdown.parse it:

julia> using Markdown

julia> x = 5;

julia> Markdown.parse("""Test: `$x`""")
  Test: 5

Last updated: Oct 02 2023 at 04:34 UTC