Skip to main content

MarkdownRenderer

Struct MarkdownRenderer 

Source
pub struct MarkdownRenderer<'a> { /* private fields */ }
Expand description

Renders markdown to HTML with GitHub Flavored Markdown extensions.

Provides GFM extensions including tables, strikethrough, autolinks, task lists, footnotes, and description lists. Uses syntect for code block syntax highlighting when language is specified. Optionally resolves relative links to repository paths when configured with LinkResolver.

Implementations§

Source§

impl<'a> MarkdownRenderer<'a>

Source

pub fn new() -> Self

Creates renderer with GitHub Flavored Markdown options.

Configures all GFM extensions and security settings:

  • Tables, strikethrough, autolinks, task lists, footnotes
  • Smart punctuation for quotes and dashes
  • HTML sanitization enabled (no raw HTML injection)
  • Syntax highlighting with syntect using CSS classes

Creates renderer with link resolution for repository internal links.

Relative links in markdown (./file.md, ../dir/) are transformed to static site URLs (blob/branch/path.html). Absolute URLs and anchor links remain unchanged. Uses depth 0 (site root level).

§Arguments
  • branch: Git branch for link resolution
  • current_path: Path to markdown file being rendered

Creates renderer with link resolution and depth for relative path generation.

Depth determines how many ../ prefixes are needed to reach site root. For index.html at root, depth is 0. For tree/branch/index.html, depth is 2.

§Arguments
  • branch: Git branch for link resolution
  • current_path: Path to markdown file being rendered
  • depth: Directory depth of rendered page from site root
Source

pub fn render(&self, content: &str) -> Result<String>

Renders markdown content to HTML string.

Parses markdown into AST, applies transformations, and renders to HTML with GFM extensions. Code blocks are syntax highlighted with CSS class names using syntect.

§Arguments
  • content: Markdown content to render
§Returns

Rendered HTML as string with syntax highlighted code blocks

§Errors

Returns error if syntax highlighting fails

Source

pub fn render_file(&self, path: impl AsRef<Path>) -> Result<String>

Renders markdown file at given path.

Convenience method that reads file and renders content.

§Arguments
  • path: Path to markdown file
§Returns

Rendered HTML string

§Errors

Returns error if file cannot be read or rendering fails

Trait Implementations§

Source§

impl<'a> Default for MarkdownRenderer<'a>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<'a> !Freeze for MarkdownRenderer<'a>

§

impl<'a> RefUnwindSafe for MarkdownRenderer<'a>

§

impl<'a> !Send for MarkdownRenderer<'a>

§

impl<'a> !Sync for MarkdownRenderer<'a>

§

impl<'a> Unpin for MarkdownRenderer<'a>

§

impl<'a> UnwindSafe for MarkdownRenderer<'a>

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

Source§

type Output = T

Should always be Self
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.