Skip to main content

textlane_core/models/
mdx.rs

1use crate::ArenaVec;
2use crate::models::data::Data;
3use crate::models::position::Position;
4
5/// A JSX element, `<a b="c">d</a>`, of mdast-util-mdx-jsx; mdast and hast share it, with
6/// their own children. A fragment, `<>d</>`, has no `name`.
7#[derive(Debug, PartialEq)]
8pub struct MdxJsxElement<'a, N> {
9    pub name: Option<&'a str>,
10    pub attributes: ArenaVec<'a, MdxJsxAttribute<'a>>,
11    pub children: ArenaVec<'a, N>,
12    pub position: Option<Position<'a>>,
13    /// unist's `data`, when the node carries any.
14    pub data: Option<&'a Data<'a>>,
15}
16
17/// One attribute of a JSX element: `b="c"` (`mdxJsxAttribute`) or `{...d}`
18/// (`mdxJsxExpressionAttribute`, its `value` the JavaScript between the braces).
19#[derive(Clone, Debug, PartialEq)]
20pub enum MdxJsxAttribute<'a> {
21    Attribute {
22        name: &'a str,
23        value: Option<MdxJsxAttributeValue<'a>>,
24        position: Option<Position<'a>>,
25        data: Option<&'a Data<'a>>,
26    },
27    Expression {
28        value: &'a str,
29        position: Option<Position<'a>>,
30        data: Option<&'a Data<'a>>,
31    },
32}
33
34/// The value of a JSX attribute: a string, or `{c}` (`mdxJsxAttributeValueExpression`).
35#[derive(Clone, Debug, PartialEq)]
36pub enum MdxJsxAttributeValue<'a> {
37    Literal(&'a str),
38    Expression {
39        value: &'a str,
40        data: Option<&'a Data<'a>>,
41    },
42}
43
44/// JavaScript in braces, `{a}`, as source: `mdxFlowExpression` or `mdxTextExpression`.
45#[derive(Clone, Debug, PartialEq)]
46pub struct MdxExpression<'a> {
47    pub value: &'a str,
48    pub position: Option<Position<'a>>,
49    /// unist's `data`, when the node carries any.
50    pub data: Option<&'a Data<'a>>,
51}
52
53/// JavaScript imports and exports, `import a from 'b'`, as source.
54#[derive(Clone, Debug, PartialEq)]
55pub struct MdxjsEsm<'a> {
56    pub value: &'a str,
57    pub position: Option<Position<'a>>,
58    /// unist's `data`, when the node carries any.
59    pub data: Option<&'a Data<'a>>,
60}