├── hayagriva_wrapper ├── .gitignore ├── Cargo.toml └── src │ └── lib.rs ├── README.md ├── .github └── workflows │ └── build.yml ├── LICENSE └── index.html /hayagriva_wrapper/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /Cargo.lock 3 | -------------------------------------------------------------------------------- /hayagriva_wrapper/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "hayagriva_wrapper" 3 | version = "0.1.1" 4 | edition = "2021" 5 | 6 | [dependencies] 7 | hayagriva = "0.8.1" 8 | wasm-bindgen = "0.2.100" 9 | 10 | [lib] 11 | crate-type = ["cdylib", "rlib"] 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Webapp for converting BibTeX to [Hayagriva](https://github.com/typst/hayagriva) 2 | 3 | 1. open [webapp](https://jonasloos.github.io/bibtex-to-hayagriva-webapp/) 4 | 2. paste BibTeX 5 | 3. copy Hayagriva 6 | 7 | --- 8 | 9 | This project is just a small wrapper around the [haragriva](https://github.com/typst/hayagriva) rust library. 10 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build and Deploy 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | 8 | permissions: 9 | contents: read 10 | pages: write 11 | id-token: write 12 | 13 | jobs: 14 | build: 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - name: Checkout 19 | uses: actions/checkout@v4 20 | - name: wasm-pack-action 21 | uses: jetli/wasm-pack-action@v0.4.0 22 | - name: Build Wasm Package 23 | run: cd hayagriva_wrapper && wasm-pack build --target web --release --no-typescript --no-pack 24 | - name: Upload artifact 25 | uses: actions/upload-pages-artifact@v3 26 | with: 27 | # Upload entire repository 28 | path: '.' 29 | 30 | deploy: 31 | environment: 32 | name: github-pages 33 | url: ${{ steps.deployment.outputs.page_url }} 34 | runs-on: ubuntu-latest 35 | needs: build 36 | steps: 37 | - name: Deploy to GitHub Pages 38 | id: deployment 39 | uses: actions/deploy-pages@v4 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Jonas Loos 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /hayagriva_wrapper/src/lib.rs: -------------------------------------------------------------------------------- 1 | use wasm_bindgen::prelude::*; 2 | use hayagriva::io::from_biblatex_str; 3 | use hayagriva::io::to_yaml_str; 4 | 5 | #[wasm_bindgen] 6 | pub fn convert_biblatex_to_hayagriva(bib_str: &str) -> String { 7 | let result = from_biblatex_str(bib_str); 8 | match result { 9 | Ok(library) => { 10 | if library.is_empty() { 11 | return "Error parsing Bibtex".to_string(); 12 | } else { 13 | return to_yaml_str(&library).unwrap_or("Error converting to YAML".to_string()); 14 | } 15 | } 16 | Err(errors) => { 17 | let mut error_str = String::new(); 18 | error_str.push_str("Error parsing Bibtex: \n"); 19 | for error in errors { 20 | error_str.push_str("* "); 21 | error_str.push_str(&error.to_string()); 22 | error_str.push_str("\n"); 23 | } 24 | return error_str; 25 | } 26 | } 27 | } 28 | 29 | #[cfg(test)] 30 | mod tests { 31 | use super::*; 32 | 33 | #[test] 34 | fn test_convert_simple_bibtex() { 35 | let bibtex = r#" 36 | @article{example, 37 | title={Test Article}, 38 | author={John Doe}, 39 | journal={Test Journal}, 40 | year={2023}, 41 | } 42 | "#; 43 | 44 | let result = convert_biblatex_to_hayagriva(bibtex); 45 | 46 | // Should not be an error message 47 | assert!(!result.starts_with("Error parsing Bibtex")); 48 | assert!(!result.starts_with("Error converting to YAML")); 49 | 50 | // Should contain YAML-like content 51 | assert!(result.contains("example")); 52 | assert!(result.contains("Test Article")); 53 | } 54 | 55 | #[test] 56 | fn test_convert_invalid_bibtex() { 57 | let invalid_bibtex = "this is not valid bibtex"; 58 | 59 | let result = convert_biblatex_to_hayagriva(invalid_bibtex); 60 | 61 | // Should be an empty library since invalid bibtex just results in no entries 62 | assert_eq!(result, "Error parsing Bibtex"); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BibTeX to Hayagriva 6 | 7 | 8 | 118 | 119 | 120 |
121 |
122 |
123 |
124 |
125 | 126 | i 127 |
128 | 129 | 130 | 147 | 180 | 181 | 182 | --------------------------------------------------------------------------------