Skip to main content

Constructs

Struct Constructs 

Source
pub struct Constructs {
Show 29 fields pub attention: bool, pub autolink: bool, pub block_quote: bool, pub character_escape: bool, pub character_reference: bool, pub code_indented: bool, pub code_fenced: bool, pub code_text: bool, pub definition: bool, pub frontmatter: bool, pub autolink_literal: bool, pub footnote_definition: bool, pub label_start_footnote: bool, pub strikethrough: bool, pub table: bool, pub task_list_item: bool, pub hard_break_escape: bool, pub hard_break_trailing: bool, pub heading_atx: bool, pub heading_setext: bool, pub html_flow: bool, pub html_text: bool, pub label_start_image: bool, pub label_start_link: bool, pub label_end: bool, pub list_item: bool, pub math_flow: bool, pub math_text: bool, pub thematic_break: bool,
}
Expand description

Control which constructs are enabled.

Not all constructs can be configured. Notably, blank lines and paragraphs cannot be turned off.

§Examples

use base_markdown::Constructs;

// Use the default trait to get `CommonMark` constructs:
let commonmark = Constructs::default();

// To turn on all of GFM, use the `gfm` method:
let gfm = Constructs::gfm();

// Or, mix and match:
let custom = Constructs {
  math_flow: true,
  math_text: true,
  ..Constructs::gfm()
};

Fields§

§attention: bool

Attention.

> | a *b* c **d**.
      ^^^   ^^^^^
§autolink: bool

Autolink.

> | a <https://example.com> b <user@example.org>.
      ^^^^^^^^^^^^^^^^^^^^^   ^^^^^^^^^^^^^^^^^^
§block_quote: bool

Block quote.

> | > a
    ^^^
§character_escape: bool

Character escape.

> | a \* b
      ^^
§character_reference: bool

Character reference.

> | a &amp; b
      ^^^^^
§code_indented: bool

Code (indented).

> |     a
    ^^^^^
§code_fenced: bool

Code (fenced).

> | ~~~js
    ^^^^^
> | console.log(1)
    ^^^^^^^^^^^^^^
> | ~~~
    ^^^
§code_text: bool

Code (text).

> | a `b` c
      ^^^
§definition: bool

Definition.

> | [a]: b "c"
    ^^^^^^^^^^
§frontmatter: bool

Frontmatter with an unindented opening fence on the first document line, outside list items and blockquotes, and a matching closing fence.

Frontmatter is language-agnostic, following Markly and cmarkly. All forms produce a source-backed opaque node with NodeSyntax::Frontmatter metadata. Untagged --- and +++ imply YAML and TOML, with an empty info string. A format hint after either delimiter (such as --- json or ---yaml), or a language-tagged backtick/tilde code fence, supplies an explicit language. The parser preserves the raw body and the full authored info string without parsing the named format; Document::frontmatter_value returns the body. HTML omits the frontmatter. Backtick/tilde fences without a language, fences later in a document, and unclosed fences remain ordinary Markdown.

Markdown serialization retains the stored info string and body while normalizing spacing around the info string. It can lengthen fences or change their marker when edited content would close them prematurely, writing an implied language explicitly when replacing an untagged dash/plus delimiter, and adds a line ending before the closing fence when an edited body needs one. Round trips preserve the body and effective language.

use base_markdown::{Constructs, Document, NodeSyntax, ParseOptions};

let options = ParseOptions {
    constructs: Constructs { frontmatter: true, ..Constructs::default() },
    ..ParseOptions::default()
};
let document = Document::parse("```json title=example\n{\"draft\": true}\n```\n\n# Hello", &options).unwrap();
let node = document.children(document.root()).next().unwrap();
let Some(NodeSyntax::Frontmatter { info, .. }) = document.syntax(node) else { panic!() };
assert_eq!(info.resolve(document.source()).unwrap(), "json title=example");
assert_eq!(document.frontmatter_value(node), Some("{\"draft\": true}\n"));
> | ---
    ^^^
> | title: Neptune
    ^^^^^^^^^^^^^^
> | ---
    ^^^
§autolink_literal: bool

Autolink literal.

> | https://example.com
    ^^^^^^^^^^^^^^^^^^^
§footnote_definition: bool

Footnote definition.

> | [^a]: b
    ^^^^^^^
§label_start_footnote: bool

Footnote label start.

> | a[^b]
     ^^
§strikethrough: bool

Strikethrough.

> | a ~b~ c.
      ^^^
§table: bool

Table.

> | | a |
    ^^^^^
> | | - |
    ^^^^^
> | | b |
    ^^^^^
§task_list_item: bool

Task list item.

> | * [x] y.
      ^^^
§hard_break_escape: bool

Hard break (escape).

> | a\
     ^
  | b
§hard_break_trailing: bool

Hard break (trailing).

> | a␠␠
     ^^
  | b
§heading_atx: bool

Heading (atx).

> | # a
    ^^^
§heading_setext: bool

Heading (setext).

> | a
    ^^
> | ==
    ^^
§html_flow: bool

HTML (flow).

> | <div>
    ^^^^^
§html_text: bool

HTML (text).

> | a <b> c
      ^^^
§label_start_image: bool

Label start (image).

> | a ![b](c) d
      ^^
§label_start_link: bool

Label start (link).

> | a [b](c) d
      ^
§label_end: bool

Label end.

> | a [b](c) d
        ^^^^
§list_item: bool

List items.

> | * a
    ^^^
§math_flow: bool

Math (flow).

> | $$
    ^^
> | \frac{1}{2}
    ^^^^^^^^^^^
> | $$
    ^^
§math_text: bool

Math (text).

> | a $b$ c
      ^^^
§thematic_break: bool

Thematic break.

> | ***
    ^^^

Implementations§

Source§

impl Constructs

Source

pub fn gfm() -> Self

GFM.

GFM stands for GitHub flavored markdown. GFM extends CommonMark and adds support for autolink literals, footnotes, strikethrough, tables, and tasklists.

For more information, see the GFM specification: https://github.github.com/gfm/.

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 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

CommonMark.

CommonMark is a relatively strong specification of how markdown works. Most markdown parsers try to follow it.

For more information, see the CommonMark specification: https://spec.commonmark.org.

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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<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.