Return `dyn Iterator` instead of `Vec` for `SupportedContent`
Dependencies
- [2]
ZRGSUUICAdd MVP list support - [3]
BA5Y6VSEOutput Rust code using `syn` - [4]
HEUMSBESOuput use statements in generated file - [5]
GYTRFADRSupport Typst subdirectories - [6]
BSJYWOYSImplement MVP Typst embedding - [7]
HEIF2O2EMigrate from `pandoc` to `typst` for AST processing - [8]
I5IZPMTHHandle empty expressions - [9]
4MMVEN5YMove generated docs inside of parent `docs` module - [10]
I3NG5A4WAdd support for content sequences - [11]
MPTQGIIJImprove `typst_rust_gen` function names - [12]
Q3IYM4WFAdd MVP table support - [13]
CQEA2ZDIParse evaluated Typst code instead of AST - [14]
YKL5NCLHImport items from `syn` - [15]
2N3KOCP7Create MVP Pandoc->Rust compiler
Change contents
- replacement in docs/test.typ at line 1
List:- First- Second- ThirdOrdered:+ First+ Second+ Third#show emph: it => {text(blue, it.body)} - replacement in docs/test.typ at line 5
#enum(enum.item(1)[First step],enum.item(5)[Fifth step],enum.item(10)[Tenth step])[2.67]This is _emphasized_ differently. - replacement in crates/typser/src/lib.rs at line 10
token, AngleBracketedGenericArguments, ExprCall, ExprLit, ExprPath, ExprTuple, GenericArgument,token, AngleBracketedGenericArguments, ExprLit, ExprTuple, GenericArgument, - edit in crates/typser/src/lib.rs at line 241[3.10600]→[3.10600:10607](∅→∅),[3.3254]→[3.3110:3113](∅→∅),[3.10607]→[3.3110:3113](∅→∅),[3.3110]→[3.3110:3113](∅→∅),[3.3113]→[3.3953:4127](∅→∅),[3.4127]→[3.3307:3316](∅→∅),[3.3307]→[3.3307:3316](∅→∅),[3.3316]→[3.1172:1212](∅→∅),[3.1212]→[3.4163:4246](∅→∅),[3.4163]→[3.4163:4246](∅→∅),[3.3449]→[3.1947:1948](∅→∅),[3.4246]→[3.1947:1948](∅→∅),[3.1947]→[3.1947:1948](∅→∅),[3.1948]→[3.3255:3366](∅→∅),[3.3366]→[3.3543:3583](∅→∅),[3.3543]→[3.3543:3583](∅→∅),[3.3583]→[3.4247:4278](∅→∅),[3.4278]→[3.3619:3767](∅→∅),[3.3619]→[3.3619:3767](∅→∅),[3.3767]→[3.1213:1244](∅→∅),[3.1244]→[3.394:397](∅→∅),[3.4305]→[3.394:397](∅→∅),[3.397]→[3.1245:1354](∅→∅),[3.1354]→[3.485:599](∅→∅),[3.485]→[3.485:599](∅→∅),[3.599]→[3.1355:1417](∅→∅)
})}fn path_segment(segment: &str) -> PathSegment {PathSegment {ident: Ident::new(segment, proc_macro2::Span::call_site()),arguments: PathArguments::None,}}fn expr_path(name: &str) -> syn::Expr {let mut segments: Punctuated<PathSegment, token::PathSep> = Punctuated::new();// The path should be elements::name// e.g. elements::h2segments.push(path_segment("elements"));segments.push(path_segment(name));let expr_path = ExprPath {attrs: Vec::new(),qself: None,path: syn::Path {leading_colon: None,segments,},};syn::Expr::Path(expr_path)}fn xilem_html_element(name: &str, expressions: Vec<syn::Expr>) -> syn::Expr {syn::Expr::Call(ExprCall {attrs: Vec::new(),func: Box::new(expr_path(name)),paren_token: token::Paren::default(),args: Punctuated::from_iter(expressions.into_iter()), - edit in crates/typser/src/content.rs at line 1
use syn::punctuated::Punctuated;use syn::{token, ExprPath, PathSegment}; - replacement in crates/typser/src/content.rs at line 8
use crate::{literal_string, xilem_html_element};use crate::literal_string; - replacement in crates/typser/src/content.rs at line 55
pub fn to_xilem(&self) -> Vec<syn::Expr> {pub fn to_xilem(&self) -> Box<dyn Iterator<Item = syn::Expr> + '_> { - replacement in crates/typser/src/content.rs at line 57
SupportedContent::Sequence(sequence) => sequence.iter().map(SupportedContent::to_xilem).flatten().collect::<Vec<_>>(),SupportedContent::Sequence(sequence) => {Box::new(sequence.iter().map(SupportedContent::to_xilem).flatten())} - replacement in crates/typser/src/content.rs at line 62
vec![xilem_html_element("h1", body_text.to_xilem())]Box::new(Some(xilem_html_element("h1", body_text.to_xilem())).into_iter()) - replacement in crates/typser/src/content.rs at line 65
vec![syn::Expr::Lit(literal_string(text.text().as_str()))]Box::new(Some(syn::Expr::Lit(literal_string(text.text().as_str()))).into_iter()) - replacement in crates/typser/src/content.rs at line 67[3.1393]→[3.1393:1634](∅→∅),[3.1634]→[3.881:983](∅→∅),[3.881]→[3.881:983](∅→∅),[3.983]→[3.1635:2885](∅→∅),[3.2885]→[2.951:1047](∅→∅)
SupportedContent::Space(_space) => vec![syn::Expr::Lit(literal_string(" "))],SupportedContent::Table(table) => vec![xilem_html_element("table",vec![syn::Expr::Tuple(syn::ExprTuple {attrs: Vec::new(),paren_token: syn::token::Paren::default(),elems: syn::punctuated::Punctuated::from_iter(table.children().into_iter().map(|content| SupportedContent::downcast(content)).map(|supported| supported.to_xilem()).flatten().collect::<Vec<_>>().chunks(2) // TODO: a slightly more sophisticated layout algorithm.map(|chunk| {xilem_html_element("tr",vec![syn::Expr::Tuple(syn::ExprTuple {attrs: Vec::new(),paren_token: syn::token::Paren::default(),elems: syn::punctuated::Punctuated::from_iter(chunk.into_iter().map(|item| item.to_owned()),),})],)}),),})],)],SupportedContent::UnorderedList(list) => {vec![xilem_html_element(SupportedContent::Space(_space) => {Box::new(Some(syn::Expr::Lit(literal_string(" "))).into_iter())}SupportedContent::Table(table) => Box::new(Some(xilem_html_element("table",Some(syn::Expr::Tuple(syn::ExprTuple {attrs: Vec::new(),paren_token: token::Paren::default(),elems: Punctuated::from_iter(table.children().into_iter().map(|content| SupportedContent::downcast(content)).map(|supported| supported.to_xilem().collect::<Vec<_>>()).flatten().collect::<Vec<_>>().chunks(2) // TODO: a slightly more sophisticated layout algorithm.map(|chunk| {xilem_html_element("tr",vec![syn::Expr::Tuple(syn::ExprTuple {attrs: Vec::new(),paren_token: token::Paren::default(),elems: Punctuated::from_iter(chunk.into_iter().map(|item| item.to_owned()),),})],)}),),})),)).into_iter(),),SupportedContent::UnorderedList(list) => Box::new(Some(xilem_html_element( - replacement in crates/typser/src/content.rs at line 107
paren_token: syn::token::Paren::default(),elems: syn::punctuated::Punctuated::from_iter(paren_token: token::Paren::default(),elems: Punctuated::from_iter( - replacement in crates/typser/src/content.rs at line 112
.map(|supported| supported.to_xilem()).map(|supported| supported.to_xilem().collect::<Vec<_>>()) - replacement in crates/typser/src/content.rs at line 116
)]}SupportedContent::OrderedList(list) => {vec![xilem_html_element()).into_iter(),),SupportedContent::OrderedList(list) => Box::new(Some(xilem_html_element( - replacement in crates/typser/src/content.rs at line 124
paren_token: syn::token::Paren::default(),elems: syn::punctuated::Punctuated::from_iter(paren_token: token::Paren::default(),elems: Punctuated::from_iter( - replacement in crates/typser/src/content.rs at line 129
.map(|supported| supported.to_xilem()).map(|supported| supported.to_xilem().collect::<Vec<_>>()) - replacement in crates/typser/src/content.rs at line 133
)]}SupportedContent::UnorderedListItem(item) => {vec![xilem_html_element()).into_iter(),),SupportedContent::UnorderedListItem(item) => Box::new(Some(xilem_html_element( - replacement in crates/typser/src/content.rs at line 143
paren_token: syn::token::Paren::default(),elems: syn::punctuated::Punctuated::from_iter(paren_token: token::Paren::default(),elems: Punctuated::from_iter( - replacement in crates/typser/src/content.rs at line 149
)]}SupportedContent::OrderedListItem(item) => {vec![xilem_html_element()).into_iter(),),SupportedContent::OrderedListItem(item) => Box::new(Some(xilem_html_element( - replacement in crates/typser/src/content.rs at line 159
paren_token: syn::token::Paren::default(),elems: syn::punctuated::Punctuated::from_iter(paren_token: token::Paren::default(),elems: Punctuated::from_iter( - replacement in crates/typser/src/content.rs at line 165
)]}SupportedContent::ParagraphBreak(_parahraph_break) => {vec![xilem_html_element()).into_iter(),),SupportedContent::ParagraphBreak(_parahraph_break) => Box::new(Some(xilem_html_element( - replacement in crates/typser/src/content.rs at line 173
paren_token: syn::token::Paren::default(),elems: syn::punctuated::Punctuated::new(),paren_token: token::Paren::default(),elems: Punctuated::new(), - replacement in crates/typser/src/content.rs at line 176
)]})).into_iter(),), - edit in crates/typser/src/content.rs at line 180
}}fn path_segment(segment: &str) -> syn::PathSegment {syn::PathSegment {ident: syn::Ident::new(segment, proc_macro2::Span::call_site()),arguments: syn::PathArguments::None, - edit in crates/typser/src/content.rs at line 189[3.4174]
fn expr_path(name: &str) -> syn::Expr {let mut segments: Punctuated<PathSegment, token::PathSep> = Punctuated::new();// The path should be elements::name// e.g. elements::h2segments.push(path_segment("elements"));segments.push(path_segment(name));let expr_path = ExprPath {attrs: Vec::new(),qself: None,path: syn::Path {leading_colon: None,segments,},};syn::Expr::Path(expr_path)}fn xilem_html_element(name: &str, expressions: impl IntoIterator<Item = syn::Expr>) -> syn::Expr {syn::Expr::Call(syn::ExprCall {attrs: Vec::new(),func: Box::new(expr_path(name)),paren_token: token::Paren::default(),args: Punctuated::from_iter(expressions.into_iter()),})}