Skip to content

Commit dafeccf

Browse files
authored
Merge pull request #65 from JuliaDocs/mg/63-link-from-publisher
Auto-link both URL and DOI
2 parents 392d454 + de9fd1f commit dafeccf

File tree

4 files changed

+43
-50
lines changed

4 files changed

+43
-50
lines changed

NEWS.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010

1111
* Warn about markdown link syntax in `.bib` files [[#60][]]
1212
* Warn about invalid DOIs in `.bib` files. The DOI field should never contain a URL (`https://doi.org/...`). This is detected as a special case, and the DOI is extracted from the URL.
13-
13+
* Automatically link both URL and DOI fields. This fixes a regression in `v1.3.0`, which would throw an error for `@book` and `@proceeding` entries with both a URL and a DOI field. Now, the DOI in such a case will be automatically linked via the `Title` field, and the DOI via the `organization`/`publisher`/`address` fields, similar to the behavior in `v1.2.0`. You may prefer to have the DOI linked via that `Title`, in which case you should add a `Note` field containing the `URL` (using `\url`/`\href`, as appropriate).
14+
1415

1516
## [Version 1.3.1][1.3.1] - 2023-11-02
1617

@@ -63,8 +64,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6364

6465
For 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.
6566

66-
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* a 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).
67-
6867
There were several bugs and limitations in version `1.2.x` for which some existing documentations may have been using workarounds. These workarounds may cause some breakage in the new version `1.3.0`. In particular:
6968

7069
* The `Pages` attribute in a `@bibliography` block in version `1.2.x` required any names to be relative to the `docs/src` directory [[#22][]]. This was both unintentional and undocumented. These names must now be updated to be relative to to the folder containing the file which contains the `@bibliography` block. This is consistent with how `Pages` is used, e.g., in `@contents` or `@index` blocks. For the common usage where `Pages` was referring to the current file, `@__FILE__` should be used.

src/formatting.jl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ function format_published_in(
230230
elseif entry.type in ["book", "proceedings"]
231231
_push!(1, format_edition(entry))
232232
_push!(1, format_vol_num_series(entry; title_transform_case=title_transform_case))
233+
_push!(2, tex_to_markdown(entry.in.organization))
233234
_push!(2, tex_to_markdown(entry.in.publisher))
234235
_push!(2, tex_to_markdown(entry.in.address))
235236
_push!(2, format_year(entry); _if=include_date)
@@ -270,7 +271,6 @@ function format_published_in(
270271
_push!(2, tex_to_markdown(entry.in.organization))
271272
_push!(2, tex_to_markdown(entry.in.publisher))
272273
_push!(2, tex_to_markdown(entry.in.address))
273-
# TODO: month/day date???
274274
_push!(2, format_year(entry); _if=include_date)
275275
_push!(3, format_chapter(entry))
276276
_push!(3, format_pages(entry))
@@ -307,16 +307,20 @@ function format_published_in(
307307
@warn "unpublished $(entry.id) does not have a 'note'"
308308
end
309309
end
310-
if length(urls) > 0
311-
@warn "Could not link $(repr(urls)) in \"published in\" information for entry $(entry.id). Add a Note field that links to the URL(s)."
312-
end
313310
mdstr = join(segments[1], ", ")
314311
if length(segments[2]) > 0
315-
mdstr *= " (" * join(segments[2], ", ") * ")"
312+
segment2 = join(segments[2], ", ")
313+
if length(urls) > 0
314+
segment2 = linkify(segment2, pop_url!(urls))
315+
end
316+
mdstr *= " (" * segment2 * ")"
316317
end
317318
if length(segments[3]) > 0
318319
mdstr *= "; " * join(segments[3], ", ")
319320
end
321+
if length(urls) > 0
322+
@warn "Could not link $(repr(urls)) in \"published in\" information for entry $(entry.id). Add a Note field that links to the URL(s)."
323+
end
320324
return mdstr
321325
end
322326

test/test_formatting.jl

Lines changed: 18 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -254,61 +254,37 @@ end
254254
numeric = Val(:numeric)
255255
authoryear = Val(:authoryear)
256256

257-
c = IOCapture.capture() do
258-
md(numeric, "JuhlARNMRS2020X")
259-
end
260-
@test contains(
261-
c.output,
262-
"Warning: Could not link [\"https://doi.org/10.1016/bs.arnmr.2019.12.001\"] in \"published in\" information for entry JuhlARNMRS2020X. Add a Note field that links to the URL(s)."
263-
)
264-
@Test c.value ==
265-
"D. W. Juhl, Z. Tošner and T. Vosegaard. [*Versatile NMR simulations using SIMPSON*](https://pure.au.dk/portal/files/230817709/Versatile_NMR_simulations_using_SIMPSON.pdf). Vol. 100 of *Annual Reports on NMR Spectroscopy*, edited by G. A. Webb (Elsevier, 2020); Chapter 1, pp. 1–59."
266-
267-
c = IOCapture.capture() do
268-
md(authoryear, "JuhlARNMRS2020X")
269-
end
270-
@test contains(
271-
c.output,
272-
"Warning: Could not link [\"https://doi.org/10.1016/bs.arnmr.2019.12.001\"] in \"published in\" information for entry JuhlARNMRS2020X. Add a Note field that links to the URL(s)."
273-
)
274-
@Test c.value ==
275-
"Juhl, D. W.; Tošner, Z. and Vosegaard, T. (2020). [*Versatile NMR simulations using SIMPSON*](https://pure.au.dk/portal/files/230817709/Versatile_NMR_simulations_using_SIMPSON.pdf). Vol. 100 of *Annual Reports on NMR Spectroscopy*, edited by Webb, G. A. (Elsevier); Chapter 1, pp. 1–59."
276-
277-
c = IOCapture.capture() do
278-
md(numeric, "Nolting1997CoulombX")
279-
end
280-
@test contains(
281-
c.output,
282-
"Warning: Could not link [\"https://doi.org/10.1007/978-3-663-14691-9\"] in \"published in\" information for entry Nolting1997CoulombX. Add a Note field that links to the URL(s)."
283-
)
284-
@Test c.value ==
285-
"W. Nolting. In: [*Quantenmechanik*](https://link.springer.com/book/10.1007/978-3-662-44230-2), Vol. 5 no. 2 of *Grundkurs Theoretische Physik* (Vieweg & Teubner Verlag, 1997); 6th chapter, p. 100."
286-
287-
c = IOCapture.capture() do
288-
md(authoryear, "Nolting1997CoulombX")
289-
end
290-
@test contains(
291-
c.output,
292-
"Warning: Could not link [\"https://doi.org/10.1007/978-3-663-14691-9\"] in \"published in\" information for entry Nolting1997CoulombX. Add a Note field that links to the URL(s)."
293-
)
294-
@Test c.value ==
295-
"Nolting, W. (1997). In: [*Quantenmechanik*](https://link.springer.com/book/10.1007/978-3-662-44230-2), Vol. 5 no. 2 of *Grundkurs Theoretische Physik* (Vieweg & Teubner Verlag); 6th chapter, p. 100."
296-
257+
@Test md(numeric, "JuhlARNMRS2020X") ==
258+
"D. W. Juhl, Z. Tošner and T. Vosegaard. [*Versatile NMR simulations using SIMPSON*](https://pure.au.dk/portal/files/230817709/Versatile_NMR_simulations_using_SIMPSON.pdf). Vol. 100 of *Annual Reports on NMR Spectroscopy*, edited by G. A. Webb ([Elsevier, 2020](https://doi.org/10.1016/bs.arnmr.2019.12.001)); Chapter 1, pp. 1–59."
259+
@Test md(authoryear, "JuhlARNMRS2020X") ==
260+
"Juhl, D. W.; Tošner, Z. and Vosegaard, T. (2020). [*Versatile NMR simulations using SIMPSON*](https://pure.au.dk/portal/files/230817709/Versatile_NMR_simulations_using_SIMPSON.pdf). Vol. 100 of *Annual Reports on NMR Spectroscopy*, edited by Webb, G. A. ([Elsevier](https://doi.org/10.1016/bs.arnmr.2019.12.001)); Chapter 1, pp. 1–59."
261+
@Test md(numeric, "Nolting1997CoulombX") ==
262+
"W. Nolting. In: [*Quantenmechanik*](https://link.springer.com/book/10.1007/978-3-662-44230-2), Vol. 5 no. 2 of *Grundkurs Theoretische Physik* ([Vieweg & Teubner Verlag, 1997](https://doi.org/10.1007/978-3-663-14691-9)); 6th chapter, p. 100."
263+
@Test md(authoryear, "Nolting1997CoulombX") ==
264+
"Nolting, W. (1997). In: [*Quantenmechanik*](https://link.springer.com/book/10.1007/978-3-662-44230-2), Vol. 5 no. 2 of *Grundkurs Theoretische Physik* ([Vieweg & Teubner Verlag](https://doi.org/10.1007/978-3-663-14691-9)); 6th chapter, p. 100."
297265
@Test md(numeric, "Shapiro2012X") ==
298266
"M. Shapiro and P. Brumer. [*Quantum Control of Molecular Processes*](https://onlinelibrary.wiley.com/doi/book/10.1002/9783527639700). ``2^{nd}`` Ed. (Wiley and Sons, 2012)."
299267
@Test md(authoryear, "Shapiro2012X") ==
300268
"Shapiro, M. and Brumer, P. (2012). [*Quantum Control of Molecular Processes*](https://onlinelibrary.wiley.com/doi/book/10.1002/9783527639700). ``2^{nd}`` Ed. (Wiley and Sons)."
301-
302269
@Test md(numeric, "PercontiSPIE2016") ==
303270
"P. Perconti, W. C. Alberts, J. Bajaj, J. Schuster and M. Reed. [*Sensors, nano-electronics and photonics for the Army of 2030 and beyond*](https://doi.org/10.1117/12.2217797). In: *Quantum Sensing and Nano Electronics and Photonics XIII*, Vol. 9755 no. 6 of *Proceedings SPIE* (2016)."
304271
@Test md(authoryear, "PercontiSPIE2016") ==
305272
"Perconti, P.; Alberts, W. C.; Bajaj, J.; Schuster, J. and Reed, M. (2016). [*Sensors, nano-electronics and photonics for the Army of 2030 and beyond*](https://doi.org/10.1117/12.2217797). In: *Quantum Sensing and Nano Electronics and Photonics XIII*, Vol. 9755 no. 6 of *Proceedings SPIE*."
306-
307273
@Test md(numeric, "DevoretLH1995") ==
308274
"M. H. Devoret. [*Quantum fluctuations in electrical circuits*](https://boulderschool.yale.edu/sites/default/files/files/devoret_quantum_fluct_les_houches.pdf). In: *Quantum Fluctuations*, Session LXIII (1995) of *the Les Houches Summer School*, edited by S. Reynaud, E. Giacobino and J. Zinn-Justin (Elsevier, 1997); Chapter 10, p. 353."
309275
@Test md(authoryear, "DevoretLH1995") ==
310276
"Devoret, M. H. (1997). [*Quantum fluctuations in electrical circuits*](https://boulderschool.yale.edu/sites/default/files/files/devoret_quantum_fluct_les_houches.pdf). In: *Quantum Fluctuations*, Session LXIII (1995) of *the Les Houches Summer School*, edited by Reynaud, S.; Giacobino, E. and Zinn-Justin, J. (Elsevier); Chapter 10, p. 353."
311277

278+
c = IOCapture.capture() do
279+
md(numeric, "Nolting1997CoulombXX")
280+
end
281+
@test contains(
282+
c.output,
283+
"Warning: Could not link [\"https://doi.org/10.1007/978-3-663-14691-9\"] in \"published in\" information for entry Nolting1997CoulombXX."
284+
)
285+
@Test c.value ==
286+
"W. Nolting. Vol. 5 no. 2 of *Grundkurs Theoretische Physik* ([Vieweg & Teubner Verlag, 1997](https://link.springer.com/book/10.1007/978-3-662-44230-2)); 6th chapter, p. 100."
287+
312288
end
313289

314290

test/test_formatting/alternative_non_articles.bib

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,20 @@ @inbook{Nolting1997CoulombX
2727
}
2828

2929

30+
@inbook{Nolting1997CoulombXX,
31+
author = {Wolfgang Nolting},
32+
series = {Grundkurs Theoretische Physik},
33+
volume = {5},
34+
number = {2},
35+
chapter = {{6th chapter}},
36+
pages = {100},
37+
doi = {10.1007/978-3-663-14691-9},
38+
url = {https://link.springer.com/book/10.1007/978-3-662-44230-2},
39+
year = 1997,
40+
publisher = {Vieweg \& Teubner Verlag},
41+
}
42+
43+
3044
@book{Shapiro2012X,
3145
author = {Shapiro, Moshe and Brumer, Paul},
3246
edition = {{$2^{nd}$ Ed.}},

0 commit comments

Comments
 (0)