Add conversion to WasmAstNode for wasm Objects.

This commit is contained in:
Tom Alexander 2023-12-27 19:53:07 -05:00
parent 7626a69fa1
commit 28ad4fd046
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
29 changed files with 235 additions and 1 deletions

View File

@ -28,3 +28,9 @@ to_wasm!(
}) })
} }
); );
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmAngleLink<'s, 'p> {
fn into(self) -> WasmAstNode<'s, 'p> {
WasmAstNode::AngleLink(self)
}
}

View File

@ -28,3 +28,9 @@ to_wasm!(
}) })
} }
); );
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmBold<'s, 'p> {
fn into(self) -> WasmAstNode<'s, 'p> {
WasmAstNode::Bold(self)
}
}

View File

@ -28,3 +28,9 @@ to_wasm!(
}) })
} }
); );
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmCitation<'s, 'p> {
fn into(self) -> WasmAstNode<'s, 'p> {
WasmAstNode::Citation(self)
}
}

View File

@ -28,3 +28,9 @@ to_wasm!(
}) })
} }
); );
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmCitationReference<'s, 'p> {
fn into(self) -> WasmAstNode<'s, 'p> {
WasmAstNode::CitationReference(self)
}
}

View File

@ -28,3 +28,9 @@ to_wasm!(
}) })
} }
); );
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmCode<'s, 'p> {
fn into(self) -> WasmAstNode<'s, 'p> {
WasmAstNode::Code(self)
}
}

View File

@ -28,3 +28,9 @@ to_wasm!(
}) })
} }
); );
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmEntity<'s, 'p> {
fn into(self) -> WasmAstNode<'s, 'p> {
WasmAstNode::Entity(self)
}
}

View File

@ -28,3 +28,9 @@ to_wasm!(
}) })
} }
); );
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmExportSnippet<'s, 'p> {
fn into(self) -> WasmAstNode<'s, 'p> {
WasmAstNode::ExportSnippet(self)
}
}

View File

@ -28,3 +28,9 @@ to_wasm!(
}) })
} }
); );
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmFootnoteReference<'s, 'p> {
fn into(self) -> WasmAstNode<'s, 'p> {
WasmAstNode::FootnoteReference(self)
}
}

View File

@ -28,3 +28,9 @@ to_wasm!(
}) })
} }
); );
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmInlineBabelCall<'s, 'p> {
fn into(self) -> WasmAstNode<'s, 'p> {
WasmAstNode::InlineBabelCall(self)
}
}

View File

@ -28,3 +28,9 @@ to_wasm!(
}) })
} }
); );
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmInlineSourceBlock<'s, 'p> {
fn into(self) -> WasmAstNode<'s, 'p> {
WasmAstNode::InlineSourceBlock(self)
}
}

View File

@ -28,3 +28,9 @@ to_wasm!(
}) })
} }
); );
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmItalic<'s, 'p> {
fn into(self) -> WasmAstNode<'s, 'p> {
WasmAstNode::Italic(self)
}
}

View File

@ -28,3 +28,9 @@ to_wasm!(
}) })
} }
); );
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmLatexFragment<'s, 'p> {
fn into(self) -> WasmAstNode<'s, 'p> {
WasmAstNode::LatexFragment(self)
}
}

View File

@ -28,3 +28,9 @@ to_wasm!(
}) })
} }
); );
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmLineBreak<'s, 'p> {
fn into(self) -> WasmAstNode<'s, 'p> {
WasmAstNode::LineBreak(self)
}
}

View File

@ -28,3 +28,9 @@ to_wasm!(
}) })
} }
); );
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmOrgMacro<'s, 'p> {
fn into(self) -> WasmAstNode<'s, 'p> {
WasmAstNode::OrgMacro(self)
}
}

View File

@ -22,9 +22,19 @@ to_wasm!(
wasm_context, wasm_context,
standard_properties, standard_properties,
{ {
let children = original
.children
.iter()
.map(|child| {
child
.to_wasm(wasm_context.clone())
.map(Into::<WasmAstNode<'_, '_>>::into)
})
.collect::<Result<Vec<_>, _>>()?;
Ok(WasmParagraph { Ok(WasmParagraph {
standard_properties, standard_properties,
children: Vec::new(), children,
}) })
} }
); );

View File

@ -28,3 +28,9 @@ to_wasm!(
}) })
} }
); );
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmPlainLink<'s, 'p> {
fn into(self) -> WasmAstNode<'s, 'p> {
WasmAstNode::PlainLink(self)
}
}

View File

@ -28,3 +28,9 @@ to_wasm!(
}) })
} }
); );
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmPlainText<'s, 'p> {
fn into(self) -> WasmAstNode<'s, 'p> {
WasmAstNode::PlainText(self)
}
}

View File

@ -28,3 +28,9 @@ to_wasm!(
}) })
} }
); );
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmRadioLink<'s, 'p> {
fn into(self) -> WasmAstNode<'s, 'p> {
WasmAstNode::RadioLink(self)
}
}

View File

@ -28,3 +28,9 @@ to_wasm!(
}) })
} }
); );
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmRadioTarget<'s, 'p> {
fn into(self) -> WasmAstNode<'s, 'p> {
WasmAstNode::RadioTarget(self)
}
}

View File

@ -28,3 +28,9 @@ to_wasm!(
}) })
} }
); );
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmRegularLink<'s, 'p> {
fn into(self) -> WasmAstNode<'s, 'p> {
WasmAstNode::RegularLink(self)
}
}

View File

@ -28,3 +28,9 @@ to_wasm!(
}) })
} }
); );
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmStatisticsCookie<'s, 'p> {
fn into(self) -> WasmAstNode<'s, 'p> {
WasmAstNode::StatisticsCookie(self)
}
}

View File

@ -28,3 +28,9 @@ to_wasm!(
}) })
} }
); );
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmStrikeThrough<'s, 'p> {
fn into(self) -> WasmAstNode<'s, 'p> {
WasmAstNode::StrikeThrough(self)
}
}

View File

@ -28,3 +28,9 @@ to_wasm!(
}) })
} }
); );
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmSubscript<'s, 'p> {
fn into(self) -> WasmAstNode<'s, 'p> {
WasmAstNode::Subscript(self)
}
}

View File

@ -28,3 +28,9 @@ to_wasm!(
}) })
} }
); );
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmSuperscript<'s, 'p> {
fn into(self) -> WasmAstNode<'s, 'p> {
WasmAstNode::Superscript(self)
}
}

View File

@ -28,3 +28,9 @@ to_wasm!(
}) })
} }
); );
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmTarget<'s, 'p> {
fn into(self) -> WasmAstNode<'s, 'p> {
WasmAstNode::Target(self)
}
}

View File

@ -28,3 +28,9 @@ to_wasm!(
}) })
} }
); );
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmTimestamp<'s, 'p> {
fn into(self) -> WasmAstNode<'s, 'p> {
WasmAstNode::Timestamp(self)
}
}

View File

@ -2,6 +2,7 @@ use super::macros::to_wasm;
use super::WasmAstNode; use super::WasmAstNode;
use crate::error::CustomError; use crate::error::CustomError;
use crate::types::Element; use crate::types::Element;
use crate::types::Object;
pub trait ToWasm<'p> { pub trait ToWasm<'p> {
type Output; type Output;
@ -90,3 +91,64 @@ to_wasm!(
} }
} }
); );
to_wasm!(
WasmAstNode<'s, 'p>,
Object<'s>,
original,
wasm_context,
standard_properties,
{
match original {
Object::Bold(inner) => inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into),
Object::Italic(inner) => inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into),
Object::Underline(inner) => inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into),
Object::StrikeThrough(inner) => {
inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into)
}
Object::Code(inner) => inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into),
Object::Verbatim(inner) => inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into),
Object::PlainText(inner) => inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into),
Object::RegularLink(inner) => {
inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into)
}
Object::RadioLink(inner) => inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into),
Object::RadioTarget(inner) => {
inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into)
}
Object::PlainLink(inner) => inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into),
Object::AngleLink(inner) => inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into),
Object::OrgMacro(inner) => inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into),
Object::Entity(inner) => inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into),
Object::LatexFragment(inner) => {
inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into)
}
Object::ExportSnippet(inner) => {
inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into)
}
Object::FootnoteReference(inner) => {
inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into)
}
Object::Citation(inner) => inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into),
Object::CitationReference(inner) => {
inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into)
}
Object::InlineBabelCall(inner) => {
inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into)
}
Object::InlineSourceBlock(inner) => {
inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into)
}
Object::LineBreak(inner) => inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into),
Object::Target(inner) => inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into),
Object::StatisticsCookie(inner) => {
inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into)
}
Object::Subscript(inner) => inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into),
Object::Superscript(inner) => {
inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into)
}
Object::Timestamp(inner) => inner.to_wasm(wasm_context).map(Into::<WasmAstNode>::into),
}
}
);

View File

@ -28,3 +28,9 @@ to_wasm!(
}) })
} }
); );
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmUnderline<'s, 'p> {
fn into(self) -> WasmAstNode<'s, 'p> {
WasmAstNode::Underline(self)
}
}

View File

@ -28,3 +28,9 @@ to_wasm!(
}) })
} }
); );
impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmVerbatim<'s, 'p> {
fn into(self) -> WasmAstNode<'s, 'p> {
WasmAstNode::Verbatim(self)
}
}