use super::prelude::*;
pub fn render_wikitext_raw(ctx: &mut HtmlContext, text: &str) {
debug!("Escaping raw string '{text}'");
match ctx.layout() {
Layout::Wikidot => {
ctx.html()
.span()
.attr(attr!("style" => "white-space: pre-wrap;"))
.contents(text);
}
Layout::Wikijump => {
ctx.html()
.span()
.attr(attr!("class" => "wj-raw"))
.contents(text);
}
}
}
pub fn render_email(ctx: &mut HtmlContext, email: &str) {
debug!("Rendering email address '{email}'");
match ctx.layout() {
Layout::Wikidot => {
ctx.html()
.span()
.attr(attr!(
"class" => "wiki-email",
"style" => "visibility: visible;",
))
.inner(|ctx| {
ctx.html()
.a()
.attr(attr!("href" => "mailto:" email))
.contents(email);
});
}
Layout::Wikijump => {
ctx.html()
.span()
.attr(attr!("class" => "wj-email"))
.contents(email);
}
}
}
pub fn render_code(ctx: &mut HtmlContext, language: Option<&str>, contents: &str) {
debug!(
"Rendering code block (language {})",
language.unwrap_or("<none>"),
);
let index = ctx.next_code_snippet_index();
ctx.handle().post_code(index, contents);
let class = {
let mut class = format!("wj-code wj-language-{}", language.unwrap_or("none"));
class.make_ascii_lowercase();
class
};
ctx.html()
.element("wj-code")
.attr(attr!("class" => &class))
.inner(|ctx| {
ctx.html()
.div()
.attr(attr!(
"class" => "wj-code-panel",
))
.inner(|ctx| {
let button_title = ctx
.handle()
.get_message(ctx.language(), "button-copy-clipboard");
ctx.html()
.element("wj-code-copy")
.attr(attr!(
"type" => "button",
"class" => "wj-code-copy",
"title" => button_title,
))
.inner(|ctx| {
ctx.html().sprite("wj-clipboard");
ctx.html().sprite("wj-clipboard-success");
});
ctx.html()
.span()
.attr(attr!(
"class" => "wj-code-language",
))
.contents(language.unwrap_or(""));
});
ctx.html().pre().inner(|ctx| {
ctx.html().code().contents(contents);
});
});
}