-
Notifications
You must be signed in to change notification settings - Fork 499
Add @evalraw syntax for programmatically generate raw contents
#2182
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
base: master
Are you sure you want to change the base?
Conversation
|
I am not necessarily against this, and I think it's a use case we should support. However, I wonder if could re-use the at-eval block somehow, without having to create a new one? On #master / 1.0, Documenter will be very picky about what objects you can create in an at-eval: Documenter.jl/src/Expanders.jl Lines 606 to 629 in 7c97a86
So I think we could have some sort of an interface where a special returned object gets rendered as HTML or something along those lines. It could even support the case where a single block gets included in different formats depending on the writer (e.g. HTML or LaTeX). Not 100% sure what the interface should be right now though. |
|
Hi @mortenpi, thanks for the fast reply result = if isnothing(result)
nothing
elseif isa(result, Docs.HTML)
content = let io = IOBuffer()
invokelatest(show, io, MIME"text/html"(), result)
String(take!(io))
end
node.element = Documenter.RawNode(:html, content)
return
elseif isa(result, Markdown.MD)
convert(Node, result)
elseI do not know exactly how the Writers work and how the LaTeX part is handled. I don't know if there is something similar for LaTeX. Edit: Maybe you were talking about writing the documenter output using the LaTeX backend rather than HTML, and not about whether the RawNode is |
|
Could this not be handled similarly to the result from |
|
Hi @fredrikekre, From a quick look it seems an interesting approach, but then are you suggesting to directly catch this in the else block and automatcally render things as Edit: I also actually just tried giving custom HTML/JS as output of the |
|
I am hesitant to just rely on the the I also don't think we should special case We could still have a way to explicitly tell Documenter to fall back to ```@eval
result = f()
Documenter.UseShowMethods(result)
```So I would advocate being explicit here somehow. |
|
I liked the idea of being explicit with your suggested I thought about only creating a function that would make a suitable input for I added methods for HTMLWriter and LatexWriter but in case you are OK with the approach I'd like to get some guidance/feedback on where to put the tests. |
|
Hi @mortenpi, would you have a chance to review the latest changes and give some feedback on whether the approach here is on the right track? |
@evalraw synthax for programmatically generate raw contents@evalraw syntax for programmatically generate raw contents
|
Sadly this PR has been a bit neglected and now has a bunch of conflicts... On the upside, we maybe have new opportunities: I am in the process of adding uniform parsing of the "language" part of codeblocks; we already have ```@eval ; format=:html, raw=trueto signal: this eval block is only mean to be used if the output format is |
This PR is motivated by the discussion started in this discourse thread
It simply adds a new synthax block called
@evalrawthat allows to generate raw html (or LaTeX) contents from Julia that are then rendered as if they were written verbatim inside ablock
I think this functionality can be very useful for generating arbitrary HTML from Julia, especially for people that do not have html/js expertise but can rely on packages that already provide HTML outputs from Julia.
The synthax is quite simple, I mostly reused the code for
@evalblocks with the simple checks from@rawand just put a hard constraints that the result has to be aString, then the resulting string is used to generate aDocumenter.RawNodeelement.At the moment I did put a normal
errorwhen the result is not a string as I am not well versed in the Documenter internals and how the@docerrormacro should be used.If the maintainers are open to the idea of adding this functionality I will write tests and docs where needed for this.