organic/src/wasm/plain_list_item.rs

61 lines
1.7 KiB
Rust
Raw Normal View History

use serde::Deserialize;
use serde::Serialize;
use super::ast_node::WasmAstNode;
use super::macros::to_wasm;
use super::to_wasm::ToWasm;
use crate::compare::ElispFact;
2023-12-29 23:06:45 -05:00
use crate::types::CheckboxType;
use crate::types::PlainListItem;
2023-12-29 23:06:45 -05:00
use crate::types::PlainListItemCounter;
use crate::types::PlainListItemPreBlank;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize, Deserialize)]
2023-12-29 12:49:43 -05:00
pub struct WasmPlainListItem {
2023-12-29 23:06:45 -05:00
pub(crate) tag: Vec<WasmAstNode>,
pub(crate) bullet: String,
pub(crate) counter: Option<PlainListItemCounter>,
pub(crate) checkbox: Option<String>,
#[serde(rename = "pre-blank")]
pub(crate) pre_blank: PlainListItemPreBlank,
}
to_wasm!(
2023-12-29 12:49:43 -05:00
WasmPlainListItem,
2023-12-25 11:51:39 -05:00
PlainListItem<'s>,
2023-12-25 12:32:35 -05:00
original,
wasm_context,
{ WasmAstNode::PlainListItem(original) },
2023-12-29 23:06:45 -05:00
{ "item".into() },
{
let children = original
.children
.iter()
.map(|child| {
child
.to_wasm(wasm_context.clone())
.map(Into::<WasmAstNode>::into)
})
.collect::<Result<Vec<_>, _>>()?;
Ok((
children,
WasmPlainListItem {
2023-12-29 23:06:45 -05:00
tag: Vec::new(),
bullet: original.bullet.to_owned(),
counter: original.counter.clone(),
checkbox: original.checkbox.as_ref().map(|(checkbox_type, _)| {
match checkbox_type {
CheckboxType::On => "on",
CheckboxType::Trans => "trans",
CheckboxType::Off => "off",
}
.to_owned()
}),
pre_blank: original.pre_blank,
},
))
}
);