Skip to content

[WIP] new render implementation at src/writer.jl:549 #259

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 24 additions & 19 deletions src/writer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -547,27 +547,32 @@
end

function render(io::IO, ::MIME"text/plain", node::Documenter.MarkdownAST.Node, contents::Documenter.ContentsNode, page, doc; kwargs...)
current_path = nothing
for (count, path, anchor) in contents.elements
path = mdext(path)
header = anchor.object
anchor_frag = Documenter.anchor_fragment(anchor)
anchor_frag = vitepress_anchor(anchor_frag)
url = replace(string(path, anchor_frag), " " => "%20")
anchor_id = replace(anchor.id, "-" => " ")
link = Markdown.Link(anchor_id, url)
level = header.level
# Reset level to 1 if this is a new path
if path != current_path
level = 1
current_path = path
end
# contents of this method copied from `latex` function in `Documenter.jl`
# Having an empty itemize block in LaTeX throws an error, so we bail early
# in that situation:
isempty(contents.elements) && (_println(io); return)

print(io, " "^(level - 1), "- ")
linkfix = ".md#"
println(io, replace(Markdown.plaininline(link), linkfix => "#"))
depth = 1
_println(io, "") # add empty line
for (count, path, anchor) in contents.elements
@assert length(anchor.node.children) == 1
header = first(anchor.node.children)
level = header.element.level
# Filter out header levels smaller than the requested mindepth
level = level - contents.mindepth + 1
level < 1 && continue
# If we're changing depth, we need to make sure we always print the
# correct number of \begin{itemize} and \end{itemize} statements.

# Print the corresponding \item statement
id = _hash(Documenter.anchor_label(anchor))
_print(io, "\\t"^(level-1) * "[", id, "](")
latex(io, header.children)
_println(io, ")")
Copy link
Collaborator

@asinghvi17 asinghvi17 May 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the other way around I think, we need the logic from

anchor_frag = Documenter.anchor_fragment(anchor)
anchor_frag = vitepress_anchor(anchor_frag)
url = replace(string(path, anchor_frag), " " => "%20")

and the underscores can be dropped from _print and _println.

It may be worth sticking to the original approach for the rendering here but we keep the rendering header.children instead. You can check what we do for lists in writer.jl to see how to do that inline. Since we need to strip the Markdown it may be nice to have the Markdown.plaininline stuff.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you put that in as a suggested change? sorry for the inconvenience

end
return println(io)

_println(io)
return
end

function render(io::IO, mime::MIME"text/plain", node::Documenter.MarkdownAST.Node, evalnode::Documenter.EvalNode, page, doc; kwargs...)
Expand Down Expand Up @@ -969,7 +974,7 @@
# Code blocks
function render(io::IO, mime::MIME"text/plain", node::Documenter.MarkdownAST.Node, code::MarkdownAST.CodeBlock, page, doc; kwargs...)
if startswith(code.info, "@")
@warn """

Check warning on line 977 in src/writer.jl

View workflow job for this annotation

GitHub Actions / build

DocumenterVitepress: un-expanded `@doctest` block encountered on page src/manual/code_example.md. The first few lines of code in this node are: ``` julia> 1 + 1 2 ```
DocumenterVitepress: un-expanded `$(code.info)` block encountered on page $(page.source).
The first few lines of code in this node are:
```
Expand Down
Loading