Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSL support #2082

Merged
merged 17 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
8d3961c
feat(packages): Add lightweight CSL engine
Omikhleia Jun 28, 2024
6b12365
chore(packgase): Add a few CSL locales and styles for testing
Omikhleia Jun 28, 2024
808c6bb
feat(packages): Use experimental CSL renderer for BibTeX
Omikhleia Jun 29, 2024
348a423
chore(packages): Add basic experimental sorting to CSL engine
Omikhleia Jul 20, 2024
df92f0e
chore(packages): Output bibliography with proper sorting
Omikhleia Jul 20, 2024
57b3b7c
feat(packages): Keep track of cited bibliography entries
Omikhleia Sep 11, 2024
8d0d0b0
chore(packages): Support CSL locators
Omikhleia Sep 12, 2024
4537789
chore(packages): Support sort order in bibliography
Omikhleia Sep 13, 2024
df2e232
chore(packages): Support more Bib(La)Tex to CSL mappings
Omikhleia Sep 13, 2024
473db0e
refactor(packages): Some CSL-related code clean-up and simplification
Omikhleia Sep 13, 2024
6221ad9
chore(packages): Proper handling of page ranges in (CSL) bibliographies
Omikhleia Sep 14, 2024
5e88b58
chore(packages): Support name particles in (CSL) bibliographies
Omikhleia Sep 14, 2024
641cc8b
test(packages): Add busted test for the CSL engine
Omikhleia Sep 16, 2024
7b12f79
chore(packages): Smoother path from legacy to CSL bibliographies
Omikhleia Sep 16, 2024
065d852
chore(packages): Support subsequent-author-substitute in CSL bibliogr…
Omikhleia Sep 16, 2024
f525583
Merge branch 'master' into bibliography-csl
alerque Nov 23, 2024
ac0b1e4
refactor(packages): Move CSL support module unter bibtex package
alerque Nov 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions packages/bibtex/csl/csl_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
SILE = require("core.sile")

local CslLocale = require("packages.bibtex.csl.locale")
local CslStyle = require("packages.bibtex.csl.style")
local CslEngine = require("packages.bibtex.csl.engine")

describe("CSL engine", function ()
local locale, err1 = CslLocale.read("packages/bibtex/csl/locales/locales-en-US.xml")
local style, err2 = CslStyle.read("packages/bibtex/csl/styles/chicago-author-date.csl")

-- The expected internal representation of the CSL entry is similar to CSL-JSON
-- but with some differences:
-- Date fields are structured tables (not an array of numbers as in CSL-JSON).
-- citation-number (mandatory) is supposed to have been added by the citation processor.
-- locator (optional, also possibly added by the citation processor) is a table with label and value fields.
local cslentrySmith2024 = {
type = "paper-conference",
["citation-key"] = "smith2024",
["citation-number"] = 1,
author = {
{
family = "Smith",
["family-short"] = "S",
given = "George",
["given-short"] = "G",
},
},
title = "Article title",
page = "30-50",
issued = {
year = "2024",
},
publisher = "Publisher",
["publisher-place"] = "Place",
volume = "10",
editor = {
{
family = "Doe",
["family-short"] = "D",
given = "Jane",
["given-short"] = "J",
},
},
locator = {
label = "page",
value = "30-35",
},
["collection-number"] = "3",
["collection-title"] = "Series",
["container-title"] = "Book Title",
}

it("should parse locale and style", function ()
assert.is.falsy(err1)
assert.is.falsy(err2)
assert.is.truthy(locale)
assert.is.truthy(style)
end)

it("should render a citation", function ()
local engine = CslEngine(style, locale)
local citation = engine:cite(cslentrySmith2024)
assert.is.equal("(Smith 2024, 30–35)", citation)
end)

it("should render a reference", function ()
local engine = CslEngine(style, locale)
local reference = engine:reference(cslentrySmith2024)
assert.is.equal(
"Smith, George. 2024. “Article title.” In <em>Book Title,</em> edited by Jane Doe, 10:30–50. Series 3. Place: Publisher.",
reference
)
end)
end)
Loading
Loading