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,58 +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::{
|
|
14
|
-
CodeBlockStyle, ConversionOptions, HeadingStyle, HighlightStyle, ListIndentType, PreprocessingOptions,
|
|
15
|
-
PreprocessingPreset, WhitespaceMode,
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
fn fixture_path(name: &str) -> PathBuf {
|
|
19
|
-
[env!("CARGO_MANIFEST_DIR"), "../../test_documents/html/issues", name]
|
|
20
|
-
.iter()
|
|
21
|
-
.collect()
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
fn issue_127_options() -> ConversionOptions {
|
|
25
|
-
ConversionOptions {
|
|
26
|
-
heading_style: HeadingStyle::Atx,
|
|
27
|
-
bullets: "-".to_string(),
|
|
28
|
-
list_indent_type: ListIndentType::Spaces,
|
|
29
|
-
list_indent_width: 2,
|
|
30
|
-
whitespace_mode: WhitespaceMode::Normalized,
|
|
31
|
-
highlight_style: HighlightStyle::DoubleEqual,
|
|
32
|
-
wrap: false,
|
|
33
|
-
br_in_tables: true,
|
|
34
|
-
code_block_style: CodeBlockStyle::Backticks,
|
|
35
|
-
strip_newlines: true,
|
|
36
|
-
extract_metadata: false,
|
|
37
|
-
preprocessing: PreprocessingOptions {
|
|
38
|
-
enabled: true,
|
|
39
|
-
preset: PreprocessingPreset::Minimal,
|
|
40
|
-
remove_navigation: true,
|
|
41
|
-
remove_forms: true,
|
|
42
|
-
},
|
|
43
|
-
..Default::default()
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
#[test]
|
|
48
|
-
fn converts_multilingual_fixture_without_utf8_boundary_panic() {
|
|
49
|
-
let html = fs::read_to_string(fixture_path("gh-127-issue.html")).expect("read issue fixture");
|
|
50
|
-
|
|
51
|
-
let markdown = convert(&html, Some(issue_127_options())).expect("convert should not panic on utf-8 boundaries");
|
|
52
|
-
|
|
53
|
-
assert!(!markdown.is_empty(), "converted output should contain content");
|
|
54
|
-
assert!(
|
|
55
|
-
markdown.contains("MW841") && markdown.contains("كريب"),
|
|
56
|
-
"converted output should preserve multilingual product content"
|
|
57
|
-
);
|
|
58
|
-
}
|
|
@@ -1,17 +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
|
-
#[test]
|
|
11
|
-
fn images_with_dimensions_render_as_markdown_links() {
|
|
12
|
-
let html = r#"<img src="data:image/png;base64,xyz==" alt="Pixel" width="100" height="100"/>"#;
|
|
13
|
-
|
|
14
|
-
let markdown = convert(html, None).expect("image conversion should succeed");
|
|
15
|
-
|
|
16
|
-
assert_eq!(markdown.trim(), "");
|
|
17
|
-
}
|
|
@@ -1,41 +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 html_to_markdown_rs::ConversionOptions;
|
|
11
|
-
use html_to_markdown_rs::options::WhitespaceMode;
|
|
12
|
-
|
|
13
|
-
#[test]
|
|
14
|
-
fn link_flattens_block_children_issue_131() {
|
|
15
|
-
let html = r#"<a href="https://www.google.com">
|
|
16
|
-
<h3>MWD08 - الابيض</h3>
|
|
17
|
-
<p><span class="money" data-cbb-price-processed="true" style="display: none;">70.00 SAR</span><span class="currency-converter-wrapper-amount-box" style="display: inline-block; white-space: nowrap; margin: 0px; padding: 0px; text-decoration: inherit;"><span class="currency-converter-amount-box" style="display: inline-block; white-space: nowrap; padding: 0px; line-height: initial; color: rgb(28, 28, 28); font-size: 14px; font-style: normal; font-weight: 400; text-decoration: rgb(28, 28, 28);"><span style="text-decoration: inherit; display: inline-block; margin-right: 3px; font-family: Nunito, sans-serif; font-size: 14px; font-weight: 400; color: inherit; float: none;" class="currency-converter-amount cbb-price-currency-USD"><span class="cbb-price-symbol" style="padding: 0px 1px; color: inherit; float: none; margin-right: 0px;">$</span><span class="cbb-price-digits" style="padding: 0px 1px; color: inherit; float: none;">18.66</span><span class="cbb-price-code" style="margin-left: 3px; padding: 0px 1px; color: inherit; float: none;">USD</span></span></span></span></p>
|
|
18
|
-
</a>"#;
|
|
19
|
-
|
|
20
|
-
let options = ConversionOptions {
|
|
21
|
-
whitespace_mode: WhitespaceMode::Normalized,
|
|
22
|
-
..Default::default()
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
let result = convert(html, Some(options)).unwrap();
|
|
26
|
-
assert_eq!(result, "[MWD08 - الابيض 70.00 SAR$18.66USD](https://www.google.com)\n");
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
#[test]
|
|
30
|
-
fn link_label_newlines_are_collapsed() {
|
|
31
|
-
let html = r#"<p><a href="https://example.com">line 1
|
|
32
|
-
line 2</a></p>"#;
|
|
33
|
-
|
|
34
|
-
let options = ConversionOptions {
|
|
35
|
-
whitespace_mode: WhitespaceMode::Normalized,
|
|
36
|
-
..Default::default()
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
let result = convert(html, Some(options)).unwrap();
|
|
40
|
-
assert_eq!(result, "[line 1 line 2](https://example.com)\n");
|
|
41
|
-
}
|
|
@@ -1,40 +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_pre_code_fixture() {
|
|
35
|
-
let html = fs::read_to_string(fixture_path("gh-134-pre-code.html")).unwrap();
|
|
36
|
-
let expected = fs::read_to_string(fixture_path("gh-134-pre-code.md")).unwrap();
|
|
37
|
-
|
|
38
|
-
let result = convert(&html, Some(default_options())).unwrap();
|
|
39
|
-
assert_eq!(normalize_newlines(&result), normalize_newlines(&expected));
|
|
40
|
-
}
|
|
@@ -1,26 +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 html_to_markdown_rs::ConversionOptions;
|
|
11
|
-
|
|
12
|
-
#[test]
|
|
13
|
-
fn long_multibyte_link_label_does_not_panic() {
|
|
14
|
-
let mut html = String::from("<a href=\"https://example.com/article\">");
|
|
15
|
-
html.push_str(&"a".repeat(511));
|
|
16
|
-
html.push('👍');
|
|
17
|
-
html.push_str("</a>");
|
|
18
|
-
|
|
19
|
-
let markdown = convert(&html, Some(ConversionOptions::default())).unwrap();
|
|
20
|
-
let expected_label = format!("{}👍", "a".repeat(511));
|
|
21
|
-
|
|
22
|
-
assert!(
|
|
23
|
-
markdown.contains(&format!("[{expected_label}]")),
|
|
24
|
-
"expected full label to appear in markdown output; got: {markdown}"
|
|
25
|
-
);
|
|
26
|
-
}
|
|
@@ -1,185 +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 escape_misc_options() -> ConversionOptions {
|
|
30
|
-
ConversionOptions {
|
|
31
|
-
extract_metadata: false,
|
|
32
|
-
autolinks: false,
|
|
33
|
-
escape_misc: true,
|
|
34
|
-
..Default::default()
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
fn normalize_newlines(input: &str) -> String {
|
|
39
|
-
input.replace("\r\n", "\n").replace('\r', "\n")
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
#[test]
|
|
43
|
-
fn converts_should_not_escape_in_pre_or_code_fixture() {
|
|
44
|
-
let pre_html = r"<pre>This pipe | should not be escaped.<pre/>";
|
|
45
|
-
|
|
46
|
-
let pre_markdown_without_misc = convert(pre_html, Some(default_options())).expect("conversion should succeed");
|
|
47
|
-
assert_eq!(
|
|
48
|
-
pre_markdown_without_misc.trim(),
|
|
49
|
-
"```\nThis pipe | should not be escaped.\n```"
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
let pre_markdown_with_misc = convert(pre_html, Some(escape_misc_options())).expect("conversion should succeed");
|
|
53
|
-
assert_eq!(
|
|
54
|
-
pre_markdown_with_misc.trim(),
|
|
55
|
-
"```\nThis pipe | should not be escaped.\n```"
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
let code_html = r"<code>This pipe | should not be escaped.<code/>";
|
|
59
|
-
|
|
60
|
-
let code_markdown_without_misc = convert(code_html, None).expect("conversion should succeed");
|
|
61
|
-
assert_eq!(
|
|
62
|
-
code_markdown_without_misc.trim(),
|
|
63
|
-
"`This pipe | should not be escaped.`"
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
let code_markdown_with_misc = convert(code_html, Some(escape_misc_options())).expect("conversion should succeed");
|
|
67
|
-
assert_eq!(code_markdown_with_misc.trim(), "`This pipe | should not be escaped.`");
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
#[test]
|
|
71
|
-
fn converts_table_cell_pipe_fixture() {
|
|
72
|
-
let html = fs::read_to_string(fixture_path("gh-140-table-cell-pipe.html")).unwrap();
|
|
73
|
-
let expected_without_misc = fs::read_to_string(fixture_path("gh-140-table-cell-pipe.md")).unwrap();
|
|
74
|
-
let expected_with_misc = fs::read_to_string(fixture_path("gh-140-table-cell-pipe-with-escape-misc.md")).unwrap();
|
|
75
|
-
|
|
76
|
-
let result_without_misc = convert(&html, Some(default_options())).expect("conversion should succeed");
|
|
77
|
-
assert_eq!(
|
|
78
|
-
normalize_newlines(&result_without_misc),
|
|
79
|
-
normalize_newlines(&expected_without_misc)
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
let result_with_misc = convert(&html, Some(escape_misc_options())).expect("conversion should succeed");
|
|
83
|
-
assert_eq!(
|
|
84
|
-
normalize_newlines(&result_with_misc),
|
|
85
|
-
normalize_newlines(&expected_with_misc)
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
#[test]
|
|
90
|
-
fn escapes_only_literal_pipes_in_table_cells() {
|
|
91
|
-
let html = r"
|
|
92
|
-
<table>
|
|
93
|
-
<thead><tr><th>Type</th><th>Span</th><th>Block</th></tr></thead>
|
|
94
|
-
<tbody>
|
|
95
|
-
<tr>
|
|
96
|
-
<td>text | content</td>
|
|
97
|
-
<td><code>code | span</code></td>
|
|
98
|
-
<td><pre>block | content</pre></td>
|
|
99
|
-
</tr>
|
|
100
|
-
</tbody>
|
|
101
|
-
</table>
|
|
102
|
-
";
|
|
103
|
-
|
|
104
|
-
let markdown = convert(html, Some(default_options())).expect("conversion should succeed");
|
|
105
|
-
assert!(
|
|
106
|
-
markdown.contains("text \\| content"),
|
|
107
|
-
"literal pipe in text cell should be escaped"
|
|
108
|
-
);
|
|
109
|
-
assert!(
|
|
110
|
-
markdown.contains("`code | span`"),
|
|
111
|
-
"pipe inside code span should not be escaped"
|
|
112
|
-
);
|
|
113
|
-
assert!(
|
|
114
|
-
!markdown.contains("`code \\| span`"),
|
|
115
|
-
"code spans must not receive backslash escaping"
|
|
116
|
-
);
|
|
117
|
-
assert!(
|
|
118
|
-
markdown.contains("block | content"),
|
|
119
|
-
"pre/code blocks should retain literal pipe characters"
|
|
120
|
-
);
|
|
121
|
-
assert!(
|
|
122
|
-
!markdown.contains("block \\| content"),
|
|
123
|
-
"pre/code block content should not be escaped"
|
|
124
|
-
);
|
|
125
|
-
|
|
126
|
-
let markdown_with_misc = convert(html, Some(escape_misc_options())).expect("conversion should succeed");
|
|
127
|
-
assert!(
|
|
128
|
-
markdown_with_misc.contains("text \\| content"),
|
|
129
|
-
"literal pipe in text cell should be escaped when escape_misc=true"
|
|
130
|
-
);
|
|
131
|
-
assert!(
|
|
132
|
-
markdown_with_misc.contains("`code | span`"),
|
|
133
|
-
"code span pipe should remain unescaped when escape_misc=true"
|
|
134
|
-
);
|
|
135
|
-
assert!(
|
|
136
|
-
!markdown_with_misc.contains("`code \\| span`"),
|
|
137
|
-
"code spans must not be escaped when escape_misc=true"
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
#[test]
|
|
142
|
-
fn nested_tables_do_not_double_escape_pipes() {
|
|
143
|
-
let html = r"
|
|
144
|
-
<table>
|
|
145
|
-
<thead><tr><th>Outer A</th><th>Outer B</th></tr></thead>
|
|
146
|
-
<tbody>
|
|
147
|
-
<tr>
|
|
148
|
-
<td>
|
|
149
|
-
<table>
|
|
150
|
-
<thead><tr><th>Inner A</th><th>Inner B</th></tr></thead>
|
|
151
|
-
<tbody>
|
|
152
|
-
<tr><td>Inner | pipe</td><td>B</td></tr>
|
|
153
|
-
</tbody>
|
|
154
|
-
</table>
|
|
155
|
-
</td>
|
|
156
|
-
<td>Outer | pipe</td>
|
|
157
|
-
</tr>
|
|
158
|
-
</tbody>
|
|
159
|
-
</table>
|
|
160
|
-
";
|
|
161
|
-
|
|
162
|
-
let markdown = convert(html, Some(default_options())).expect("conversion should succeed");
|
|
163
|
-
assert!(
|
|
164
|
-
markdown
|
|
165
|
-
.lines()
|
|
166
|
-
.any(|line| line.contains("Inner A") && line.contains("Inner B")),
|
|
167
|
-
"nested table structure should be preserved: {markdown}"
|
|
168
|
-
);
|
|
169
|
-
assert!(
|
|
170
|
-
markdown.contains("Inner \\| pipe"),
|
|
171
|
-
"literal pipe text inside nested table should be escaped once"
|
|
172
|
-
);
|
|
173
|
-
assert!(
|
|
174
|
-
!markdown.contains("Inner \\\\| pipe"),
|
|
175
|
-
"nested table text should not be double-escaped"
|
|
176
|
-
);
|
|
177
|
-
assert!(
|
|
178
|
-
markdown.contains("Outer \\| pipe"),
|
|
179
|
-
"outer cell literal pipe should be escaped"
|
|
180
|
-
);
|
|
181
|
-
assert!(
|
|
182
|
-
!markdown.contains("Outer \\\\| pipe"),
|
|
183
|
-
"outer cell text should only be escaped once"
|
|
184
|
-
);
|
|
185
|
-
}
|
|
@@ -1,100 +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 options_with_wrap() -> ConversionOptions {
|
|
22
|
-
ConversionOptions {
|
|
23
|
-
wrap: true,
|
|
24
|
-
wrap_width: 80,
|
|
25
|
-
extract_metadata: false,
|
|
26
|
-
autolinks: false,
|
|
27
|
-
..Default::default()
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
fn normalize_newlines(input: &str) -> String {
|
|
32
|
-
input.replace("\r\n", "\n").replace('\r', "\n")
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
#[test]
|
|
36
|
-
fn split_closing_tag_does_not_merge_nested_list() {
|
|
37
|
-
// Regression: tl parser mishandles </tag\n> (closing bracket on next line).
|
|
38
|
-
// The <a> element absorbs the nested <ul> because the closing </a\n> isn't
|
|
39
|
-
// recognised, so all nested items end up inside the link text.
|
|
40
|
-
// Note: the `>` closing the opening <a> and the `>` closing </a are on
|
|
41
|
-
// separate lines (JSX-style formatting). tl must still parse this correctly.
|
|
42
|
-
let html = r##"<ul>
|
|
43
|
-
<li>
|
|
44
|
-
<a href="#beyond"
|
|
45
|
-
>Beyond triads</a
|
|
46
|
-
>
|
|
47
|
-
<ul>
|
|
48
|
-
<li><a href="#c">Child</a></li>
|
|
49
|
-
</ul>
|
|
50
|
-
</li>
|
|
51
|
-
<li>
|
|
52
|
-
<a href="#sibling"
|
|
53
|
-
>Sibling item</a
|
|
54
|
-
>
|
|
55
|
-
<ul>
|
|
56
|
-
<li><a href="#d">Deep child</a></li>
|
|
57
|
-
</ul>
|
|
58
|
-
</li>
|
|
59
|
-
</ul>"##;
|
|
60
|
-
let opts = ConversionOptions {
|
|
61
|
-
wrap: false,
|
|
62
|
-
extract_metadata: false,
|
|
63
|
-
autolinks: false,
|
|
64
|
-
..Default::default()
|
|
65
|
-
};
|
|
66
|
-
let result = convert(html, Some(opts)).expect("conversion should succeed");
|
|
67
|
-
// The nested list items must appear on their own lines, not merged into the
|
|
68
|
-
// parent link text.
|
|
69
|
-
assert!(
|
|
70
|
-
result.contains("Child"),
|
|
71
|
-
"nested item 'Child' should be present: got {result:?}"
|
|
72
|
-
);
|
|
73
|
-
assert!(
|
|
74
|
-
result.contains("Sibling item"),
|
|
75
|
-
"sibling list item should be present: got {result:?}"
|
|
76
|
-
);
|
|
77
|
-
assert!(
|
|
78
|
-
result.contains("Deep child"),
|
|
79
|
-
"deep nested item should be present: got {result:?}"
|
|
80
|
-
);
|
|
81
|
-
// None of the nested items should appear inside the link text of the parent item.
|
|
82
|
-
assert!(
|
|
83
|
-
!result.contains("triads * [") && !result.contains("triads - [Child"),
|
|
84
|
-
"nested items must not be merged into parent link text: got {result:?}"
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
#[test]
|
|
89
|
-
fn wrap_preserves_link_only_list_items() {
|
|
90
|
-
let html = fs::read_to_string(fixture_path("gh-143-links-wordwrap.html")).unwrap();
|
|
91
|
-
let expected = fs::read_to_string(fixture_path("gh-143-links-wordwrap.md")).unwrap();
|
|
92
|
-
|
|
93
|
-
let result = convert(&html, Some(options_with_wrap())).expect("conversion should succeed");
|
|
94
|
-
|
|
95
|
-
assert_eq!(
|
|
96
|
-
normalize_newlines(&result).trim(),
|
|
97
|
-
normalize_newlines(&expected).trim(),
|
|
98
|
-
"word wrapping should not merge nested link-only list items"
|
|
99
|
-
);
|
|
100
|
-
}
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
#![allow(missing_docs)]
|
|
2
|
-
|
|
3
|
-
use html_to_markdown_rs::ConversionOptions;
|
|
4
|
-
|
|
5
|
-
#[test]
|
|
6
|
-
fn test_strip_newlines_preserves_block_spacing() {
|
|
7
|
-
let html = r"<section>
|
|
8
|
-
<h1>Heading</h1>
|
|
9
|
-
<p>Paragraph one.</p>
|
|
10
|
-
<p>Paragraph two.</p>
|
|
11
|
-
</section>";
|
|
12
|
-
|
|
13
|
-
let options = ConversionOptions {
|
|
14
|
-
strip_newlines: true,
|
|
15
|
-
extract_metadata: false,
|
|
16
|
-
..Default::default()
|
|
17
|
-
};
|
|
18
|
-
let result = convert(html, Some(options)).unwrap();
|
|
19
|
-
|
|
20
|
-
let lines: Vec<&str> = result.lines().collect();
|
|
21
|
-
|
|
22
|
-
let mut max_consecutive_blank = 0;
|
|
23
|
-
let mut current_blank_count = 0;
|
|
24
|
-
for line in &lines {
|
|
25
|
-
if line.trim().is_empty() {
|
|
26
|
-
current_blank_count += 1;
|
|
27
|
-
max_consecutive_blank = max_consecutive_blank.max(current_blank_count);
|
|
28
|
-
} else {
|
|
29
|
-
current_blank_count = 0;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
assert!(
|
|
34
|
-
max_consecutive_blank <= 1,
|
|
35
|
-
"excessive blank lines detected: {max_consecutive_blank} consecutive blanks in:\n{result}"
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
assert!(result.contains("Heading"), "heading missing from: {result}");
|
|
39
|
-
assert!(result.contains("Paragraph one"), "paragraph one missing from: {result}");
|
|
40
|
-
assert!(result.contains("Paragraph two"), "paragraph two missing from: {result}");
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
#[test]
|
|
44
|
-
fn test_strip_newlines_removes_inline_newlines() {
|
|
45
|
-
let html = r"<p>This is a paragraph
|
|
46
|
-
with line breaks
|
|
47
|
-
in the middle</p>";
|
|
48
|
-
|
|
49
|
-
let options = ConversionOptions {
|
|
50
|
-
strip_newlines: true,
|
|
51
|
-
extract_metadata: false,
|
|
52
|
-
..Default::default()
|
|
53
|
-
};
|
|
54
|
-
let result = convert(html, Some(options)).unwrap();
|
|
55
|
-
|
|
56
|
-
let text = result.trim();
|
|
57
|
-
|
|
58
|
-
let content_lines: Vec<&str> = text.lines().collect();
|
|
59
|
-
|
|
60
|
-
let has_paragraph_line = content_lines.iter().any(|line| {
|
|
61
|
-
let trimmed = line.trim();
|
|
62
|
-
trimmed.contains("This is a paragraph")
|
|
63
|
-
&& trimmed.contains("with line breaks")
|
|
64
|
-
&& trimmed.contains("in the middle")
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
assert!(
|
|
68
|
-
has_paragraph_line,
|
|
69
|
-
"paragraph should have inline newlines converted to spaces in: {result}"
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
#[test]
|
|
74
|
-
fn test_strip_newlines_handles_nested_blocks() {
|
|
75
|
-
let html = r"<section>
|
|
76
|
-
<div>
|
|
77
|
-
<h2>Nested Heading</h2>
|
|
78
|
-
<p>Content inside nested div.</p>
|
|
79
|
-
</div>
|
|
80
|
-
<div>
|
|
81
|
-
<h2>Another Section</h2>
|
|
82
|
-
<p>More content here.</p>
|
|
83
|
-
</div>
|
|
84
|
-
</section>";
|
|
85
|
-
|
|
86
|
-
let options = ConversionOptions {
|
|
87
|
-
strip_newlines: true,
|
|
88
|
-
extract_metadata: false,
|
|
89
|
-
..Default::default()
|
|
90
|
-
};
|
|
91
|
-
let result = convert(html, Some(options)).unwrap();
|
|
92
|
-
|
|
93
|
-
assert!(
|
|
94
|
-
result.contains("Nested Heading"),
|
|
95
|
-
"nested heading missing from: {result}"
|
|
96
|
-
);
|
|
97
|
-
assert!(
|
|
98
|
-
result.contains("Content inside nested div"),
|
|
99
|
-
"nested content missing from: {result}"
|
|
100
|
-
);
|
|
101
|
-
assert!(
|
|
102
|
-
result.contains("Another Section"),
|
|
103
|
-
"another section heading missing from: {result}"
|
|
104
|
-
);
|
|
105
|
-
assert!(
|
|
106
|
-
result.contains("More content here"),
|
|
107
|
-
"more content missing from: {result}"
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
let lines: Vec<&str> = result.lines().collect();
|
|
111
|
-
let mut max_consecutive_blank = 0;
|
|
112
|
-
let mut current_blank_count = 0;
|
|
113
|
-
for line in &lines {
|
|
114
|
-
if line.trim().is_empty() {
|
|
115
|
-
current_blank_count += 1;
|
|
116
|
-
max_consecutive_blank = max_consecutive_blank.max(current_blank_count);
|
|
117
|
-
} else {
|
|
118
|
-
current_blank_count = 0;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
assert!(
|
|
123
|
-
max_consecutive_blank <= 1,
|
|
124
|
-
"excessive blank lines in nested blocks: {max_consecutive_blank} consecutive blanks in:\n{result}"
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
fn convert(
|
|
129
|
-
html: &str,
|
|
130
|
-
opts: Option<html_to_markdown_rs::ConversionOptions>,
|
|
131
|
-
) -> html_to_markdown_rs::error::Result<String> {
|
|
132
|
-
html_to_markdown_rs::convert(html, opts).map(|r| r.content.unwrap_or_default())
|
|
133
|
-
}
|