Skip to content

Commit

Permalink
refactor(packages): Better handling of number ranges in bibliographies
Browse files Browse the repository at this point in the history
Sort of a hack for now, see in-code comments.
The whole global picture would be harder, so let's go for a quick win
although imperfect.
  • Loading branch information
Omikhleia authored and Didier Willis committed Sep 14, 2024
1 parent 95ecae9 commit ccf2cde
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions csl/core/engine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ local CslLocale = require("csl.core.locale").CslLocale

local superfolding = require("csl.core.utils.superfolding")
local endash = luautf8.char(0x2013)
local emdash = luautf8.char(0x2014)

local CslEngine = pl.class()

Expand Down Expand Up @@ -1229,6 +1230,24 @@ function CslEngine:_postrender (text)
-- or a question mark. But it's ugly.
text = luautf8.gsub(text, "([…!?%.]" .. rdquote .. ")%.", "%1")
end
-- HACK: Numbers ranges.
-- This is a shortcut, deviating from the CSL specification.
-- One one hand, it uses the page-range-delimiter to format all number ranges:
-- CSL says it should be used for page ranges only, and that an endash is implied otherwise.
-- But honestly, this is against most good typographic practices (in French, at least,
-- the single dash is recommended, but consistency is key anyhow, so chapter ranges
-- for instance should use the same delimiter as page ranges).
-- On the other hand, doing such things that late in the process is not great.
-- Looking at citeproc-lua, it does a lots of things in cs:number processing,
-- e.g. "1 & 2" is valid, and in "ordinal" form, it should be "1st & 2nd".
-- We aren't implementing that yet.
-- I'm not sure (at a glance) that those other citeproc implementations handle
-- roman page numbers (which may occur in some book front matters), etc.
-- Needless to say, centuries in titles, etc. are another can of worms.
local range = self.punctuation.page_range_delimiter or endash
range = range == "-" and "%-" or range -- escape hyphen
local dashes = "%-" .. endash .. emdash .. range
text = luautf8.gsub(text, "(%d+)[^%d]+%s*[" .. dashes .. "]+%s*(%d+)", "%1" .. range .. "%2")
return text
end

Expand Down

0 comments on commit ccf2cde

Please sign in to comment.