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.
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,337 +0,0 @@
1
- //! Handler for ruby annotation inline elements (ruby, rb, rt, rp, rtc).
2
- //!
3
- //! Converts HTML ruby annotation elements to Markdown format with support for:
4
- //! - Ruby base text elements (<ruby>, <rb>)
5
- //! - Ruby text annotations (<rt>) for phonetic guidance (common in CJK)
6
- //! - Ruby parentheses (<rp>) for fallback presentation in browsers without ruby support
7
- //! - Ruby text container (<rtc>) for secondary annotations or separate ruby text grouping
8
- //! - Interleaved rendering mode: rb/rt pairs rendered inline (rb1(rt1)rb2(rt2))
9
- //! - Grouped rendering mode: all rb text followed by rt annotations in parentheses
10
- //! - Proper handling of CJK (Chinese/Japanese/Korean) text with multiple annotations
11
- //! - Visitor callbacks for custom ruby processing
12
- //! - Whitespace normalization and trimming
13
-
14
- use crate::options::ConversionOptions;
15
- use tl::{NodeHandle, Parser};
16
-
17
- // Type aliases for Context and DomContext to avoid circular imports
18
- type Context = crate::converter::Context;
19
- type DomContext = crate::converter::DomContext;
20
-
21
- /// Handles ruby annotation elements: ruby, rb, rt, rp, rtc.
22
- ///
23
- /// Ruby annotations are used in East Asian typography to show pronunciation guides
24
- /// or provide alternate text. The handler supports two rendering modes:
25
- ///
26
- /// # Rendering Modes
27
- ///
28
- /// **Interleaved mode** (when rb and rt elements are alternated without rtc):
29
- /// - Renders ruby text inline with base text: `base(annotation)base(annotation)`
30
- /// - Example: `<ruby><rb>漢</rb><rt>かん</rt></ruby>` → `漢(かん)`
31
- ///
32
- /// **Grouped mode** (when rtc is present or rb/rt are not interleaved):
33
- /// - Renders all base text first, then all annotations in parentheses: `base(annotation1annotation2)`
34
- /// - Handles multiple rt elements and rtc (ruby text container) grouping
35
- /// - Example: `<ruby><rb>東</rb><rb>京</rb><rt>とう</rt><rt>きょう</rt></ruby>` → `東京(とうきょう)`
36
- ///
37
- /// # Element Handling
38
- ///
39
- /// - `<ruby>`: Main container, detects layout and delegates to appropriate rendering mode
40
- /// - `<rb>`: Base text; content is extracted and used in output
41
- /// - `<rt>`: Annotation text; wrapped in parentheses in standalone contexts
42
- /// - `<rp>`: Ruby parentheses (fallback for browsers without ruby support); skipped in most contexts
43
- /// - `<rtc>`: Ruby text container for grouped annotations; content extracted after rt annotations
44
- ///
45
- /// # Note
46
- /// This function references `walk_node` and `normalized_tag_name` from converter.rs,
47
- /// which must be accessible (pub(crate)) for this module to work correctly.
48
- pub fn handle(
49
- tag_name: &str,
50
- node_handle: &NodeHandle,
51
- parser: &Parser,
52
- output: &mut String,
53
- options: &ConversionOptions,
54
- ctx: &Context,
55
- depth: usize,
56
- dom_ctx: &DomContext,
57
- ) {
58
- // Import helper functions from parent converter module
59
- use crate::converter::{normalized_tag_name, walk_node};
60
-
61
- let Some(node) = node_handle.get(parser) else { return };
62
-
63
- let tag = match node {
64
- tl::Node::Tag(tag) => tag,
65
- _ => return,
66
- };
67
-
68
- match tag_name {
69
- "ruby" => {
70
- // Clone context for ruby children processing
71
- let ruby_ctx = ctx.clone();
72
-
73
- // Scan child elements to determine rendering mode
74
- let tag_sequence: Vec<String> = tag
75
- .children()
76
- .top()
77
- .iter()
78
- .filter_map(|child_handle| {
79
- if let Some(tl::Node::Tag(child_tag)) = child_handle.get(parser) {
80
- let tag_name = normalized_tag_name(child_tag.name().as_utf8_str());
81
- // Only track rb, rt, rtc tags to determine structure
82
- if matches!(tag_name.as_ref(), "rb" | "rt" | "rtc") {
83
- Some(tag_name.into_owned())
84
- } else {
85
- None
86
- }
87
- } else {
88
- None
89
- }
90
- })
91
- .collect();
92
-
93
- // Detect presence of ruby text container
94
- let has_rtc = tag_sequence.iter().any(|tag| tag == "rtc");
95
-
96
- // Detect interleaved mode: rb followed immediately by rt
97
- let is_interleaved = tag_sequence.windows(2).any(|w| w[0] == "rb" && w[1] == "rt");
98
-
99
- if is_interleaved && !has_rtc {
100
- // Interleaved rendering: process rb/rt pairs inline
101
- let mut current_base = String::new();
102
- let children = tag.children();
103
- {
104
- for child_handle in children.top().iter() {
105
- if let Some(node) = child_handle.get(parser) {
106
- match node {
107
- tl::Node::Tag(child_tag) => {
108
- let tag_name = normalized_tag_name(child_tag.name().as_utf8_str());
109
- if tag_name == "rt" {
110
- // Process rt (ruby text/annotation)
111
- let mut annotation = String::new();
112
- walk_node(
113
- child_handle,
114
- parser,
115
- &mut annotation,
116
- options,
117
- &ruby_ctx,
118
- depth,
119
- dom_ctx,
120
- );
121
- // Output any pending base text
122
- if !current_base.is_empty() {
123
- output.push_str(current_base.trim());
124
- current_base.clear();
125
- }
126
- // Output annotation text
127
- output.push_str(annotation.trim());
128
- } else if tag_name == "rb" {
129
- // Process rb (ruby base)
130
- if !current_base.is_empty() {
131
- output.push_str(current_base.trim());
132
- current_base.clear();
133
- }
134
- walk_node(
135
- child_handle,
136
- parser,
137
- &mut current_base,
138
- options,
139
- &ruby_ctx,
140
- depth,
141
- dom_ctx,
142
- );
143
- } else if tag_name != "rp" {
144
- // Skip rp, process other elements into current_base
145
- walk_node(
146
- child_handle,
147
- parser,
148
- &mut current_base,
149
- options,
150
- &ruby_ctx,
151
- depth,
152
- dom_ctx,
153
- );
154
- }
155
- }
156
- tl::Node::Raw(_) => {
157
- // Process raw text nodes
158
- walk_node(
159
- child_handle,
160
- parser,
161
- &mut current_base,
162
- options,
163
- &ruby_ctx,
164
- depth,
165
- dom_ctx,
166
- );
167
- }
168
- _ => {}
169
- }
170
- }
171
- }
172
- }
173
- // Flush remaining base text
174
- if !current_base.is_empty() {
175
- output.push_str(current_base.trim());
176
- }
177
- } else {
178
- // Grouped rendering: collect all bases, then annotations
179
- let mut base_text = String::new();
180
- let mut rt_annotations = Vec::new();
181
- let mut rtc_content = String::new();
182
-
183
- let children = tag.children();
184
- {
185
- for child_handle in children.top().iter() {
186
- if let Some(node) = child_handle.get(parser) {
187
- match node {
188
- tl::Node::Tag(child_tag) => {
189
- let tag_name = normalized_tag_name(child_tag.name().as_utf8_str());
190
- if tag_name == "rt" {
191
- // Collect rt annotations
192
- let mut annotation = String::new();
193
- walk_node(
194
- child_handle,
195
- parser,
196
- &mut annotation,
197
- options,
198
- &ruby_ctx,
199
- depth,
200
- dom_ctx,
201
- );
202
- rt_annotations.push(annotation);
203
- } else if tag_name == "rtc" {
204
- // Collect rtc (ruby text container) content
205
- walk_node(
206
- child_handle,
207
- parser,
208
- &mut rtc_content,
209
- options,
210
- &ruby_ctx,
211
- depth,
212
- dom_ctx,
213
- );
214
- } else if tag_name != "rp" {
215
- // Collect base text (skip rp elements)
216
- walk_node(
217
- child_handle,
218
- parser,
219
- &mut base_text,
220
- options,
221
- &ruby_ctx,
222
- depth,
223
- dom_ctx,
224
- );
225
- }
226
- }
227
- tl::Node::Raw(_) => {
228
- // Collect raw text into base
229
- walk_node(child_handle, parser, &mut base_text, options, &ruby_ctx, depth, dom_ctx);
230
- }
231
- _ => {}
232
- }
233
- }
234
- }
235
- }
236
-
237
- // Output base text
238
- let trimmed_base = base_text.trim();
239
- output.push_str(trimmed_base);
240
-
241
- // Output rt annotations in parentheses if present
242
- if !rt_annotations.is_empty() {
243
- let rt_text = rt_annotations.iter().map(|s| s.trim()).collect::<Vec<_>>().join("");
244
- if !rt_text.is_empty() {
245
- // Wrap in parentheses only if we have rtc content and multiple annotations
246
- if has_rtc && !rtc_content.trim().is_empty() && rt_annotations.len() > 1 {
247
- output.push('(');
248
- output.push_str(&rt_text);
249
- output.push(')');
250
- } else {
251
- output.push_str(&rt_text);
252
- }
253
- }
254
- }
255
-
256
- // Output rtc content after rt annotations
257
- if !rtc_content.trim().is_empty() {
258
- output.push_str(rtc_content.trim());
259
- }
260
- }
261
- }
262
-
263
- "rb" => {
264
- // Ruby base text element (typically used within ruby)
265
- // When standalone, just extract and output the text
266
- let mut text = String::new();
267
- let children = tag.children();
268
- {
269
- for child_handle in children.top().iter() {
270
- walk_node(child_handle, parser, &mut text, options, ctx, depth + 1, dom_ctx);
271
- }
272
- }
273
- output.push_str(text.trim());
274
- }
275
-
276
- "rt" => {
277
- // Ruby text/annotation element
278
- // When standalone (outside ruby context), wrap annotation in parentheses
279
- let mut text = String::new();
280
- let children = tag.children();
281
- {
282
- for child_handle in children.top().iter() {
283
- walk_node(child_handle, parser, &mut text, options, ctx, depth + 1, dom_ctx);
284
- }
285
- }
286
- let trimmed = text.trim();
287
-
288
- // Check if output already ends with opening paren (interleaved mode)
289
- if output.ends_with('(') {
290
- output.push_str(trimmed);
291
- } else {
292
- // Otherwise wrap annotation in parentheses
293
- output.push('(');
294
- output.push_str(trimmed);
295
- output.push(')');
296
- }
297
- }
298
-
299
- "rp" => {
300
- // Ruby parenthesis element (fallback for non-ruby-supporting browsers)
301
- // In Markdown output, generally skip these as annotations are in parentheses
302
- let mut content = String::new();
303
- let children = tag.children();
304
- {
305
- for child_handle in children.top().iter() {
306
- walk_node(child_handle, parser, &mut content, options, ctx, depth + 1, dom_ctx);
307
- }
308
- }
309
- let trimmed = content.trim();
310
- // Only output non-empty rp content
311
- if !trimmed.is_empty() {
312
- output.push_str(trimmed);
313
- }
314
- }
315
-
316
- "rtc" => {
317
- // Ruby text container element
318
- // When standalone, just process children normally
319
- let children = tag.children();
320
- {
321
- for child_handle in children.top().iter() {
322
- walk_node(child_handle, parser, output, options, ctx, depth, dom_ctx);
323
- }
324
- }
325
- }
326
-
327
- _ => {
328
- // Fallback for unknown ruby-related tags: process children normally
329
- let children = tag.children();
330
- {
331
- for child_handle in children.top().iter() {
332
- walk_node(child_handle, parser, output, options, ctx, depth + 1, dom_ctx);
333
- }
334
- }
335
- }
336
- }
337
- }