Skip to main content

Constructs

Struct Constructs 

Source
pub struct Constructs {
Show 21 fields pub autolink: bool, pub code_indented: bool, pub html_flow: bool, pub html_text: bool, pub gfm_autolink_literal: bool, pub gfm_footnote: bool, pub gfm_strikethrough: bool, pub gfm_strikethrough_single_tilde: bool, pub gfm_table: bool, pub gfm_task_list_item: bool, pub math_flow: bool, pub math_text: bool, pub math_text_single_dollar: bool, pub liquid: bool, pub wiki_link: bool, pub container_directive: bool, pub mdx_esm: bool, pub mdx_expression_flow: bool, pub mdx_expression_text: bool, pub mdx_jsx_flow: bool, pub mdx_jsx_text: bool,
}
Expand description

Which syntax constructs the parser recognizes.

CommonMark’s core (paragraphs, headings, thematic breaks, blockquotes, lists, fenced code, emphasis, links, hard breaks) is always on. Everything listed here is a construct that some dialect turns off or bolts on.

The default set mirrors Prettier’s parser composition: GFM + math + wiki-link + liquid, plus container directives (:::), which Prettier lacks and consequently corrupts.

Fields§

§autolink: bool

<https://example.com> / <user@example.com>. Syntax error in MDX.

§code_indented: bool

4-space indented code blocks. In MDX the indent is an ordinary paragraph (continuation) instead.

§html_flow: bool

HTML blocks (CommonMark types 1–7). In MDX < at flow start is JSX.

§html_text: bool

Inline HTML tags/comments. In MDX < in text is JSX.

§gfm_autolink_literal: bool

GFM bare-URL links (www.example.com). Printed verbatim.

§gfm_footnote: bool

GFM footnotes ([^label]).

§gfm_strikethrough: bool

GFM strikethrough (~~x~~).

§gfm_strikethrough_single_tilde: bool

Whether a single ~ also opens strikethrough. GitHub and Prettier (singleTilde: false) require ~~; keep this off to leave subscript conventions like H~2~O alone.

§gfm_table: bool

GFM tables.

§gfm_task_list_item: bool

GFM task list items (- [x]).

§math_flow: bool

$$ … $$ display math.

§math_text: bool

$$ … $$ inline math, printed verbatim.

§math_text_single_dollar: bool

Whether a single $ also opens inline math. Prettier (singleDollarTextMath: false) requires $$; keep this off to leave prose like $FOO and $10 alone.

§liquid: bool

{% … %} / {{ … }} template tags, multi-line capable. Never interpreted, kept lossless.

§wiki_link: bool

[[target]] wiki links, alias-less minimal form, printed verbatim.

§container_directive: bool

::: … ::: container directives. Fence lines are kept verbatim (dialects disagree on their grammar); only children are markdown.

§mdx_esm: bool

MDX import / export statements at flow start.

§mdx_expression_flow: bool

MDX {expr} as its own flow block.

§mdx_expression_text: bool

MDX {expr} in text.

§mdx_jsx_flow: bool

MDX JSX elements at flow start.

§mdx_jsx_text: bool

MDX JSX elements in text.

Implementations§

Source§

impl Constructs

Source

pub fn markdown() -> Self

Markdown mode: CommonMark + GFM + Prettier’s extensions + directives.

Source

pub fn mdx() -> Self

MDX mode: autolink / code_indented / html_flow / html_text off, the mdx_* family on. Unlike markdown mode, parsing can emit diagnostics (MDX has syntax errors; CommonMark does not).

TODO: Not usable yet: the mdx_* constructs are unimplemented, and disabling code_indented must also lift micromark’s 4-space/3-column indent limits engine-wide (currently hardcoded), so this preset misparses e.g. # hi.

NOTE: Design:

  • Expression boundaries need JavaScript lexing ({"}"}, {/* } */}, template literals), so this preset lives behind an mdx cargo feature that adds oxc_parser as an optional dependency. No injection point: the scanner is this crate’s own module, tested here. The oxc workspace patches oxc_parser to its path crate, as it does oxc_allocator.
  • Semantics follow Prettier’s MDX v3 parser (prettier/prettier#18533, micromark-extension-mdx-*):
    • {expr} (flow, text, JSX attribute values): at each candidate }, the text so far must be a complete expression (Parser::parse_expression, which rejects trailing content); otherwise continue to the next }, and fail at EOF.
    • import / export: ends at a blank line unless the parse error is at the end of input (label start == length, or an Unterminated ... lexer error), then continue past it. Prettier’s dummyAcorn does not validate the body, so neither do we.
    • JSX tags are lexed here; only their {...} attribute values consult the scanner.
    • A hand-written brace scanner would agree on every input Prettier can format (they differ only inside invalid JS, where Prettier throws), which is why oxc_lexer, once published, can replace the probing without changing fixtures.

Trait Implementations§

Source§

impl Clone for Constructs

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Constructs

Source§

impl Debug for Constructs

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Constructs

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for Constructs

Source§

impl PartialEq for Constructs

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Constructs

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<'a, T> FromIn<'a, T> for T

Source§

fn from_in(t: T, _: &'a Allocator) -> T

Converts to this type from the input type within the given allocator.
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<'a, T, U> IntoIn<'a, U> for T
where U: FromIn<'a, T>,

Source§

fn into_in(self, allocator: &'a Allocator) -> U

Converts this type into the (usually inferred) input type within the given allocator.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.