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 #66

Merged
merged 70 commits into from
Oct 31, 2023
Merged

CSL #66

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
b1f60e8
Get started with CSL
reknih Sep 21, 2023
9a55f72
Refactoring, number parsing
reknih Sep 21, 2023
4fa816f
Add label and number rendering
reknih Sep 22, 2023
0fb5abe
Add date formatting and approximate dates
reknih Sep 22, 2023
bf99b6a
Add support for non-dropping name particles
reknih Sep 25, 2023
2f419fd
Add CSL name formatting
reknih Sep 26, 2023
72a9a80
All rendering elements implemented! 🎉
reknih Sep 26, 2023
1e788d1
Start with variable definitions
reknih Sep 26, 2023
9c47e10
Minor fixes
reknih Sep 28, 2023
cdecebe
Change to typed frontend
reknih Sep 28, 2023
4b7f37e
Remove dependencies
reknih Sep 28, 2023
ecfc45a
Code Review
reknih Oct 2, 2023
5a3c079
Add back getters and setters
reknih Oct 2, 2023
625c66f
Convert parsing to serde
reknih Oct 3, 2023
1bcfeed
Code Review I
reknih Oct 9, 2023
e01ae4c
Code Review II
reknih Oct 9, 2023
fdafa16
Merge branch 'new-frontend' into csl
reknih Oct 9, 2023
3af5ec7
Complete merge
reknih Oct 9, 2023
a0ccd47
Add variable queries
reknih Oct 10, 2023
5c5ef23
Map to CSL types
reknih Oct 10, 2023
9cfcc19
Remove legacy styles
reknih Oct 10, 2023
090e5fe
Correct groups, integrate case folding
reknih Oct 12, 2023
0e5dcff
Inherit name options
reknih Oct 12, 2023
f9716b4
Add page range formatting
reknih Oct 12, 2023
65b25cd
Improve nesting handling
reknih Oct 14, 2023
fb8e359
Add CSL style sort to Numeric and Date
reknih Oct 14, 2023
b307aa1
Compare persons, tidy up context
reknih Oct 14, 2023
357afd8
Sort stuff
reknih Oct 14, 2023
b075183
Delimiters in citations
reknih Oct 14, 2023
32f6d42
Move `Elem` stuff to submodule
reknih Oct 15, 2023
b5e395c
Add first speculative pass
reknih Oct 16, 2023
f981729
Implement disambiguation
reknih Oct 18, 2023
9d1135e
Add cite grouping
reknih Oct 18, 2023
66d4146
Print bibliography
reknih Oct 18, 2023
d24d69a
Add link, markup, gendered ordinals
reknih Oct 19, 2023
e57f6ab
Fix grouping, respect locale
reknih Oct 19, 2023
719ae0d
Prepare for showtime
reknih Oct 19, 2023
a25d8da
Change serial number repr
reknih Oct 19, 2023
7b68f3b
Factor out function for standalone citations
reknih Oct 20, 2023
d76576b
Reexport `LongShortForm`
reknih Oct 20, 2023
77a6b39
Package styles, update CLI
reknih Oct 23, 2023
903f3d6
Remove explicit size for bytes
reknih Oct 23, 2023
f69bb7e
Export locale code
reknih Oct 24, 2023
83fdb5e
Do not print empty text elements
reknih Oct 24, 2023
ff0a8e1
Respect label name order
reknih Oct 26, 2023
96dd1a1
Expose aliases, full titles, and IDs
reknih Oct 26, 2023
1123d79
Make Hayagriva generic over the entry
reknih Oct 26, 2023
5edb66d
Remove dependent aliases and add Entry meta
reknih Oct 27, 2023
767f488
Add tests and fix some bugs
reknih Oct 27, 2023
37ec79e
Merge branch 'test-csl' into csl
reknih Oct 29, 2023
65d8aaa
Add key to CSL-JSON
reknih Oct 29, 2023
01c5f39
More Fixes
reknih Oct 29, 2023
2b74362
Docs fixes
laurmaedje Oct 29, 2023
5116f86
Improved range parsing and conversion
reknih Oct 29, 2023
ea45b07
Fix author only mode and labels
reknih Oct 29, 2023
1f88800
Order case-insensitively
reknih Oct 29, 2023
c880446
Allow transparent locators
reknih Oct 30, 2023
67175ca
Use the term override locale for case folding
reknih Oct 30, 2023
7ec7d66
Add cite purposes
reknih Oct 30, 2023
7b3e5a9
Some spacing and punctuation fixes
reknih Oct 30, 2023
f32c2a3
Ship alphanumeric style
reknih Oct 30, 2023
86fb40d
CBOR
reknih Oct 30, 2023
2db0447
Compiles again
reknih Oct 30, 2023
1366da0
Switch from `csl_json_valley` to `citationberg::json`
laurmaedje Oct 30, 2023
111acd8
Fix issue, right group delimiter
reknih Oct 30, 2023
a217517
Pass formatting for transparent
reknih Oct 30, 2023
7670172
Order archive
reknih Oct 30, 2023
f837f72
No reviews!
reknih Oct 30, 2023
b4d304f
Add docs
reknih Oct 30, 2023
af4d3a1
Version bump
reknih Oct 31, 2023
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
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- name: Check out CSL styles
run: |
cd ..
git clone --depth 1 https://github.com/citation-style-language/styles
- run: cargo build
- run: cargo test
- run: cargo test --features csl-json
102 changes: 102 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# 0.4.0

## Breaking changes:

Hayagriva now uses the [Citation Style Language](https://citationstyles.org) to
encode formatting styles. This means that Hayagriva's own formatting styles have
been deprecated.

### For users:
- The YAML input format has changed.
- Titles and formattable strings have been merged into one type. All
formattable strings can have a shorthand now.
- Formattable Strings do not have `title-case` and `sentence-case` keys
anymore. `shorthand` has been renamed to `short`. To prevent changes of
the text case of formattable strings, you can use braces. Enclose a part
of a formattable string (or `short`) in `{braces}` to print it as-is.
- The fields `doi`, `isbn`, and `issn` have been moved to `serial-number`
which can now be a dictionary containing these and arbitrary other serial
numbers like a `pmid` (PubMed ID) and `arxiv` (ArXiv Identifier).
- The `tweet` entry type has been renamed to `post`.
- All numeric variables can now also contains strings. Numbers can have
string affixes.

Refer to the updated
[file format](https://github.com/typst/hayagriva/blob/main/docs/file-format.md)
docs for examples.

### For developers:
- To use a CSL style, you can either supply a CSL file or use an archive of
provided styles with the `archive` feature.
- The `from_yaml_str` function will now return the new `Library` struct, with the
entries within.
- The `Database` struct has been replaced by the easier to handle
`BibliographyDriver`.
- We switched from `yaml_rust` to `serde_yaml`. The `Entry` now implement's
`serde`'s `Serialize` and `Deserialize` traits. Hence, the `from_yaml` and
`to_yaml` functions have been deleted.
- Brackets are no longer individually overridable. Instead, use the new
`CitePurpose`.
- `Entry::kind` has been renamed to `Entry::entry_type`.
- The citation styles `AuthorTitle` and `Keys` have been removed but can be
realized with CSL.

This release fixes many bugs and makes Hayagriva a serious contender for
reference management.

## Other changes

- We added the entry types `Performance` and `Original`.
- We added the field `call-number`.


# 0.3.2

Fixes a title case formatting bug introduced in the previous release.

# 0.3.1

_Bug Fixes:_
- Added an option to turn off abbreviation of journals (thanks to @CMDJojo)
- Fixed bugs with title case formatting (thanks to @jmskov)
- Fixed off-by-one error with dates in APA style (thanks to @bluebear94)
- Fixed supplements in the Alphanumeric and AuthorTitle styles (thanks to @lynn)
- Fixed bugs with sentence case formatting
- Fixed `verbatim` option
- Fixed terminal formatting
- Fixed some typos (thanks to @kianmeng and @bluebear94)

# 0.3.0

*Breaking:*
- Updated to `biblatex` 0.8.0

*Bug Fixes:*
- Fixed string indexing for titles, removed panic
- More permissive BibLaTeX parsing

# 0.2.1

*Bug Fixes:*
- Fixed APA bibliography ordering

# 0.2.0

*Breaking:*
- Replaced `NoHyphenation` formatting with `Link` formatting
- Switched to newest BibLaTeX (which is part of the public API)

*Bug Fixes:*
- Fixed IEEE bibliography ordering
- Fixed A, B, C, ... suffixes for Author Date citations
- Removed `println` calls

# 0.1.1

🐞 This release fixes the documentation of the CLI in the `README.md` file.
✨ There are new options for bracketed citations in the CLI.
✅ No breaking changes.

# 0.1.0

🎉 This is the initial release!
46 changes: 29 additions & 17 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "hayagriva"
version = "0.3.2"
version = "0.4.0"
authors = ["Martin Haug <mhaug@live.de>"]
edition = "2018"
edition = "2021"
license = "MIT OR Apache-2.0"
description = "Work with references: Literature database management, storage, and citation formatting"
repository = "https://github.com/typst/hayagriva"
Expand All @@ -11,25 +11,37 @@ categories = ["template-engine", "value-formatting", "command-line-utilities"]
keywords = ["bibliography", "citation", "reference", "bibtex", "literature"]

[features]
default = ["biblatex"]
cli = ["clap"]
default = ["biblatex", "archive"]
cli = ["clap", "strum"]
archive = ["rkyv", "ciborium"]
csl-json = ["citationberg/json"]

[dependencies]
biblatex = { version = "0.8", optional = true }
clap = { version = "3.1", optional = true, features = ["cargo"] }
chrono = { version = "0.4", default-features = false }
isolang = "2.1"
lazy_static = "1.4.0"
linked-hash-map = "0.5.3"
paste = "1.0.0"
regex = { version = "1.4", default-features = false, features = ["std", "unicode-perl"] }
strum = { version = "0.24", features = ["derive"] }
thiserror = "1.0.20"
unic-langid = "0.9.0"
citationberg = { version = "0.1" }
indexmap = { version = "2.0.2", features = ["serde"] }
numerals = "0.1.4"
paste = "1.0.14"
serde = { version = "1", features = ["derive"] }
serde_yaml = "0.9.25"
thiserror = "1.0.48"
unic-langid = { version = "0.9.0", features = ["serde"] }
unicode-segmentation = "1.6.0"
url = "2.1.1"
yaml-rust = "0.4.4"
unscanny = "0.1.0"
url = { version = "2.4", features = ["serde"] }
biblatex = { version = "0.8.1", optional = true }
ciborium = { version = "0.2.1", optional = true }
clap = { version = "3.1", optional = true, features = ["cargo"] }
rkyv = { version = "0.7.42", optional = true }
strum = { version = "0.24", features = ["derive"], optional = true }

[dev-dependencies]
serde_json = "1"

[[bin]]
name = "hayagriva"
required-features = ["cli"]

[[test]]
name = "citeproc"
path = "tests/citeproc.rs"
required-features = ["csl-json"]
8 changes: 8 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Licenses for third party components used by this project can be found below.

================================================================================
The Creative Commons BY-SA 3.0 DEED License applies to:
* The CSL styles found in `tests/data/*`
* The CSL styles and locales found in `styles.cbor.rkyv`

https://creativecommons.org/licenses/by-sa/3.0/
91 changes: 51 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,14 @@ to install and use Hayagriva on your terminal.

## Supported styles

- Institute of Electrical and Electronics Engineers (IEEE)
- References
- Numerical citations
- Modern Language Association (MLA), 8th edition of the MLA Handbook
- "Works Cited" references
- Chicago Manual of Style (CMoS), 17th edition
- Notes and Bibliography
- Author-Date references and citations
- American Psychological Association (APA), 7th edition of the APA Publication Manual
- References
- Other in-text citation styles
- Alphanumerical (e. g. "Rass97")
- Author Title

## Usage

Add this to your `Cargo.toml`:
```toml
[dependencies]
hayagriva = "0.3"
```
Hayagriva supports all styles provided in the
[official Citation Style Language repository](https://github.com/citation-style-language/styles),
currently over 2,600.

Below, there is an example of how to parse a YAML database and get a Modern
Language Association-style citation.
# Usage

```rust
use hayagriva::io::from_yaml_str;
use hayagriva::style::{Database, Mla};

let yaml = r#"
crazy-rich:
Expand All @@ -65,20 +45,46 @@ crazy-rich:

// Parse a bibliography
let bib = from_yaml_str(yaml).unwrap();
assert_eq!(bib[0].date().unwrap().year, 2014);
assert_eq!(bib.get("crazy-rich").unwrap().date().unwrap().year, 2014);

// Format the reference
let db = Database::from_entries(bib.iter());
let mut mla = Mla::new();
let reference = db.bibliography(&mut mla, None);
assert_eq!(reference[0].display.value, "Kwan, Kevin. Crazy Rich Asians. Anchor Books, 2014.");
use std::fs;
use hayagriva::{
BibliographyDriver, BibliographyRequest, BufWriteFormat,
CitationItem, CitationRequest,
};
use hayagriva::citationberg::{LocaleFile, IndependentStyle};

let en_locale = fs::read_to_string("tests/data/locales-en-US.xml").unwrap();
let locales = [LocaleFile::from_xml(&en_locale).unwrap().into()];

let style = fs::read_to_string("tests/data/art-history.csl").unwrap();
let style = IndependentStyle::from_xml(&style).unwrap();

let mut driver = BibliographyDriver::new();

for entry in bib.iter() {
let items = vec![CitationItem::with_entry(entry)];
driver.citation(CitationRequest::from_items(items, &style, &locales));
}

let result = driver.finish(BibliographyRequest {
style: &style,
locale: None,
locale_files: &locales,
});

for cite in result.citations {
println!("{}", cite.citation.to_string())
}
```

Formatting for in-text citations is available through implementors of the
`hayagriva::style::CitationStyle` trait whereas bibliographies can be created by
`hayagriva::style::BibliographyStyle`. Both traits are used through
`style::Database` which provides methods to format its records as bibliographies
and citations.
To format entries, you need to wrap them in a `CitationRequest`. Each of these
can reference multiple entries in their respective `CitationItem`s.
Use these with a `BibliographyDriver` to obtain formatted citations and bibliographies.

You can either supply your own CSL files or choose from about 100 bundled
citation styles using the `archive` feature.

If the default features are enabled, Hayagriva supports BibTeX and BibLaTeX
bibliographies. You can use `io::from_biblatex_str` to parse such
Expand Down Expand Up @@ -133,7 +139,7 @@ quantized-vortex:

let entries = from_yaml_str(yaml).unwrap();
let journal = select!((Article["date"]) > ("journal":Periodical));
assert!(journal.matches(&entries[0]));
assert!(journal.matches(entries.nth(0).unwrap()));
```

There are two ways to check if a selector matches an entry.
Expand Down Expand Up @@ -164,7 +170,8 @@ dependence:
title: The program dependence graph and its use in optimization
author: ["Ferrante, Jeanne", "Ottenstein, Karl J.", "Warren, Joe D."]
date: 1987-07
doi: "10.1145/24039.24041"
serial-number:
doi: "10.1145/24039.24041"
parent:
type: Periodical
title: ACM Transactions on Programming Languages and Systems
Expand Down Expand Up @@ -254,12 +261,10 @@ tab. We would also be very happy to accept PRs for bug fixes, minor
refactorings, features that were requested in the issues and greenlit by us, as
well as the planned features listed below:

- More citation and reference styles (especially styles used in the 'hard'
sciences would be incredibly appreciated)
- Implementing the YAML-to-BibLaTeX conversion
- Improvements to the sentence and title formatter
- Work for non-English bibliographies
- Documentation improvements
- CSL bugfixes
- CSL-M Support

We wish to thank each and every prospective contributor for the effort you (plan
to) invest in this project and for adopting it!
Expand All @@ -271,3 +276,9 @@ Hayagriva is licensed under a MIT / Apache 2.0 dual license.
Users and consumers of the library may choose which of those licenses they want
to apply whereas contributors have to accept that their code is in compliance
and distributed under the terms of both of these licenses.

Hayagriva includes CSL styles that are licensed as CC-BY-SA 3.0 Deed if the
`archive` feature is enabled. The file `styles.cbor.rkyv` is a collection of
these works and falls under this license. Retrieve attribution information by
deserializing it using the `styles` function and reading the `StyleInfo`
structs.
Loading