| 1 |
use pretty_assertions::assert_eq; |
| 2 |
use std::sync::Arc; |
| 3 |
|
| 4 |
use super::*; |
| 5 |
|
| 6 |
#[test] |
| 7 |
fn markdown_list_bullets() { |
| 8 |
let dash = "- a\n"; |
| 9 |
let plus = "+ a\n"; |
| 10 |
let star = "* a\n"; |
| 11 |
let mut dash_opts = Options::default(); |
| 12 |
dash_opts.render.list_style = options::ListStyleType::Dash; |
| 13 |
let mut plus_opts = Options::default(); |
| 14 |
plus_opts.render.list_style = options::ListStyleType::Plus; |
| 15 |
let mut star_opts = Options::default(); |
| 16 |
star_opts.render.list_style = options::ListStyleType::Star; |
| 17 |
|
| 18 |
commonmark(dash, dash, Some(&dash_opts)); |
| 19 |
commonmark(plus, dash, Some(&dash_opts)); |
| 20 |
commonmark(star, dash, Some(&dash_opts)); |
| 21 |
|
| 22 |
commonmark(dash, plus, Some(&plus_opts)); |
| 23 |
commonmark(plus, plus, Some(&plus_opts)); |
| 24 |
commonmark(star, plus, Some(&plus_opts)); |
| 25 |
|
| 26 |
commonmark(dash, star, Some(&star_opts)); |
| 27 |
commonmark(plus, star, Some(&star_opts)); |
| 28 |
commonmark(star, star, Some(&star_opts)); |
| 29 |
} |
| 30 |
|
| 31 |
#[test] |
| 32 |
fn width_breaks() { |
| 33 |
let mut options = Options::default(); |
| 34 |
options.render.width = 72; |
| 35 |
let input = concat!( |
| 36 |
"this should break because it has breakable characters. break right here newline\n", |
| 37 |
"\n", |
| 38 |
"don't break\n", |
| 39 |
"\n", |
| 40 |
"a-long-line-that-won't-break-because-there-is-no-character-it-can-break-on\n" |
| 41 |
); |
| 42 |
let output = concat!( |
| 43 |
"this should break because it has breakable characters. break right here\n", |
| 44 |
"newline\n", |
| 45 |
"\n", |
| 46 |
"don't break\n", |
| 47 |
"\n", |
| 48 |
"a-long-line-that-won't-break-because-there-is-no-character-it-can-break-on\n" |
| 49 |
); |
| 50 |
|
| 51 |
commonmark(input, output, Some(&options)); |
| 52 |
} |
| 53 |
|
| 54 |
#[test] |
| 55 |
fn smart_chars() { |
| 56 |
html_opts!( |
| 57 |
[parse.smart], |
| 58 |
"Why 'hello' \"there\". It's good.", |
| 59 |
"<p>Why ‘hello’ “there”. It’s good.</p>\n", |
| 60 |
); |
| 61 |
|
| 62 |
html_opts!( |
| 63 |
[parse.smart], |
| 64 |
"Hm. Hm.. hm... yes- indeed-- quite---!", |
| 65 |
"<p>Hm. Hm.. hm… yes- indeed– quite—!</p>\n", |
| 66 |
); |
| 67 |
} |
| 68 |
|
| 69 |
#[test] |
| 70 |
fn smart_guillemets() { |
| 71 |
html_opts!([parse.smart], "<<hello>>\n", "<p>\u{ab}hello\u{bb}</p>\n",); |
| 72 |
|
| 73 |
html_opts!( |
| 74 |
[parse.smart], |
| 75 |
"<< guillemets >> here\n", |
| 76 |
"<p>\u{ab} guillemets \u{bb} here</p>\n", |
| 77 |
); |
| 78 |
|
| 79 |
// Single < and > should not be affected |
| 80 |
html_opts!([parse.smart], "a < b > c\n", "<p>a < b > c</p>\n",); |
| 81 |
|
| 82 |
// Autolinks should still work |
| 83 |
html_opts!( |
| 84 |
[parse.smart], |
| 85 |
"<https://example.com>\n", |
| 86 |
"<p><a href=\"https://example.com\">https://example.com</a></p>\n", |
| 87 |
); |
| 88 |
} |
| 89 |
|
| 90 |
#[test] |
| 91 |
fn broken_link_callback() { |
| 92 |
let cb = |link_ref: options::BrokenLinkReference| match link_ref.normalized { |
| 93 |
"foo" => Some(ResolvedReference { |
| 94 |
url: "https://www.rust-lang.org/".to_string(), |
| 95 |
title: "The Rust Language".to_string(), |
| 96 |
}), |
| 97 |
_ => None, |
| 98 |
}; |
| 99 |
let mut options = Options::default(); |
| 100 |
options.parse.broken_link_callback = Some(Arc::new(cb)); |
| 101 |
|
| 102 |
let output = markdown_to_html( |
| 103 |
"# Cool input!\nWow look at this cool [link][foo]. A [broken link] renders as text.", |
| 104 |
&options, |
| 105 |
); |
| 106 |
assert_eq!( |
| 107 |
output, |
| 108 |
"<h1>Cool input!</h1>\n<p>Wow look at this cool \ |
| 109 |
<a href=\"https://www.rust-lang.org/\" title=\"The Rust Language\">link</a>. \ |
| 110 |
A [broken link] renders as text.</p>\n" |
| 111 |
); |
| 112 |
} |