diff options
| author | Philipp A | 2020-11-01 16:46:16 +0100 | 
|---|---|---|
| committer | GitHub | 2020-11-01 16:46:16 +0100 | 
| commit | 44e9d2b79f307d9b741a606d5acd2fe6166efa5f (patch) | |
| tree | 0ae04d6262c74081ac3a1a9d4259a8db156d7d89 /renderer/src | |
| parent | 89d123ec6586b9d0e48c2f99f11575b254b46e72 (diff) | |
| download | rust-rst-44e9d2b79f307d9b741a606d5acd2fe6166efa5f.tar.bz2 | |
Implement literal blocks (#28)
Diffstat (limited to 'renderer/src')
| -rw-r--r-- | renderer/src/html.rs | 23 | ||||
| -rw-r--r-- | renderer/src/html/tests.rs | 11 | 
2 files changed, 30 insertions, 4 deletions
| diff --git a/renderer/src/html.rs b/renderer/src/html.rs index bb7c42e..4244349 100644 --- a/renderer/src/html.rs +++ b/renderer/src/html.rs @@ -172,7 +172,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"], 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!(Paragraph => p, 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  // circumvent E0119 @@ -199,6 +199,27 @@ impl<I> HTMLRender for I where I: e::Element + a::ExtraAttributes<a::Image> + IM  	}  } +impl HTMLRender for e::LiteralBlock { +	fn render_html<W>(&self, renderer: &mut HTMLRenderer<W>) -> Result<(), Error> where W: Write { +		let mut cls_iter = self.classes().iter(); +		let is_code = cls_iter.next() == Some(&"code".to_owned()); +		write!(renderer.stream, "<pre>")?; +		if is_code {  // TODO: support those classes not being at the start +			if let Some(lang) = cls_iter.next() { +				write!(renderer.stream, "<code class=\"language-{}\">", lang)?; +			} else { +				write!(renderer.stream, "<code>")?; +			} +		} +		for c in self.children() { +			(*c).render_html(renderer)?; +		} +		if is_code { write!(renderer.stream, "</code>")?; } +		write!(renderer.stream, "</pre>")?; +		Ok(()) +	} +} +  impl HTMLRender for e::DoctestBlock {  	fn render_html<W>(&self, _renderer: &mut HTMLRenderer<W>) -> Result<(), Error> where W: Write {  		// TODO diff --git a/renderer/src/html/tests.rs b/renderer/src/html/tests.rs index 6387238..a4ec633 100644 --- a/renderer/src/html/tests.rs +++ b/renderer/src/html/tests.rs @@ -100,8 +100,13 @@ hello ``foo.map(|world| world + 42)``  .. code::     foo.map(|world| world + 42) + +:: + +    hay! |x|  ", "<p>hello <code>foo.map(|world| world + 42)</code></p> -<pre>foo.map(|world| world + 42)\n</pre>"); +<pre><code>foo.map(|world| world + 42)\n</code></pre> +<pre>hay! |x|\n</pre>");  }  /* @@ -305,11 +310,11 @@ fn code() {         # comment  ", "\ -<pre class=\"python\">def foo(): +<pre><code class=\"language-python\">def foo():      print('Hi!')      # comment -</pre>\ +</code></pre>\  ");  } | 
