Use generated Typst code from Rust
Dependencies
- [2]
HEUMSBESOuput use statements in generated file - [3]
C73UJ7ZYCreate simple `xilem_html` demo - [4]
A4E5KLI2Turn arguments into sidebar - [5]
REI53XR4Render argument state as HTML - [6]
JFJVY57RList `clap` argument IDs - [7]
BSJYWOYSImplement MVP Typst embedding - [8]
BA5Y6VSEOutput Rust code using `syn` - [*]
BMG4FSHNAdd basic `clap` support - [*]
2N3KOCP7Create MVP Pandoc->Rust compiler
Change contents
- edit in src/main.rs at line 7
include!(concat!(env!("OUT_DIR"), "/docs.rs")); - edit in src/main.rs at line 81
}fn content(state: &AppState) -> impl View<AppState> + ViewMarker {el::div(include_str!("../dist/.stage/docs/test.html")) - replacement in src/main.rs at line 93
el::div(content(&state)).attr("id", "content"),el::div(test()).attr("id", "content"), - edit in crates/typst_rust_gen/src/lib.rs at line 114
syn::UseTree::Name(syn::UseName {ident: syn::Ident::new("ViewMarker",proc_macro2::Span::call_site(),),}), - replacement in crates/typst_rust_gen/src/lib.rs at line 131
generics: syn::Generics::default(),generics: syn::Generics { lt_token: None, params: Punctuated::from_iter(vec![syn::GenericParam::Type(syn::TypeParam { attrs: Vec::new(), ident: syn::Ident::new("T", proc_macro2::Span::call_site()), colon_token: None, bounds: Punctuated::new(), eq_token: None, default: None })].into_iter()), gt_token: None, where_clause: None }, - replacement in crates/typst_rust_gen/src/lib.rs at line 135
output: syn::ReturnType::Default,output: syn::ReturnType::Type(syn::token::RArrow::default(),Box::new(syn::Type::ImplTrait(syn::TypeImplTrait {impl_token: syn::token::Impl::default(),bounds: Punctuated::from_iter(vec![syn::TypeParamBound::Trait(syn::TraitBound {paren_token: None,modifier: syn::TraitBoundModifier::None,lifetimes: None,path: syn::Path {leading_colon: None,segments: Punctuated::from_iter(vec![syn::PathSegment {ident: syn::Ident::new("ViewSequence",proc_macro2::Span::call_site(),),arguments: syn::PathArguments::AngleBracketed(syn::AngleBracketedGenericArguments {colon2_token: None,lt_token: syn::token::Lt::default(),args: Punctuated::from_iter(vec![syn::GenericArgument::Type(syn::Type::Path(syn::TypePath {qself: None,path: syn::Path {leading_colon: None,segments: Punctuated::from_iter(vec![syn::PathSegment { ident: syn::Ident::new("T", proc_macro2::Span::call_site()), arguments: syn::PathArguments::None }].into_iter()),},}),)].into_iter(),),gt_token: syn::token::Gt::default(),},),}].into_iter(),),},})].into_iter(),),})),), - replacement in build.rs at line 1
use std::{ffi::OsStr, path::PathBuf, process::Command};use std::{ffi::OsStr, path::PathBuf}; - edit in build.rs at line 3
use typst_rust_gen::transform_pandoc; - edit in build.rs at line 6
const TRUNK_STAGING_DIRECTORY: &str = "dist/.stage"; - edit in build.rs at line 10
println!("cargo:rerun-if-changed=docs");println!("cargo:rerun-if-changed=crates/typst_rust_gen"); - replacement in build.rs at line 24
std::fs::create_dir_all(TRUNK_STAGING_DIRECTORY).unwrap();let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());std::fs::create_dir_all(&out_dir).unwrap(); - edit in build.rs at line 29
let staging_dir = PathBuf::from(TRUNK_STAGING_DIRECTORY).join(DOCS_SOURCE); - replacement in build.rs at line 33
// Handle nested directories correctlylet remainder = if parent != prefix {assert!(parent.starts_with(&prefix));parent.strip_prefix(&prefix).unwrap().to_path_buf()} else {PathBuf::new()};// TODO: Handle nested directories correctly// let remainder = if parent != prefix {// assert!(parent.starts_with(&prefix));// parent.strip_prefix(&prefix).unwrap().to_path_buf()// } else {// PathBuf::new()// }; - replacement in build.rs at line 41
// Create the appropriate directory layoutlet mut output_path = staging_dir.join(remainder).join(file.path().file_name().unwrap());// Our input is .typ, but output is .htmloutput_path.set_extension("html");// Store everything inside one large autogenerated Rust filelet output_path = out_dir.join("docs.rs"); - replacement in build.rs at line 45
Command::new("pandoc").args([file.path().to_str().unwrap(),"-o",output_path.to_str().unwrap(),]).status().expect("Error running pandoc. Check if it's installed");// TODO: this will only work for a single file, in the top-level directorylet rust_code = transform_pandoc(file.path());std::fs::write(&output_path, rust_code).unwrap();