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>
impl<'a> MarkdownRenderer<'a>
Sourcepub fn new() -> Self
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
Sourcepub fn with_link_resolver(
branch: impl Into<String>,
current_path: impl AsRef<Path>,
) -> Self
pub fn with_link_resolver( branch: impl Into<String>, current_path: impl AsRef<Path>, ) -> Self
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 resolutioncurrent_path: Path to markdown file being rendered
Sourcepub fn with_link_resolver_depth(
branch: impl Into<String>,
current_path: impl AsRef<Path>,
depth: usize,
) -> Self
pub fn with_link_resolver_depth( branch: impl Into<String>, current_path: impl AsRef<Path>, depth: usize, ) -> Self
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 resolutioncurrent_path: Path to markdown file being rendereddepth: Directory depth of rendered page from site root
Sourcepub fn render(&self, content: &str) -> Result<String>
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