-
-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Interpolation into md-strings #180
Comments
I was also looking for such an option, similar to what Weave provides with inline bode blocks (https://weavejl.mpastell.com/stable/usage/#inline-code). What you can do now is to use a postprocessing function that replaces the interpolation syntax with the value. However, you cannot directly access the global variables of your script, so you have to store them somewhere and read them back in in the postprocessing functions. I did this with a temporary YAML file. It was clunky at best 😉 Would be great to have a better, build-in solution. |
I needed to include contents from a file in order to display the definition of a function, I am using the following preprocessing function: function displaycode(str)
regexp = r"# DISPLAYCODE\(\"(?<filename>.*\.jl)\",(?<startline>\d+),(?<endline>\d+)\)"
repfun = (s) -> begin
r = match(regexp, s)
lines = readlines(r[:filename])[parse(Int,r[:startline]):parse(Int,r[:endline])]
"""
# ```julia
# $(join(lines, "\n# "))
# ```
"""
end
replace(str, regexp=>repfun)
end It replaces a line in a markdown chunk like this one (you must specify start and end line numbers to include):
|
It would be cool, if interpolation into md-strings worked. For example:
currently produces via
Literate.notebook("tmp.jl", execute=true, mdstrings=true)
I think it would be ok and best if interpolation only works with md-strings and not with general comments.
The text was updated successfully, but these errors were encountered: