| 1 |
use crate::nodes::{Ast, NodeValue}; |
| 2 |
|
| 3 |
use super::*; |
| 4 |
|
| 5 |
#[test] |
| 6 |
fn raw_node() { |
| 7 |
let user_input = "User input: <iframe></iframe>"; |
| 8 |
let system_input_inline = "System Inline input: <iframe></iframe>"; |
| 9 |
let system_input_block = "System Block input: <iframe></iframe>"; |
| 10 |
let input = user_input.to_owned() + system_input_inline + "\n\n" + system_input_block + "\n"; |
| 11 |
|
| 12 |
let mut options = Options::default(); |
| 13 |
options.render.escape = true; |
| 14 |
options.render.r#unsafe = false; |
| 15 |
options.extension.tagfilter = true; |
| 16 |
|
| 17 |
let arena = Arena::new(); |
| 18 |
let root = parse_document(&arena, user_input, &options); |
| 19 |
let raw_ast_inline = Ast::new( |
| 20 |
NodeValue::Raw(system_input_inline.to_string()), |
| 21 |
(0, 0).into(), |
| 22 |
); |
| 23 |
let raw_node_inline = arena.alloc(raw_ast_inline.into()); |
| 24 |
root.first_child() |
| 25 |
.unwrap() |
| 26 |
.last_child() |
| 27 |
.unwrap() |
| 28 |
.insert_after(raw_node_inline); |
| 29 |
let raw_ast_block = Ast::new( |
| 30 |
NodeValue::Raw(system_input_block.to_string()), |
| 31 |
(0, 0).into(), |
| 32 |
); |
| 33 |
let raw_node_block = arena.alloc(raw_ast_block.into()); |
| 34 |
root.first_child().unwrap().insert_after(raw_node_block); |
| 35 |
|
| 36 |
let mut output = String::new(); |
| 37 |
html::format_document(root, &options, &mut output).unwrap(); |
| 38 |
compare_strs( |
| 39 |
&output, |
| 40 |
concat!( |
| 41 |
"<p>User input: <iframe></iframe>", |
| 42 |
"System Inline input: <iframe></iframe></p>\n", |
| 43 |
"System Block input: <iframe></iframe>" |
| 44 |
), |
| 45 |
"html", |
| 46 |
&input, |
| 47 |
); |
| 48 |
|
| 49 |
let mut md = String::new(); |
| 50 |
cm::format_document_with_plugins(root, &options, &mut md, &options::Plugins::default()) |
| 51 |
.unwrap(); |
| 52 |
compare_strs(&md, &input, "cm", &input); |
| 53 |
|
| 54 |
let mut xml = String::new(); |
| 55 |
crate::xml::format_document(root, &options, &mut xml).unwrap(); |
| 56 |
compare_strs( |
| 57 |
&xml, |
| 58 |
concat!( |
| 59 |
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", |
| 60 |
"<!DOCTYPE document SYSTEM \"CommonMark.dtd\">\n", |
| 61 |
"<document xmlns=\"http://commonmark.org/xml/1.0\">\n", |
| 62 |
" <paragraph>\n", |
| 63 |
" <text xml:space=\"preserve\">User input: </text>\n", |
| 64 |
" <html_inline xml:space=\"preserve\"><iframe></html_inline>\n", |
| 65 |
" <html_inline xml:space=\"preserve\"></iframe></html_inline>\n", |
| 66 |
" <raw xml:space=\"preserve\">System Inline input: <iframe></iframe></raw>\n", |
| 67 |
" </paragraph>\n", |
| 68 |
" <raw xml:space=\"preserve\">System Block input: <iframe></iframe></raw>\n</document>\n" |
| 69 |
), |
| 70 |
"xml", |
| 71 |
&input, |
| 72 |
); |
| 73 |
} |