html-to-markdown 2.30.0 → 3.0.1

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 (166) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +6 -19
  3. data/README.md +37 -50
  4. data/ext/html-to-markdown-rb/native/Cargo.lock +13 -701
  5. data/ext/html-to-markdown-rb/native/Cargo.toml +1 -4
  6. data/ext/html-to-markdown-rb/native/README.md +4 -13
  7. data/ext/html-to-markdown-rb/native/src/conversion/inline_images.rs +2 -73
  8. data/ext/html-to-markdown-rb/native/src/conversion/metadata.rs +5 -49
  9. data/ext/html-to-markdown-rb/native/src/conversion/mod.rs +0 -6
  10. data/ext/html-to-markdown-rb/native/src/lib.rs +76 -213
  11. data/ext/html-to-markdown-rb/native/src/options.rs +0 -3
  12. data/lib/html_to_markdown/version.rb +1 -1
  13. data/lib/html_to_markdown.rb +13 -194
  14. data/sig/html_to_markdown.rbs +12 -373
  15. data/vendor/Cargo.toml +6 -3
  16. data/vendor/html-to-markdown-rs/Cargo.toml +4 -10
  17. data/vendor/html-to-markdown-rs/README.md +126 -52
  18. data/vendor/html-to-markdown-rs/examples/basic.rs +6 -1
  19. data/vendor/html-to-markdown-rs/examples/table.rs +6 -1
  20. data/vendor/html-to-markdown-rs/examples/test_escape.rs +6 -1
  21. data/vendor/html-to-markdown-rs/examples/test_inline_formatting.rs +8 -2
  22. data/vendor/html-to-markdown-rs/examples/test_lists.rs +6 -1
  23. data/vendor/html-to-markdown-rs/examples/test_semantic_tags.rs +6 -1
  24. data/vendor/html-to-markdown-rs/examples/test_tables.rs +6 -1
  25. data/vendor/html-to-markdown-rs/examples/test_task_lists.rs +6 -1
  26. data/vendor/html-to-markdown-rs/examples/test_whitespace.rs +6 -1
  27. data/vendor/html-to-markdown-rs/src/convert_api.rs +151 -745
  28. data/vendor/html-to-markdown-rs/src/converter/block/blockquote.rs +3 -5
  29. data/vendor/html-to-markdown-rs/src/converter/block/div.rs +1 -7
  30. data/vendor/html-to-markdown-rs/src/converter/block/heading.rs +18 -5
  31. data/vendor/html-to-markdown-rs/src/converter/block/paragraph.rs +10 -0
  32. data/vendor/html-to-markdown-rs/src/converter/block/preformatted.rs +3 -5
  33. data/vendor/html-to-markdown-rs/src/converter/block/table/builder.rs +16 -11
  34. data/vendor/html-to-markdown-rs/src/converter/block/table/cell.rs +20 -0
  35. data/vendor/html-to-markdown-rs/src/converter/block/table/cells.rs +4 -17
  36. data/vendor/html-to-markdown-rs/src/converter/block/table/mod.rs +140 -0
  37. data/vendor/html-to-markdown-rs/src/converter/block/table/scanner.rs +4 -18
  38. data/vendor/html-to-markdown-rs/src/converter/block/table/utils.rs +2 -18
  39. data/vendor/html-to-markdown-rs/src/converter/context.rs +8 -0
  40. data/vendor/html-to-markdown-rs/src/converter/dom_context.rs +1 -6
  41. data/vendor/html-to-markdown-rs/src/converter/form/elements.rs +14 -14
  42. data/vendor/html-to-markdown-rs/src/converter/handlers/blockquote.rs +4 -5
  43. data/vendor/html-to-markdown-rs/src/converter/handlers/code_block.rs +5 -10
  44. data/vendor/html-to-markdown-rs/src/converter/handlers/graphic.rs +3 -5
  45. data/vendor/html-to-markdown-rs/src/converter/handlers/image.rs +3 -5
  46. data/vendor/html-to-markdown-rs/src/converter/handlers/link.rs +3 -5
  47. data/vendor/html-to-markdown-rs/src/converter/inline/code.rs +3 -5
  48. data/vendor/html-to-markdown-rs/src/converter/inline/emphasis.rs +4 -10
  49. data/vendor/html-to-markdown-rs/src/converter/inline/link.rs +4 -170
  50. data/vendor/html-to-markdown-rs/src/converter/inline/semantic/marks.rs +7 -19
  51. data/vendor/html-to-markdown-rs/src/converter/list/item.rs +3 -5
  52. data/vendor/html-to-markdown-rs/src/converter/list/ordered.rs +4 -10
  53. data/vendor/html-to-markdown-rs/src/converter/list/unordered.rs +6 -12
  54. data/vendor/html-to-markdown-rs/src/converter/list/utils.rs +1 -12
  55. data/vendor/html-to-markdown-rs/src/converter/main.rs +85 -56
  56. data/vendor/html-to-markdown-rs/src/converter/main_helpers.rs +4 -68
  57. data/vendor/html-to-markdown-rs/src/converter/media/embedded.rs +1 -5
  58. data/vendor/html-to-markdown-rs/src/converter/media/graphic.rs +3 -40
  59. data/vendor/html-to-markdown-rs/src/converter/media/image.rs +0 -8
  60. data/vendor/html-to-markdown-rs/src/converter/media/svg.rs +3 -13
  61. data/vendor/html-to-markdown-rs/src/converter/metadata.rs +1 -1
  62. data/vendor/html-to-markdown-rs/src/converter/mod.rs +0 -8
  63. data/vendor/html-to-markdown-rs/src/converter/plain_text.rs +37 -12
  64. data/vendor/html-to-markdown-rs/src/converter/semantic/attributes.rs +5 -30
  65. data/vendor/html-to-markdown-rs/src/converter/semantic/figure.rs +29 -0
  66. data/vendor/html-to-markdown-rs/src/converter/text/escaping.rs +1 -36
  67. data/vendor/html-to-markdown-rs/src/converter/text/mod.rs +1 -3
  68. data/vendor/html-to-markdown-rs/src/converter/text/normalization.rs +0 -53
  69. data/vendor/html-to-markdown-rs/src/converter/text_node.rs +1 -1
  70. data/vendor/html-to-markdown-rs/src/converter/utility/attributes.rs +0 -41
  71. data/vendor/html-to-markdown-rs/src/converter/utility/caching.rs +2 -1
  72. data/vendor/html-to-markdown-rs/src/converter/utility/content.rs +15 -98
  73. data/vendor/html-to-markdown-rs/src/converter/utility/preprocessing.rs +113 -4
  74. data/vendor/html-to-markdown-rs/src/converter/utility/serialization.rs +3 -0
  75. data/vendor/html-to-markdown-rs/src/converter/visitor_hooks.rs +4 -10
  76. data/vendor/html-to-markdown-rs/src/exports.rs +1 -4
  77. data/vendor/html-to-markdown-rs/src/inline_images.rs +1 -1
  78. data/vendor/html-to-markdown-rs/src/lib.rs +13 -133
  79. data/vendor/html-to-markdown-rs/src/metadata/collector.rs +4 -4
  80. data/vendor/html-to-markdown-rs/src/metadata/mod.rs +22 -22
  81. data/vendor/html-to-markdown-rs/src/metadata/types.rs +3 -3
  82. data/vendor/html-to-markdown-rs/src/options/conversion.rs +351 -323
  83. data/vendor/html-to-markdown-rs/src/options/preprocessing.rs +8 -2
  84. data/vendor/html-to-markdown-rs/src/prelude.rs +1 -15
  85. data/vendor/html-to-markdown-rs/src/rcdom.rs +7 -1
  86. data/vendor/html-to-markdown-rs/src/text.rs +25 -14
  87. data/vendor/html-to-markdown-rs/src/types/document.rs +175 -0
  88. data/vendor/html-to-markdown-rs/src/types/mod.rs +17 -0
  89. data/vendor/html-to-markdown-rs/src/types/result.rs +49 -0
  90. data/vendor/html-to-markdown-rs/src/types/structure_builder.rs +790 -0
  91. data/vendor/html-to-markdown-rs/src/types/structure_collector.rs +442 -0
  92. data/vendor/html-to-markdown-rs/src/types/tables.rs +47 -0
  93. data/vendor/html-to-markdown-rs/src/types/warnings.rs +28 -0
  94. data/vendor/html-to-markdown-rs/src/visitor/mod.rs +0 -6
  95. data/vendor/html-to-markdown-rs/src/visitor/traits.rs +0 -1
  96. data/vendor/html-to-markdown-rs/src/visitor_helpers/helpers/callbacks/mod.rs +1 -21
  97. data/vendor/html-to-markdown-rs/src/visitor_helpers/helpers/mod.rs +0 -5
  98. data/vendor/html-to-markdown-rs/src/visitor_helpers.rs +1 -845
  99. data/vendor/html-to-markdown-rs/tests/br_in_inline_test.rs +8 -1
  100. data/vendor/html-to-markdown-rs/tests/commonmark_compliance_test.rs +8 -8
  101. data/vendor/html-to-markdown-rs/tests/djot_output_test.rs +8 -2
  102. data/vendor/html-to-markdown-rs/tests/integration_test.rs +23 -6
  103. data/vendor/html-to-markdown-rs/tests/issue_121_regressions.rs +8 -1
  104. data/vendor/html-to-markdown-rs/tests/issue_127_regressions.rs +8 -2
  105. data/vendor/html-to-markdown-rs/tests/issue_128_regressions.rs +6 -1
  106. data/vendor/html-to-markdown-rs/tests/issue_131_regressions.rs +8 -1
  107. data/vendor/html-to-markdown-rs/tests/issue_134_regressions.rs +8 -1
  108. data/vendor/html-to-markdown-rs/tests/issue_139_regressions.rs +8 -1
  109. data/vendor/html-to-markdown-rs/tests/issue_140_regressions.rs +8 -1
  110. data/vendor/html-to-markdown-rs/tests/issue_143_regressions.rs +8 -1
  111. data/vendor/html-to-markdown-rs/tests/issue_145_regressions.rs +8 -7
  112. data/vendor/html-to-markdown-rs/tests/issue_146_regressions.rs +8 -7
  113. data/vendor/html-to-markdown-rs/tests/issue_176_regressions.rs +12 -2
  114. data/vendor/html-to-markdown-rs/tests/issue_190_regressions.rs +8 -1
  115. data/vendor/html-to-markdown-rs/tests/issue_199_regressions.rs +6 -1
  116. data/vendor/html-to-markdown-rs/tests/issue_200_regressions.rs +6 -1
  117. data/vendor/html-to-markdown-rs/tests/issue_212_regressions.rs +6 -1
  118. data/vendor/html-to-markdown-rs/tests/issue_216_217_regressions.rs +6 -1
  119. data/vendor/html-to-markdown-rs/tests/json_ld_script_extraction.rs +4 -6
  120. data/vendor/html-to-markdown-rs/tests/lists_test.rs +8 -1
  121. data/vendor/html-to-markdown-rs/tests/plain_output_test.rs +8 -2
  122. data/vendor/html-to-markdown-rs/tests/preprocessing_tests.rs +8 -1
  123. data/vendor/html-to-markdown-rs/tests/skip_images_test.rs +8 -11
  124. data/vendor/html-to-markdown-rs/tests/tables_test.rs +12 -2
  125. data/vendor/html-to-markdown-rs/tests/test_custom_elements.rs +8 -1
  126. data/vendor/html-to-markdown-rs/tests/test_nested_simple.rs +8 -1
  127. data/vendor/html-to-markdown-rs/tests/test_script_style_stripping.rs +17 -28
  128. data/vendor/html-to-markdown-rs/tests/test_spa_bisect.rs +8 -1
  129. data/vendor/html-to-markdown-rs/tests/visitor_integration_test.rs +29 -33
  130. data/vendor/html-to-markdown-rs/tests/xml_tables_test.rs +8 -1
  131. metadata +9 -37
  132. data/bin/benchmark.rb +0 -232
  133. data/ext/html-to-markdown-rb/native/src/conversion/tables.rs +0 -71
  134. data/ext/html-to-markdown-rb/native/src/profiling.rs +0 -215
  135. data/ext/html-to-markdown-rb/native/src/visitor/bridge.rs +0 -252
  136. data/ext/html-to-markdown-rb/native/src/visitor/callbacks.rs +0 -640
  137. data/ext/html-to-markdown-rb/native/src/visitor/mod.rs +0 -12
  138. data/spec/convert_spec.rb +0 -77
  139. data/spec/convert_with_tables_spec.rb +0 -194
  140. data/spec/metadata_extraction_spec.rb +0 -437
  141. data/spec/visitor_issue_187_spec.rb +0 -605
  142. data/spec/visitor_spec.rb +0 -1149
  143. data/vendor/html-to-markdown-rs/src/hocr/converter/code_analysis.rs +0 -254
  144. data/vendor/html-to-markdown-rs/src/hocr/converter/core.rs +0 -249
  145. data/vendor/html-to-markdown-rs/src/hocr/converter/elements.rs +0 -382
  146. data/vendor/html-to-markdown-rs/src/hocr/converter/hierarchy.rs +0 -379
  147. data/vendor/html-to-markdown-rs/src/hocr/converter/keywords.rs +0 -55
  148. data/vendor/html-to-markdown-rs/src/hocr/converter/layout.rs +0 -313
  149. data/vendor/html-to-markdown-rs/src/hocr/converter/mod.rs +0 -26
  150. data/vendor/html-to-markdown-rs/src/hocr/converter/output.rs +0 -78
  151. data/vendor/html-to-markdown-rs/src/hocr/extractor.rs +0 -232
  152. data/vendor/html-to-markdown-rs/src/hocr/mod.rs +0 -42
  153. data/vendor/html-to-markdown-rs/src/hocr/parser.rs +0 -333
  154. data/vendor/html-to-markdown-rs/src/hocr/spatial/coords.rs +0 -129
  155. data/vendor/html-to-markdown-rs/src/hocr/spatial/grouping.rs +0 -165
  156. data/vendor/html-to-markdown-rs/src/hocr/spatial/layout.rs +0 -335
  157. data/vendor/html-to-markdown-rs/src/hocr/spatial/mod.rs +0 -15
  158. data/vendor/html-to-markdown-rs/src/hocr/spatial/output.rs +0 -63
  159. data/vendor/html-to-markdown-rs/src/hocr/types.rs +0 -269
  160. data/vendor/html-to-markdown-rs/src/visitor/async_traits.rs +0 -249
  161. data/vendor/html-to-markdown-rs/src/visitor_helpers/helpers/callbacks/bridge.rs +0 -189
  162. data/vendor/html-to-markdown-rs/src/visitor_helpers/helpers/callbacks/bridge_visitor.rs +0 -343
  163. data/vendor/html-to-markdown-rs/src/visitor_helpers/helpers/callbacks/macros.rs +0 -217
  164. data/vendor/html-to-markdown-rs/tests/async_visitor_test.rs +0 -57
  165. data/vendor/html-to-markdown-rs/tests/convert_with_metadata_no_frontmatter.rs +0 -100
  166. data/vendor/html-to-markdown-rs/tests/hocr_compliance_test.rs +0 -509
@@ -1,640 +0,0 @@
1
- //! HtmlVisitor trait implementation for Ruby visitor wrapper.
2
-
3
- use super::bridge::RubyVisitorWrapper;
4
- use html_to_markdown_rs::visitor::{HtmlVisitor, NodeContext, VisitResult};
5
- use magnus::Ruby;
6
- use magnus::prelude::*;
7
-
8
- impl HtmlVisitor for RubyVisitorWrapper {
9
- fn visit_element_start(&mut self, ctx: &NodeContext) -> VisitResult {
10
- if let Ok(ruby) = Ruby::get() {
11
- if let Ok(node_ctx) = self.ruby_to_node_context(ctx, &ruby) {
12
- if let Ok(result) = self.call_visitor_method("visit_element_start", &[node_ctx]) {
13
- return result;
14
- }
15
- }
16
- }
17
- VisitResult::Continue
18
- }
19
-
20
- fn visit_element_end(&mut self, ctx: &NodeContext, output: &str) -> VisitResult {
21
- if let Ok(ruby) = Ruby::get() {
22
- if let Ok(node_ctx) = self.ruby_to_node_context(ctx, &ruby) {
23
- if let Ok(result) = self.call_visitor_method(
24
- "visit_element_end",
25
- &[node_ctx, ruby.str_from_slice(output.as_bytes()).as_value()],
26
- ) {
27
- return result;
28
- }
29
- }
30
- }
31
- VisitResult::Continue
32
- }
33
-
34
- fn visit_text(&mut self, ctx: &NodeContext, text: &str) -> VisitResult {
35
- if let Ok(ruby) = Ruby::get() {
36
- if let Ok(node_ctx) = self.ruby_to_node_context(ctx, &ruby) {
37
- if let Ok(result) = self.call_visitor_method("visit_text", &[node_ctx, self.utf8_str(&ruby, text)]) {
38
- return result;
39
- }
40
- }
41
- }
42
- VisitResult::Continue
43
- }
44
-
45
- fn visit_link(&mut self, ctx: &NodeContext, href: &str, text: &str, title: Option<&str>) -> VisitResult {
46
- if let Ok(ruby) = Ruby::get() {
47
- if let Ok(node_ctx) = self.ruby_to_node_context(ctx, &ruby) {
48
- let title_val = match title {
49
- Some(t) => ruby.str_from_slice(t.as_bytes()).as_value(),
50
- None => ruby.qnil().as_value(),
51
- };
52
- if let Ok(result) = self.call_visitor_method(
53
- "visit_link",
54
- &[
55
- node_ctx,
56
- ruby.str_from_slice(href.as_bytes()).as_value(),
57
- ruby.str_from_slice(text.as_bytes()).as_value(),
58
- title_val,
59
- ],
60
- ) {
61
- return result;
62
- }
63
- }
64
- }
65
- VisitResult::Continue
66
- }
67
-
68
- fn visit_image(&mut self, ctx: &NodeContext, src: &str, alt: &str, title: Option<&str>) -> VisitResult {
69
- if let Ok(ruby) = Ruby::get() {
70
- if let Ok(node_ctx) = self.ruby_to_node_context(ctx, &ruby) {
71
- let title_val = match title {
72
- Some(t) => ruby.str_from_slice(t.as_bytes()).as_value(),
73
- None => ruby.qnil().as_value(),
74
- };
75
- if let Ok(result) = self.call_visitor_method(
76
- "visit_image",
77
- &[
78
- node_ctx,
79
- ruby.str_from_slice(src.as_bytes()).as_value(),
80
- ruby.str_from_slice(alt.as_bytes()).as_value(),
81
- title_val,
82
- ],
83
- ) {
84
- return result;
85
- }
86
- }
87
- }
88
- VisitResult::Continue
89
- }
90
-
91
- fn visit_heading(&mut self, ctx: &NodeContext, level: u32, text: &str, id: Option<&str>) -> VisitResult {
92
- if let Ok(ruby) = Ruby::get() {
93
- if let Ok(node_ctx) = self.ruby_to_node_context(ctx, &ruby) {
94
- let id_val = match id {
95
- Some(i) => ruby.str_from_slice(i.as_bytes()).as_value(),
96
- None => ruby.qnil().as_value(),
97
- };
98
- if let Ok(result) = self.call_visitor_method(
99
- "visit_heading",
100
- &[
101
- node_ctx,
102
- ruby.integer_from_i64(i64::from(level)).as_value(),
103
- ruby.str_from_slice(text.as_bytes()).as_value(),
104
- id_val,
105
- ],
106
- ) {
107
- return result;
108
- }
109
- }
110
- }
111
- VisitResult::Continue
112
- }
113
-
114
- fn visit_code_block(&mut self, ctx: &NodeContext, lang: Option<&str>, code: &str) -> VisitResult {
115
- if let Ok(ruby) = Ruby::get() {
116
- if let Ok(node_ctx) = self.ruby_to_node_context(ctx, &ruby) {
117
- let lang_val = match lang {
118
- Some(l) => ruby.str_from_slice(l.as_bytes()).as_value(),
119
- None => ruby.qnil().as_value(),
120
- };
121
- if let Ok(result) = self.call_visitor_method(
122
- "visit_code_block",
123
- &[node_ctx, lang_val, ruby.str_from_slice(code.as_bytes()).as_value()],
124
- ) {
125
- return result;
126
- }
127
- }
128
- }
129
- VisitResult::Continue
130
- }
131
-
132
- fn visit_code_inline(&mut self, ctx: &NodeContext, code: &str) -> VisitResult {
133
- if let Ok(ruby) = Ruby::get() {
134
- if let Ok(node_ctx) = self.ruby_to_node_context(ctx, &ruby) {
135
- if let Ok(result) = self.call_visitor_method(
136
- "visit_code_inline",
137
- &[node_ctx, ruby.str_from_slice(code.as_bytes()).as_value()],
138
- ) {
139
- return result;
140
- }
141
- }
142
- }
143
- VisitResult::Continue
144
- }
145
-
146
- fn visit_list_item(&mut self, ctx: &NodeContext, ordered: bool, marker: &str, text: &str) -> VisitResult {
147
- if let Ok(ruby) = Ruby::get() {
148
- if let Ok(node_ctx) = self.ruby_to_node_context(ctx, &ruby) {
149
- let ordered_val = if ordered {
150
- ruby.qtrue().as_value()
151
- } else {
152
- ruby.qfalse().as_value()
153
- };
154
- if let Ok(result) = self.call_visitor_method(
155
- "visit_list_item",
156
- &[
157
- node_ctx,
158
- ordered_val,
159
- ruby.str_from_slice(marker.as_bytes()).as_value(),
160
- ruby.str_from_slice(text.as_bytes()).as_value(),
161
- ],
162
- ) {
163
- return result;
164
- }
165
- }
166
- }
167
- VisitResult::Continue
168
- }
169
-
170
- fn visit_list_start(&mut self, ctx: &NodeContext, ordered: bool) -> VisitResult {
171
- if let Ok(ruby) = Ruby::get() {
172
- if let Ok(node_ctx) = self.ruby_to_node_context(ctx, &ruby) {
173
- let ordered_val = if ordered {
174
- ruby.qtrue().as_value()
175
- } else {
176
- ruby.qfalse().as_value()
177
- };
178
- if let Ok(result) = self.call_visitor_method("visit_list_start", &[node_ctx, ordered_val]) {
179
- return result;
180
- }
181
- }
182
- }
183
- VisitResult::Continue
184
- }
185
-
186
- fn visit_list_end(&mut self, ctx: &NodeContext, ordered: bool, output: &str) -> VisitResult {
187
- if let Ok(ruby) = Ruby::get() {
188
- if let Ok(node_ctx) = self.ruby_to_node_context(ctx, &ruby) {
189
- let ordered_val = if ordered {
190
- ruby.qtrue().as_value()
191
- } else {
192
- ruby.qfalse().as_value()
193
- };
194
- if let Ok(result) = self.call_visitor_method(
195
- "visit_list_end",
196
- &[node_ctx, ordered_val, ruby.str_from_slice(output.as_bytes()).as_value()],
197
- ) {
198
- return result;
199
- }
200
- }
201
- }
202
- VisitResult::Continue
203
- }
204
-
205
- fn visit_table_start(&mut self, ctx: &NodeContext) -> VisitResult {
206
- if let Ok(ruby) = Ruby::get() {
207
- if let Ok(node_ctx) = self.ruby_to_node_context(ctx, &ruby) {
208
- if let Ok(result) = self.call_visitor_method("visit_table_start", &[node_ctx]) {
209
- return result;
210
- }
211
- }
212
- }
213
- VisitResult::Continue
214
- }
215
-
216
- fn visit_table_row(&mut self, ctx: &NodeContext, cells: &[String], is_header: bool) -> VisitResult {
217
- if let Ok(ruby) = Ruby::get() {
218
- if let Ok(node_ctx) = self.ruby_to_node_context(ctx, &ruby) {
219
- let cells_array = ruby.ary_new();
220
- for cell in cells {
221
- let _ = cells_array.push(ruby.str_from_slice(cell.as_bytes()).as_value());
222
- }
223
- let is_header_val = if is_header {
224
- ruby.qtrue().as_value()
225
- } else {
226
- ruby.qfalse().as_value()
227
- };
228
- if let Ok(result) =
229
- self.call_visitor_method("visit_table_row", &[node_ctx, cells_array.as_value(), is_header_val])
230
- {
231
- return result;
232
- }
233
- }
234
- }
235
- VisitResult::Continue
236
- }
237
-
238
- fn visit_table_end(&mut self, ctx: &NodeContext, output: &str) -> VisitResult {
239
- if let Ok(ruby) = Ruby::get() {
240
- if let Ok(node_ctx) = self.ruby_to_node_context(ctx, &ruby) {
241
- if let Ok(result) = self.call_visitor_method(
242
- "visit_table_end",
243
- &[node_ctx, ruby.str_from_slice(output.as_bytes()).as_value()],
244
- ) {
245
- return result;
246
- }
247
- }
248
- }
249
- VisitResult::Continue
250
- }
251
-
252
- fn visit_blockquote(&mut self, ctx: &NodeContext, content: &str, depth: usize) -> VisitResult {
253
- if let Ok(ruby) = Ruby::get() {
254
- if let Ok(node_ctx) = self.ruby_to_node_context(ctx, &ruby) {
255
- if let Ok(result) = self.call_visitor_method(
256
- "visit_blockquote",
257
- &[
258
- node_ctx,
259
- ruby.str_from_slice(content.as_bytes()).as_value(),
260
- ruby.integer_from_i64(depth as i64).as_value(),
261
- ],
262
- ) {
263
- return result;
264
- }
265
- }
266
- }
267
- VisitResult::Continue
268
- }
269
-
270
- fn visit_strong(&mut self, ctx: &NodeContext, text: &str) -> VisitResult {
271
- if let Ok(ruby) = Ruby::get() {
272
- if let Ok(node_ctx) = self.ruby_to_node_context(ctx, &ruby) {
273
- if let Ok(result) = self.call_visitor_method(
274
- "visit_strong",
275
- &[node_ctx, ruby.str_from_slice(text.as_bytes()).as_value()],
276
- ) {
277
- return result;
278
- }
279
- }
280
- }
281
- VisitResult::Continue
282
- }
283
-
284
- fn visit_emphasis(&mut self, ctx: &NodeContext, text: &str) -> VisitResult {
285
- if let Ok(ruby) = Ruby::get() {
286
- if let Ok(node_ctx) = self.ruby_to_node_context(ctx, &ruby) {
287
- if let Ok(result) = self.call_visitor_method(
288
- "visit_emphasis",
289
- &[node_ctx, ruby.str_from_slice(text.as_bytes()).as_value()],
290
- ) {
291
- return result;
292
- }
293
- }
294
- }
295
- VisitResult::Continue
296
- }
297
-
298
- fn visit_strikethrough(&mut self, ctx: &NodeContext, text: &str) -> VisitResult {
299
- if let Ok(ruby) = Ruby::get() {
300
- if let Ok(node_ctx) = self.ruby_to_node_context(ctx, &ruby) {
301
- if let Ok(result) = self.call_visitor_method(
302
- "visit_strikethrough",
303
- &[node_ctx, ruby.str_from_slice(text.as_bytes()).as_value()],
304
- ) {
305
- return result;
306
- }
307
- }
308
- }
309
- VisitResult::Continue
310
- }
311
-
312
- fn visit_underline(&mut self, ctx: &NodeContext, text: &str) -> VisitResult {
313
- if let Ok(ruby) = Ruby::get() {
314
- if let Ok(node_ctx) = self.ruby_to_node_context(ctx, &ruby) {
315
- if let Ok(result) = self.call_visitor_method(
316
- "visit_underline",
317
- &[node_ctx, ruby.str_from_slice(text.as_bytes()).as_value()],
318
- ) {
319
- return result;
320
- }
321
- }
322
- }
323
- VisitResult::Continue
324
- }
325
-
326
- fn visit_subscript(&mut self, ctx: &NodeContext, text: &str) -> VisitResult {
327
- if let Ok(ruby) = Ruby::get() {
328
- if let Ok(node_ctx) = self.ruby_to_node_context(ctx, &ruby) {
329
- if let Ok(result) = self.call_visitor_method(
330
- "visit_subscript",
331
- &[node_ctx, ruby.str_from_slice(text.as_bytes()).as_value()],
332
- ) {
333
- return result;
334
- }
335
- }
336
- }
337
- VisitResult::Continue
338
- }
339
-
340
- fn visit_superscript(&mut self, ctx: &NodeContext, text: &str) -> VisitResult {
341
- if let Ok(ruby) = Ruby::get() {
342
- if let Ok(node_ctx) = self.ruby_to_node_context(ctx, &ruby) {
343
- if let Ok(result) = self.call_visitor_method(
344
- "visit_superscript",
345
- &[node_ctx, ruby.str_from_slice(text.as_bytes()).as_value()],
346
- ) {
347
- return result;
348
- }
349
- }
350
- }
351
- VisitResult::Continue
352
- }
353
-
354
- fn visit_mark(&mut self, ctx: &NodeContext, text: &str) -> VisitResult {
355
- if let Ok(ruby) = Ruby::get() {
356
- if let Ok(node_ctx) = self.ruby_to_node_context(ctx, &ruby) {
357
- if let Ok(result) = self.call_visitor_method(
358
- "visit_mark",
359
- &[node_ctx, ruby.str_from_slice(text.as_bytes()).as_value()],
360
- ) {
361
- return result;
362
- }
363
- }
364
- }
365
- VisitResult::Continue
366
- }
367
-
368
- fn visit_line_break(&mut self, ctx: &NodeContext) -> VisitResult {
369
- if let Ok(ruby) = Ruby::get() {
370
- if let Ok(node_ctx) = self.ruby_to_node_context(ctx, &ruby) {
371
- if let Ok(result) = self.call_visitor_method("visit_line_break", &[node_ctx]) {
372
- return result;
373
- }
374
- }
375
- }
376
- VisitResult::Continue
377
- }
378
-
379
- fn visit_horizontal_rule(&mut self, ctx: &NodeContext) -> VisitResult {
380
- if let Ok(ruby) = Ruby::get() {
381
- if let Ok(node_ctx) = self.ruby_to_node_context(ctx, &ruby) {
382
- if let Ok(result) = self.call_visitor_method("visit_horizontal_rule", &[node_ctx]) {
383
- return result;
384
- }
385
- }
386
- }
387
- VisitResult::Continue
388
- }
389
-
390
- fn visit_custom_element(&mut self, ctx: &NodeContext, tag_name: &str, html: &str) -> VisitResult {
391
- if let Ok(ruby) = Ruby::get() {
392
- if let Ok(node_ctx) = self.ruby_to_node_context(ctx, &ruby) {
393
- if let Ok(result) = self.call_visitor_method(
394
- "visit_custom_element",
395
- &[
396
- node_ctx,
397
- ruby.str_from_slice(tag_name.as_bytes()).as_value(),
398
- ruby.str_from_slice(html.as_bytes()).as_value(),
399
- ],
400
- ) {
401
- return result;
402
- }
403
- }
404
- }
405
- VisitResult::Continue
406
- }
407
-
408
- fn visit_definition_list_start(&mut self, ctx: &NodeContext) -> VisitResult {
409
- if let Ok(ruby) = Ruby::get() {
410
- if let Ok(node_ctx) = self.ruby_to_node_context(ctx, &ruby) {
411
- if let Ok(result) = self.call_visitor_method("visit_definition_list_start", &[node_ctx]) {
412
- return result;
413
- }
414
- }
415
- }
416
- VisitResult::Continue
417
- }
418
-
419
- fn visit_definition_term(&mut self, ctx: &NodeContext, text: &str) -> VisitResult {
420
- if let Ok(ruby) = Ruby::get() {
421
- if let Ok(node_ctx) = self.ruby_to_node_context(ctx, &ruby) {
422
- if let Ok(result) = self.call_visitor_method(
423
- "visit_definition_term",
424
- &[node_ctx, ruby.str_from_slice(text.as_bytes()).as_value()],
425
- ) {
426
- return result;
427
- }
428
- }
429
- }
430
- VisitResult::Continue
431
- }
432
-
433
- fn visit_definition_description(&mut self, ctx: &NodeContext, text: &str) -> VisitResult {
434
- if let Ok(ruby) = Ruby::get() {
435
- if let Ok(node_ctx) = self.ruby_to_node_context(ctx, &ruby) {
436
- if let Ok(result) = self.call_visitor_method(
437
- "visit_definition_description",
438
- &[node_ctx, ruby.str_from_slice(text.as_bytes()).as_value()],
439
- ) {
440
- return result;
441
- }
442
- }
443
- }
444
- VisitResult::Continue
445
- }
446
-
447
- fn visit_definition_list_end(&mut self, ctx: &NodeContext, output: &str) -> VisitResult {
448
- if let Ok(ruby) = Ruby::get() {
449
- if let Ok(node_ctx) = self.ruby_to_node_context(ctx, &ruby) {
450
- if let Ok(result) = self.call_visitor_method(
451
- "visit_definition_list_end",
452
- &[node_ctx, ruby.str_from_slice(output.as_bytes()).as_value()],
453
- ) {
454
- return result;
455
- }
456
- }
457
- }
458
- VisitResult::Continue
459
- }
460
-
461
- fn visit_form(&mut self, ctx: &NodeContext, action: Option<&str>, method: Option<&str>) -> VisitResult {
462
- if let Ok(ruby) = Ruby::get() {
463
- if let Ok(node_ctx) = self.ruby_to_node_context(ctx, &ruby) {
464
- let action_val = match action {
465
- Some(a) => ruby.str_from_slice(a.as_bytes()).as_value(),
466
- None => ruby.qnil().as_value(),
467
- };
468
- let method_val = match method {
469
- Some(m) => ruby.str_from_slice(m.as_bytes()).as_value(),
470
- None => ruby.qnil().as_value(),
471
- };
472
- if let Ok(result) = self.call_visitor_method("visit_form", &[node_ctx, action_val, method_val]) {
473
- return result;
474
- }
475
- }
476
- }
477
- VisitResult::Continue
478
- }
479
-
480
- fn visit_input(
481
- &mut self,
482
- ctx: &NodeContext,
483
- input_type: &str,
484
- name: Option<&str>,
485
- value: Option<&str>,
486
- ) -> VisitResult {
487
- if let Ok(ruby) = Ruby::get() {
488
- if let Ok(node_ctx) = self.ruby_to_node_context(ctx, &ruby) {
489
- let name_val = match name {
490
- Some(n) => ruby.str_from_slice(n.as_bytes()).as_value(),
491
- None => ruby.qnil().as_value(),
492
- };
493
- let value_val = match value {
494
- Some(v) => ruby.str_from_slice(v.as_bytes()).as_value(),
495
- None => ruby.qnil().as_value(),
496
- };
497
- if let Ok(result) = self.call_visitor_method(
498
- "visit_input",
499
- &[
500
- node_ctx,
501
- ruby.str_from_slice(input_type.as_bytes()).as_value(),
502
- name_val,
503
- value_val,
504
- ],
505
- ) {
506
- return result;
507
- }
508
- }
509
- }
510
- VisitResult::Continue
511
- }
512
-
513
- fn visit_button(&mut self, ctx: &NodeContext, text: &str) -> VisitResult {
514
- if let Ok(ruby) = Ruby::get() {
515
- if let Ok(node_ctx) = self.ruby_to_node_context(ctx, &ruby) {
516
- if let Ok(result) = self.call_visitor_method(
517
- "visit_button",
518
- &[node_ctx, ruby.str_from_slice(text.as_bytes()).as_value()],
519
- ) {
520
- return result;
521
- }
522
- }
523
- }
524
- VisitResult::Continue
525
- }
526
-
527
- fn visit_audio(&mut self, ctx: &NodeContext, src: Option<&str>) -> VisitResult {
528
- if let Ok(ruby) = Ruby::get() {
529
- if let Ok(node_ctx) = self.ruby_to_node_context(ctx, &ruby) {
530
- let src_val = match src {
531
- Some(s) => ruby.str_from_slice(s.as_bytes()).as_value(),
532
- None => ruby.qnil().as_value(),
533
- };
534
- if let Ok(result) = self.call_visitor_method("visit_audio", &[node_ctx, src_val]) {
535
- return result;
536
- }
537
- }
538
- }
539
- VisitResult::Continue
540
- }
541
-
542
- fn visit_video(&mut self, ctx: &NodeContext, src: Option<&str>) -> VisitResult {
543
- if let Ok(ruby) = Ruby::get() {
544
- if let Ok(node_ctx) = self.ruby_to_node_context(ctx, &ruby) {
545
- let src_val = match src {
546
- Some(s) => ruby.str_from_slice(s.as_bytes()).as_value(),
547
- None => ruby.qnil().as_value(),
548
- };
549
- if let Ok(result) = self.call_visitor_method("visit_video", &[node_ctx, src_val]) {
550
- return result;
551
- }
552
- }
553
- }
554
- VisitResult::Continue
555
- }
556
-
557
- fn visit_iframe(&mut self, ctx: &NodeContext, src: Option<&str>) -> VisitResult {
558
- if let Ok(ruby) = Ruby::get() {
559
- if let Ok(node_ctx) = self.ruby_to_node_context(ctx, &ruby) {
560
- let src_val = match src {
561
- Some(s) => ruby.str_from_slice(s.as_bytes()).as_value(),
562
- None => ruby.qnil().as_value(),
563
- };
564
- if let Ok(result) = self.call_visitor_method("visit_iframe", &[node_ctx, src_val]) {
565
- return result;
566
- }
567
- }
568
- }
569
- VisitResult::Continue
570
- }
571
-
572
- fn visit_details(&mut self, ctx: &NodeContext, open: bool) -> VisitResult {
573
- if let Ok(ruby) = Ruby::get() {
574
- if let Ok(node_ctx) = self.ruby_to_node_context(ctx, &ruby) {
575
- let open_val = if open {
576
- ruby.qtrue().as_value()
577
- } else {
578
- ruby.qfalse().as_value()
579
- };
580
- if let Ok(result) = self.call_visitor_method("visit_details", &[node_ctx, open_val]) {
581
- return result;
582
- }
583
- }
584
- }
585
- VisitResult::Continue
586
- }
587
-
588
- fn visit_summary(&mut self, ctx: &NodeContext, text: &str) -> VisitResult {
589
- if let Ok(ruby) = Ruby::get() {
590
- if let Ok(node_ctx) = self.ruby_to_node_context(ctx, &ruby) {
591
- if let Ok(result) = self.call_visitor_method(
592
- "visit_summary",
593
- &[node_ctx, ruby.str_from_slice(text.as_bytes()).as_value()],
594
- ) {
595
- return result;
596
- }
597
- }
598
- }
599
- VisitResult::Continue
600
- }
601
-
602
- fn visit_figure_start(&mut self, ctx: &NodeContext) -> VisitResult {
603
- if let Ok(ruby) = Ruby::get() {
604
- if let Ok(node_ctx) = self.ruby_to_node_context(ctx, &ruby) {
605
- if let Ok(result) = self.call_visitor_method("visit_figure_start", &[node_ctx]) {
606
- return result;
607
- }
608
- }
609
- }
610
- VisitResult::Continue
611
- }
612
-
613
- fn visit_figcaption(&mut self, ctx: &NodeContext, text: &str) -> VisitResult {
614
- if let Ok(ruby) = Ruby::get() {
615
- if let Ok(node_ctx) = self.ruby_to_node_context(ctx, &ruby) {
616
- if let Ok(result) = self.call_visitor_method(
617
- "visit_figcaption",
618
- &[node_ctx, ruby.str_from_slice(text.as_bytes()).as_value()],
619
- ) {
620
- return result;
621
- }
622
- }
623
- }
624
- VisitResult::Continue
625
- }
626
-
627
- fn visit_figure_end(&mut self, ctx: &NodeContext, output: &str) -> VisitResult {
628
- if let Ok(ruby) = Ruby::get() {
629
- if let Ok(node_ctx) = self.ruby_to_node_context(ctx, &ruby) {
630
- if let Ok(result) = self.call_visitor_method(
631
- "visit_figure_end",
632
- &[node_ctx, ruby.str_from_slice(output.as_bytes()).as_value()],
633
- ) {
634
- return result;
635
- }
636
- }
637
- }
638
- VisitResult::Continue
639
- }
640
- }
@@ -1,12 +0,0 @@
1
- //! Visitor support for Ruby bindings.
2
- //!
3
- //! This module provides the bridge between Ruby visitor objects and the Rust HtmlVisitor trait.
4
-
5
- #[cfg(feature = "visitor")]
6
- pub mod bridge;
7
-
8
- #[cfg(feature = "visitor")]
9
- pub mod callbacks;
10
-
11
- #[cfg(feature = "visitor")]
12
- pub use bridge::RubyVisitorWrapper;