html-to-markdown 3.4.0 → 3.6.0.pre.rc.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE +21 -0
- data/README.md +347 -0
- data/Steepfile +10 -2
- data/ext/html_to_markdown_rb/Cargo.toml +3 -2
- data/ext/html_to_markdown_rb/extconf.rb +5 -5
- data/ext/html_to_markdown_rb/native/Cargo.lock +962 -0
- data/ext/html_to_markdown_rb/native/Cargo.toml +6 -11
- data/ext/html_to_markdown_rb/native/extconf.rb +14 -0
- data/ext/html_to_markdown_rb/src/lib.rs +1715 -646
- data/lib/html_to_markdown/native.rb +913 -37
- data/lib/html_to_markdown/version.rb +3 -3
- data/lib/html_to_markdown.rb +9 -4
- data/lib/html_to_markdown_rb.so +0 -0
- data/sig/types.rbs +59 -292
- metadata +32 -179
- data/ext/html_to_markdown_rb/Makefile +0 -592
- data/lib/bin/html-to-markdown +0 -0
- data/vendor/Cargo.toml +0 -33
- data/vendor/html-to-markdown-rs/Cargo.toml +0 -54
- data/vendor/html-to-markdown-rs/README.md +0 -278
- data/vendor/html-to-markdown-rs/examples/basic.rs +0 -24
- data/vendor/html-to-markdown-rs/examples/table.rs +0 -25
- data/vendor/html-to-markdown-rs/examples/test_deser.rs +0 -12
- data/vendor/html-to-markdown-rs/examples/test_escape.rs +0 -58
- data/vendor/html-to-markdown-rs/examples/test_inline_formatting.rs +0 -113
- data/vendor/html-to-markdown-rs/examples/test_lists.rs +0 -39
- data/vendor/html-to-markdown-rs/examples/test_semantic_tags.rs +0 -89
- data/vendor/html-to-markdown-rs/examples/test_tables.rs +0 -100
- data/vendor/html-to-markdown-rs/examples/test_task_lists.rs +0 -61
- data/vendor/html-to-markdown-rs/examples/test_whitespace.rs +0 -34
- data/vendor/html-to-markdown-rs/src/convert_api.rs +0 -349
- data/vendor/html-to-markdown-rs/src/converter/block/blockquote.rs +0 -178
- data/vendor/html-to-markdown-rs/src/converter/block/container.rs +0 -114
- data/vendor/html-to-markdown-rs/src/converter/block/div.rs +0 -149
- data/vendor/html-to-markdown-rs/src/converter/block/heading.rs +0 -428
- data/vendor/html-to-markdown-rs/src/converter/block/horizontal_rule.rs +0 -103
- data/vendor/html-to-markdown-rs/src/converter/block/line_break.rs +0 -89
- data/vendor/html-to-markdown-rs/src/converter/block/mod.rs +0 -10
- data/vendor/html-to-markdown-rs/src/converter/block/paragraph.rs +0 -140
- data/vendor/html-to-markdown-rs/src/converter/block/preformatted.rs +0 -298
- data/vendor/html-to-markdown-rs/src/converter/block/table/builder.rs +0 -453
- data/vendor/html-to-markdown-rs/src/converter/block/table/caption.rs +0 -44
- data/vendor/html-to-markdown-rs/src/converter/block/table/cell.rs +0 -276
- data/vendor/html-to-markdown-rs/src/converter/block/table/cells.rs +0 -336
- data/vendor/html-to-markdown-rs/src/converter/block/table/layout.rs +0 -58
- data/vendor/html-to-markdown-rs/src/converter/block/table/mod.rs +0 -266
- data/vendor/html-to-markdown-rs/src/converter/block/table/scanner.rs +0 -146
- data/vendor/html-to-markdown-rs/src/converter/block/table/utils.rs +0 -34
- data/vendor/html-to-markdown-rs/src/converter/block/unknown.rs +0 -138
- data/vendor/html-to-markdown-rs/src/converter/context.rs +0 -208
- data/vendor/html-to-markdown-rs/src/converter/dom_context.rs +0 -337
- data/vendor/html-to-markdown-rs/src/converter/form/elements.rs +0 -770
- data/vendor/html-to-markdown-rs/src/converter/form/mod.rs +0 -82
- data/vendor/html-to-markdown-rs/src/converter/format/djot.rs +0 -64
- data/vendor/html-to-markdown-rs/src/converter/format/markdown.rs +0 -59
- data/vendor/html-to-markdown-rs/src/converter/format/mod.rs +0 -43
- data/vendor/html-to-markdown-rs/src/converter/handlers/blockquote.rs +0 -173
- data/vendor/html-to-markdown-rs/src/converter/handlers/code_block.rs +0 -434
- data/vendor/html-to-markdown-rs/src/converter/handlers/graphic.rs +0 -234
- data/vendor/html-to-markdown-rs/src/converter/handlers/image.rs +0 -282
- data/vendor/html-to-markdown-rs/src/converter/handlers/link.rs +0 -316
- data/vendor/html-to-markdown-rs/src/converter/handlers/mod.rs +0 -26
- data/vendor/html-to-markdown-rs/src/converter/inline/code.rs +0 -306
- data/vendor/html-to-markdown-rs/src/converter/inline/emphasis.rs +0 -345
- data/vendor/html-to-markdown-rs/src/converter/inline/link.rs +0 -428
- data/vendor/html-to-markdown-rs/src/converter/inline/mod.rs +0 -237
- data/vendor/html-to-markdown-rs/src/converter/inline/ruby.rs +0 -337
- data/vendor/html-to-markdown-rs/src/converter/inline/semantic/marks.rs +0 -566
- data/vendor/html-to-markdown-rs/src/converter/inline/semantic/mod.rs +0 -86
- data/vendor/html-to-markdown-rs/src/converter/inline/semantic/typography.rs +0 -558
- data/vendor/html-to-markdown-rs/src/converter/list/definition.rs +0 -232
- data/vendor/html-to-markdown-rs/src/converter/list/item.rs +0 -332
- data/vendor/html-to-markdown-rs/src/converter/list/mod.rs +0 -70
- data/vendor/html-to-markdown-rs/src/converter/list/ordered.rs +0 -201
- data/vendor/html-to-markdown-rs/src/converter/list/unordered.rs +0 -195
- data/vendor/html-to-markdown-rs/src/converter/list/utils.rs +0 -314
- data/vendor/html-to-markdown-rs/src/converter/main.rs +0 -710
- data/vendor/html-to-markdown-rs/src/converter/main_helpers.rs +0 -452
- data/vendor/html-to-markdown-rs/src/converter/media/embedded.rs +0 -393
- data/vendor/html-to-markdown-rs/src/converter/media/graphic.rs +0 -4
- data/vendor/html-to-markdown-rs/src/converter/media/image.rs +0 -183
- data/vendor/html-to-markdown-rs/src/converter/media/mod.rs +0 -87
- data/vendor/html-to-markdown-rs/src/converter/media/svg.rs +0 -280
- data/vendor/html-to-markdown-rs/src/converter/metadata.rs +0 -220
- data/vendor/html-to-markdown-rs/src/converter/mod.rs +0 -156
- data/vendor/html-to-markdown-rs/src/converter/plain_text.rs +0 -516
- data/vendor/html-to-markdown-rs/src/converter/preprocessing_helpers.rs +0 -201
- data/vendor/html-to-markdown-rs/src/converter/reference_collector.rs +0 -69
- data/vendor/html-to-markdown-rs/src/converter/semantic/attributes.rs +0 -269
- data/vendor/html-to-markdown-rs/src/converter/semantic/definition_list.rs +0 -266
- data/vendor/html-to-markdown-rs/src/converter/semantic/figure.rs +0 -391
- data/vendor/html-to-markdown-rs/src/converter/semantic/mod.rs +0 -112
- data/vendor/html-to-markdown-rs/src/converter/semantic/sectioning.rs +0 -85
- data/vendor/html-to-markdown-rs/src/converter/semantic/summary.rs +0 -324
- data/vendor/html-to-markdown-rs/src/converter/text/mod.rs +0 -8
- data/vendor/html-to-markdown-rs/src/converter/text/processing.rs +0 -56
- data/vendor/html-to-markdown-rs/src/converter/text_node.rs +0 -269
- data/vendor/html-to-markdown-rs/src/converter/utility/attributes.rs +0 -151
- data/vendor/html-to-markdown-rs/src/converter/utility/caching.rs +0 -74
- data/vendor/html-to-markdown-rs/src/converter/utility/content.rs +0 -271
- data/vendor/html-to-markdown-rs/src/converter/utility/mod.rs +0 -17
- data/vendor/html-to-markdown-rs/src/converter/utility/preprocessing.rs +0 -1002
- data/vendor/html-to-markdown-rs/src/converter/utility/serialization.rs +0 -126
- data/vendor/html-to-markdown-rs/src/converter/utility/siblings.rs +0 -97
- data/vendor/html-to-markdown-rs/src/converter/visitor_hooks.rs +0 -189
- data/vendor/html-to-markdown-rs/src/error.rs +0 -43
- data/vendor/html-to-markdown-rs/src/exports.rs +0 -24
- data/vendor/html-to-markdown-rs/src/inline_images.rs +0 -336
- data/vendor/html-to-markdown-rs/src/lib.rs +0 -139
- data/vendor/html-to-markdown-rs/src/metadata/collector.rs +0 -457
- data/vendor/html-to-markdown-rs/src/metadata/config.rs +0 -394
- data/vendor/html-to-markdown-rs/src/metadata/extraction.rs +0 -398
- data/vendor/html-to-markdown-rs/src/metadata/mod.rs +0 -288
- data/vendor/html-to-markdown-rs/src/metadata/types.rs +0 -477
- data/vendor/html-to-markdown-rs/src/options/conversion.rs +0 -559
- data/vendor/html-to-markdown-rs/src/options/inline_image.rs +0 -111
- data/vendor/html-to-markdown-rs/src/options/mod.rs +0 -20
- data/vendor/html-to-markdown-rs/src/options/preprocessing.rs +0 -201
- data/vendor/html-to-markdown-rs/src/options/validation.rs +0 -416
- data/vendor/html-to-markdown-rs/src/prelude.rs +0 -1
- data/vendor/html-to-markdown-rs/src/rcdom.rs +0 -487
- data/vendor/html-to-markdown-rs/src/text.rs +0 -358
- data/vendor/html-to-markdown-rs/src/types/document.rs +0 -191
- data/vendor/html-to-markdown-rs/src/types/mod.rs +0 -17
- data/vendor/html-to-markdown-rs/src/types/result.rs +0 -54
- data/vendor/html-to-markdown-rs/src/types/structure_builder.rs +0 -791
- data/vendor/html-to-markdown-rs/src/types/structure_collector.rs +0 -483
- data/vendor/html-to-markdown-rs/src/types/tables.rs +0 -52
- data/vendor/html-to-markdown-rs/src/types/warnings.rs +0 -33
- data/vendor/html-to-markdown-rs/src/validation.rs +0 -158
- data/vendor/html-to-markdown-rs/src/visitor/default_impl.rs +0 -63
- data/vendor/html-to-markdown-rs/src/visitor/mod.rs +0 -41
- data/vendor/html-to-markdown-rs/src/visitor/traits.rs +0 -370
- data/vendor/html-to-markdown-rs/src/visitor/types.rs +0 -319
- data/vendor/html-to-markdown-rs/src/visitor_helpers/helpers/callbacks/mod.rs +0 -1
- data/vendor/html-to-markdown-rs/src/visitor_helpers/helpers/content.rs +0 -126
- data/vendor/html-to-markdown-rs/src/visitor_helpers/helpers/mod.rs +0 -27
- data/vendor/html-to-markdown-rs/src/visitor_helpers/helpers/state.rs +0 -110
- data/vendor/html-to-markdown-rs/src/visitor_helpers/helpers/traversal.rs +0 -250
- data/vendor/html-to-markdown-rs/src/visitor_helpers.rs +0 -597
- data/vendor/html-to-markdown-rs/src/wrapper/sync.rs +0 -413
- data/vendor/html-to-markdown-rs/src/wrapper/utils.rs +0 -290
- data/vendor/html-to-markdown-rs/src/wrapper.rs +0 -9
- data/vendor/html-to-markdown-rs/tests/br_in_inline_test.rs +0 -87
- data/vendor/html-to-markdown-rs/tests/commonmark_compliance_test.rs +0 -297
- data/vendor/html-to-markdown-rs/tests/djot_output_test.rs +0 -153
- data/vendor/html-to-markdown-rs/tests/exclude_selectors_test.rs +0 -132
- data/vendor/html-to-markdown-rs/tests/integration_test.rs +0 -631
- data/vendor/html-to-markdown-rs/tests/issue_121_regressions.rs +0 -49
- data/vendor/html-to-markdown-rs/tests/issue_127_regressions.rs +0 -58
- data/vendor/html-to-markdown-rs/tests/issue_128_regressions.rs +0 -17
- data/vendor/html-to-markdown-rs/tests/issue_131_regressions.rs +0 -41
- data/vendor/html-to-markdown-rs/tests/issue_134_regressions.rs +0 -40
- data/vendor/html-to-markdown-rs/tests/issue_139_regressions.rs +0 -26
- data/vendor/html-to-markdown-rs/tests/issue_140_regressions.rs +0 -185
- data/vendor/html-to-markdown-rs/tests/issue_143_regressions.rs +0 -100
- data/vendor/html-to-markdown-rs/tests/issue_145_regressions.rs +0 -133
- data/vendor/html-to-markdown-rs/tests/issue_146_regressions.rs +0 -144
- data/vendor/html-to-markdown-rs/tests/issue_176_regressions.rs +0 -62
- data/vendor/html-to-markdown-rs/tests/issue_190_regressions.rs +0 -128
- data/vendor/html-to-markdown-rs/tests/issue_199_regressions.rs +0 -20
- data/vendor/html-to-markdown-rs/tests/issue_200_regressions.rs +0 -62
- data/vendor/html-to-markdown-rs/tests/issue_212_regressions.rs +0 -68
- data/vendor/html-to-markdown-rs/tests/issue_216_217_regressions.rs +0 -87
- data/vendor/html-to-markdown-rs/tests/issue_336_regressions.rs +0 -74
- data/vendor/html-to-markdown-rs/tests/issue_339_regressions.rs +0 -92
- data/vendor/html-to-markdown-rs/tests/issue_347_regressions.rs +0 -154
- data/vendor/html-to-markdown-rs/tests/issue_348_visitor_plain.rs +0 -93
- data/vendor/html-to-markdown-rs/tests/json_ld_script_extraction.rs +0 -44
- data/vendor/html-to-markdown-rs/tests/lists_test.rs +0 -199
- data/vendor/html-to-markdown-rs/tests/plain_output_test.rs +0 -273
- data/vendor/html-to-markdown-rs/tests/preprocessing_tests.rs +0 -61
- data/vendor/html-to-markdown-rs/tests/reference_links_test.rs +0 -169
- data/vendor/html-to-markdown-rs/tests/sectioning_elements_test.rs +0 -137
- data/vendor/html-to-markdown-rs/tests/skip_images_test.rs +0 -522
- data/vendor/html-to-markdown-rs/tests/tables_test.rs +0 -743
- data/vendor/html-to-markdown-rs/tests/test_custom_elements.rs +0 -41
- data/vendor/html-to-markdown-rs/tests/test_issue_187.rs +0 -204
- data/vendor/html-to-markdown-rs/tests/test_issue_218.rs +0 -68
- data/vendor/html-to-markdown-rs/tests/test_issue_277.rs +0 -77
- data/vendor/html-to-markdown-rs/tests/test_max_depth.rs +0 -82
- data/vendor/html-to-markdown-rs/tests/test_nested_simple.rs +0 -45
- data/vendor/html-to-markdown-rs/tests/test_script_style_stripping.rs +0 -396
- data/vendor/html-to-markdown-rs/tests/test_spa_bisect.rs +0 -34
- data/vendor/html-to-markdown-rs/tests/visitor_code_integration_test.rs +0 -121
- data/vendor/html-to-markdown-rs/tests/visitor_integration_test.rs +0 -1190
- data/vendor/html-to-markdown-rs/tests/xml_tables_test.rs +0 -372
|
@@ -1,631 +0,0 @@
|
|
|
1
|
-
#![allow(missing_docs)]
|
|
2
|
-
|
|
3
|
-
use html_to_markdown_rs::ConversionOptions;
|
|
4
|
-
|
|
5
|
-
#[test]
|
|
6
|
-
fn test_basic_paragraph() {
|
|
7
|
-
let html = "<p>Hello world</p>";
|
|
8
|
-
let result = convert(html, None).unwrap();
|
|
9
|
-
assert_eq!(result, "Hello world\n");
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
#[test]
|
|
13
|
-
fn test_multiple_paragraphs() {
|
|
14
|
-
let html = "<p>First paragraph</p><p>Second paragraph</p>";
|
|
15
|
-
let result = convert(html, None).unwrap();
|
|
16
|
-
assert_eq!(result, "First paragraph\n\nSecond paragraph\n");
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
#[test]
|
|
20
|
-
fn test_atx_headings() {
|
|
21
|
-
let html = "<h1>H1</h1><h2>H2</h2><h3>H3</h3><h4>H4</h4><h5>H5</h5><h6>H6</h6>";
|
|
22
|
-
let result = convert(html, None).unwrap();
|
|
23
|
-
assert_eq!(result, "# H1\n\n## H2\n\n### H3\n\n#### H4\n\n##### H5\n\n###### H6\n");
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
#[test]
|
|
27
|
-
fn test_bold() {
|
|
28
|
-
let html = "<p>Text with <strong>bold</strong> word</p>";
|
|
29
|
-
let result = convert(html, None).unwrap();
|
|
30
|
-
assert_eq!(result, "Text with **bold** word\n");
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
#[test]
|
|
34
|
-
fn test_italic() {
|
|
35
|
-
let html = "<p>Text with <em>italic</em> word</p>";
|
|
36
|
-
let result = convert(html, None).unwrap();
|
|
37
|
-
assert_eq!(result, "Text with *italic* word\n");
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
#[test]
|
|
41
|
-
fn test_bold_and_italic() {
|
|
42
|
-
let html = "<p><strong><em>Bold and italic</em></strong></p>";
|
|
43
|
-
let result = convert(html, None).unwrap();
|
|
44
|
-
assert_eq!(result, "***Bold and italic***\n");
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
#[test]
|
|
48
|
-
fn test_inline_code() {
|
|
49
|
-
let html = "<p>Use <code>code</code> here</p>";
|
|
50
|
-
let result = convert(html, None).unwrap();
|
|
51
|
-
assert_eq!(result, "Use `code` here\n");
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
#[test]
|
|
55
|
-
fn test_code_block() {
|
|
56
|
-
let html = "<pre><code>fn main() {\n println!(\"Hello\");\n}</code></pre>";
|
|
57
|
-
let result = convert(html, None).unwrap();
|
|
58
|
-
assert_eq!(result, "```\nfn main() {\n println!(\"Hello\");\n}\n```\n");
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
#[test]
|
|
62
|
-
fn test_simple_link() {
|
|
63
|
-
let html = "<p><a href=\"https://example.com\">Link text</a></p>";
|
|
64
|
-
let result = convert(html, None).unwrap();
|
|
65
|
-
assert_eq!(result, "[Link text](https://example.com)\n");
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
#[test]
|
|
69
|
-
fn test_link_with_title() {
|
|
70
|
-
let html = "<p><a href=\"/url\" title=\"title\">Link</a></p>";
|
|
71
|
-
let result = convert(html, None).unwrap();
|
|
72
|
-
assert_eq!(result, "[Link](/url \"title\")\n");
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
#[test]
|
|
76
|
-
fn test_simple_image() {
|
|
77
|
-
let html = "<p><img src=\"image.jpg\" alt=\"Alt text\" /></p>";
|
|
78
|
-
let result = convert(html, None).unwrap();
|
|
79
|
-
assert_eq!(result, "\n");
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
#[test]
|
|
83
|
-
fn test_graphic_with_url() {
|
|
84
|
-
let html = "<p><graphic url=\"diagram.svg\" alt=\"Diagram\" /></p>";
|
|
85
|
-
let result = convert(html, None).unwrap();
|
|
86
|
-
assert_eq!(result, "\n");
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
#[test]
|
|
90
|
-
fn test_graphic_with_href() {
|
|
91
|
-
let html = "<p><graphic href=\"image.png\" alt=\"Image\" /></p>";
|
|
92
|
-
let result = convert(html, None).unwrap();
|
|
93
|
-
assert_eq!(result, "\n");
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
#[test]
|
|
97
|
-
fn test_graphic_with_xlink_href() {
|
|
98
|
-
let html = "<p><graphic xlink:href=\"chart.svg\" alt=\"Chart\" /></p>";
|
|
99
|
-
let result = convert(html, None).unwrap();
|
|
100
|
-
assert_eq!(result, "\n");
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
#[test]
|
|
104
|
-
fn test_graphic_with_src() {
|
|
105
|
-
let html = "<p><graphic src=\"fallback.jpg\" alt=\"Fallback\" /></p>";
|
|
106
|
-
let result = convert(html, None).unwrap();
|
|
107
|
-
assert_eq!(result, "\n");
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
#[test]
|
|
111
|
-
fn test_graphic_with_filename_fallback() {
|
|
112
|
-
let html = "<p><graphic url=\"image.png\" filename=\"my-image.png\" /></p>";
|
|
113
|
-
let result = convert(html, None).unwrap();
|
|
114
|
-
assert_eq!(result, "\n");
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
#[test]
|
|
118
|
-
fn test_graphic_attribute_priority() {
|
|
119
|
-
// url should take priority over href, xlink:href, src
|
|
120
|
-
let html = "<p><graphic url=\"priority.svg\" href=\"second.svg\" xlink:href=\"third.svg\" src=\"fourth.svg\" alt=\"Priority\" /></p>";
|
|
121
|
-
let result = convert(html, None).unwrap();
|
|
122
|
-
assert_eq!(result, "\n");
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
#[test]
|
|
126
|
-
fn test_unordered_list() {
|
|
127
|
-
let html = "<ul><li>Item 1</li><li>Item 2</li><li>Item 3</li></ul>";
|
|
128
|
-
let result = convert(html, None).unwrap();
|
|
129
|
-
assert_eq!(result, "- Item 1\n- Item 2\n- Item 3\n");
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
#[test]
|
|
133
|
-
fn test_ordered_list() {
|
|
134
|
-
let html = "<ol><li>First</li><li>Second</li><li>Third</li></ol>";
|
|
135
|
-
let result = convert(html, None).unwrap();
|
|
136
|
-
assert_eq!(result, "1. First\n2. Second\n3. Third\n");
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
#[test]
|
|
140
|
-
fn test_nested_lists() {
|
|
141
|
-
let html = "<ul><li>Item 1<ul><li>Nested 1</li><li>Nested 2</li></ul></li><li>Item 2</li></ul>";
|
|
142
|
-
let result = convert(html, None).unwrap();
|
|
143
|
-
assert!(result.contains("- Item 1"));
|
|
144
|
-
assert!(result.contains("Nested 1"), "Expected 'Nested 1' in result: {result:?}");
|
|
145
|
-
assert!(result.contains("Nested 2"), "Expected 'Nested 2' in result: {result:?}");
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
#[test]
|
|
149
|
-
fn test_blockquote() {
|
|
150
|
-
let html = "<blockquote><p>Quoted text</p></blockquote>";
|
|
151
|
-
let result = convert(html, None).unwrap();
|
|
152
|
-
assert_eq!(result, "> Quoted text\n");
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
#[test]
|
|
156
|
-
fn test_nested_blockquote() {
|
|
157
|
-
let html = "<blockquote><blockquote><p>Nested quote</p></blockquote></blockquote>";
|
|
158
|
-
let result = convert(html, None).unwrap();
|
|
159
|
-
assert_eq!(result, "> > Nested quote\n");
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
#[test]
|
|
163
|
-
fn test_horizontal_rule() {
|
|
164
|
-
let html = "<hr>";
|
|
165
|
-
let result = convert(html, None).unwrap();
|
|
166
|
-
assert_eq!(result, "---\n");
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
#[test]
|
|
170
|
-
fn test_hr_after_paragraph_keeps_blank_line() {
|
|
171
|
-
let html = "<p>paragraph</p><hr>";
|
|
172
|
-
let result = convert(html, None).unwrap();
|
|
173
|
-
assert_eq!(result, "paragraph\n\n---\n");
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
#[test]
|
|
177
|
-
fn test_comment_between_paragraphs() {
|
|
178
|
-
let html = "<p>yes</p><!----><p>but no</p>";
|
|
179
|
-
let result = convert(html, None).unwrap();
|
|
180
|
-
assert_eq!(result, "yes\n\nbut no\n");
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
#[test]
|
|
184
|
-
fn test_line_break() {
|
|
185
|
-
let html = "<p>Line 1<br>Line 2</p>";
|
|
186
|
-
let result = convert(html, None).unwrap();
|
|
187
|
-
assert_eq!(result, "Line 1 \nLine 2\n");
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
#[test]
|
|
191
|
-
fn test_strikethrough() {
|
|
192
|
-
let html = "<p><del>Deleted text</del></p>";
|
|
193
|
-
let result = convert(html, None).unwrap();
|
|
194
|
-
assert_eq!(result, "~~Deleted text~~\n");
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
#[test]
|
|
198
|
-
fn test_simple_table() {
|
|
199
|
-
let html = "<table><tr><th>Header</th></tr><tr><td>Cell</td></tr></table>";
|
|
200
|
-
let result = convert(html, None).unwrap();
|
|
201
|
-
assert!(result.contains("| Header |"), "header row missing: {result}");
|
|
202
|
-
// Separator uses at least as many dashes as the widest cell ("Header" = 6).
|
|
203
|
-
assert!(
|
|
204
|
-
result.lines().any(|l| l.starts_with("| ----")),
|
|
205
|
-
"separator row missing: {result}"
|
|
206
|
-
);
|
|
207
|
-
assert!(result.contains("| Cell"), "cell row missing: {result}");
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
#[test]
|
|
211
|
-
fn test_table_rowspan() {
|
|
212
|
-
let html = r#"<table>
|
|
213
|
-
<tr><th>Header 1</th><th>Header 2</th></tr>
|
|
214
|
-
<tr><td rowspan="2">Spanning cell</td><td>
|
|
215
|
-
<div>First row content</div>
|
|
216
|
-
<div>Second line</div>
|
|
217
|
-
</td></tr>
|
|
218
|
-
<tr><td>
|
|
219
|
-
<div>Next row</div>
|
|
220
|
-
<div>More content</div>
|
|
221
|
-
</td></tr>
|
|
222
|
-
</table>"#;
|
|
223
|
-
let options = ConversionOptions {
|
|
224
|
-
br_in_tables: true,
|
|
225
|
-
..Default::default()
|
|
226
|
-
};
|
|
227
|
-
let result = convert(html, Some(options)).unwrap();
|
|
228
|
-
// Columns are padded to the widest cell per column (rowspan accounted):
|
|
229
|
-
// col 0: max("Header 1"=8, "Spanning cell"=13, ""=0) = 13
|
|
230
|
-
// col 1: max("Header 2"=8, "First row content<br>Second line"=32, "Next row<br>More content"=24) = 32
|
|
231
|
-
let expected = "| Header 1 | Header 2 |\n| ------------- | -------------------------------- |\n| Spanning cell | First row content<br>Second line |\n| | Next row<br>More content |\n";
|
|
232
|
-
assert_eq!(result, expected);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
#[test]
|
|
236
|
-
fn test_empty_element() {
|
|
237
|
-
let html = "<p></p>";
|
|
238
|
-
let result = convert(html, None).unwrap();
|
|
239
|
-
assert_eq!(result, "");
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
#[test]
|
|
243
|
-
fn test_whitespace_normalization() {
|
|
244
|
-
let html = "<p>Multiple spaces here</p>";
|
|
245
|
-
let result = convert(html, None).unwrap();
|
|
246
|
-
assert_eq!(result, "Multiple spaces here\n");
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
#[test]
|
|
250
|
-
fn test_unicode_content() {
|
|
251
|
-
let html = "<p>Hello 世界 🌍</p>";
|
|
252
|
-
let result = convert(html, None).unwrap();
|
|
253
|
-
assert_eq!(result, "Hello 世界 🌍\n");
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
#[test]
|
|
257
|
-
fn test_html_entities() {
|
|
258
|
-
let html = "<p><div> & "quotes"</p>";
|
|
259
|
-
let result = convert(html, None).unwrap();
|
|
260
|
-
assert_eq!(result, "<div> & \"quotes\"\n");
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
#[test]
|
|
264
|
-
fn test_nested_formatting() {
|
|
265
|
-
let html = "<p><strong>Bold <em>and italic</em> text</strong></p>";
|
|
266
|
-
let result = convert(html, None).unwrap();
|
|
267
|
-
assert_eq!(result, "**Bold *and italic* text**\n");
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
#[test]
|
|
271
|
-
fn test_link_inside_paragraph() {
|
|
272
|
-
let html = "<p>Check out <a href=\"https://example.com\">this link</a> for more info.</p>";
|
|
273
|
-
let result = convert(html, None).unwrap();
|
|
274
|
-
assert_eq!(result, "Check out [this link](https://example.com) for more info.\n");
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
#[test]
|
|
278
|
-
fn test_code_with_special_chars() {
|
|
279
|
-
let html = "<code><html></code>";
|
|
280
|
-
let result = convert(html, None).unwrap();
|
|
281
|
-
assert_eq!(result, "`<html>`\n");
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
#[test]
|
|
285
|
-
fn test_empty_link() {
|
|
286
|
-
let html = "<p><a href=\"\">Empty</a></p>";
|
|
287
|
-
let result = convert(html, None).unwrap();
|
|
288
|
-
assert_eq!(result, "[Empty](<>)\n");
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
#[test]
|
|
292
|
-
fn test_div_as_block() {
|
|
293
|
-
let html = "<div>Block content</div>";
|
|
294
|
-
let result = convert(html, None).unwrap();
|
|
295
|
-
assert_eq!(result, "Block content\n");
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
#[test]
|
|
299
|
-
fn test_multiple_divs() {
|
|
300
|
-
let html = "<div>First</div><div>Second</div>";
|
|
301
|
-
let result = convert(html, None).unwrap();
|
|
302
|
-
assert_eq!(result, "First\n\nSecond\n");
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
#[test]
|
|
306
|
-
fn test_span_inline() {
|
|
307
|
-
let html = "<p>Text with <span>span</span> element</p>";
|
|
308
|
-
let result = convert(html, None).unwrap();
|
|
309
|
-
assert_eq!(result, "Text with span element\n");
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
#[test]
|
|
313
|
-
fn test_subscript() {
|
|
314
|
-
let html = "<p>H<sub>2</sub>O</p>";
|
|
315
|
-
let opts = ConversionOptions {
|
|
316
|
-
sub_symbol: "~".to_string(),
|
|
317
|
-
..Default::default()
|
|
318
|
-
};
|
|
319
|
-
let result = convert(html, Some(opts)).unwrap();
|
|
320
|
-
assert_eq!(result, "H~2~O\n");
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
#[test]
|
|
324
|
-
fn test_subscript_trailing_whitespace() {
|
|
325
|
-
let html = "<p><sub>hello </sub>world</p>";
|
|
326
|
-
let opts = ConversionOptions {
|
|
327
|
-
sub_symbol: "~".to_string(),
|
|
328
|
-
..Default::default()
|
|
329
|
-
};
|
|
330
|
-
let result = convert(html, Some(opts)).unwrap();
|
|
331
|
-
assert_eq!(result, "~hello~ world\n");
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
#[test]
|
|
335
|
-
fn test_subscript_leading_whitespace() {
|
|
336
|
-
let html = "<p>hello<sub> world</sub></p>";
|
|
337
|
-
let opts = ConversionOptions {
|
|
338
|
-
sub_symbol: "~".to_string(),
|
|
339
|
-
..Default::default()
|
|
340
|
-
};
|
|
341
|
-
let result = convert(html, Some(opts)).unwrap();
|
|
342
|
-
assert_eq!(result, "hello ~world~\n");
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
#[test]
|
|
346
|
-
fn test_superscript() {
|
|
347
|
-
let html = "<p>x<sup>2</sup></p>";
|
|
348
|
-
let opts = ConversionOptions {
|
|
349
|
-
sup_symbol: "^".to_string(),
|
|
350
|
-
..Default::default()
|
|
351
|
-
};
|
|
352
|
-
let result = convert(html, Some(opts)).unwrap();
|
|
353
|
-
assert_eq!(result, "x^2^\n");
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
#[test]
|
|
357
|
-
fn test_superscript_trailing_whitespace() {
|
|
358
|
-
let html = "<p><sup>hello </sup>world</p>";
|
|
359
|
-
let opts = ConversionOptions {
|
|
360
|
-
sup_symbol: "^".to_string(),
|
|
361
|
-
..Default::default()
|
|
362
|
-
};
|
|
363
|
-
let result = convert(html, Some(opts)).unwrap();
|
|
364
|
-
assert_eq!(result, "^hello^ world\n");
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
#[test]
|
|
368
|
-
fn test_superscript_leading_whitespace() {
|
|
369
|
-
let html = "<p>hello<sup> world</sup></p>";
|
|
370
|
-
let opts = ConversionOptions {
|
|
371
|
-
sup_symbol: "^".to_string(),
|
|
372
|
-
..Default::default()
|
|
373
|
-
};
|
|
374
|
-
let result = convert(html, Some(opts)).unwrap();
|
|
375
|
-
assert_eq!(result, "hello ^world^\n");
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
#[test]
|
|
379
|
-
fn test_subscript_default_passthrough() {
|
|
380
|
-
let html = "<p>H<sub>2</sub>O</p>";
|
|
381
|
-
let result = convert(html, None).unwrap();
|
|
382
|
-
assert_eq!(result, "H2O\n");
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
#[test]
|
|
386
|
-
fn test_superscript_default_passthrough() {
|
|
387
|
-
let html = "<p>x<sup>2</sup> + y<sup>3</sup></p>";
|
|
388
|
-
let result = convert(html, None).unwrap();
|
|
389
|
-
assert_eq!(result, "x2 + y3\n");
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
#[test]
|
|
393
|
-
fn test_subscript_superscript_combined_default() {
|
|
394
|
-
let html = "<p>CO<sub>2</sub><sup>*</sup></p>";
|
|
395
|
-
let result = convert(html, None).unwrap();
|
|
396
|
-
assert_eq!(result, "CO2*\n");
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
#[test]
|
|
400
|
-
fn test_subscript_html_tag_symbol() {
|
|
401
|
-
let html = "<p>H<sub>2</sub>O</p>";
|
|
402
|
-
let opts = ConversionOptions {
|
|
403
|
-
sub_symbol: "<sub>".to_string(),
|
|
404
|
-
..Default::default()
|
|
405
|
-
};
|
|
406
|
-
let result = convert(html, Some(opts)).unwrap();
|
|
407
|
-
assert_eq!(result, "H<sub>2</sub>O\n");
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
#[test]
|
|
411
|
-
fn test_adjacent_links_with_newline_separator() {
|
|
412
|
-
let html = "<p>\n<a href=\"/page1\">Link 1</a>\n<a href=\"/page2\">Link 2</a>\n</p>";
|
|
413
|
-
let result = convert(html, None).unwrap();
|
|
414
|
-
assert_eq!(result, "[Link 1](/page1) [Link 2](/page2)\n");
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
#[test]
|
|
418
|
-
fn test_adjacent_links_no_whitespace() {
|
|
419
|
-
let html = "<p><a href=\"/page1\">Link 1</a><a href=\"/page2\">Link 2</a></p>";
|
|
420
|
-
let result = convert(html, None).unwrap();
|
|
421
|
-
assert_eq!(result, "[Link 1](/page1)[Link 2](/page2)\n");
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
#[test]
|
|
425
|
-
fn test_adjacent_links_with_space() {
|
|
426
|
-
let html = "<p><a href=\"/page1\">Link 1</a> <a href=\"/page2\">Link 2</a></p>";
|
|
427
|
-
let result = convert(html, None).unwrap();
|
|
428
|
-
assert_eq!(result, "[Link 1](/page1) [Link 2](/page2)\n");
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
#[test]
|
|
432
|
-
fn test_adjacent_inline_elements_with_newline() {
|
|
433
|
-
let html = "<p><strong>bold</strong>\n<em>italic</em></p>";
|
|
434
|
-
let result = convert(html, None).unwrap();
|
|
435
|
-
assert_eq!(result, "**bold** *italic*\n");
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
#[test]
|
|
439
|
-
fn test_autolink() {
|
|
440
|
-
let html = "<p><a href=\"https://example.com\">https://example.com</a></p>";
|
|
441
|
-
let result = convert(html, None).unwrap();
|
|
442
|
-
assert_eq!(result, "<https://example.com>\n");
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
#[test]
|
|
446
|
-
fn test_email_autolink() {
|
|
447
|
-
let html = "<p><a href=\"mailto:test@example.com\">test@example.com</a></p>";
|
|
448
|
-
let result = convert(html, None).unwrap();
|
|
449
|
-
assert_eq!(result, "<test@example.com>\n");
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
#[test]
|
|
453
|
-
fn test_metadata_extraction() {
|
|
454
|
-
let html = "<html><head><title>Page Title</title></head><body><p>Content</p></body></html>";
|
|
455
|
-
let opts = ConversionOptions {
|
|
456
|
-
extract_metadata: true,
|
|
457
|
-
..Default::default()
|
|
458
|
-
};
|
|
459
|
-
let result = convert(html, Some(opts)).unwrap();
|
|
460
|
-
assert!(result.contains("Page Title"));
|
|
461
|
-
assert!(result.contains("Content"));
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
#[test]
|
|
465
|
-
fn test_metadata_disabled() {
|
|
466
|
-
let html = "<html><head><title>Page Title</title></head><body><p>Content</p></body></html>";
|
|
467
|
-
let opts = ConversionOptions {
|
|
468
|
-
extract_metadata: false,
|
|
469
|
-
..Default::default()
|
|
470
|
-
};
|
|
471
|
-
let result = convert(html, Some(opts)).unwrap();
|
|
472
|
-
assert!(!result.contains("<!--"));
|
|
473
|
-
assert!(result.contains("Content"));
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
#[test]
|
|
477
|
-
fn test_task_list() {
|
|
478
|
-
let html = "<ul><li><input type=\"checkbox\" checked> Done</li><li><input type=\"checkbox\"> Todo</li></ul>";
|
|
479
|
-
let result = convert(html, None).unwrap();
|
|
480
|
-
assert!(result.contains("- [x] Done"));
|
|
481
|
-
assert!(result.contains("- [ ] Todo"));
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
#[test]
|
|
485
|
-
fn test_definition_list() {
|
|
486
|
-
let html = "<dl><dt>Term</dt><dd>Definition</dd></dl>";
|
|
487
|
-
let result = convert(html, None).unwrap();
|
|
488
|
-
assert!(result.contains("Term"));
|
|
489
|
-
assert!(result.contains("Definition"));
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
#[test]
|
|
493
|
-
fn test_malformed_html() {
|
|
494
|
-
let html = "<p>Unclosed paragraph<p>Another";
|
|
495
|
-
let result = convert(html, None);
|
|
496
|
-
assert!(result.is_ok());
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
#[test]
|
|
500
|
-
fn test_deeply_nested_structure() {
|
|
501
|
-
let html = "<div><div><div><div><p>Deeply nested</p></div></div></div></div>";
|
|
502
|
-
let result = convert(html, None).unwrap();
|
|
503
|
-
assert_eq!(result, "Deeply nested\n");
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
#[test]
|
|
507
|
-
fn test_mixed_content() {
|
|
508
|
-
let html = r#"
|
|
509
|
-
<h1>Title</h1>
|
|
510
|
-
<p>Paragraph with <strong>bold</strong> and <em>italic</em>.</p>
|
|
511
|
-
<ul>
|
|
512
|
-
<li>List item 1</li>
|
|
513
|
-
<li>List item 2</li>
|
|
514
|
-
</ul>
|
|
515
|
-
<p>Link: <a href="https://example.com">Example</a></p>
|
|
516
|
-
"#;
|
|
517
|
-
let result = convert(html, None).unwrap();
|
|
518
|
-
assert!(result.contains("# Title"));
|
|
519
|
-
assert!(result.contains("**bold**"));
|
|
520
|
-
assert!(result.contains("*italic*"));
|
|
521
|
-
assert!(result.contains("- List item 1"));
|
|
522
|
-
assert!(result.contains("[Example](https://example.com)"));
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
#[test]
|
|
526
|
-
fn test_ordered_list_with_heading_and_table() {
|
|
527
|
-
let html = r"
|
|
528
|
-
<ol>
|
|
529
|
-
<li>
|
|
530
|
-
<h3>h3</h3>
|
|
531
|
-
</li>
|
|
532
|
-
<li>
|
|
533
|
-
<table>
|
|
534
|
-
<caption>table</caption>
|
|
535
|
-
<tr>
|
|
536
|
-
<td>blah</td>
|
|
537
|
-
</tr>
|
|
538
|
-
</table>
|
|
539
|
-
</li>
|
|
540
|
-
</ol>
|
|
541
|
-
";
|
|
542
|
-
|
|
543
|
-
let result = convert(html, None).unwrap();
|
|
544
|
-
// Separator dashes match the column width ("blah" = 4 chars → 4 dashes).
|
|
545
|
-
let expected = "1. ### h3\n2. *table*\n\n | blah |\n | ---- |\n";
|
|
546
|
-
assert_eq!(result, expected);
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
#[test]
|
|
550
|
-
fn test_heading_wrapped_in_link_issue_115() {
|
|
551
|
-
let html = r#"<a href="https://domain.local"><h2>Heading A</h2></a>"#;
|
|
552
|
-
let result = convert(html, None).unwrap();
|
|
553
|
-
assert_eq!(result, "## [Heading A](https://domain.local)\n");
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
#[test]
|
|
557
|
-
fn test_link_text_escaping_issue_114() {
|
|
558
|
-
let html = r#"<a href="https://domain.local">Hi :]</a><br><a href="https://domain.local">1<2</a>"#;
|
|
559
|
-
let result = convert(html, None).unwrap();
|
|
560
|
-
assert_eq!(
|
|
561
|
-
result,
|
|
562
|
-
"[Hi :\\]](https://domain.local) \n[1<2](https://domain.local)\n"
|
|
563
|
-
);
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
#[test]
|
|
567
|
-
fn test_uppercase_tags_issue_113() {
|
|
568
|
-
let html = r"<B>Foo<Br />Bar</B>";
|
|
569
|
-
let result = convert(html, None).unwrap();
|
|
570
|
-
assert_eq!(result, "**Foo \nBar**\n");
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
#[test]
|
|
574
|
-
fn test_breaks_and_newlines_issue_112() {
|
|
575
|
-
let html = "<br>\n1\n2\n<b>3</b>";
|
|
576
|
-
let result = convert(html, None).unwrap();
|
|
577
|
-
assert_eq!(result, "\n1\n2\n**3**\n");
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
#[test]
|
|
581
|
-
fn test_nested_bold_issue_111() {
|
|
582
|
-
let html = "<b>bold<b>er</b></b>";
|
|
583
|
-
let result = convert(html, None).unwrap();
|
|
584
|
-
assert_eq!(result, "**bolder**\n");
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
#[test]
|
|
588
|
-
fn hidden_elements_stripped() {
|
|
589
|
-
let html = "<p>visible</p><div hidden>secret</div><p>also visible</p>";
|
|
590
|
-
let result = convert(html, None).unwrap();
|
|
591
|
-
assert!(!result.contains("secret"));
|
|
592
|
-
assert!(result.contains("visible"));
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
#[test]
|
|
596
|
-
fn q_element_produces_quotes() {
|
|
597
|
-
let html = "<p>He said <q>hello</q> to me</p>";
|
|
598
|
-
let result = convert(html, None).unwrap();
|
|
599
|
-
assert!(result.contains(r#""hello""#), "q element should add quotes: {result}");
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
#[test]
|
|
603
|
-
fn test_wikipedia_back_reference_caret_normalized() {
|
|
604
|
-
// Wikipedia back-references use <a href="#cite_ref-N">^</a>
|
|
605
|
-
// The caret should be normalized to ↑ to avoid confusion with markdown footnote syntax
|
|
606
|
-
let html = r##"<p>Some text<sup><a href="#cite_ref-1">^</a></sup> more text</p>"##;
|
|
607
|
-
let result = convert(html, None).unwrap();
|
|
608
|
-
assert!(
|
|
609
|
-
result.contains("[↑](#cite_ref-1)"),
|
|
610
|
-
"Back-reference caret should be normalized to ↑: {result}"
|
|
611
|
-
);
|
|
612
|
-
assert!(
|
|
613
|
-
!result.contains("[^]"),
|
|
614
|
-
"Should not produce [^] which looks like footnote syntax: {result}"
|
|
615
|
-
);
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
#[test]
|
|
619
|
-
fn test_regular_caret_link_not_affected() {
|
|
620
|
-
// Regular links with ^ text but no # href should keep the ^
|
|
621
|
-
let html = r#"<a href="https://example.com">^</a>"#;
|
|
622
|
-
let result = convert(html, None).unwrap();
|
|
623
|
-
assert!(result.contains("[^]"), "Non-anchor caret links should keep ^: {result}");
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
fn convert(
|
|
627
|
-
html: &str,
|
|
628
|
-
opts: Option<html_to_markdown_rs::ConversionOptions>,
|
|
629
|
-
) -> html_to_markdown_rs::error::Result<String> {
|
|
630
|
-
html_to_markdown_rs::convert(html, opts).map(|r| r.content.unwrap_or_default())
|
|
631
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
#![allow(missing_docs)]
|
|
2
|
-
|
|
3
|
-
fn convert(
|
|
4
|
-
html: &str,
|
|
5
|
-
opts: Option<html_to_markdown_rs::ConversionOptions>,
|
|
6
|
-
) -> html_to_markdown_rs::error::Result<String> {
|
|
7
|
-
html_to_markdown_rs::convert(html, opts).map(|r| r.content.unwrap_or_default())
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
use std::fs;
|
|
11
|
-
use std::path::PathBuf;
|
|
12
|
-
|
|
13
|
-
use html_to_markdown_rs::ConversionOptions;
|
|
14
|
-
|
|
15
|
-
fn fixture_path(name: &str) -> PathBuf {
|
|
16
|
-
[env!("CARGO_MANIFEST_DIR"), "../../test_documents/html/issues", name]
|
|
17
|
-
.iter()
|
|
18
|
-
.collect()
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
fn default_options() -> ConversionOptions {
|
|
22
|
-
ConversionOptions {
|
|
23
|
-
extract_metadata: false,
|
|
24
|
-
autolinks: false,
|
|
25
|
-
..Default::default()
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
fn normalize_newlines(input: &str) -> String {
|
|
30
|
-
input.replace("\r\n", "\n").replace('\r', "\n")
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
#[test]
|
|
34
|
-
fn converts_spa_menu_fixture() {
|
|
35
|
-
let html = fs::read_to_string(fixture_path("gh-121-spa-app.html")).expect("read spa html");
|
|
36
|
-
let expected = fs::read_to_string(fixture_path("gh-121-spa-app.md")).expect("read spa markdown");
|
|
37
|
-
|
|
38
|
-
let result = convert(&html, Some(default_options())).expect("convert spa html");
|
|
39
|
-
assert_eq!(normalize_newlines(&result), normalize_newlines(&expected));
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
#[test]
|
|
43
|
-
fn converts_hacker_news_fixture() {
|
|
44
|
-
let html = fs::read_to_string(fixture_path("gh-121-hacker-news.html")).expect("read hn html");
|
|
45
|
-
let expected = fs::read_to_string(fixture_path("gh-121-hacker-news.md")).expect("read hn markdown");
|
|
46
|
-
|
|
47
|
-
let result = convert(&html, Some(default_options())).expect("convert hn html");
|
|
48
|
-
assert_eq!(normalize_newlines(&result), normalize_newlines(&expected));
|
|
49
|
-
}
|