feat(export): update html render

This commit is contained in:
PoiScript 2019-06-27 01:53:50 +08:00
parent 33f78ee207
commit 0a876e2f2b
10 changed files with 213 additions and 358 deletions

View file

@ -1,17 +1,17 @@
extern crate orgize;
use orgize::export::HtmlRender;
use std::io::Cursor;
use orgize::Org;
macro_rules! html_test {
($name:ident, $content:expr, $expected:expr) => {
#[test]
fn $name() {
let mut cursor = Cursor::new(Vec::new());
let mut render = HtmlRender::default(&mut cursor, $content);
render.render().expect("render error");
let s = String::from_utf8(cursor.into_inner()).expect("invalid utf-8");
assert_eq!(s, $expected);
let mut writer = Vec::new();
let mut org = Org::new($content);
org.parse();
org.html_default(&mut writer).unwrap();
let string = String::from_utf8(writer).unwrap();
assert_eq!(string, $expected);
}
};
}
@ -19,7 +19,7 @@ macro_rules! html_test {
html_test!(
emphasis,
"*bold*, /italic/,_underlined_, =verbatim= and ~code~",
"<section><p><b>bold</b>, <i>italic</i>,<u>underlined</u>, <code>verbatim</code> and <code>code</code></p></section>"
"<main><section><p><b>bold</b>, <i>italic</i>,<u>underlined</u>, <code>verbatim</code> and <code>code</code></p></section></main>"
);
html_test!(
@ -32,14 +32,14 @@ _Section 2_
/Section 3/
* Title 4
=Section 4="#,
"<h1>Title 1</h1>\
"<main><h1>Title 1</h1>\
<section><p><b>Section 1</b></p></section>\
<h2>Title 2</h2>\
<section><p><u>Section 2</u></p></section>\
<h1>Title 3</h1>\
<section><p><i>Section 3</i></p></section>\
<h1>Title 4</h1>\
<section><p><code>Section 4</code></p></section>"
<section><p><code>Section 4</code></p></section></main>"
);
html_test!(
@ -53,15 +53,15 @@ html_test!(
- 4
+ 5"#,
"<section><ul>\
"<main><section><ul>\
<li><p>1</p></li>\
<li><p>2</p><ul><li><p>3</p></li><li><p>4</p></li></ul></li>\
<li><p>5</p></li>\
</ul></section>"
</ul></section></main>"
);
html_test!(
snippet,
"@@html:<del>@@delete this@@html:</del>@@",
"<section><p><del>delete this</del></p></section>"
"<main><section><p><del>delete this</del></p></section></main>"
);