Skip to content

Commit 1079555

Browse files
committed
docs
1 parent 0b2d9c3 commit 1079555

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/hast_util_to_swc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ pub struct Program {
5454
}
5555

5656
impl Program {
57+
/// Serialize to JS.
5758
pub fn serialize(&mut self) -> String {
5859
serialize(&mut self.module, Some(&self.comments))
5960
}

src/lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,26 @@ pub fn compile(value: &str, options: &Options) -> Result<String, message::Messag
6464
Ok(serialize(&mut program.module, Some(&program.comments)))
6565
}
6666

67+
/// Turn markdown into a syntax tree.
68+
///
69+
/// ## Errors
70+
///
71+
/// There are several errors that can occur with how
72+
/// JSX, expressions, or ESM are written.
73+
///
74+
/// ## Examples
75+
///
76+
/// ```
77+
/// use mdxjs::{mdast_util_from_mdx, Options};
78+
/// # fn main() -> Result<(), markdown::message::Message> {
79+
///
80+
/// let tree = mdast_util_from_mdx("# Hey, *you*!", &Options::default())?;
81+
///
82+
/// println!("{:?}", tree);
83+
/// // => Root { children: [Heading { children: [Text { value: "Hey, ", position: Some(1:3-1:8 (2-7)) }, Emphasis { children: [Text { value: "you", position: Some(1:9-1:12 (8-11)) }], position: Some(1:8-1:13 (7-12)) }, Text { value: "!", position: Some(1:13-1:14 (12-13)) }], position: Some(1:1-1:14 (0-13)), depth: 1 }], position: Some(1:1-1:14 (0-13)) }
84+
/// # Ok(())
85+
/// # }
86+
/// ```
6787
pub fn mdast_util_from_mdx(
6888
value: &str,
6989
options: &Options,
@@ -114,6 +134,7 @@ pub fn mdast_util_from_mdx(
114134
to_mdast(value, &parse_options)
115135
}
116136

137+
/// Compile hast into SWC’s ES AST.
117138
pub fn hast_util_to_swc(
118139
hast: &hast::Node,
119140
value: &str,

0 commit comments

Comments
 (0)