-
-
Notifications
You must be signed in to change notification settings - Fork 975
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
Use vignette index entry as vignette title #1789
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. This looks quite heavy, I see that we can't just add a title
argument because it has to be at the top level of the YAML header.
I wonder if we should extract the pre_processor
function and add unit tests for that function, and only do one integration test (the first test in this PR), perhaps using verify_output()
.
Sorry I did not follow. add a title argument where ?
You're right - it seems better to simplify the other test I added. thank you |
- only render once for integration test - use a helper functions to generate temp vignette Rmd
I modified the tests by separating the vignette pre_processor function. Currently, I suggest to use Also, I thought at first it would be simpler to use
@krlmlr I am still not sure I understood what you wanted to do initially with a title argument. I may have missed a simpler way to add this feature. 🤔 |
It's fine. I don't see a simpler way than via the preprocessor, because the title has to be at the top level of the yaml and is not normally provided by the document format. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR looks good to me. We probably don't need to try()
here. Thank you very much!
Unfortunately I think this is the wrong way around: |
AFAICT |
Oh, hmmmm. Well at least that explains why I designed it in this way in the first place. In that case, given that other tools (e.g. pkgdown) will expect the title to be in the yaml metadata, I think a better solution might be to error if the |
If only Anyway, a warning when |
This is how R searches for .get_vignette_metadata <-
function(lines, tag)
{
## <FIXME>
## Why don't we anchor this to the beginning of a line?
meta_RE <- paste0("[[:space:]]*%+[[:space:]]*\\\\Vignette",
tag, "\\{([^}]*(\\{[^}]*\\})*[^}]*)\\}.*")
## </FIXME>
meta <- grep(meta_RE, lines, value = TRUE, useBytes = TRUE)
trimws(gsub(meta_RE, "\\1", meta))
} The following might just work, but also requires changes to downstream tooling: title: "%\VignetteIndexEntry{Title of the article}" I agree that a check might be the safest option here. Didn't think it through when opening the issue. |
I was thinking about a warning initially, so I agree this a good option too. Should we revert this feature then and add a warning instead ? |
Should the title be a substring of the index entry? The |
I think you're overthinking this and I think it's fine to say that a vignette has one title. If people want to override it, they could just put |
@krlmlr By "special case", I meant all vignette metadata are in Your proposal title: "%\VignetteIndexEntry{Title of the article}" sounds very interesting! If users provide a title in this way, we can definitely post-process it by stripping off |
Anything that requires special parsing of the |
@yihui should we revert this until we add a better suited solution if this new feature is not the good one ? It would prevent the change to be added in the next CRAN version as it is already merged. |
@cderv I just reverted it, and now |
This will resolve #1765 by adding a
pre_processor
to add vignette title as metadata pandoc argument if no title is provided to the Rmd file. I usedtools::vignetteInfo
to get the title as it already integrate the correct regex. It also assumes that title, if any, is set in the Rmd yaml header and not otherwise. Is this a correct assumption ?I added some small tests but it may need more.
html_vignette
is a sensible format widely used and it needs a thorough review. The change is simple though has thepre_processor
only affect vignette with no title.@yihui What do you think of this solution ? Do you see edge cases we need to verify ?
I don't want to break anything. I wonder if a
try()
is welcomed here just in case. 🤔Also, should it cover more ground like warn if title is different that vignette index, or help detect unset vignette index entry ?