extern crate markdown; use markdown::{ mdast::{Html, Node, Root}, to_html, to_html_with_options, to_mdast, unist::Position, CompileOptions, Constructs, Options, ParseOptions, }; use pretty_assertions::assert_eq; #[test] fn html_flow() -> Result<(), String> { let danger = Options { compile: CompileOptions { allow_dangerous_html: true, allow_dangerous_protocol: true, ..CompileOptions::default() }, ..Options::default() }; assert_eq!( to_html(""), "<!-- asd -->", "should support a heading w/ rank 1" ); assert_eq!( to_html_with_options("", &danger)?, "", "should support a heading w/ rank 1" ); assert_eq!( to_html_with_options( "", &Options { parse: ParseOptions { constructs: Constructs { html_flow: false, ..Constructs::default() }, ..ParseOptions::default() }, ..Options::default() } )?, "

<x>

", "should support turning off html (flow)" ); assert_eq!( to_mdast("
\nstuff\n
", &ParseOptions::default())?, Node::Root(Root { children: vec![Node::Html(Html { value: "
\nstuff\n
".into(), position: Some(Position::new(1, 1, 0, 3, 7, 18)) })], position: Some(Position::new(1, 1, 0, 3, 7, 18)) }), "should support HTML (flow) as `Html`s in mdast" ); Ok(()) } #[test] fn html_flow_1_raw() -> Result<(), String> { let danger = Options { compile: CompileOptions { allow_dangerous_html: true, allow_dangerous_protocol: true, ..CompileOptions::default() }, ..Options::default() }; assert_eq!( to_html_with_options( "

import Text.HTML.TagSoup

main :: IO ()
main = print $ parseTags tags
okay", &danger )?, "

import Text.HTML.TagSoup

main :: IO ()
main = print $ parseTags tags

okay

", "should support raw pre tags (type 1)" ); assert_eq!( to_html_with_options( " okay", &danger )?, "

okay

", "should support raw script tags" ); assert_eq!( to_html_with_options( " okay", &danger )?, "

okay

", "should support raw style tags" ); assert_eq!( to_html_with_options("\n\nfoo", &danger)?, "\n\nfoo", "should support raw tags w/o ending" ); assert_eq!( to_html_with_options("\n*foo*", &danger)?, "\n

foo

", "should support raw tags w/ start and end on a single line" ); assert_eq!( to_html_with_options("1. *bar*", &danger)?, "1. *bar*", "should support raw tags w/ more data on ending line" ); assert_eq!( to_html_with_options("</script\nmore

", "should not support a raw closing tag" ); assert_eq!( to_html_with_options("", &danger)?, "", "should support blank lines in raw" ); assert_eq!( to_html_with_options(">