Skip to content

Commit

Permalink
Add a new "direct" biblio display style (#2191)
Browse files Browse the repository at this point in the history
  • Loading branch information
brycelelbach committed Dec 15, 2021
1 parent a79b33e commit 1f16618
Show file tree
Hide file tree
Showing 18 changed files with 740 additions and 222 deletions.
2 changes: 1 addition & 1 deletion bikeshed/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion bikeshed/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
17 changes: 12 additions & 5 deletions bikeshed/shorthands/oldShorthands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"] = ""
Expand Down
1 change: 1 addition & 0 deletions bikeshed/unsortedJunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
14 changes: 8 additions & 6 deletions docs/index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -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.)
* <dfn>Default Biblio Display</dfn> takes the values "index" (default) or "inline",
* <dfn>Default Biblio Display</dfn> 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.)
* <dfn>Markup Shorthands</dfn> 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 <a>boolish</a> values, like `css no, biblio yes`. The currently-recognized categories are:

Expand Down Expand Up @@ -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.
Expand Down
Loading

0 comments on commit 1f16618

Please sign in to comment.