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
Option to include source code in each docstring #1473
Comments
Best option may be to implement a custom abbreviation using https://github.com/JuliaDocs/DocStringExtensions.jl, which should be able to achieve most of what you're looking for. Edit: as some starter code, this will get you going: struct SourceCode <: Abbreviation end
const SOURCECODE = SourceCode()
export SOURCECODE
function format(abbrv::SourceCode, buf, doc)
file = doc.data[:path]
if isfile(file)
lines = Base.Iterators.drop(eachline(file), doc.data[:linenumber] - 1)
text = join(lines, '\n')
_, from = Meta.parse(text, 1; greedy=false)
_, to = Meta.parse(text, from)
println(buf, "```julia")
println(buf, rstrip(text[from:to]))
println(buf, "```")
end
return nothing
end Then just use """
$SOURCECODE
"""
function foo(x)
# ...
end |
This is great, thanks so much for the quick reply and code. I tried this out in my package, and it displays the code perfectly. Do you know of any way to have abbreviations only work in some output formats, and not others? For example - set I haven't seen this option in An alternative option might be to have a separate branch with |
See
Probably easiest to make |
Does anyone know the best way to include source code in Markdown / PDF documents produced by
Documenter.jl
?Recently, I've been looking into how to best publish a Julia package, and people posted solutions including the
minted
package for LaTeX. I thought about making a new package to parse each module / function / struct and then output the strings to LaTeX/XeTeX withminted
, but the documents produced byDocumenter.jl
look really great already.For regular documentation hosting purposes, including the source would get unruly pretty quick. However, for archival purposes or for publishing, it might be helpful to have the option to include each function / struct's source code in the docstring automatically.
Just a thought. Are there any glaring issues / complications with a feature like this? Or does this belong somewhere else (another package, as I mentioned above)?
The text was updated successfully, but these errors were encountered: