From 6974ac8e14f31f6c9ee9c70da32a597ae22481aa Mon Sep 17 00:00:00 2001 From: jialin Date: Thu, 24 Oct 2024 19:17:56 +0800 Subject: [PATCH] chore: parse bibtex --- package.json | 1 + pnpm-lock.yaml | 7 ++++ src/components/bibtex-viewer/index.tsx | 47 ++++++++++++++++++++++++ src/components/markdown-viewer/index.tsx | 4 ++ typings.d.ts | 1 + 5 files changed, 60 insertions(+) create mode 100644 src/components/bibtex-viewer/index.tsx diff --git a/package.json b/package.json index 85e174c1..d58ef876 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "@huggingface/hub": "^0.15.1", "@huggingface/tasks": "^0.11.6", "@monaco-editor/react": "^4.6.0", + "@orcid/bibtex-parse-js": "^0.0.25", "@react-hook/resize-observer": "^2.0.2", "@types/lodash": "^4.17.4", "@umijs/max": "^4.2.11", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 956c3821..dd4d0034 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -26,6 +26,9 @@ dependencies: '@monaco-editor/react': specifier: ^4.6.0 version: 4.6.0(monaco-editor@0.52.0)(react-dom@18.2.0)(react@18.2.0) + '@orcid/bibtex-parse-js': + specifier: ^0.0.25 + version: 0.0.25 '@react-hook/resize-observer': specifier: ^2.0.2 version: 2.0.2(react@18.2.0) @@ -4604,6 +4607,10 @@ packages: '@nodelib/fs.scandir': 2.1.5 fastq: 1.17.1 + /@orcid/bibtex-parse-js@0.0.25: + resolution: {integrity: sha512-n6VuG5/WjiifC1DoUzq0sUCWNSbAyRZznBgvPcY4jVZ/2eJiMv2tNUAt2NukbnFExOUa0RyTOFsqhH2MGpiLgQ==, tarball: https://registry.npmjs.org/@orcid/bibtex-parse-js/-/bibtex-parse-js-0.0.25.tgz} + dev: false + /@pkgjs/parseargs@0.11.0: resolution: {integrity: sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==, tarball: https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz} engines: {node: '>=14'} diff --git a/src/components/bibtex-viewer/index.tsx b/src/components/bibtex-viewer/index.tsx new file mode 100644 index 00000000..372c955c --- /dev/null +++ b/src/components/bibtex-viewer/index.tsx @@ -0,0 +1,47 @@ +import bibtexParse from '@orcid/bibtex-parse-js'; +import { Typography } from 'antd'; +import React from 'react'; + +/* + @inproceedings{Lysenko:2010:GMC:1839778.1839781,\ + author = {Lysenko, Mikola and Nelaturi, Saigopal and Shapiro, Vadim},\ + title = {Group morphology with convolution algebras},\ + booktitle = {Proceedings of the 14th ACM Symposium on Solid and Physical Modeling},\ + series = {SPM '10},\ + year = {2010},\ + isbn = {978-1-60558-984-8},\ + location = {Haifa, Israel},\ + pages = {11--22},\ + numpages = {12},\ + url = {http://doi.acm.org/10.1145/1839778.1839781},\ + doi = {10.1145/1839778.1839781},\ + acmid = {1839781},\ + publisher = {ACM},\ + address = {New York, NY, USA},\ + } +*/ + +const BibTeXViewer: React.FC<{ data: string }> = ({ data }) => { + if (!data) { + return null; + } + const dataList = bibtexParse.toJSON(data); + return ( +
    + {dataList.map((item: any, index: number) => ( +
  1. + + {item.entryTags?.title}.{' '} + + {item.entryTags?.author}. + [{item.entryTags?.year}] + {item.entryTags?.journal && ( + .({item.entryTags?.journal}) + )} +
  2. + ))} +
+ ); +}; + +export default BibTeXViewer; diff --git a/src/components/markdown-viewer/index.tsx b/src/components/markdown-viewer/index.tsx index 969682b8..42dd5b00 100644 --- a/src/components/markdown-viewer/index.tsx +++ b/src/components/markdown-viewer/index.tsx @@ -42,6 +42,7 @@ const MarkdownViewer: React.FC = ({ 'del', 'blockquote', 'checkbox' + // 'bibtex' ]; // renderer.link = ({ href, title, text }) => { @@ -69,6 +70,7 @@ const MarkdownViewer: React.FC = ({ const renderItem = useCallback( (token: any, render: any) => { + console.log('token====', token); if (!reDefineTypes.includes(token.type)) { return ( = ({ if (token.type === 'paragraph') { htmlstr = {text}; } + if (token.type === 'code') { htmlstr = ( ); } + if (token.type === 'link') { htmlstr = (