html-to-markdown 3.4.0 → 3.6.0.pre.rc.23

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.
Files changed (188) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +21 -0
  3. data/README.md +347 -0
  4. data/Steepfile +10 -2
  5. data/ext/html_to_markdown_rb/Cargo.toml +3 -2
  6. data/ext/html_to_markdown_rb/extconf.rb +5 -5
  7. data/ext/html_to_markdown_rb/native/Cargo.lock +962 -0
  8. data/ext/html_to_markdown_rb/native/Cargo.toml +6 -11
  9. data/ext/html_to_markdown_rb/native/extconf.rb +14 -0
  10. data/ext/html_to_markdown_rb/src/lib.rs +1715 -646
  11. data/lib/html_to_markdown/native.rb +913 -37
  12. data/lib/html_to_markdown/version.rb +3 -3
  13. data/lib/html_to_markdown.rb +9 -4
  14. data/lib/html_to_markdown_rb.so +0 -0
  15. data/sig/types.rbs +59 -292
  16. metadata +32 -179
  17. data/ext/html_to_markdown_rb/Makefile +0 -592
  18. data/lib/bin/html-to-markdown +0 -0
  19. data/vendor/Cargo.toml +0 -33
  20. data/vendor/html-to-markdown-rs/Cargo.toml +0 -54
  21. data/vendor/html-to-markdown-rs/README.md +0 -278
  22. data/vendor/html-to-markdown-rs/examples/basic.rs +0 -24
  23. data/vendor/html-to-markdown-rs/examples/table.rs +0 -25
  24. data/vendor/html-to-markdown-rs/examples/test_deser.rs +0 -12
  25. data/vendor/html-to-markdown-rs/examples/test_escape.rs +0 -58
  26. data/vendor/html-to-markdown-rs/examples/test_inline_formatting.rs +0 -113
  27. data/vendor/html-to-markdown-rs/examples/test_lists.rs +0 -39
  28. data/vendor/html-to-markdown-rs/examples/test_semantic_tags.rs +0 -89
  29. data/vendor/html-to-markdown-rs/examples/test_tables.rs +0 -100
  30. data/vendor/html-to-markdown-rs/examples/test_task_lists.rs +0 -61
  31. data/vendor/html-to-markdown-rs/examples/test_whitespace.rs +0 -34
  32. data/vendor/html-to-markdown-rs/src/convert_api.rs +0 -349
  33. data/vendor/html-to-markdown-rs/src/converter/block/blockquote.rs +0 -178
  34. data/vendor/html-to-markdown-rs/src/converter/block/container.rs +0 -114
  35. data/vendor/html-to-markdown-rs/src/converter/block/div.rs +0 -149
  36. data/vendor/html-to-markdown-rs/src/converter/block/heading.rs +0 -428
  37. data/vendor/html-to-markdown-rs/src/converter/block/horizontal_rule.rs +0 -103
  38. data/vendor/html-to-markdown-rs/src/converter/block/line_break.rs +0 -89
  39. data/vendor/html-to-markdown-rs/src/converter/block/mod.rs +0 -10
  40. data/vendor/html-to-markdown-rs/src/converter/block/paragraph.rs +0 -140
  41. data/vendor/html-to-markdown-rs/src/converter/block/preformatted.rs +0 -298
  42. data/vendor/html-to-markdown-rs/src/converter/block/table/builder.rs +0 -453
  43. data/vendor/html-to-markdown-rs/src/converter/block/table/caption.rs +0 -44
  44. data/vendor/html-to-markdown-rs/src/converter/block/table/cell.rs +0 -276
  45. data/vendor/html-to-markdown-rs/src/converter/block/table/cells.rs +0 -336
  46. data/vendor/html-to-markdown-rs/src/converter/block/table/layout.rs +0 -58
  47. data/vendor/html-to-markdown-rs/src/converter/block/table/mod.rs +0 -266
  48. data/vendor/html-to-markdown-rs/src/converter/block/table/scanner.rs +0 -146
  49. data/vendor/html-to-markdown-rs/src/converter/block/table/utils.rs +0 -34
  50. data/vendor/html-to-markdown-rs/src/converter/block/unknown.rs +0 -138
  51. data/vendor/html-to-markdown-rs/src/converter/context.rs +0 -208
  52. data/vendor/html-to-markdown-rs/src/converter/dom_context.rs +0 -337
  53. data/vendor/html-to-markdown-rs/src/converter/form/elements.rs +0 -770
  54. data/vendor/html-to-markdown-rs/src/converter/form/mod.rs +0 -82
  55. data/vendor/html-to-markdown-rs/src/converter/format/djot.rs +0 -64
  56. data/vendor/html-to-markdown-rs/src/converter/format/markdown.rs +0 -59
  57. data/vendor/html-to-markdown-rs/src/converter/format/mod.rs +0 -43
  58. data/vendor/html-to-markdown-rs/src/converter/handlers/blockquote.rs +0 -173
  59. data/vendor/html-to-markdown-rs/src/converter/handlers/code_block.rs +0 -434
  60. data/vendor/html-to-markdown-rs/src/converter/handlers/graphic.rs +0 -234
  61. data/vendor/html-to-markdown-rs/src/converter/handlers/image.rs +0 -282
  62. data/vendor/html-to-markdown-rs/src/converter/handlers/link.rs +0 -316
  63. data/vendor/html-to-markdown-rs/src/converter/handlers/mod.rs +0 -26
  64. data/vendor/html-to-markdown-rs/src/converter/inline/code.rs +0 -306
  65. data/vendor/html-to-markdown-rs/src/converter/inline/emphasis.rs +0 -345
  66. data/vendor/html-to-markdown-rs/src/converter/inline/link.rs +0 -428
  67. data/vendor/html-to-markdown-rs/src/converter/inline/mod.rs +0 -237
  68. data/vendor/html-to-markdown-rs/src/converter/inline/ruby.rs +0 -337
  69. data/vendor/html-to-markdown-rs/src/converter/inline/semantic/marks.rs +0 -566
  70. data/vendor/html-to-markdown-rs/src/converter/inline/semantic/mod.rs +0 -86
  71. data/vendor/html-to-markdown-rs/src/converter/inline/semantic/typography.rs +0 -558
  72. data/vendor/html-to-markdown-rs/src/converter/list/definition.rs +0 -232
  73. data/vendor/html-to-markdown-rs/src/converter/list/item.rs +0 -332
  74. data/vendor/html-to-markdown-rs/src/converter/list/mod.rs +0 -70
  75. data/vendor/html-to-markdown-rs/src/converter/list/ordered.rs +0 -201
  76. data/vendor/html-to-markdown-rs/src/converter/list/unordered.rs +0 -195
  77. data/vendor/html-to-markdown-rs/src/converter/list/utils.rs +0 -314
  78. data/vendor/html-to-markdown-rs/src/converter/main.rs +0 -710
  79. data/vendor/html-to-markdown-rs/src/converter/main_helpers.rs +0 -452
  80. data/vendor/html-to-markdown-rs/src/converter/media/embedded.rs +0 -393
  81. data/vendor/html-to-markdown-rs/src/converter/media/graphic.rs +0 -4
  82. data/vendor/html-to-markdown-rs/src/converter/media/image.rs +0 -183
  83. data/vendor/html-to-markdown-rs/src/converter/media/mod.rs +0 -87
  84. data/vendor/html-to-markdown-rs/src/converter/media/svg.rs +0 -280
  85. data/vendor/html-to-markdown-rs/src/converter/metadata.rs +0 -220
  86. data/vendor/html-to-markdown-rs/src/converter/mod.rs +0 -156
  87. data/vendor/html-to-markdown-rs/src/converter/plain_text.rs +0 -516
  88. data/vendor/html-to-markdown-rs/src/converter/preprocessing_helpers.rs +0 -201
  89. data/vendor/html-to-markdown-rs/src/converter/reference_collector.rs +0 -69
  90. data/vendor/html-to-markdown-rs/src/converter/semantic/attributes.rs +0 -269
  91. data/vendor/html-to-markdown-rs/src/converter/semantic/definition_list.rs +0 -266
  92. data/vendor/html-to-markdown-rs/src/converter/semantic/figure.rs +0 -391
  93. data/vendor/html-to-markdown-rs/src/converter/semantic/mod.rs +0 -112
  94. data/vendor/html-to-markdown-rs/src/converter/semantic/sectioning.rs +0 -85
  95. data/vendor/html-to-markdown-rs/src/converter/semantic/summary.rs +0 -324
  96. data/vendor/html-to-markdown-rs/src/converter/text/mod.rs +0 -8
  97. data/vendor/html-to-markdown-rs/src/converter/text/processing.rs +0 -56
  98. data/vendor/html-to-markdown-rs/src/converter/text_node.rs +0 -269
  99. data/vendor/html-to-markdown-rs/src/converter/utility/attributes.rs +0 -151
  100. data/vendor/html-to-markdown-rs/src/converter/utility/caching.rs +0 -74
  101. data/vendor/html-to-markdown-rs/src/converter/utility/content.rs +0 -271
  102. data/vendor/html-to-markdown-rs/src/converter/utility/mod.rs +0 -17
  103. data/vendor/html-to-markdown-rs/src/converter/utility/preprocessing.rs +0 -1002
  104. data/vendor/html-to-markdown-rs/src/converter/utility/serialization.rs +0 -126
  105. data/vendor/html-to-markdown-rs/src/converter/utility/siblings.rs +0 -97
  106. data/vendor/html-to-markdown-rs/src/converter/visitor_hooks.rs +0 -189
  107. data/vendor/html-to-markdown-rs/src/error.rs +0 -43
  108. data/vendor/html-to-markdown-rs/src/exports.rs +0 -24
  109. data/vendor/html-to-markdown-rs/src/inline_images.rs +0 -336
  110. data/vendor/html-to-markdown-rs/src/lib.rs +0 -139
  111. data/vendor/html-to-markdown-rs/src/metadata/collector.rs +0 -457
  112. data/vendor/html-to-markdown-rs/src/metadata/config.rs +0 -394
  113. data/vendor/html-to-markdown-rs/src/metadata/extraction.rs +0 -398
  114. data/vendor/html-to-markdown-rs/src/metadata/mod.rs +0 -288
  115. data/vendor/html-to-markdown-rs/src/metadata/types.rs +0 -477
  116. data/vendor/html-to-markdown-rs/src/options/conversion.rs +0 -559
  117. data/vendor/html-to-markdown-rs/src/options/inline_image.rs +0 -111
  118. data/vendor/html-to-markdown-rs/src/options/mod.rs +0 -20
  119. data/vendor/html-to-markdown-rs/src/options/preprocessing.rs +0 -201
  120. data/vendor/html-to-markdown-rs/src/options/validation.rs +0 -416
  121. data/vendor/html-to-markdown-rs/src/prelude.rs +0 -1
  122. data/vendor/html-to-markdown-rs/src/rcdom.rs +0 -487
  123. data/vendor/html-to-markdown-rs/src/text.rs +0 -358
  124. data/vendor/html-to-markdown-rs/src/types/document.rs +0 -191
  125. data/vendor/html-to-markdown-rs/src/types/mod.rs +0 -17
  126. data/vendor/html-to-markdown-rs/src/types/result.rs +0 -54
  127. data/vendor/html-to-markdown-rs/src/types/structure_builder.rs +0 -791
  128. data/vendor/html-to-markdown-rs/src/types/structure_collector.rs +0 -483
  129. data/vendor/html-to-markdown-rs/src/types/tables.rs +0 -52
  130. data/vendor/html-to-markdown-rs/src/types/warnings.rs +0 -33
  131. data/vendor/html-to-markdown-rs/src/validation.rs +0 -158
  132. data/vendor/html-to-markdown-rs/src/visitor/default_impl.rs +0 -63
  133. data/vendor/html-to-markdown-rs/src/visitor/mod.rs +0 -41
  134. data/vendor/html-to-markdown-rs/src/visitor/traits.rs +0 -370
  135. data/vendor/html-to-markdown-rs/src/visitor/types.rs +0 -319
  136. data/vendor/html-to-markdown-rs/src/visitor_helpers/helpers/callbacks/mod.rs +0 -1
  137. data/vendor/html-to-markdown-rs/src/visitor_helpers/helpers/content.rs +0 -126
  138. data/vendor/html-to-markdown-rs/src/visitor_helpers/helpers/mod.rs +0 -27
  139. data/vendor/html-to-markdown-rs/src/visitor_helpers/helpers/state.rs +0 -110
  140. data/vendor/html-to-markdown-rs/src/visitor_helpers/helpers/traversal.rs +0 -250
  141. data/vendor/html-to-markdown-rs/src/visitor_helpers.rs +0 -597
  142. data/vendor/html-to-markdown-rs/src/wrapper/sync.rs +0 -413
  143. data/vendor/html-to-markdown-rs/src/wrapper/utils.rs +0 -290
  144. data/vendor/html-to-markdown-rs/src/wrapper.rs +0 -9
  145. data/vendor/html-to-markdown-rs/tests/br_in_inline_test.rs +0 -87
  146. data/vendor/html-to-markdown-rs/tests/commonmark_compliance_test.rs +0 -297
  147. data/vendor/html-to-markdown-rs/tests/djot_output_test.rs +0 -153
  148. data/vendor/html-to-markdown-rs/tests/exclude_selectors_test.rs +0 -132
  149. data/vendor/html-to-markdown-rs/tests/integration_test.rs +0 -631
  150. data/vendor/html-to-markdown-rs/tests/issue_121_regressions.rs +0 -49
  151. data/vendor/html-to-markdown-rs/tests/issue_127_regressions.rs +0 -58
  152. data/vendor/html-to-markdown-rs/tests/issue_128_regressions.rs +0 -17
  153. data/vendor/html-to-markdown-rs/tests/issue_131_regressions.rs +0 -41
  154. data/vendor/html-to-markdown-rs/tests/issue_134_regressions.rs +0 -40
  155. data/vendor/html-to-markdown-rs/tests/issue_139_regressions.rs +0 -26
  156. data/vendor/html-to-markdown-rs/tests/issue_140_regressions.rs +0 -185
  157. data/vendor/html-to-markdown-rs/tests/issue_143_regressions.rs +0 -100
  158. data/vendor/html-to-markdown-rs/tests/issue_145_regressions.rs +0 -133
  159. data/vendor/html-to-markdown-rs/tests/issue_146_regressions.rs +0 -144
  160. data/vendor/html-to-markdown-rs/tests/issue_176_regressions.rs +0 -62
  161. data/vendor/html-to-markdown-rs/tests/issue_190_regressions.rs +0 -128
  162. data/vendor/html-to-markdown-rs/tests/issue_199_regressions.rs +0 -20
  163. data/vendor/html-to-markdown-rs/tests/issue_200_regressions.rs +0 -62
  164. data/vendor/html-to-markdown-rs/tests/issue_212_regressions.rs +0 -68
  165. data/vendor/html-to-markdown-rs/tests/issue_216_217_regressions.rs +0 -87
  166. data/vendor/html-to-markdown-rs/tests/issue_336_regressions.rs +0 -74
  167. data/vendor/html-to-markdown-rs/tests/issue_339_regressions.rs +0 -92
  168. data/vendor/html-to-markdown-rs/tests/issue_347_regressions.rs +0 -154
  169. data/vendor/html-to-markdown-rs/tests/issue_348_visitor_plain.rs +0 -93
  170. data/vendor/html-to-markdown-rs/tests/json_ld_script_extraction.rs +0 -44
  171. data/vendor/html-to-markdown-rs/tests/lists_test.rs +0 -199
  172. data/vendor/html-to-markdown-rs/tests/plain_output_test.rs +0 -273
  173. data/vendor/html-to-markdown-rs/tests/preprocessing_tests.rs +0 -61
  174. data/vendor/html-to-markdown-rs/tests/reference_links_test.rs +0 -169
  175. data/vendor/html-to-markdown-rs/tests/sectioning_elements_test.rs +0 -137
  176. data/vendor/html-to-markdown-rs/tests/skip_images_test.rs +0 -522
  177. data/vendor/html-to-markdown-rs/tests/tables_test.rs +0 -743
  178. data/vendor/html-to-markdown-rs/tests/test_custom_elements.rs +0 -41
  179. data/vendor/html-to-markdown-rs/tests/test_issue_187.rs +0 -204
  180. data/vendor/html-to-markdown-rs/tests/test_issue_218.rs +0 -68
  181. data/vendor/html-to-markdown-rs/tests/test_issue_277.rs +0 -77
  182. data/vendor/html-to-markdown-rs/tests/test_max_depth.rs +0 -82
  183. data/vendor/html-to-markdown-rs/tests/test_nested_simple.rs +0 -45
  184. data/vendor/html-to-markdown-rs/tests/test_script_style_stripping.rs +0 -396
  185. data/vendor/html-to-markdown-rs/tests/test_spa_bisect.rs +0 -34
  186. data/vendor/html-to-markdown-rs/tests/visitor_code_integration_test.rs +0 -121
  187. data/vendor/html-to-markdown-rs/tests/visitor_integration_test.rs +0 -1190
  188. data/vendor/html-to-markdown-rs/tests/xml_tables_test.rs +0 -372
@@ -1,126 +0,0 @@
1
- //! Output serialization and formatting.
2
- //!
3
- //! Utilities for serializing HTML elements back to string format, used for preserving
4
- //! original HTML for elements like SVG, math, and custom elements.
5
-
6
- use crate::converter::utility::content::normalized_tag_name;
7
-
8
- /// Serialize an element to HTML string (for SVG and Math elements).
9
- #[allow(clippy::trivially_copy_pass_by_ref)]
10
- #[allow(dead_code)] // used with visitor feature
11
- pub fn serialize_element(node_handle: &tl::NodeHandle, parser: &tl::Parser) -> String {
12
- if let Some(tl::Node::Tag(tag)) = node_handle.get(parser) {
13
- let tag_name = normalized_tag_name(tag.name().as_utf8_str());
14
- let mut html = String::with_capacity(256);
15
- html.push('<');
16
- html.push_str(&tag_name);
17
-
18
- for (key, value_opt) in tag.attributes().iter() {
19
- html.push(' ');
20
- html.push_str(&key);
21
- if let Some(value) = value_opt {
22
- html.push_str("=\"");
23
- html.push_str(&value);
24
- html.push('"');
25
- }
26
- }
27
-
28
- let has_children = !tag.children().top().is_empty();
29
- if has_children {
30
- html.push('>');
31
- let children = tag.children();
32
- {
33
- for child_handle in children.top().iter() {
34
- html.push_str(&serialize_node(child_handle, parser));
35
- }
36
- }
37
- html.push_str("</");
38
- html.push_str(&tag_name);
39
- html.push('>');
40
- } else {
41
- html.push_str(" />");
42
- }
43
- return html;
44
- }
45
- String::new()
46
- }
47
-
48
- /// Serialize a node to HTML string.
49
- #[allow(clippy::trivially_copy_pass_by_ref)]
50
- #[allow(dead_code)] // used with visitor feature
51
- pub fn serialize_node(node_handle: &tl::NodeHandle, parser: &tl::Parser) -> String {
52
- if let Some(node) = node_handle.get(parser) {
53
- match node {
54
- tl::Node::Raw(bytes) => bytes.as_utf8_str().to_string(),
55
- tl::Node::Tag(_) => serialize_element(node_handle, parser),
56
- _ => String::new(),
57
- }
58
- } else {
59
- String::new()
60
- }
61
- }
62
-
63
- /// Serialize a tag to HTML, wrapping serialize_node_to_html.
64
- pub fn serialize_tag_to_html(handle: &tl::NodeHandle, parser: &tl::Parser) -> String {
65
- let mut html = String::new();
66
- serialize_node_to_html(handle, parser, &mut html);
67
- html
68
- }
69
-
70
- /// Recursively serialize a node to HTML.
71
- #[allow(clippy::trivially_copy_pass_by_ref)]
72
- #[allow(dead_code)] // used with visitor feature
73
- pub fn serialize_node_to_html(handle: &tl::NodeHandle, parser: &tl::Parser, output: &mut String) {
74
- match handle.get(parser) {
75
- Some(tl::Node::Tag(tag)) => {
76
- let tag_name = normalized_tag_name(tag.name().as_utf8_str());
77
-
78
- output.push('<');
79
- output.push_str(&tag_name);
80
-
81
- for (key, value) in tag.attributes().iter() {
82
- output.push(' ');
83
- output.push_str(&key);
84
- if let Some(val) = value {
85
- output.push_str("=\"");
86
- output.push_str(&val);
87
- output.push('"');
88
- }
89
- }
90
-
91
- output.push('>');
92
-
93
- let children = tag.children();
94
- for child_handle in children.top().iter() {
95
- serialize_node_to_html(child_handle, parser, output);
96
- }
97
-
98
- if !matches!(
99
- tag_name.as_ref(),
100
- "br" | "hr"
101
- | "img"
102
- | "input"
103
- | "meta"
104
- | "link"
105
- | "area"
106
- | "base"
107
- | "col"
108
- | "embed"
109
- | "param"
110
- | "source"
111
- | "track"
112
- | "wbr"
113
- ) {
114
- output.push_str("</");
115
- output.push_str(&tag_name);
116
- output.push('>');
117
- }
118
- }
119
- Some(tl::Node::Raw(bytes)) => {
120
- if let Ok(text) = std::str::from_utf8(bytes.as_bytes()) {
121
- output.push_str(text);
122
- }
123
- }
124
- _ => {}
125
- }
126
- }
@@ -1,97 +0,0 @@
1
- //! Sibling node navigation and handling.
2
- //!
3
- //! Utilities for working with sibling nodes in the DOM tree, including navigation functions
4
- //! and inline/block element detection for whitespace handling.
5
-
6
- use crate::converter::DomContext;
7
-
8
- /// Get the tag name of the next sibling element.
9
- #[allow(clippy::trivially_copy_pass_by_ref)]
10
- pub fn get_next_sibling_tag<'a>(
11
- node_handle: &tl::NodeHandle,
12
- parser: &'a tl::Parser,
13
- dom_ctx: &'a DomContext,
14
- ) -> Option<&'a str> {
15
- dom_ctx.next_tag_name(*node_handle, parser)
16
- }
17
-
18
- /// Get the tag name of the previous sibling element.
19
- #[allow(clippy::trivially_copy_pass_by_ref)]
20
- pub fn get_previous_sibling_tag<'a>(
21
- node_handle: &tl::NodeHandle,
22
- parser: &tl::Parser,
23
- dom_ctx: &'a DomContext,
24
- ) -> Option<&'a str> {
25
- let id = node_handle.get_inner();
26
- let parent = dom_ctx.parent_of(id);
27
-
28
- let siblings = if let Some(parent_id) = parent {
29
- dom_ctx.children_of(parent_id)?
30
- } else {
31
- &dom_ctx.root_children
32
- };
33
-
34
- let position = dom_ctx.sibling_index(id).or_else(|| {
35
- siblings
36
- .iter()
37
- .position(|handle: &tl::NodeHandle| handle.get_inner() == id)
38
- })?;
39
-
40
- for sibling in siblings.iter().take(position).rev() {
41
- if let Some(info) = dom_ctx.tag_info(sibling.get_inner(), parser) {
42
- return Some(info.name.as_str());
43
- }
44
- if let Some(tl::Node::Raw(raw)) = sibling.get(parser) {
45
- if !raw.as_utf8_str().trim().is_empty() {
46
- return None;
47
- }
48
- }
49
- }
50
-
51
- None
52
- }
53
-
54
- /// Check if the previous sibling is an inline tag.
55
- #[allow(clippy::trivially_copy_pass_by_ref)]
56
- pub fn previous_sibling_is_inline_tag(node_handle: &tl::NodeHandle, parser: &tl::Parser, dom_ctx: &DomContext) -> bool {
57
- dom_ctx.previous_inline_like(*node_handle, parser)
58
- }
59
-
60
- /// Check if the next sibling is whitespace-only text.
61
- #[allow(clippy::trivially_copy_pass_by_ref)]
62
- pub fn next_sibling_is_whitespace_text(
63
- node_handle: &tl::NodeHandle,
64
- parser: &tl::Parser,
65
- dom_ctx: &DomContext,
66
- ) -> bool {
67
- dom_ctx.next_whitespace_text(*node_handle, parser)
68
- }
69
-
70
- /// Check if the next sibling is an inline tag.
71
- #[allow(clippy::trivially_copy_pass_by_ref)]
72
- pub fn next_sibling_is_inline_tag(node_handle: &tl::NodeHandle, parser: &tl::Parser, dom_ctx: &DomContext) -> bool {
73
- dom_ctx.next_inline_like(*node_handle, parser)
74
- }
75
-
76
- /// Append an inline suffix to output, with smart whitespace handling.
77
- ///
78
- /// Avoids adding spaces before siblings that are already whitespace.
79
- #[allow(clippy::trivially_copy_pass_by_ref)]
80
- pub fn append_inline_suffix(
81
- output: &mut String,
82
- suffix: &str,
83
- has_core_content: bool,
84
- node_handle: &tl::NodeHandle,
85
- parser: &tl::Parser,
86
- dom_ctx: &DomContext,
87
- ) {
88
- if suffix.is_empty() {
89
- return;
90
- }
91
-
92
- if suffix == " " && has_core_content && next_sibling_is_whitespace_text(node_handle, parser, dom_ctx) {
93
- return;
94
- }
95
-
96
- output.push_str(suffix);
97
- }
@@ -1,189 +0,0 @@
1
- //! Visitor callback hooks for custom HTML traversal during conversion.
2
- //!
3
- //! This module contains the visitor pattern implementation hooks that are called
4
- //! before and after element processing during the HTML to Markdown conversion tree walk.
5
- //! These hooks enable custom processing, analysis, or modification of elements during conversion.
6
-
7
- use std::collections::BTreeMap;
8
-
9
- #[cfg(feature = "visitor")]
10
- use crate::converter::utility::content::collect_tag_attributes;
11
- use crate::converter::utility::content::is_block_level_element;
12
- use crate::visitor::{NodeContext, NodeType, VisitResult};
13
-
14
- /// Handles visitor callback for element start (before processing).
15
- ///
16
- /// This function is called when entering an element during tree traversal,
17
- /// before the element's content is processed. The visitor can:
18
- /// - Continue with normal processing (Continue)
19
- /// - Skip the element entirely (Skip)
20
- /// - Provide custom output to replace the element (Custom)
21
- /// - Signal an error (Error)
22
- ///
23
- /// # Arguments
24
- ///
25
- /// * `visitor_handle` - Reference to the visitor for callbacks
26
- /// * `tag_name` - The normalized tag name being processed
27
- /// * `node_handle` - Handle to the DOM node
28
- /// * `tag` - Reference to the tag object
29
- /// * `parser` - Reference to the tl parser
30
- /// * `output` - Mutable reference to output string
31
- /// * `ctx` - Reference to the conversion context
32
- /// * `depth` - Current tree depth
33
- /// * `dom_ctx` - Reference to DOM context for tree navigation
34
- ///
35
- /// # Returns
36
- ///
37
- /// `VisitAction` enum indicating what should happen next:
38
- /// - `VisitAction::Continue` - Process element normally
39
- /// - `VisitAction::Skip` - Skip element, don't process or call visit_element_end
40
- /// - `VisitAction::Custom(output)` - Use custom output, skip normal processing
41
- /// - `VisitAction::Error` - Stop processing with error
42
- pub fn handle_visitor_element_start(
43
- visitor_handle: &crate::visitor::VisitorHandle,
44
- tag_name: &str,
45
- node_handle: &tl::NodeHandle,
46
- tag: &tl::HTMLTag,
47
- parser: &tl::Parser<'_>,
48
- output: &mut String,
49
- _ctx: &crate::converter::Context,
50
- depth: usize,
51
- dom_ctx: &crate::converter::DomContext,
52
- ) -> VisitAction {
53
- let attributes: BTreeMap<String, String> = collect_tag_attributes(tag);
54
-
55
- let node_id = node_handle.get_inner();
56
- let parent_tag = dom_ctx.parent_tag_name(node_id, parser);
57
- let index_in_parent = dom_ctx.get_sibling_index(node_id).unwrap_or(0);
58
-
59
- let node_ctx = NodeContext {
60
- node_type: NodeType::Element,
61
- tag_name: tag_name.to_string(),
62
- attributes,
63
- depth,
64
- index_in_parent,
65
- parent_tag,
66
- is_inline: !is_block_level_element(tag_name),
67
- };
68
-
69
- let visitor_start_result = {
70
- let mut visitor = visitor_handle.borrow_mut();
71
- visitor.visit_element_start(&node_ctx)
72
- };
73
-
74
- match visitor_start_result {
75
- crate::visitor::VisitResult::Continue => VisitAction::Continue,
76
- crate::visitor::VisitResult::Skip => VisitAction::Skip,
77
- crate::visitor::VisitResult::Custom(custom_output) => {
78
- output.push_str(&custom_output);
79
-
80
- // For custom output, still call visit_element_end (except for tables)
81
- if !matches!(tag_name, "table") {
82
- let element_content = &custom_output;
83
- let mut visitor = visitor_handle.borrow_mut();
84
- let _ = visitor.visit_element_end(&node_ctx, element_content);
85
- }
86
-
87
- VisitAction::Custom
88
- }
89
- crate::visitor::VisitResult::Error(_msg) => VisitAction::Error,
90
- _ => VisitAction::Continue,
91
- }
92
- }
93
-
94
- /// Handles visitor callback for element end (after processing).
95
- ///
96
- /// This function is called when exiting an element after its content has been processed.
97
- /// The visitor can:
98
- /// - Accept the output normally (Continue)
99
- /// - Replace the output with custom content (Custom)
100
- /// - Remove the output entirely (Skip)
101
- /// - Signal an error (Error)
102
- ///
103
- /// # Arguments
104
- ///
105
- /// * `visitor_handle` - Reference to the visitor for callbacks
106
- /// * `tag_name` - The normalized tag name that was processed
107
- /// * `node_handle` - Handle to the DOM node
108
- /// * `tag` - Reference to the tag object
109
- /// * `parser` - Reference to the tl parser
110
- /// * `output` - Mutable reference to output string
111
- /// * `element_output_start` - Byte position where this element's output started
112
- /// * `ctx` - Reference to the conversion context
113
- /// * `depth` - Current tree depth
114
- /// * `dom_ctx` - Reference to DOM context for tree navigation
115
- pub fn handle_visitor_element_end(
116
- visitor_handle: &crate::visitor::VisitorHandle,
117
- tag_name: &str,
118
- node_handle: &tl::NodeHandle,
119
- tag: &tl::HTMLTag,
120
- parser: &tl::Parser<'_>,
121
- output: &mut String,
122
- element_output_start: usize,
123
- ctx: &crate::converter::Context,
124
- depth: usize,
125
- dom_ctx: &crate::converter::DomContext,
126
- ) {
127
- // Skip visitor callback for table elements
128
- if matches!(tag_name, "table") {
129
- return;
130
- }
131
-
132
- let attributes: BTreeMap<String, String> = collect_tag_attributes(tag);
133
-
134
- let node_id = node_handle.get_inner();
135
- let parent_tag = dom_ctx.parent_tag_name(node_id, parser);
136
- let index_in_parent = dom_ctx.get_sibling_index(node_id).unwrap_or(0);
137
-
138
- let node_ctx = NodeContext {
139
- node_type: NodeType::Element,
140
- tag_name: tag_name.to_string(),
141
- attributes,
142
- depth,
143
- index_in_parent,
144
- parent_tag,
145
- is_inline: !is_block_level_element(tag_name),
146
- };
147
-
148
- // The saved `element_output_start` can become stale in two ways:
149
- // 1. A child visitor returning Custom/Skip truncates `output`, making the
150
- // saved position point past the end of the now-shorter string.
151
- // 2. Element handlers (e.g. div) trim trailing whitespace that was present
152
- // when the position was captured, then append new multi-byte content.
153
- // The old position can land inside a multi-byte character.
154
- // Clamp to output length, then retreat to a valid char boundary.
155
- let safe_start = element_output_start.min(output.len());
156
- let safe_start = crate::converter::utility::content::floor_char_boundary(output, safe_start);
157
- let element_content = &output[safe_start..];
158
-
159
- let mut visitor = visitor_handle.borrow_mut();
160
- match visitor.visit_element_end(&node_ctx, element_content) {
161
- VisitResult::Continue => {}
162
- VisitResult::Custom(custom) => {
163
- output.truncate(safe_start);
164
- output.push_str(&custom);
165
- }
166
- VisitResult::Skip => {
167
- output.truncate(safe_start);
168
- }
169
- VisitResult::Error(err) => {
170
- if ctx.visitor_error.borrow().is_none() {
171
- *ctx.visitor_error.borrow_mut() = Some(err);
172
- }
173
- }
174
- VisitResult::PreserveHtml => {}
175
- }
176
- }
177
-
178
- /// Result of visitor element start callback indicating what should happen next.
179
- #[derive(Debug, Clone, Copy, PartialEq, Eq)]
180
- pub enum VisitAction {
181
- /// Continue with normal element processing
182
- Continue,
183
- /// Skip the element entirely (don't process children or call visit_element_end)
184
- Skip,
185
- /// Custom output was provided, skip normal processing
186
- Custom,
187
- /// Error occurred during visitor callback
188
- Error,
189
- }
@@ -1,43 +0,0 @@
1
- //! Error types for HTML to Markdown conversion.
2
-
3
- use thiserror::Error;
4
-
5
- /// Result type for conversion operations.
6
- pub type Result<T> = std::result::Result<T, ConversionError>;
7
-
8
- /// Errors that can occur during HTML to Markdown conversion.
9
- #[derive(Error, Debug)]
10
- pub enum ConversionError {
11
- /// HTML parsing error
12
- #[error("HTML parsing error: {0}")]
13
- ParseError(String),
14
-
15
- /// HTML sanitization error
16
- #[error("Sanitization error: {0}")]
17
- SanitizationError(String),
18
-
19
- /// Invalid configuration
20
- #[error("Invalid configuration: {0}")]
21
- ConfigError(String),
22
-
23
- /// I/O error
24
- #[error("I/O error: {0}")]
25
- IoError(#[from] std::io::Error),
26
-
27
- /// Panic caught during conversion to prevent unwinding across FFI boundaries
28
- #[error("Internal panic: {0}")]
29
- Panic(String),
30
-
31
- /// Invalid input data
32
- #[error("Invalid input: {0}")]
33
- InvalidInput(String),
34
-
35
- /// Visitor callback error
36
- #[cfg(feature = "visitor")]
37
- #[error("Visitor error: {0}")]
38
- Visitor(String),
39
-
40
- /// Generic conversion error
41
- #[error("Conversion error: {0}")]
42
- Other(String),
43
- }
@@ -1,24 +0,0 @@
1
- //! Public API re-exports from submodules.
2
- //!
3
- //! This module centralizes all public type and function exports,
4
- //! making the crate's public interface clear and organized.
5
-
6
- pub use crate::error::{ConversionError, Result};
7
-
8
- #[cfg(feature = "inline-images")]
9
- pub use crate::inline_images::{
10
- DEFAULT_INLINE_IMAGE_LIMIT, HtmlExtraction, InlineImage, InlineImageConfig, InlineImageConfigUpdate,
11
- InlineImageFormat, InlineImageSource, InlineImageWarning,
12
- };
13
-
14
- #[cfg(feature = "metadata")]
15
- pub use crate::metadata::{
16
- DEFAULT_MAX_STRUCTURED_DATA_SIZE, DocumentMetadata, HeaderMetadata, HtmlMetadata, ImageMetadata, ImageType,
17
- LinkMetadata, LinkType, MetadataConfig, MetadataConfigUpdate, StructuredData, StructuredDataType, TextDirection,
18
- };
19
-
20
- pub use crate::options::{
21
- CodeBlockStyle, ConversionOptions, ConversionOptionsBuilder, ConversionOptionsUpdate, HeadingStyle, HighlightStyle,
22
- LinkStyle, ListIndentType, NewlineStyle, OutputFormat, PreprocessingOptions, PreprocessingOptionsUpdate,
23
- PreprocessingPreset, WhitespaceMode,
24
- };