Skip to content
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

Support @__FILE__ in Pages in @content and @index blocks #2301

Open
goerz opened this issue Oct 16, 2023 · 1 comment
Open

Support @__FILE__ in Pages in @content and @index blocks #2301

goerz opened this issue Oct 16, 2023 · 1 comment

Comments

@goerz
Copy link
Member

goerz commented Oct 16, 2023

JuliaDocs/DocumenterCitations.jl#22 (comment) proposed accepting @__FILE__ in the Pages attribute of a @bibliography block to indicate the current page. I've implemented this in JuliaDocs/DocumenterCitations.jl#48.

For consistency (and because this seems like a useful feature, making it easier to move around/rename .md files in the documentation), it would be nice if Documenter itself would also support this in the Pages attribute of @content and @index blocks. Probably also in @autodocs, although Pages in @autodocs is handled differently from @content and @index.

The function I'm using to handle @__FILE__ in DocumenterCitations is this:

# Deal with `@__FILE__` in `Pages`, convert it to the name of the current file.
 function _resolve__FILE__(Pages, page)
     __FILE__ = let ex = Meta.parse("_ = @__FILE__", 1; raise=false)[1]
         # What does a `@__FILE__` in the Pages list evaluate to?
         # Cf. `Core.eval` in `parse_bibliography_block`.
         # Should be the string "none", but that's an implementation detail.
         Core.eval(Main, ex.args[2])
     end
     result = String[]
     for name in Pages
         if name == __FILE__
             # Replace @__FILE__ in Pages with the current file:
             name = basename(page.source)
             @debug "__@FILE__ -> $(repr(name)) in Pages attribute of @bibliography block on page $(page.source)"
         end
         push!(result, name)
     end
     return result
 end

It's applied to the parsed/eval'ed Pages list.

Issue #760 is related, but seems mostly about @example and @eval (which probably need pre-processing instead of post-processing)

@mortenpi
Copy link
Member

This seems like a good idea to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants