aboutsummaryrefslogtreecommitdiffstats
path: root/src/renderer/html.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/renderer/html.rs')
-rw-r--r--src/renderer/html.rs24
1 files changed, 13 insertions, 11 deletions
diff --git a/src/renderer/html.rs b/src/renderer/html.rs
index c892e5f..1bc85c0 100644
--- a/src/renderer/html.rs
+++ b/src/renderer/html.rs
@@ -22,6 +22,7 @@ pub fn render_html<W>(document: &Document, mut stream: W, standalone: bool) -> R
let stream = stream.by_ref();
for c in document.children() {
(*c).render_html(stream)?;
+ writeln!(stream)?;
}
Ok(())
}
@@ -59,17 +60,17 @@ macro_rules! impl_html_render_simple {
( $type:ident => $tag:ident ) => {
impl_html_render_simple!($type => $tag[""]);
};
- ( $type:ident => $tag:ident [$post:expr] ) => {
- impl_html_render_simple!($type => $tag["", $post]);
- };
- ( $type:ident => $tag:ident [ $post1:expr, $post2:expr ] ) => {
+ ( $type:ident => $tag:ident [ $post:expr ] ) => {
impl HTMLRender for e::$type {
fn render_html<W>(&self, stream: &mut W) -> Result<(), Error> where W: Write {
- write!(stream, concat!("<{}>", $post1), stringify!($tag))?;
+ let multiple_children = self.children().len() > 1;
+ write!(stream, "<{}>", stringify!($tag))?;
+ if multiple_children { write!(stream, $post)?; }
for c in self.children() {
(*c).render_html(stream)?;
+ if multiple_children { write!(stream, $post)?; }
}
- write!(stream, concat!("</{}>", $post2), stringify!($tag))?;
+ write!(stream, "</{}>", stringify!($tag))?;
Ok(())
}
}
@@ -89,11 +90,12 @@ macro_rules! impl_html_render_simple_nochildren {( $($type:ident => $tag:ident),
impl HTMLRender for Document {
fn render_html<W>(&self, stream: &mut W) -> Result<(), Error> where W: Write {
- write!(stream, "<!doctype html><html>")?;
+ writeln!(stream, "<!doctype html><html>")?;
for c in self.children() {
(*c).render_html(stream)?;
+ writeln!(stream)?;
}
- write!(stream, "</html>")?;
+ writeln!(stream, "</html>")?;
Ok(())
}
}
@@ -116,7 +118,7 @@ impl HTMLRender for e::Decoration {
}
impl_html_render_cat!(SubStructure { Topic, Sidebar, Transition, Section, BodyElement });
-impl_html_render_simple!(Sidebar => aside, Section => section);
+impl_html_render_simple!(Sidebar => aside, Section => section["\n"]);
impl HTMLRender for e::Transition {
fn render_html<W>(&self, stream: &mut W) -> Result<(), Error> where W: Write {
@@ -133,7 +135,7 @@ impl HTMLRender for e::Topic {
}
impl_html_render_cat!(BodyElement { Paragraph, LiteralBlock, DoctestBlock, MathBlock, Rubric, SubstitutionDefinition, Comment, Pending, Target, Raw, Image, Compound, Container, BulletList, EnumeratedList, DefinitionList, FieldList, OptionList, LineBlock, BlockQuote, Admonition, Attention, Hint, Note, Caution, Danger, Error, Important, Tip, Warning, Footnote, Citation, SystemMessage, Figure, Table });
-impl_html_render_simple!(Paragraph => p, LiteralBlock => pre, MathBlock => math, Rubric => a, Compound => p, Container => div, BulletList => ul["\n", "\n"], EnumeratedList => ol["\n", "\n"], DefinitionList => dl["\n", "\n"], FieldList => dl["\n", "\n"], OptionList => pre, LineBlock => div["\n", "\n"], BlockQuote => blockquote, Admonition => aside, Attention => aside, Hint => aside, Note => aside, Caution => aside, Danger => aside, Error => aside, Important => aside, Tip => aside, Warning => aside, Figure => figure);
+impl_html_render_simple!(Paragraph => p, LiteralBlock => pre, MathBlock => math, Rubric => a, Compound => p, Container => div, BulletList => ul["\n"], EnumeratedList => ol["\n"], DefinitionList => dl["\n"], FieldList => dl["\n"], OptionList => pre, LineBlock => div["\n"], BlockQuote => blockquote, Admonition => aside, Attention => aside, Hint => aside, Note => aside, Caution => aside, Danger => aside, Error => aside, Important => aside, Tip => aside, Warning => aside, Figure => figure);
impl_html_render_simple_nochildren!(Table => table); //TODO: after implementing the table, move it to elems with children
impl<I> HTMLRender for I where I: e::Element + a::ExtraAttributes<a::Image> {
@@ -297,7 +299,7 @@ impl HTMLRender for e::RawInline {
impl_html_render_cat!(SubTopic { Title, BodyElement });
impl_html_render_cat!(SubSidebar { Topic, Title, Subtitle, BodyElement });
-impl_html_render_simple!(ListItem => li["\n"]);
+impl_html_render_simple!(ListItem => li);
impl HTMLRender for e::DefinitionListItem {
fn render_html<W>(&self, _stream: &mut W) -> Result<(), Error> where W: Write {