Skip to content

Commit

Permalink
Add a fallback for Pages to behave as in pre-1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
goerz committed Nov 2, 2023
1 parent 376e062 commit 25479fe
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 9 deletions.
19 changes: 19 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased][]

### Fixed

* Added a fallback for the `Pages` attribute in a `@bibliography` block to behave as in pre-`1.3.0`: If `Pages` references a file with a path relative to the `docs/src` directory (which was the unintentional requirement pre-`1.3.0`), this now works again, but shows a warning that the name should be updated to be relative to the folder containing the file that contains the `@bibliography` block. This fixes the `v1.3.0` release arguably having been "breaking" [[#59][]] in that anybody who was using `Pages` pre-1.3.0 would have had to use paths relative to `docs/src`, even though that was a workaround for a known bug [[#22][]]. Note that whenever `Pages` references the current file, `@__FILE__` should be used.


## [Version 1.3.0][1.3.0] - 2023-11-01

Expand Down Expand Up @@ -42,6 +48,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Any `@bibliography` block is now internally expanded into an internal `BibliographyNode` instead of a raw HTML node. This `BibliographyNode` can then be translated into the desired output format by `Documenter.HTMLWriter` or `Documenter.LaTeXWriter`. This is how support for bibliographies with `format=Documenter.LaTeX()` can be achieved.
* The routine `format_bibliography_reference` must now return a markdown string instead of an HTML string.

**Upgrade guidelines**:

If anyone who was using custom styles, which rely on the [Internals](https://juliadocs.org/DocumenterCitations.jl/stable/internals/) of `DocumenterCitations`, this release will almost certainly break the customization. See the above list of internal changes.

There were some subtle changes in how DOI and URL fields are linked in the rendered documentation, which may require adjustments. In particular, in version `1.3.0`, non-`@article` entries that do not have both a `title` and a `booktitle` can only have a DOI *or* or URL, but not both. This most likely occurs for `@book` entries. For `@book` entries that have both a DOI and a URL, the URL should be placed in the `note` field (using `\url`/`\href`, as appropriate).

There were several bugs and limitations in version `1.2.x`, for which some existing documentations may have been using workarounds. These workarounds my cause some breakage in the new version `1.3.0`. In particular:

* The `Pages` attribute in a `@bibliography` in version `1.2.x` (unintentionally, and without documentation) required any names to be relative to the `docs/src` directory [[#22][]]. These names must be updated to be relative to to the folder containing the file which contains the `@bibliography` block. For the common usage where `Pages` was referring to the current file, `@__FILE__` should be used.

* Pre-`1.3.0`, strings in entries in the `.bib` file were extremely limited in that there was no official support for any kind of `tex` macros. Only plain-text unicode was guaranteed to work in version `1.2.x`. As a workaround, some users exploited an (undocumented/buggy) implementation detail that would cause html or markdown strings inside the `.bib` file to "work", e.g. for adding links in a `note` field. These workarounds may break in `v1.3.0`. While unicode is still very much supported (`ö` over `\"{o}`), `.bib` files should be otherwise be written to be fully compatible with `bibtex`. For links in particular, the LaTeX `\href` macro should be used. Any `tex` commands that are not supported (`Error: Unsupported command`) should be reported. Some `tex` characters (`$%@{}&`) that may have worked directly pre-`1.3.0` will have to be escaped in version `1.3.0`.


## [Version 1.2.1][1.2.1] - 2023-09-22

Expand Down Expand Up @@ -119,6 +137,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[1.2.0]: https://github.com/JuliaDocs/DocumenterCitations.jl/compare/v1.1.0...v1.2.0
[1.1.0]: https://github.com/JuliaDocs/DocumenterCitations.jl/compare/v1.0.0...v1.1.0
[1.0.0]: https://github.com/JuliaDocs/DocumenterCitations.jl/compare/v0.2.12...v1.0.0
[#59]: https://github.com/JuliaDocs/DocumenterCitations.jl/issues/59
[#56]: https://github.com/JuliaDocs/DocumenterCitations.jl/pull/56
[#53]: https://github.com/JuliaDocs/DocumenterCitations.jl/issues/53
[#42]: https://github.com/JuliaDocs/DocumenterCitations.jl/pull/42
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "DocumenterCitations"
uuid = "daee34ce-89f3-4625-b898-19384cb65244"
authors = ["Michael Goerz <[email protected]>"]
version = "1.3.0"
version = "1.3.1-dev"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand Down
20 changes: 16 additions & 4 deletions src/expand_bibliography.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
_ALLOW_PRE_13_FALLBACK = true

"""Pipeline step to expand all `@bibliography` blocks.
Runs after [`CollectCitations`](@ref) but before [`ExpandCitations`](@ref).
Expand Down Expand Up @@ -273,12 +275,22 @@ function expand_bibliography(node::MarkdownAST.Node, meta, page, doc)
expected_file = normpath(doc.user.source, page_folder, name)
if isfile(expected_file)
@error "Invalid $(repr(name)) in Pages attribute of @bibliography block on page $(page.source): File $(repr(expected_file)) exists but no references were collected."
push!(doc.internal.errors, :bibliography_block)
else
# Files that don't contain any citations don't show up in
# `page_citations`.
@error "Invalid $(repr(name)) in Pages attribute of @bibliography block on page $(page.source): No such file $(repr(expected_file))."
# try falling back to pre-1.3 behavior
exists_in_src = isfile(joinpath(doc.user.source, name))
valid_pre_13 = exists_in_src && haskey(page_citations, name)
if _ALLOW_PRE_13_FALLBACK && valid_pre_13
@warn "The entry $(repr(name)) in the Pages attribute of the @bibliography block on page $(page.source) appears to be relative to $(repr(doc.user.source)). Starting with DocumenterCitations 1.3, names in `Pages` must be relative to the folder containing the file which contains the `@bibliography` block."
@debug "Add keys cited in $(abspath(normpath(doc.user.source, name))) to keys_to_show (pre-1.3 fallback)"
push!(keys_in_pages, page_citations[name]...)
else
# Files that don't contain any citations don't show up in
# `page_citations`.
@error "Invalid $(repr(name)) in Pages attribute of @bibliography block on page $(page.source): No such file $(repr(expected_file))."
push!(doc.internal.errors, :bibliography_block)
end
end
push!(doc.internal.errors, :bibliography_block)
continue
end
end
Expand Down
6 changes: 4 additions & 2 deletions test/test_bibliography_block_pages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ end

@test success
#! format: off
@test contains(output, prx("Error: Invalid \"index.md\" in Pages attribute of @bibliography block on page src/part3/section2/invalidpages.md: No such file \"src/part3/section2/index.md\"."))
@test_broken contains(output, prx("Error: Invalid \"index.md\" in Pages attribute of @bibliography block on page src/part3/section2/invalidpages.md: No such file \"src/part3/section2/index.md\"."))
@test contains(output, prx("Warning: The entry \"index.md\" in the Pages attribute of the @bibliography block on page src/part3/section2/invalidpages.md appears to be relative to \"src\"."))
@test contains(output, prx("Error: Invalid \"p3_s1_page.md\" in Pages attribute of @bibliography block on page src/part3/section2/invalidpages.md: No such file \"src/part3/section2/p3_s1_page.md\"."))
@test contains(output, prx("Error: Invalid \"noexist.md\" in Pages attribute of @bibliography block on page src/part3/section2/invalidpages.md: No such file \"src/part3/section2/noexist.md\"."))
@test contains(output, "Warning: No cited keys remaining after filtering to Pages")
Expand Down Expand Up @@ -174,7 +175,8 @@ end

@test !success
#! format: off
@test contains(output, prx("Error: Invalid \"index.md\" in Pages attribute of @bibliography block on page src/part3/section2/invalidpages.md: No such file \"src/part3/section2/index.md\"."))
@test_broken contains(output, prx("Error: Invalid \"index.md\" in Pages attribute of @bibliography block on page src/part3/section2/invalidpages.md: No such file \"src/part3/section2/index.md\"."))
@test contains(output, prx("Warning: The entry \"index.md\" in the Pages attribute of the @bibliography block on page src/part3/section2/invalidpages.md appears to be relative to \"src\"."))
@test contains(output, prx("Error: Invalid \"p3_s1_page.md\" in Pages attribute of @bibliography block on page src/part3/section2/invalidpages.md: No such file \"src/part3/section2/p3_s1_page.md\"."))
@test contains(output, prx("Error: Invalid \"noexist.md\" in Pages attribute of @bibliography block on page src/part3/section2/invalidpages.md: No such file \"src/part3/section2/noexist.md\"."))
@test contains(output, "Warning: No cited keys remaining after filtering to Pages")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

## References from Nonexisting Pages

Nothing should render here
Nothing should render here (except for the fallback introduced in version 1.3.1)

```@bibliography
Canonical = false
Pages = [
"index.md",
"index.md", # not valid in 1.3, valid in 1.3.1 (fallback)
"p3_s1_page.md",
"noexist.md",
]
Expand Down

0 comments on commit 25479fe

Please sign in to comment.