NAME
Chandra::Markdown - Render Markdown in Chandra apps
SYNOPSIS
use Chandra::Markdown;
my $md = Chandra::Markdown->new(app => $app);
$md->set("# Hello\nThis is **Markdown**.");
# Render to HTML string without updating the webview
my $html = $md->render("# Hello");
# Register routes for a docs directory + get nav HTML
my $nav = $md->render_dir('docs', base_route => '/docs');
# Add a search widget (registers the bind handler)
my $search = $md->search_widget(placeholder => 'Search docs...');
METHODS
new(%opts)
app is required. Available options:
gfm(default 1)-
Enable GFM extensions: tables, strikethrough, task lists, autolinks, and raw HTML sanitisation. Set to
0for strict CommonMark. hard_breaks(default 0)-
Emit
<br />for soft line breaks inside paragraphs. highlight(default 1)-
Syntax-highlight fenced code blocks that carry a language tag (e.g.
```perl). Tokens are wrapped in<span class="esh-X">elements styled by the injected CSS. Blocks with no language tag are unaffected. Set to0to emit plain HTML-escaped code. id(defaultchandra-markdown)css(default 1)-
Inject the built-in stylesheet (
.chandra-markdownlayout rules plus.esh-*token colours) into the app on construction. Set to0to supply your own styles.
render($markdown)
Convert $markdown to HTML. Does not update the webview.
set($markdown) / append($markdown)
Render and set/append innerHTML of the target element. Return $self.
render_dir($dir, %opts)
Scan $dir for *.md files, register routes and index content for search. Returns a <nav> HTML string. Options: recursive, base_route, nav_id, sort, index.
search($query, $limit)
Search the index built by render_dir. Returns an arrayref of {route, title, score, snippet} hashrefs, sorted by score descending.
search_widget(%opts)
Register the __chandra_md_search invoke handler and return HTML for the search input. Options: placeholder, limit, min_length. Embed the returned HTML in your layout.
AUTHOR
LNATION <email@lnation.org>
LICENSE
Artistic License 2.0