change: bump typst ver + streamline cmd arguments
This commit is contained in:
parent
654b790fcb
commit
ad20a850fb
3 changed files with 698 additions and 277 deletions
918
Cargo.lock
generated
918
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
11
Cargo.toml
11
Cargo.toml
|
|
@ -6,9 +6,10 @@ edition = "2021"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
typst = "0.13.1"
|
clap = { version = "4.6.1", features = ["derive"] }
|
||||||
typst-as-lib = { version = "0.14.4", features = ["typst-html", "typst-kit-fonts", "typst-kit-embed-fonts"] }
|
typst = "0.14.2"
|
||||||
typst-html = "0.13.1"
|
typst-as-lib = { version = "0.15.4", features = ["typst-html", "typst-kit-fonts", "typst-kit-embed-fonts"] }
|
||||||
typst-pdf = "0.13.1"
|
typst-html = "0.14.2"
|
||||||
typst-svg = "0.13.1"
|
typst-pdf = "0.14.2"
|
||||||
|
typst-svg = "0.14.2"
|
||||||
|
|
||||||
|
|
|
||||||
46
src/main.rs
46
src/main.rs
|
|
@ -1,28 +1,47 @@
|
||||||
use typst_as_lib::{typst_kit_options::TypstKitFontOptions, TypstEngine};
|
use typst_as_lib::{typst_kit_options::TypstKitFontOptions, TypstEngine};
|
||||||
use typst::{ecow::EcoString, html::{HtmlAttr, HtmlDocument, HtmlElement, HtmlNode}};
|
use typst::{ecow::EcoString};
|
||||||
|
use typst_html::{HtmlAttr, HtmlDocument, HtmlElement, HtmlNode};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::path::Path;
|
use std::path::PathBuf;
|
||||||
|
use clap::Parser;
|
||||||
|
|
||||||
static COMMON: &str = include_str!("../common.typ");
|
#[derive(Parser)]
|
||||||
|
struct Args {
|
||||||
|
#[arg(default_value = ".")]
|
||||||
|
dir: PathBuf,
|
||||||
|
|
||||||
|
#[arg(long)]
|
||||||
|
prepend: Option<PathBuf>,
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args: Vec<String> = env::args().collect();
|
|
||||||
|
|
||||||
match env::current_dir() {
|
match env::current_dir() {
|
||||||
Ok(path) => println!("Current working directory: {}", path.display()),
|
Ok(path) => println!("Current working directory: {}", path.display()),
|
||||||
Err(e) => eprintln!("Error getting current directory: {}", e),
|
Err(e) => eprintln!("Error getting current directory: {}", e),
|
||||||
}
|
}
|
||||||
|
|
||||||
let file_path = Path::new(args.get(1).unwrap());
|
let args = Args::parse();
|
||||||
let article_dir: &str = file_path.parent().unwrap().to_str().unwrap();
|
|
||||||
let template_file = format!("{}/article.typ", article_dir);
|
let article_dir = args.dir;
|
||||||
let output = format!("{}/article.html", article_dir);
|
|
||||||
let outline_file = format!("{}/outline.html", article_dir);
|
let template_file = article_dir.join("article.typ");
|
||||||
|
let output = article_dir.join("article.html");
|
||||||
|
let outline_file = article_dir.join("outline.html");
|
||||||
|
|
||||||
|
let prepend_content = if let Some(prepend_file) = args.prepend {
|
||||||
|
fs::read_to_string(&prepend_file).unwrap_or_else(|_| {
|
||||||
|
panic!("Could not find prepend file {}.", prepend_file.to_str().unwrap());
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
fs::read_to_string(article_dir.join("prepend.typ")).unwrap_or_default()
|
||||||
|
};
|
||||||
|
|
||||||
let mut template: EcoString = EcoString::new();
|
let mut template: EcoString = EcoString::new();
|
||||||
template.push_str(COMMON);
|
template.push_str(&prepend_content);
|
||||||
template.push_str(fs::read_to_string(template_file).unwrap().as_str());
|
template.push_str(fs::read_to_string(&template_file).unwrap_or_else(|_| {
|
||||||
|
panic!("Could not find file {}.", &template_file.to_str().unwrap());
|
||||||
|
}).as_str());
|
||||||
|
|
||||||
let template = TypstEngine::builder()
|
let template = TypstEngine::builder()
|
||||||
.main_file(template.to_string())
|
.main_file(template.to_string())
|
||||||
|
|
@ -131,7 +150,8 @@ fn parse(elem: &mut HtmlElement, outline: &mut EcoString, curr_level: &mut u32)
|
||||||
elem.attrs.push(HtmlAttr::intern("id").unwrap(), slug);
|
elem.attrs.push(HtmlAttr::intern("id").unwrap(), slug);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for child in &mut elem.children {
|
|
||||||
|
for child in elem.children.make_mut().iter_mut() {
|
||||||
match child {
|
match child {
|
||||||
HtmlNode::Element(e) => {parse(e, outline, curr_level)}
|
HtmlNode::Element(e) => {parse(e, outline, curr_level)}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue