Markdown parser fork with extended syntax for personal use.
1//! MDX JSX (text) occurs in the [text][] content type.
2//!
3//! ## Grammar
4//!
5//! MDX JSX (text) forms with the following BNF
6//! (<small>see [construct][crate::construct] for character groups</small>):
7//!
8//! ```bnf
9//! mdx_jsx_text ::= mdx_jsx
10//!
11//! ; See the `partial_mdx_jsx` construct for the BNF of that part.
12//! ```
13//!
14//! See [`mdx_jsx`][mdx_jsx] for more info.
15//!
16//! ## Tokens
17//!
18//! * [`MdxJsxTextTag`][Name::MdxJsxTextTag]
19//! * see [`mdx_jsx`][mdx_jsx] for more
20//!
21//! ## Recommendation
22//!
23//! See [`mdx_jsx`][mdx_jsx] for recommendations.
24//!
25//! ## References
26//!
27//! * [`jsx-text.js` in `micromark-extension-mdx-jsx`](https://github.com/micromark/micromark-extension-mdx-jsx/blob/main/dev/lib/jsx-text.js)
28//! * [`mdxjs.com`](https://mdxjs.com)
29//!
30//! [text]: crate::construct::text
31//! [mdx_jsx]: crate::construct::partial_mdx_jsx
32
33use crate::event::Name;
34use crate::state::{Name as StateName, State};
35use crate::tokenizer::Tokenizer;
36
37/// Start of MDX: JSX (text).
38///
39/// ```markdown
40/// > | a <B /> c
41/// ^
42/// ```
43pub fn start(tokenizer: &mut Tokenizer) -> State {
44 if Some(b'<') == tokenizer.current && tokenizer.parse_state.options.constructs.mdx_jsx_text {
45 tokenizer.tokenize_state.token_1 = Name::MdxJsxTextTag;
46 tokenizer.attempt(
47 State::Next(StateName::MdxJsxTextAfter),
48 State::Next(StateName::MdxJsxTextNok),
49 );
50 State::Retry(StateName::MdxJsxStart)
51 } else {
52 State::Nok
53 }
54}
55
56/// After an MDX JSX (text) tag.
57///
58/// ```markdown
59/// > | a <b> c
60/// ^
61/// ```
62pub fn after(tokenizer: &mut Tokenizer) -> State {
63 tokenizer.tokenize_state.token_1 = Name::Data;
64 State::Ok
65}
66
67/// At something that wasn’t an MDX JSX (text) tag.
68///
69/// ```markdown
70/// > | a < b
71/// ^
72/// ```
73pub fn nok(tokenizer: &mut Tokenizer) -> State {
74 tokenizer.tokenize_state.token_1 = Name::Data;
75 State::Nok
76}