LuxDL / DocumenterVitepress.jl

Documentation with Documenter.jl and VitePress
https://luxdl.github.io/DocumenterVitepress.jl/
MIT License
63 stars 9 forks source link

`@repl` not rendered properly #102

Closed thofma closed 3 months ago

thofma commented 3 months ago

The following

```@repl
1 + 1
2 + 3
4 + 5
will result in an empty `julia-repl` block. The reason is that

julia> x Documenter.MultiCodeBlock([...])

julia> x.codeblock MarkdownAST.CodeBlock("@repl", "1 + 1\n2 + 3\n4 + 5")

julia> x.content Markdown.Code[]


and the `join_multiblock` function only looks at the `.content` field: https://github.com/LuxDL/DocumenterVitepress.jl/blob/eac3f79d1e7c3c47a6e70b72efa91dab5ff05efa/src/writer.jl#L364
But this seems to be not quite correct. Apparently all the information is in the corresponding node. This is how it is done for LaTexWriter: https://github.com/JuliaDocs/Documenter.jl/blob/4fe9cf1237293c530633bcf0ef183b48417f23d7/src/latex/LaTeXWriter.jl#L522-L536
asinghvi17 commented 3 months ago

Thanks for the debugging! I should be able to get this done today.

asinghvi17 commented 3 months ago

Looks like the function in LaTeXWriter is:

function join_multiblock(node::Node)
    @assert node.element isa Documenter.MultiCodeBlock
    io = IOBuffer()
    codeblocks = [n.element::MarkdownAST.CodeBlock for n in node.children]
    for (i, thing) in enumerate(codeblocks)
        print(io, thing.code)
        if i != length(codeblocks)
            println(io)
            if findnext(x -> x.info == node.element.language, codeblocks, i + 1) == i + 1
                println(io)
            end
        end
    end
    return MarkdownAST.CodeBlock(node.element.language, String(take!(io)))
end
asinghvi17 commented 3 months ago

@thofma does this work for you?

thofma commented 3 months ago

Thanks for the fix! I will check it later today