Skip to main content

MarkdownExtensions

Struct MarkdownExtensions 

Source
pub struct MarkdownExtensions { /* private fields */ }
Expand description

Registry for custom Markdown parsing and rendering.

Implementations§

Source§

impl MarkdownExtensions

Source

pub fn parser_revision(self, revision: u64) -> Self

Change this revision when parser captures or plugin configuration change. Reusing it allows equivalent registrations rebuilt during rendering to retain the parsed document. Renderer-only changes do not need a new value.

Source

pub fn frontmatter(self) -> Self

Enable YAML frontmatter parsing.

Frontmatter is disabled by default because it is not part of CommonMark or GFM. Register a block parser or MarkdownPlugin to render the resulting mdast::Node::Yaml node.

Source

pub fn mdx(self) -> Self

Enable MDX JSX/expression constructs.

This disables raw HTML constructs because markdown-rs gives HTML priority over MDX when both are enabled.

Source

pub fn block_parser<F>(self, parser: F) -> Self
where F: for<'a> Fn(&Node, &MarkdownParseContext<'a>) -> Option<MarkdownNode> + Send + Sync + 'static,

Register a parser for block-level Markdown AST nodes.

Source

pub fn block_renderer<F, E>( self, name: impl Into<SharedString>, renderer: F, ) -> Self
where F: Fn(&MarkdownNode, &mut Window, &mut App) -> E + Send + Sync + 'static, E: IntoElement,

Register a renderer for a custom block node name.

Source

pub fn block_surface<F>(self, name: impl Into<SharedString>, render: F) -> Self
where F: Fn(&mut Window, &mut App) -> Div + Send + Sync + 'static,

Draw a top-level blockquote that opens with the marker [!name] inside a container.

> [!summary]
> Blocks of any kind, as many as you like.
>
> - They stay part of the document.

This is the syntax of GitHub alerts, with names of your own, and other renderers show it as a blockquote. Names match ASCII-case-insensitively, so [!NOTE] opens a surface registered as note. The marker is alone on the first line, and is not document text; the lines after it are the first paragraph.

render runs each time the document renders and returns the container with its background, shape, padding and text style, and any children to show before the blocks, such as an icon and a title. The blocks are appended to it and bring the view’s paragraph gap, so a gap on the container adds to that. Read theme colors in render, so a theme change needs no new parse. What the container shows itself is not document text. Unless the container sets a width, it takes the row’s.

The blocks remain the document’s: selection, range highlights and reveals go across and inside the container, and rendered_text has them without the marker. A select-all copies the source verbatim. A partial source copy is quoted under the marker line, as a blockquote’s is quoted.

Only a blockquote at the top level of a Markdown view, with a registered name, is a surface. A nested one stays a blockquote, and so does one with text after the marker on its line, such as Obsidian’s > [!note] Title: the container shows its own title. Surfaces do not nest. The marker is markup, so escape text you don’t control, as with any other Markdown.

A surface is one row of a scrollable view, so keep it to what fits a few screens. While it is the last block of a streaming view, each append parses and measures all of it again, so streaming one costs time quadratic in its length. Until its marker line is complete, it shows as a blockquote.

Source

pub fn plugin<P>(self, plugin: P) -> Self
where P: MarkdownPlugin,

Apply a reusable Markdown plugin.

Trait Implementations§

Source§

impl Clone for MarkdownExtensions

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 Default for MarkdownExtensions

Source§

fn default() -> Self

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

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> NoneValue for T
where T: Default,

Source§

type NoneType = T

Source§

fn null_value() -> T

The none-equivalent value.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more