Currently styling is completely ignored, obviously that will need to change when doing styling re-work. Also, may end up being wiser to implement as flex-boxes, but will have to investigate further.
Q3IYM4WFHTO2IQLR2ZJ52FIE7U4RYIHQHXTPCK2HENSPVI7CPUZAC
I3NG5A4WXPELEOY3KFQKYBZVKA56VPGLI5R7O7TDCZTQAA7EROTQC
BSJYWOYSJRERQ45AD7RN3364RYQ5P3IM76S67262VLFZPFO3B5JQC
I5IZPMTHBVJWTR4RWCNMD75E3FHAHN3KY4XQPKAEV72PCDNFDOLQC
CQEA2ZDITRMPXKCO5T346QH7JJOOGOPRC66F3MG6VEMEQGLYYUZAC
2N3KOCP74PCK2ETO5PCWBDR5PA57DDNT2KR4JLBPZPQPA56SAR4QC
MPTQGIIJUNQSRWF5G63WDZLYH6EYURPENFTJ7J46VKPAWC6QQUGAC
BA5Y6VSEHJQBOYBS6R6FE6IZDRNAPNIN5ITJXWK7L46RJVHNI7JAC
YKL5NCLHVHFQMBIWC6HW4NFPPYK5DR6XTCKJ5VBHNLVP2RO3H24AC
JCYJWUI32EEUQVQBLUNTSWZI6OXZJIRQMDU72DXWTJVU2LJJ6QWQC
HEIF2O2ELHA3M7K77CK7AHBZ4656AUS3QW5M4E2DUY7ECOLVWKIAC
}
fn typst_expr_to_xilem(value: &typst::eval::Value) -> Option<syn::Expr> {
match value {
typst::eval::Value::Str(string) => Some(syn::Expr::Lit(literal_string(string.as_str()))),
typst::eval::Value::Content(content) => {
let supported_content = content::SupportedContent::downcast(content)?;
Some(supported_content.to_xilem()?)
}
_ => {
dbg!(value);
todo!()
}
}
let children = if let Some(typst::eval::Value::Array(array)) = root.get_by_name("children") {
array
} else {
dbg!(root);
todo!();
};
let xilem_expressions = children
.iter()
// Remove any empty expressions (`None`)
.filter_map(typst_expr_to_xilem)
let typed_content = content::SupportedContent::downcast(&root);
let xilem_expressions = typed_content
.to_xilem()
.into_iter()
pub fn downcast(value: &'a Content) -> Option<Self> {
if value.is_empty() {
None
} else if let Some(sequence) = value.to_sequence() {
pub fn downcast(value: &'a Content) -> Self {
if let Some(sequence) = value.to_sequence() {
pub fn to_xilem(&self) -> Option<syn::Expr> {
Some(match self {
SupportedContent::Sequence(sequence) => {
let children = split_tuple(
sequence
.iter()
.filter_map(SupportedContent::to_xilem)
.collect::<Vec<_>>(),
);
syn::Expr::Tuple(syn::ExprTuple {
pub fn to_xilem(&self) -> Vec<syn::Expr> {
match self {
SupportedContent::Sequence(sequence) => sequence
.iter()
.map(SupportedContent::to_xilem)
.flatten()
.collect::<Vec<_>>(),
SupportedContent::Heading(heading) => {
let body_text = Self::downcast(heading.body());
vec![xilem_html_element("h1", body_text.to_xilem())]
}
SupportedContent::Text(text) => {
vec![syn::Expr::Lit(literal_string(text.text().as_str()))]
}
SupportedContent::Space(_space) => vec![syn::Expr::Lit(literal_string(" "))],
SupportedContent::Table(table) => vec![xilem_html_element(
"table",
vec![syn::Expr::Tuple(syn::ExprTuple {
elems: syn::punctuated::Punctuated::from_iter(children.into_iter()),
})
}
SupportedContent::Heading(heading) => {
let body_text = Self::downcast(heading.body())?;
xilem_html_element("h1", vec![body_text.to_xilem()?])
}
SupportedContent::Text(text) => syn::Expr::Lit(literal_string(text.text().as_str())),
SupportedContent::Space(_space) => syn::Expr::Lit(literal_string(" ")),
})
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()),
),
})],
)
}),
),
})],
)],
}