diff --git a/example/lumina.md b/example/lumina.md index 229ae6e..6782ad8 100644 --- a/example/lumina.md +++ b/example/lumina.md @@ -20,6 +20,9 @@ Her smallest creation: - [Bernardo](bernardo) +Bernardo looks like this: +![bernardo-picture](bernardo.png) + --- ## Enemy diff --git a/example/sword-of-conjuring.md b/example/sword-of-conjuring.md index 2248191..68a4f0a 100644 --- a/example/sword-of-conjuring.md +++ b/example/sword-of-conjuring.md @@ -1,3 +1,19 @@ # Sword of Conjuring This is a sword what do you expect + +Here's some rendered html: + +```html +
+

You can use raw HTML inside wiki pages:

+ +
+``` + +```rendered_html +
+

You can use raw HTML inside wiki pages:

+ +
+``` diff --git a/example/sword-of-conjuring.toml b/example/sword-of-conjuring.toml index 00033d2..ba8aef9 100644 --- a/example/sword-of-conjuring.toml +++ b/example/sword-of-conjuring.toml @@ -1,7 +1,7 @@ title = "Sword of Conjuring" category = "Items" -image = "azrak.png" -content_file = "azrak.md" +image = "sword-of-conjuring.png" +content_file = "sword-of-conjuring.md" [infobox] "Weapon type" = "Sword" diff --git a/src/rendering.rs b/src/rendering.rs index eb34ab3..0d95f59 100644 --- a/src/rendering.rs +++ b/src/rendering.rs @@ -59,6 +59,29 @@ impl<'a> Iterator for Renderer<'a> { })) } + Event::Start(Tag::Image { + link_type, + dest_url, + title, + id, + }) => { + let mut new_url = dest_url.to_string(); + + if !new_url.contains("://") + && !new_url.starts_with('/') + && !new_url.starts_with("./") + { + new_url = format!("images/{}", new_url); + } + + Some(Event::Start(Tag::Image { + link_type, + dest_url: CowStr::Boxed(new_url.into_boxed_str()), + title, + id, + })) + } + Event::Start(Tag::CodeBlock(kind)) => { let mut code_content = String::new(); @@ -75,14 +98,17 @@ impl<'a> Iterator for Renderer<'a> { CodeBlockKind::Fenced(ref language) => language.as_ref(), }; - let rendered_html = render_code_to_html(&code_content, lang); + if lang == "rendered_html" { + return Some(Event::Html(CowStr::Boxed(code_content.into_boxed_str()))); + } + let rendered_html = render_code_to_html(&code_content, lang); let mut escaped_code = String::new(); let _ = escape_html(&mut escaped_code, &code_content); - - let rendered_html = - rendered_html.replace(" return Some(event), diff --git a/templates/page.html b/templates/page.html index 2b3c31c..7c05dfa 100644 --- a/templates/page.html +++ b/templates/page.html @@ -43,21 +43,34 @@