Skip to main content

MarkdownViewer

Struct MarkdownViewer 

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

Markdown viewer component.

Renders markdown content with support for:

  • Headings (h1-h6)
  • Paragraphs
  • Bold, italic, and strikethrough text
  • Code (inline and blocks)
  • Lists (ordered and unordered)
  • Tables
  • Images
  • Links
  • Blockquotes
  • Horizontal rules
  • Custom inline elements (see MarkdownViewer::inline_element)

With the code-editor feature enabled, code blocks are rendered with the CodeEditor component for syntax highlighting. Otherwise they fall back to plain monospace text.

§Example

fn app() -> impl IntoElement {
    MarkdownViewer::new("# Hello World\n\nThis is **bold** and *italic* text.")
}

Implementations§

Source§

impl MarkdownViewer

Source

pub fn new(content: impl Into<Cow<'static, str>>) -> Self

Source

pub fn inline_element<ReturnedElement: IntoElement + 'static>( self, handler: impl Into<Callback<String, Option<ReturnedElement>>>, ) -> Self

Set a handler for custom inline elements.

Each raw inline HTML tag in a paragraph (for example <rust-logo/>) is passed to the handler, which returns the element to inline, or None to keep the tag as plain text.

fn app() -> impl IntoElement {
    MarkdownViewer::new("Made with Rust <rust-logo/> btw")
        .inline_element(|html: String| html.starts_with("<rust-logo").then(|| "🦀"))
}
Source

pub fn code_editor_font_family( self, font_family: impl Into<Cow<'static, str>>, ) -> Self

Sets the font family used for code blocks. Defaults to "Jetbrains Mono".

Source

pub fn code_editor_language( self, resolver: impl Into<Callback<String, Option<EditorLanguage>>>, ) -> Self

Sets a resolver mapping a code block’s language to an EditorLanguage for highlighting.

Trait Implementations§

Source§

impl Component for MarkdownViewer

Source§

fn render(&self) -> impl IntoElement

Source§

fn render_key(&self) -> DiffKey

Source§

impl ContainerExt for MarkdownViewer

§

fn position(self, position: impl Into<Position>) -> Self

Set how the element is placed relative to its parent or the window. See [Position].
§

fn padding(self, padding: impl Into<Gaps>) -> Self

Set the inner spacing between the element’s edges and its content. See [Gaps].
§

fn margin(self, margin: impl Into<Gaps>) -> Self

Set the outer spacing between the element’s edges and its surroundings. See [Gaps].
§

fn min_width(self, minimum_width: impl Into<Size>) -> Self

Set the minimum width the element can shrink to. See [Size].
§

fn min_height(self, minimum_height: impl Into<Size>) -> Self

Set the minimum height the element can shrink to. See [Size].
§

fn max_width(self, maximum_width: impl Into<Size>) -> Self

Set the maximum width the element can grow to. See [Size].
§

fn max_height(self, maximum_height: impl Into<Size>) -> Self

Set the maximum height the element can grow to. See [Size].
§

fn visible_width(self, visible_width: impl Into<VisibleSize>) -> Self

Set how much of the measured width is actually used in layout. See [VisibleSize].
§

fn visible_height(self, visible_height: impl Into<VisibleSize>) -> Self

Set how much of the measured height is actually used in layout. See [VisibleSize].
Source§

impl KeyExt for MarkdownViewer

Source§

fn write_key(&mut self) -> &mut DiffKey

Returns a mutable reference to the element’s diff key.
§

fn key(self, key: impl Hash) -> Self

Assign a key derived from any hashable value, used to reconcile elements in dynamic lists.
Source§

impl LayoutExt for MarkdownViewer

Source§

fn get_layout(&mut self) -> &mut LayoutData

Returns a mutable reference to the element’s layout data.
§

fn layout(self, layout: LayoutData) -> Self

Replace all of the element’s layout data at once. See [LayoutData].
Source§

impl MarkdownViewerThemePartialExt for MarkdownViewer

Source§

fn color(self, color: impl Into<Color>) -> Self

Source§

fn background_code(self, background_code: impl Into<Color>) -> Self

Source§

fn color_code(self, color_code: impl Into<Color>) -> Self

Source§

fn background_blockquote(self, background_blockquote: impl Into<Color>) -> Self

Source§

fn border_blockquote(self, border_blockquote: impl Into<Color>) -> Self

Source§

fn background_divider(self, background_divider: impl Into<Color>) -> Self

Source§

fn heading_h1(self, heading_h1: impl Into<f32>) -> Self

Source§

fn heading_h2(self, heading_h2: impl Into<f32>) -> Self

Source§

fn heading_h3(self, heading_h3: impl Into<f32>) -> Self

Source§

fn heading_h4(self, heading_h4: impl Into<f32>) -> Self

Source§

fn heading_h5(self, heading_h5: impl Into<f32>) -> Self

Source§

fn heading_h6(self, heading_h6: impl Into<f32>) -> Self

Source§

fn paragraph_size(self, paragraph_size: impl Into<f32>) -> Self

Source§

fn code_font_size(self, code_font_size: impl Into<f32>) -> Self

Source§

fn table_font_size(self, table_font_size: impl Into<f32>) -> Self

Source§

impl PartialEq for MarkdownViewer

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for MarkdownViewer

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
§

impl<T> ComponentKey for T
where T: Component,

§

fn default_key(&self) -> DiffKey

§

impl<T> ComponentProps for T
where T: Any + PartialEq,

§

fn changed(&self, other: &(dyn ComponentProps + 'static)) -> bool

§

impl<T> ContainerSizeExt for T
where T: ContainerExt,

§

fn width(self, width: impl Into<Size>) -> Self

Set the element’s width. See [Size].
§

fn height(self, height: impl Into<Size>) -> Self

Set the element’s height. See [Size].
§

fn expanded(self) -> Self

Expand both width and height using [Size::fill()].
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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
§

impl<T> IntoElement for T
where T: Into<Element>,

§

fn into_element(self) -> Element

§

impl<T> IntoReadable<T> for T
where T: 'static + PartialEq,

§

fn into_readable(self) -> Readable<T>

§

impl<T> MaybeExt for T
where T: Component,

§

fn maybe(self, bool: impl Into<bool>, then: impl FnOnce(Self) -> Self) -> Self

Apply then to the element only when the condition is true.
§

fn map<T>(self, data: Option<T>, then: impl FnOnce(Self, T) -> Self) -> Self

Apply then to the element only when the Option is Some, passing the inner value.
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

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

Source§

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