organic/src/wasm/footnote_reference.rs
2023-12-30 16:05:41 -05:00

50 lines
1.4 KiB
Rust

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;
use crate::types::FootnoteReference;
use crate::types::FootnoteReferenceType;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize, Deserialize)]
pub struct WasmFootnoteReference {
pub(crate) label: Option<String>,
#[serde(rename = "type")]
pub(crate) footnote_reference_type: String,
}
to_wasm!(
WasmFootnoteReference,
FootnoteReference<'s>,
original,
wasm_context,
{ WasmAstNode::FootnoteReference(original) },
{ "footnote-reference".into() },
{
let children = original
.definition
.iter()
.map(|child| {
child
.to_wasm(wasm_context.clone())
.map(Into::<WasmAstNode>::into)
})
.collect::<Result<Vec<_>, _>>()?;
Ok((
children,
WasmFootnoteReference {
label: original.label.map(|s| s.to_owned()),
footnote_reference_type: match original.get_type() {
FootnoteReferenceType::Standard => "standard",
FootnoteReferenceType::Inline => "inline",
}
.to_owned(),
},
))
}
);