Skip to content

Commit

Permalink
Restore bibtex-parse-js
Browse files Browse the repository at this point in the history
  • Loading branch information
hubgit committed Oct 20, 2019
1 parent a690edc commit 2e9cffa
Show file tree
Hide file tree
Showing 4 changed files with 2,297 additions and 31 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -12,6 +12,7 @@
"@retorquere/bibtex-parser": "^1.0.74", "@retorquere/bibtex-parser": "^1.0.74",
"astrocite-bibtex": "^0.15.4", "astrocite-bibtex": "^0.15.4",
"biblatex-csl-converter": "^1.6.9", "biblatex-csl-converter": "^1.6.9",
"bibtex-parse-js": "^0.0.24",
"json-stable-stringify": "^1.0.1", "json-stable-stringify": "^1.0.1",
"react": "^16.10.2", "react": "^16.10.2",
"react-dom": "^16.10.2" "react-dom": "^16.10.2"
Expand Down
2 changes: 2 additions & 0 deletions src/App.tsx
Expand Up @@ -2,6 +2,7 @@ import React, { FormEvent, useCallback, useState } from 'react'
import './App.css' import './App.css'
import { Astrocite } from './Astrocite' import { Astrocite } from './Astrocite'
import { BibLatexCslConverter } from './BibLatexCslConverter' import { BibLatexCslConverter } from './BibLatexCslConverter'
import { BibtexParse } from './BibtexParse'
import { BibtexParser } from './BibtexParser' import { BibtexParser } from './BibtexParser'
import { Citation } from './Citation' import { Citation } from './Citation'


Expand Down Expand Up @@ -58,6 +59,7 @@ export const App: React.FC = () => {
<BibtexParser input={inputToParse} /> <BibtexParser input={inputToParse} />
<BibLatexCslConverter input={inputToParse} /> <BibLatexCslConverter input={inputToParse} />
<Citation input={inputToParse} /> <Citation input={inputToParse} />
<BibtexParse input={inputToParse} />
</> </>
)} )}
</div> </div>
Expand Down
46 changes: 46 additions & 0 deletions src/BibtexParse.tsx
@@ -0,0 +1,46 @@
import React, { useEffect, useState } from 'react'
import { toJSON } from 'bibtex-parse-js'
import { Item } from './Item'

export const BibtexParse: React.FC<{
input: string
}> = React.memo(({ input }) => {
const [items, setItems] = useState<CSL.Data[]>()
const [error, setError] = useState<string>()

useEffect(() => {
if (input) {
setError(undefined)

try {
const result = toJSON(input)
setItems(result)
} catch (error) {
setError(error.message)
}
}
}, [input])

if (!items) {
return null
}

if (error) {
return <div>{error}</div>
}

return (
<section>
<h2>
<a href={'https://github.com/ORCID/bibtexParseJs'}>bibtexParseJs</a>
</h2>
<ol>
{items.map(item => (
<li key={item.citationKey}>
<Item data={item} />
</li>
))}
</ol>
</section>
)
})

0 comments on commit 2e9cffa

Please sign in to comment.