-
Notifications
You must be signed in to change notification settings - Fork 3
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
First stab at adding support for the BibTeX format #94
base: main
Are you sure you want to change the base?
Changes from all commits
0cab413
087849a
e6d28da
2ca305c
89cc7e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
- [YAML](./yaml/) | ||
- [CSV](./csv/) | ||
- [TOML](./toml/) | ||
- [BibTeX](./bibtex/) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# BibTeX Format | ||
|
||
Uses the [`biblatex-csl-converter`](https://www.npmjs.com/package/biblatex-csl-converter) npm package. | ||
|
||
See the [supported options](https://github.com/fiduswriter/biblatex-csl-converter/blob/1a9c5903e7bdf517bcc61e0d61b8befbea91f21e/src/import/biblatex.ts#L33-L110) for low-level usage. | ||
|
||
Known issues: | ||
- doesn't preserve the formatting in the source `.bib` file on saving (see https://github.com/fiduswriter/biblatex-csl-converter/issues/132) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import Format from "../../src/format.js"; | ||
import { BibLatexParser, BibLatexExporter } from "https://esm.sh/biblatex-csl-converter/lib/index.js"; | ||
|
||
export default class BibTeX extends Format { | ||
static defaultOptions = { | ||
processUnexpected: true, | ||
processUnknown: true, | ||
}; | ||
|
||
static extensions = ["bib"]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That’s the most popular one, but pretty sure there are a few more extensions in use. |
||
static mimeTypes = ["text/plain"]; | ||
|
||
static parse (str, options) { | ||
options = this.resolveOptions(options, "parse"); | ||
return new BibLatexParser(str, options).parse(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIRC this does not produce a useful format by itself, though it preserves duplicate keys which could be useful for some use cases like reference managers. |
||
} | ||
|
||
static stringify (obj, options) { | ||
options = this.resolveOptions(options, "stringify"); | ||
return new BibLatexExporter(obj.entries, false, options).parse(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure we’d want to expose these options wholesale. We may want to expose the functionality, but with a different API. I’d not expose for now — once you expose, you need to support that forever.
Remember ideally we should be able to swap out the parser/serializer for a different package and our end-users shouldn't have to change much.