use htmd::{
options::{CodeBlockStyle, HeadingStyle, HrStyle, Options},
HtmlToMarkdownBuilder,
};
/// Contents are copied from https://mixmark-io.github.io/turndown/
#[test]
fn run_cases() {
let html = r#"
Turndown Demo
This demonstrates turndown – an HTML to Markdown converter in JavaScript.
Usage
var turndownService = new TurndownService()
console.log(
turndownService.turndown('<h1>Hello world</h1>')
)
It aims to be CommonMark
compliant, and includes options to style the output. These options include:
- headingStyle (setext or atx)
- horizontalRule (*, -, or _)
- bullet (*, -, or +)
- codeBlockStyle (indented or fenced)
- fence (` or ~)
- emDelimiter (_ or *)
- strongDelimiter (** or __)
- linkStyle (inlined or referenced)
- linkReferenceStyle (full, collapsed, or shortcut)
"#;
let expected = r#"Turndown Demo
=============
This demonstrates [turndown](https://github.com/mixmark-io/turndown) – an HTML to Markdown converter in JavaScript.
Usage
-----
var turndownService = new TurndownService()
console.log(
turndownService.turndown('Hello world
')
)
* * *
It aims to be [CommonMark](http://commonmark.org/) compliant, and includes options to style the output. These options include:
* headingStyle (setext or atx)
* horizontalRule (\*, -, or \_)
* bullet (\*, -, or +)
* codeBlockStyle (indented or fenced)
* fence (\` or ~)
* emDelimiter (\_ or \*)
* strongDelimiter (\*\* or \_\_)
* linkStyle (inlined or referenced)
* linkReferenceStyle (full, collapsed, or shortcut)"#;
let options = Options {
heading_style: HeadingStyle::Setex,
hr_style: HrStyle::Asterisks,
code_block_style: CodeBlockStyle::Indented,
..Default::default()
};
let converter = HtmlToMarkdownBuilder::new().options(options).build();
let md = converter.convert(html).unwrap();
assert_eq!(expected, md);
}