From 1f1661843554a272b4a14c35637caf3f2e16fa8a Mon Sep 17 00:00:00 2001 From: Bryce Adelstein Lelbach aka wash Date: Wed, 15 Dec 2021 14:50:57 -0500 Subject: [PATCH] Add a new "direct" biblio display style (#2191) --- bikeshed/constants.py | 2 +- bikeshed/metadata.py | 2 +- bikeshed/shorthands/oldShorthands.py | 17 +- bikeshed/unsortedJunk.py | 1 + docs/index.bs | 14 +- docs/index.html | 400 +++++++++++++----------- tests/biblio002.bs | 4 +- tests/biblio002.html | 3 +- tests/biblio003.bs | 4 +- tests/biblio003.html | 3 +- tests/biblio004.bs | 4 +- tests/biblio004.html | 3 +- tests/biblio005.bs | 11 +- tests/biblio005.html | 12 +- tests/biblio006.bs | 8 +- tests/biblio006.html | 13 +- tests/biblio007.bs | 17 + tests/biblio007.html | 444 +++++++++++++++++++++++++++ 18 files changed, 740 insertions(+), 222 deletions(-) create mode 100644 tests/biblio007.bs create mode 100644 tests/biblio007.html diff --git a/bikeshed/constants.py b/bikeshed/constants.py index ed3a03de8f..7a36701cc4 100644 --- a/bikeshed/constants.py +++ b/bikeshed/constants.py @@ -7,7 +7,7 @@ quiet = True asciiOnly = False refStatus = StringEnum("current", "snapshot") -biblioDisplay = StringEnum("index", "inline") +biblioDisplay = StringEnum("index", "inline", "direct") specClass: t.Optional[t.Spec] specClass = None testAnnotationURL = "https://test.csswg.org/harness/annotate.js" diff --git a/bikeshed/metadata.py b/bikeshed/metadata.py index c25f4662d6..1f3c7cc66d 100644 --- a/bikeshed/metadata.py +++ b/bikeshed/metadata.py @@ -618,7 +618,7 @@ def parseBiblioDisplay(key, val, lineNum): val = val.strip().lower() if val in constants.biblioDisplay: return val - die(f"'{key}' must be either 'inline' or 'index'. Got '{val}'", lineNum=lineNum) + die(f"'{key}' must be either 'inline', 'index', or 'direct'. Got '{val}'", lineNum=lineNum) return constants.biblioDisplay.index diff --git a/bikeshed/shorthands/oldShorthands.py b/bikeshed/shorthands/oldShorthands.py index 17a6a08d61..2b2e5ea6b3 100644 --- a/bikeshed/shorthands/oldShorthands.py +++ b/bikeshed/shorthands/oldShorthands.py @@ -345,7 +345,7 @@ def transformText(text): \[\[ (!)? ([\w.+-]+) - (\s+(?:current|snapshot|inline|index|obsolete)\s*)* + (\s+(?:current|snapshot|inline|index|direct|obsolete)\s*)* (?:\|([^\]]+))? \]\]""", re.X, @@ -380,10 +380,17 @@ def biblioReplacer(match): displayInline = "inline" in modifiers displayIndex = "index" in modifiers - if displayInline and displayIndex: - die(f"Biblio shorthand {match.group(0)} contains *both* 'inline' and 'index', please pick one.") - elif displayInline or displayIndex: - attrs["data-biblio-display"] = "inline" if displayInline else "index" + displayDirect = "direct" in modifiers + if (displayInline + displayIndex + displayDirect) > 1: + die( + f"Biblio shorthand {match.group(0)} contains more than one of 'inline', 'index' and 'direct', please pick one." + ) + elif displayInline: + attrs["data-biblio-display"] = "inline" + elif displayIndex: + attrs["data-biblio-display"] = "index" + elif displayDirect: + attrs["data-biblio-display"] = "direct" if "obsolete" in modifiers: attrs["data-biblio-obsolete"] = "" diff --git a/bikeshed/unsortedJunk.py b/bikeshed/unsortedJunk.py index 8e1395c786..0786252eab 100644 --- a/bikeshed/unsortedJunk.py +++ b/bikeshed/unsortedJunk.py @@ -871,6 +871,7 @@ def processBiblioLinks(doc): ): # False if it's already been replaced by an author supplied text using the [[FOOBAR inline|custom text]] syntax. clearContents(el) appendChild(el, E.cite(ref.title)) + if biblioDisplay in ("inline", "direct"): if ref.url is not None: el.set("href", ref.url) diff --git a/docs/index.bs b/docs/index.bs index e26a93afd4..5038813f2a 100644 --- a/docs/index.bs +++ b/docs/index.bs @@ -1070,10 +1070,11 @@ There are several additional optional keys: and selects which URL you want to default to for bibliography and autolinks entries that have both "current" and "snapshot" URLs. (You can also specify this per-biblio entry or per-autolink.) - * Default Biblio Display takes the values "index" (default) or "inline", + * Default Biblio Display takes the values "index" (default), "inline", or "direct" and selects whether biblio autolinks default to - displaying as their shortname and linking to the bibliography index, - or displaying as their title and linking straight to the referenced document. + displaying as their shortname and linking to the bibliography index ("index"), + displaying as their title and linking straight to the referenced document ("inline"), or + displaying as their shortname and linking to the referenced document ("direct"). (You can also specify this per-biblio entry.) * Markup Shorthands lets you specify which categories of markup shorthands you want to use; for example, you can turn off CSS shorthands and reclaim use of single quotes in your spec. You can still link to things with explicit markup even if the shorthand is turned off. Its value is a comma-separated list of markup categories and boolish values, like `css no, biblio yes`. The currently-recognized categories are: @@ -2928,13 +2929,14 @@ after the biblio name. * By default, biblio autolinks are formatted like you typed, just with a single set of square brackets: `[[FOO]]` will produce a link with the text "\[FOO]", which links to the bibliography. + can make them display "direct", where they link straight to the document, + rather than going to the bibliography first. + (It still adds an entry to the bibliography index.) Alternately, you can force them to display "inline", where the link text is the actual title of the referenced document, and the link goes straight to that document, - rather than going to the bibliography first. - (It still adds an entry to the bibliography index.) - You can control this by setting `inline` or `index` in the shorthand, + You can control this by setting `inline`, `direct`, or `index` in the shorthand, like `[[FOO inline]]`, or change the default for all biblio links in the document by setting the [=metadata/Default Biblio Display=] metadata. diff --git a/docs/index.html b/docs/index.html index 885629b7bc..03c39d2e9c 100644 --- a/docs/index.html +++ b/docs/index.html @@ -12,7 +12,7 @@ * - .toc for the Table of Contents (
    ) * + for the section numbers * - #toc for the Table of Contents (