Skip to content

Commit

Permalink
Move the creation out of the closure
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacasonato committed Nov 8, 2024
1 parent ff90c5f commit 49012ff
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/html/comrak.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,21 +334,27 @@ pub fn create_renderer(
ammonia_hook: Option<AmmoniaHook>,
url_rewriter: Option<URLRewriter>,
) -> super::jsdoc::MarkdownRenderer {
let mut options = comrak::Options::default();
options.extension.autolink = true;
options.extension.description_lists = true;
options.extension.strikethrough = true;
options.extension.superscript = true;
options.extension.table = true;
options.extension.tagfilter = true;
options.extension.tasklist = true;
options.render.unsafe_ = true; // its fine because we run ammonia afterwards

let mut ammonia = create_ammonia();

if let Some(ammonia_hook) = ammonia_hook.clone() {
ammonia_hook(&mut ammonia);
}

let renderer = move |md: &str,
title_only: bool,
file_path: Option<ShortPath>,
anchorizer: super::jsdoc::Anchorizer|
-> Option<String> {
let mut options = comrak::Options::default();
options.extension.autolink = true;
options.extension.description_lists = true;
options.extension.strikethrough = true;
options.extension.superscript = true;
options.extension.table = true;
options.extension.tagfilter = true;
options.extension.tasklist = true;
options.render.unsafe_ = true; // its fine because we run ammonia afterwards

let mut plugins = comrak::Plugins::default();
let heading_adapter = ComrakHeadingAdapter(anchorizer);

Expand Down Expand Up @@ -385,12 +391,6 @@ pub fn create_renderer(
CURRENT_FILE.set(Some(file_path));
URL_REWRITER.set(Some(url_rewriter.clone()));

let mut ammonia = create_ammonia();

if let Some(ammonia_hook) = ammonia_hook.clone() {
ammonia_hook(&mut ammonia);
}

let html = format!(
r#"<div class="{class_name}">{}</div>"#,
ammonia.clean(&html)
Expand Down

0 comments on commit 49012ff

Please sign in to comment.