larsgw / citation.js

Citation.js converts formats like BibTeX, Wikidata JSON and ContentMine JSON to CSL-JSON to convert to other formats like APA, Vancouver and back to BibTeX.
https://citation.js.org/
MIT License
222 stars 30 forks source link

Bibtext: @STRING cause error. #160

Closed RichardEb closed 4 years ago

RichardEb commented 5 years ago

citation.js can't parse Bibtext: @STRING . Here is an example code:

var sample = Cite.input('@string { foo = "Mrs. Foo" } @manual{article,' +
  'author  = {Test Name}, ' +
  'title   = foo  # "The title of the work",' +
  'journal = {The name of the journal},' +
  'address = {Address},'+
  'year    = 1993,' +
  'number  = 2,' +
  'pages   = {201-213},' +
  'month   = 7,' +
  'note    = {An optional note}, ' +
  'volume  = 4'+
'}');

This will throw rhis error:

Uncaught SyntaxError: Unexpected token at index 14: Expected ",", got "=". Returning completed entries.

Ref: http://www.bibtex.org/Format/

larsgw commented 5 years ago

Hi, thanks for the report :slightly_smiling_face:. I haven't implemented this yet, but it has been on my radar for a while (see #56). I'm looking into replacing the parser altogether which would make things like this much easier, but I still have to figure out what method would be best for that. I'll see if I can make a temporary patch for the current parser soon.

nichtich commented 5 years ago

I counted at least four BibTeX parsing modules at npmjs, wouldn't it make more sense to join forces with one of them instead of managing another parser?

RichardEb commented 5 years ago

Citation.js is quite the best. I also rely on the structure of the generated (json) object

larsgw commented 5 years ago

@nichtich You could always insert a different parser with the plugins API:

let Cite = require('citation-js')
let {parse} = require('astrocite-bibtex')

Cite.plugins.input.addDataParser('@bibtex/text', {parser: parse})

Cite('...').data

Run on RunKit

larsgw commented 4 years ago

Quick update: I'm working on a new parser with better performance and support for @string, among other things. I don't have an ETA, since I don't know if I want to bundle this update with the BibTeX mappings update, that depends on how fast things move along. EDIT: code at https://github.com/citation-js/bibtex-parser-experiments/tree/master/src/idea-reworked, you could probably use it already like I showed for astrocite above.

larsgw commented 4 years ago

This has been released in v0.5.0-alpha.3. I'll close this issue for now.