make djot divs generate arbitrary elements rather than just divs

this makes it possible to use elements like figure/figcaption
This commit is contained in:
りき萌 2025-08-31 12:54:13 +02:00
parent 32b6713269
commit 944a56800e
3 changed files with 25 additions and 18 deletions

View file

@ -173,7 +173,14 @@ impl<'a> Writer<'a> {
Container::Table => out.push_str("<table"),
Container::TableRow { .. } => out.push_str("<tr"),
Container::Section { .. } => {}
Container::Div { .. } => out.push_str("<div"),
Container::Div { class } => {
if !class.is_empty() {
out.push('<');
write_attr(class, out);
} else {
out.push_str("<div");
}
}
Container::Paragraph => {
if matches!(self.list_tightness.last(), Some(true)) {
return Ok(());
@ -268,9 +275,6 @@ impl<'a> Writer<'a> {
}
if attrs.into_iter().any(|(a, _)| a == "class")
|| matches!(
c,
Container::Div { class } if !class.is_empty())
|| matches!(c, |Container::Math { .. }| Container::List {
kind: ListKind::Task,
..
@ -303,15 +307,6 @@ impl<'a> Writer<'a> {
first_written = true;
class.parts().for_each(|part| write_attr(part, out));
}
// div class goes after classes from attrs
if let Container::Div { class } = c
&& !class.is_empty()
{
if first_written {
out.push(' ');
}
out.push_str(class);
}
out.push('"');
}
@ -435,7 +430,15 @@ impl<'a> Writer<'a> {
Container::Table => out.push_str("</table>"),
Container::TableRow { .. } => out.push_str("</tr>"),
Container::Section { .. } => {}
Container::Div { .. } => out.push_str("</div>"),
Container::Div { class } => {
if !class.is_empty() {
out.push_str("</");
write_attr(class, out);
out.push('>');
} else {
out.push_str("</div>");
}
}
Container::Paragraph => {
if matches!(self.list_tightness.last(), Some(true)) {
return Ok(());