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

view this post on Zulip Adrian Hill (Mar 02 2022 at 16:54):

Thanks a lot! :smiling_face:

view this post on Zulip Notification Bot (Mar 02 2022 at 16:55):

Adrian Hill has marked this topic as resolved.


Last updated: Dec 28 2024 at 04:38 UTC