-
#{breadcrumbs}
-
- {inner}
+
+
+
+
#{breadcrumbs}
+
+ {inner}
+
-
-
-
-
- },
- ])
+
+
+
+ },
+ ],
+ )
}
-fn convert_wikitext_to_html(
+fn convert_wikitext_to_html<'bump>(
+ bump: &'bump Bump,
evaluator: &mut TemplateEvaluator<'_>,
node: &WikitextSimplifiedNode,
page_context: &PageContext,
-) -> paxhtml::Element {
+) -> paxhtml::Element<'bump> {
use WikitextSimplifiedNode as WSN;
- use paxhtml::html;
- fn parse_attributes_from_wsn(
+ fn parse_attributes_from_wsn<'b>(
+ bump: &'b Bump,
evaluator: &mut TemplateEvaluator<'_>,
attributes_context: &str,
attributes: &[WSN],
page_context: &PageContext,
- ) -> Vec
{
+ ) -> bumpalo::collections::Vec<'b, paxhtml::Attribute<'b>> {
if attributes.is_empty() {
- return vec![];
+ return bumpalo::collections::Vec::new_in(bump);
}
// Instantiate the attributes before extracting the text
let attributes = pollster::block_on(
@@ -551,31 +588,43 @@ fn convert_wikitext_to_html(
);
}
- paxhtml::Attribute::parse_from_str(&merged_text).unwrap()
+ paxhtml::Attribute::parse_from_str(bump, &merged_text).unwrap()
}
- fn parse_optional_attributes_from_wsn(
+ fn parse_optional_attributes_from_wsn<'b>(
+ bump: &'b Bump,
evaluator: &mut TemplateEvaluator<'_>,
attributes_context: &str,
attributes: &Option>>,
page_context: &PageContext,
- ) -> Vec {
+ ) -> bumpalo::collections::Vec<'b, paxhtml::Attribute<'b>> {
attributes
.as_ref()
.map(|attributes| {
let unwrapped: Vec = attributes.iter().map(|s| s.value.clone()).collect();
- parse_attributes_from_wsn(evaluator, attributes_context, &unwrapped, page_context)
+ parse_attributes_from_wsn(
+ bump,
+ evaluator,
+ attributes_context,
+ &unwrapped,
+ page_context,
+ )
})
- .unwrap_or_default()
+ .unwrap_or_else(|| bumpalo::collections::Vec::new_in(bump))
}
+ let b = paxhtml::builder::Builder::new(bump);
+
let convert_children =
|evaluator: &mut TemplateEvaluator<'_>, children: &[Spanned]| {
paxhtml::Element::from_iter(
+ bump,
children
.iter()
.skip_while(|node| matches!(node.value, WSN::ParagraphBreak | WSN::Newline))
- .map(|node| convert_wikitext_to_html(evaluator, &node.value, page_context)),
+ .map(|node| {
+ convert_wikitext_to_html(bump, evaluator, &node.value, page_context)
+ }),
)
};
@@ -585,10 +634,10 @@ fn convert_wikitext_to_html(
let template = pollster::block_on(
evaluator.instantiate(TemplateToInstantiate::Name(name), parameters),
);
- convert_wikitext_to_html(evaluator, &template, page_context)
+ convert_wikitext_to_html(bump, evaluator, &template, page_context)
}
tpu @ WSN::TemplateParameterUse { .. } => {
- html! { <>{tpu.to_wikitext()}> }
+ paxhtml::html! { in bump; <>{tpu.to_wikitext()}> }
}
WSN::Heading { level, children } => {
let class = match level {
@@ -597,46 +646,47 @@ fn convert_wikitext_to_html(
4 => "text-lg font-semibold mt-4 mb-2",
_ => "font-semibold mt-4 mb-2",
};
- paxhtml::builder::tag(
- format!("h{level}"),
- paxhtml::Attribute::parse_from_str(&format!("class=\"{}\"", class)).unwrap(),
+ let tag_name = format!("h{level}");
+ b.tag(
+ &tag_name,
+ paxhtml::Attribute::parse_from_str(bump, &format!("class=\"{}\"", class)).unwrap(),
false,
)(convert_children(evaluator, children))
}
WSN::Link { text, title } => {
- html! {
+ paxhtml::html! { in bump;
- {paxhtml::Element::Raw { html: text.to_string() }}
+ {b.raw(text)}
}
}
WSN::ExtLink { link, text } => {
- html! {
+ paxhtml::html! { in bump;
- {paxhtml::Element::Raw { html: text.as_ref().unwrap_or(link).to_string() }}
+ {b.raw(text.as_ref().unwrap_or(link))}
}
}
WSN::Bold { children } => {
- html! { {convert_children(evaluator, children)} }
+ paxhtml::html! { in bump; {convert_children(evaluator, children)} }
}
WSN::Italic { children } => {
- html! { {convert_children(evaluator, children)} }
+ paxhtml::html! { in bump; {convert_children(evaluator, children)} }
}
WSN::Blockquote { children } => {
- html! { {convert_children(evaluator, children)}
}
+ paxhtml::html! { in bump; {convert_children(evaluator, children)}
}
}
WSN::Superscript { children } => {
- html! { {convert_children(evaluator, children)} }
+ paxhtml::html! { in bump; {convert_children(evaluator, children)} }
}
WSN::Subscript { children } => {
- html! { {convert_children(evaluator, children)} }
+ paxhtml::html! { in bump; {convert_children(evaluator, children)} }
}
WSN::Small { children } => {
- html! { {convert_children(evaluator, children)} }
+ paxhtml::html! { in bump; {convert_children(evaluator, children)} }
}
WSN::Preformatted { children } => {
- html! { {convert_children(evaluator, children)} }
+ paxhtml::html! { in bump; {convert_children(evaluator, children)} }
}
WSN::Tag {
name,
@@ -668,39 +718,41 @@ fn convert_wikitext_to_html(
text.trim()
} else {
// If not simple text, fall back to plain rendering
- let parsed_attributes = paxhtml::Attribute::parse_from_str(attrs_str).unwrap();
- return html! { {convert_children(evaluator, children)}
};
+ let parsed_attributes =
+ paxhtml::Attribute::parse_from_str(bump, attrs_str).unwrap();
+ return paxhtml::html! { in bump; {convert_children(evaluator, children)}
};
};
// Use syntax highlighter
if let Some(highlighter) = SYNTAX_HIGHLIGHTER.get() {
- match highlighter.highlight_code(lang, code) {
+ match highlighter.highlight_code(bump, lang, code) {
Ok(highlighted) => {
- html! { {highlighted}
}
+ paxhtml::html! { in bump; {highlighted}
}
}
Err(_) => {
// Fallback to plain text if highlighting fails
let parsed_attributes =
- paxhtml::Attribute::parse_from_str(attrs_str).unwrap();
- html! { {code}
}
+ paxhtml::Attribute::parse_from_str(bump, attrs_str).unwrap();
+ paxhtml::html! { in bump; {code}
}
}
}
} else {
// Fallback if highlighter not initialized
- let parsed_attributes = paxhtml::Attribute::parse_from_str(attrs_str).unwrap();
- html! { {code}
}
+ let parsed_attributes =
+ paxhtml::Attribute::parse_from_str(bump, attrs_str).unwrap();
+ paxhtml::html! { in bump; {code}
}
}
} else {
- let parsed_attributes =
- paxhtml::Attribute::parse_from_str(attributes.as_deref().unwrap_or_default())
- .unwrap();
+ let parsed_attributes = paxhtml::Attribute::parse_from_str(
+ bump,
+ attributes.as_deref().unwrap_or_default(),
+ )
+ .unwrap();
let children = convert_children(evaluator, children);
- paxhtml::builder::tag(name.to_string(), parsed_attributes, false)(children)
+ b.tag(name, parsed_attributes, false)(children)
}
}
- WSN::Text { text } => paxhtml::Element::Raw {
- html: text.to_string(),
- },
+ WSN::Text { text } => b.raw(text),
WSN::Table {
attributes,
captions,
@@ -750,9 +802,14 @@ fn convert_wikitext_to_html(
.iter()
.map(|s| s.value.clone())
.collect();
- let attributes =
- parse_attributes_from_wsn(evaluator, "main", &unwrapped_attributes, page_context);
- html! {
+ let attributes = parse_attributes_from_wsn(
+ bump,
+ evaluator,
+ "main",
+ &unwrapped_attributes,
+ page_context,
+ );
+ paxhtml::html! { in bump;
@@ -760,12 +817,13 @@ fn convert_wikitext_to_html(
.iter()
.map(|caption| {
let attributes = parse_optional_attributes_from_wsn(
+ bump,
evaluator,
"caption",
&caption.attributes,
page_context,
);
- html! {
+ paxhtml::html! { in bump;
|
{convert_children(evaluator, &caption.content)}
|
@@ -781,24 +839,26 @@ fn convert_wikitext_to_html(
.map(|(idx, row)| {
let unwrapped_row_attrs: Vec = row.attributes.iter().map(|s| s.value.clone()).collect();
let attributes = parse_attributes_from_wsn(
+ bump,
evaluator,
"row",
&unwrapped_row_attrs,
page_context,
);
let row_class = if idx % 2 == 0 { "bg-white" } else { "bg-gray-50" };
- html! {
+ paxhtml::html! { in bump;
#{row.cells
.iter()
.map(|cell| {
let attributes = parse_optional_attributes_from_wsn(
+ bump,
evaluator,
"cell",
&cell.attributes,
page_context,
);
- html! {
+ paxhtml::html! { in bump;
|
{convert_children(evaluator, &cell.content)}
|
@@ -814,24 +874,24 @@ fn convert_wikitext_to_html(
}
}
WSN::OrderedList { items } => {
- html! {
+ paxhtml::html! { in bump;
#{items
.iter()
.map(|i| {
- html! { - {convert_children(evaluator, &i.content)}
}
+ paxhtml::html! { in bump; - {convert_children(evaluator, &i.content)}
}
})
}
}
}
WSN::UnorderedList { items } => {
- html! {
+ paxhtml::html! { in bump;
#{items
.iter()
.map(|i| {
- html! { - {convert_children(evaluator, &i.content)}
}
+ paxhtml::html! { in bump; - {convert_children(evaluator, &i.content)}
}
})
}
@@ -839,26 +899,28 @@ fn convert_wikitext_to_html(
}
WSN::DefinitionList { items } => {
use wikitext_simplified::DefinitionListItemType;
- html! {
+ paxhtml::html! { in bump;
#{items.iter().map(|i| {
let children = convert_children(evaluator, &i.content);
match i.type_ {
- DefinitionListItemType::Term => html! { - {children}
},
- DefinitionListItemType::Details => html! { - {children}
},
+ DefinitionListItemType::Term => paxhtml::html! { in bump; - {children}
},
+ DefinitionListItemType::Details => paxhtml::html! { in bump; - {children}
},
}
})}
}
}
- WSN::Redirect { target } => html! {
+ WSN::Redirect { target } => paxhtml::html! { in bump;
"REDIRECT: "{target}
},
- WSN::HorizontalDivider => html! {
},
- WSN::ParagraphBreak => html! {
},
- WSN::Newline => html! {
},
+ WSN::HorizontalDivider => {
+ paxhtml::html! { in bump;
}
+ }
+ WSN::ParagraphBreak => paxhtml::html! { in bump;
},
+ WSN::Newline => paxhtml::html! { in bump;
},
}
}
@@ -873,30 +935,34 @@ fn page_title_to_route_path(title: &str) -> paxhtml::RoutePath {
)
}
-fn redirect(to_url: &str) -> paxhtml::Document {
- paxhtml::Document::new([
- paxhtml::builder::doctype(["html".into()]),
- paxhtml::html! {
-
-
- "Redirecting..."
-
-
-
-
-
-
-
-
- },
- ])
+fn redirect<'bump>(bump: &'bump Bump, to_url: &str) -> paxhtml::Document<'bump> {
+ let b = paxhtml::builder::Builder::new(bump);
+ paxhtml::Document::new(
+ bump,
+ [
+ b.doctype([b.attr("html")]),
+ paxhtml::html! { in bump;
+
+
+ "Redirecting..."
+
+
+
+
+
+
+
+
+ },
+ ],
+ )
}
/// Tokenize text into searchable words
diff --git a/src/syntax.rs b/src/syntax.rs
index 095af0e..cec5b4c 100644
--- a/src/syntax.rs
+++ b/src/syntax.rs
@@ -1,3 +1,4 @@
+use paxhtml::bumpalo::Bump;
use syntect::{
highlighting::ThemeSet,
html::{ClassStyle, ClassedHTMLGenerator, css_for_theme_with_class_style},
@@ -40,11 +41,12 @@ impl SyntaxHighlighter {
})
}
- pub fn highlight_code(
+ pub fn highlight_code<'bump>(
&self,
+ bump: &'bump Bump,
language: Option<&str>,
code: &str,
- ) -> Result {
+ ) -> Result, syntect::Error> {
let syntax = self.lookup_language(language);
let mut html_generator = ClassedHTMLGenerator::new_with_class_style(
syntax,
@@ -54,8 +56,7 @@ impl SyntaxHighlighter {
for line in LinesWithEndings::from(code) {
html_generator.parse_html_for_line_which_includes_newline(line)?;
}
- Ok(paxhtml::Element::Raw {
- html: html_generator.finalize(),
- })
+ let b = paxhtml::builder::Builder::new(bump);
+ Ok(b.raw(&html_generator.finalize()))
}
}