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 all 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 @@ function vitepress_anchor(anchor::String)
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, " "^(level-1) * "[", id, "](")
latex(io, header.children)
_println(io, ")")
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