-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Merge branch 'develop'
Showing
24 changed files
with
444 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,49 @@ jobs: | |
- run: cargo install cross | ||
- name: Build | ||
run: cross build --target ${{ matrix.target }} | ||
wasm: | ||
name: Cargo wasm build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: dtolnay/rust-toolchain@stable | ||
with: | ||
targets: wasm32-unknown-unknown | ||
- uses: Swatinem/rust-cache@v2 | ||
- uses: jetli/[email protected] | ||
with: | ||
version: '0.2.95' | ||
- name: Build wasm | ||
run: cargo build -r --lib --target wasm32-unknown-unknown | ||
- name: Bind wasm | ||
run: | | ||
wasm-bindgen --target web --out-dir web/pkg \ | ||
target/wasm32-unknown-unknown/release/tex_fmt.wasm | ||
- name: Optimize wasm | ||
uses: NiklasEi/wasm-opt-action@v2 | ||
with: | ||
options: -Oz | ||
file: web/pkg/tex_fmt_bg.wasm | ||
output: web/pkg/tex_fmt_bg.wasm | ||
- name: Upload wasm | ||
if: github.ref == 'refs/heads/main' | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
path: "web/pkg" | ||
pages: | ||
if: github.ref == 'refs/heads/main' | ||
name: Deploy to GitHub Pages | ||
runs-on: ubuntu-latest | ||
needs: wasm | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Download WASM and JS artifacts | ||
uses: actions/download-artifact@v3 | ||
- run: mkdir -p web/pkg && mv pkg/* web/pkg/ && rmdir pkg | ||
- uses: peaceiris/actions-gh-pages@v3 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
publish_dir: web | ||
nix: | ||
name: Nix build | ||
runs-on: ubuntu-latest | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
**/*.rs.bk | ||
*.pdb | ||
/result | ||
*.html | ||
*.log | ||
flamegraph.svg | ||
perf.data* | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//! Main library | ||
pub mod args; | ||
pub mod cli; | ||
pub mod comments; | ||
pub mod config; | ||
pub mod format; | ||
pub mod ignore; | ||
pub mod indent; | ||
pub mod logging; | ||
pub mod read; | ||
pub mod regexes; | ||
pub mod subs; | ||
pub mod verbatim; | ||
pub mod wasm; | ||
pub mod wrap; | ||
pub mod write; | ||
|
||
#[cfg(test)] | ||
pub mod tests; | ||
|
||
#[cfg(any(target_family = "unix", target_family = "wasm"))] | ||
/// Line ending for unix | ||
const LINE_END: &str = "\n"; | ||
|
||
#[cfg(target_family = "windows")] | ||
/// Line ending for Windows | ||
const LINE_END: &str = "\r\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use js_sys::{Object, Reflect}; | ||
use merge::Merge; | ||
use std::path::PathBuf; | ||
use wasm_bindgen::prelude::*; | ||
|
||
use crate::args::*; | ||
use crate::config::*; | ||
use crate::format::*; | ||
use crate::logging::*; | ||
|
||
#[wasm_bindgen] | ||
pub fn main(text: &str, config: &str) -> JsValue { | ||
// Get args | ||
let config = Some((PathBuf::new(), "".to_string(), config.to_string())); | ||
let mut args: OptionArgs = get_config_args(config).unwrap(); | ||
args.merge(OptionArgs::default()); | ||
let mut args = Args::from(args); | ||
args.stdin = true; | ||
|
||
// Run tex-fmt | ||
let mut logs = Vec::<Log>::new(); | ||
args.resolve(&mut logs); | ||
let file = "input"; | ||
let new_text = format_file(text, file, &args, &mut logs); | ||
let logs = format_logs(&mut logs, &args); | ||
|
||
// Wrap into JS object | ||
let js_object = Object::new(); | ||
Reflect::set(&js_object, &"output".into(), &new_text.into()).unwrap(); | ||
Reflect::set(&js_object, &"logs".into(), &logs.into()).unwrap(); | ||
js_object.into() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title> tex-fmt </title> | ||
</head> | ||
|
||
<body> | ||
<h1> tex-fmt </h1> | ||
<h3> An extremely fast LaTex formatter </h3> | ||
|
||
<!-- Buttons --> | ||
<div> | ||
<button id="submitButton">Format</button> | ||
<button id="copyButton">Copy output to clipboard</button> | ||
</div> | ||
|
||
<!-- Input and output --> | ||
<div style="display: flex; gap: 20px;"> | ||
|
||
<div style="flex: 1; display: flex; flex-direction: column; max-width: 600px;"> | ||
<h3> Input </h3> | ||
<textarea id="textInput" rows="30" cols="80"></textarea> | ||
</div> | ||
|
||
<div style="flex: 1; display: flex; flex-direction: column; max-width: 600px;"> | ||
<h3> Output </h3> | ||
<textarea id="textOutput" rows="30" cols="80" readonly></textarea> | ||
</div> | ||
|
||
</div> | ||
|
||
<!-- Config and logs --> | ||
<div style="display: flex; gap: 20px;"> | ||
|
||
<div style="flex: 1; display: flex; flex-direction: column; max-width: 600px;"> | ||
<h3> Config (optional) </h3> | ||
<textarea id="textConfig" rows="20" cols="80"></textarea> | ||
</div> | ||
|
||
<div style="flex: 1; display: flex; flex-direction: column; max-width: 600px;"> | ||
<h3> Logs </h3> | ||
<textarea id="textLog" rows="20" cols="80" readonly></textarea> | ||
</div> | ||
|
||
</div> | ||
|
||
<!-- Import script --> | ||
<script type="module" src="./index.js"></script> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Import wasm | ||
import init, { main } from './pkg/tex_fmt.js'; | ||
|
||
// Initialize wasm | ||
(async () => { | ||
try { | ||
await init(); | ||
console.log('WASM initialized successfully.'); | ||
} catch (error) { | ||
console.error('Error initializing WASM :', error); | ||
alert('Failed to initialize WASM. Check console for details.'); | ||
} | ||
})(); | ||
|
||
// Submit button logic | ||
document.getElementById('submitButton').addEventListener( | ||
'click', async () => { | ||
const inputText = document.getElementById('textInput').value; | ||
const outputBox = document.getElementById('textOutput'); | ||
const logBox = document.getElementById('textLog'); | ||
try { | ||
const configText = document.getElementById('textConfig').value; | ||
const result = await main(inputText, configText); | ||
outputBox.value = result.output; | ||
logBox.value = result.logs; | ||
} catch (error) { | ||
console.error('Error calling WebAssembly function:', error); | ||
alert('An error occurred. Check the console for details.'); | ||
} | ||
} | ||
); | ||
|
||
// Copy output text to clipboard | ||
document.getElementById('copyButton').addEventListener( | ||
'click', () => { | ||
const outputBox = document.getElementById('textOutput'); | ||
outputBox.select(); | ||
outputBox.setSelectionRange(0, 99999); | ||
try { | ||
document.execCommand('copy'); | ||
alert('Copied to clipboard:\n\n' + outputBox.value); | ||
} catch (err) { | ||
console.error('Failed to copy text: ', err); | ||
} | ||
} | ||
); |