aboutsummaryrefslogtreecommitdiffstats
path: root/src/to_mdast.rs
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-09-19 17:29:59 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-09-19 17:29:59 +0200
commit9cb9e37c33173c16cbafd345f43e43b5a550537d (patch)
tree6b02d2ea2c3ba904887b01f88aee369bd1a026d8 /src/to_mdast.rs
parentdfe1f2da522afa3e86680fa763b2f3c75e86b3ca (diff)
downloadmarkdown-rs-9cb9e37c33173c16cbafd345f43e43b5a550537d.tar.gz
markdown-rs-9cb9e37c33173c16cbafd345f43e43b5a550537d.tar.bz2
markdown-rs-9cb9e37c33173c16cbafd345f43e43b5a550537d.zip
Add structs, enums for `mdast`
Diffstat (limited to '')
-rw-r--r--src/to_mdast.rs40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/to_mdast.rs b/src/to_mdast.rs
new file mode 100644
index 0000000..d56134a
--- /dev/null
+++ b/src/to_mdast.rs
@@ -0,0 +1,40 @@
+//! Turn events into a syntax tree.
+
+// To do: example.
+
+use crate::event::Event;
+use crate::mdast;
+use crate::Options;
+use alloc::vec;
+
+/// Turn events and bytes into a syntax tree.
+pub fn compile(events: &[Event], _bytes: &[u8], _options: &Options) -> mdast::Root {
+ mdast::Root {
+ kind: mdast::Kind::Root,
+ children: vec![],
+ position: Some(mdast::Position {
+ start: if events.is_empty() {
+ create_point(1, 1, 0)
+ } else {
+ point_from_event(&events[0])
+ },
+ end: if events.is_empty() {
+ create_point(1, 1, 0)
+ } else {
+ point_from_event(&events[events.len() - 1])
+ },
+ }),
+ }
+}
+
+fn point_from_event(event: &Event) -> mdast::Point {
+ create_point(event.point.line, event.point.column, event.point.index)
+}
+
+fn create_point(line: usize, column: usize, offset: usize) -> mdast::Point {
+ mdast::Point {
+ line,
+ column,
+ offset,
+ }
+}