html-to-markdown 3.10.6 → 3.11.2

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.
@@ -1,7 +1,7 @@
1
1
  # This file is auto-generated by alef — DO NOT EDIT.
2
- # alef:hash:f44000653901d10b61e9069d2e901a11b70b0e643ba63d75f2222729c924ae82
2
+ # alef:hash:7f3c74ddad62b174cb8ff3a57759bff2fc8e3af68b56501137ccef0857114d98
3
3
  # To regenerate: alef generate
4
- # To verify freshness: alef verify --exit-code
4
+ # To verify freshness: alef verify
5
5
  # frozen_string_literal: true
6
6
 
7
7
  require "json"
@@ -18,7 +18,7 @@ library_candidates = dlexts.flat_map do |dlext|
18
18
  File.join(__dir__, "..", extension_name, ruby_abi, "#{extension_name}.#{dlext}"),
19
19
  File.join(__dir__, "..", extension_name, ruby_abi, "lib#{extension_name}.#{dlext}"),
20
20
  File.join(__dir__, "..", "#{extension_name}.#{dlext}"),
21
- File.join(__dir__, "..", "lib#{extension_name}.#{dlext}")
21
+ File.join(__dir__, "..", "lib#{extension_name}.#{dlext}"),
22
22
  ]
23
23
  end
24
24
 
@@ -34,7 +34,6 @@ unless native_extension
34
34
  end
35
35
 
36
36
  require native_extension
37
-
38
37
  module HtmlToMarkdown
39
38
  # Re-export public types from the native extension (curated list, excludes Update/Builder types)
40
39
  ConversionOptions = HtmlToMarkdownRs.const_get(:ConversionOptions)
@@ -57,11 +56,8 @@ module HtmlToMarkdown
57
56
  TableGrid = HtmlToMarkdownRs.const_get(:TableGrid)
58
57
  TextAnnotation = HtmlToMarkdownRs.const_get(:TextAnnotation)
59
58
  # Re-export public module functions from the native extension (curated list)
60
- define_singleton_method(:convert) { |*args, **kwargs, &blk|
61
- HtmlToMarkdownRs.public_send(:convert, *args, **kwargs, &blk)
62
- }
59
+ define_singleton_method(:convert) { |*args, **kwargs, &blk| HtmlToMarkdownRs.public_send(:convert, *args, **kwargs, &blk) }
63
60
  end
64
-
65
61
  module HtmlToMarkdown
66
62
  # The semantic content type of a document node.
67
63
  #
@@ -79,34 +75,20 @@ module HtmlToMarkdown
79
75
  def self.from_hash(hash)
80
76
  discriminator = hash[:node_type] || hash["node_type"]
81
77
  case discriminator
82
- when "heading"
83
- NodeContentHeading.from_hash(hash)
84
- when "paragraph"
85
- NodeContentParagraph.from_hash(hash)
86
- when "list"
87
- NodeContentList.from_hash(hash)
88
- when "list_item"
89
- NodeContentListItem.from_hash(hash)
90
- when "table"
91
- NodeContentTable.from_hash(hash)
92
- when "image"
93
- NodeContentImage.from_hash(hash)
94
- when "code"
95
- NodeContentCode.from_hash(hash)
96
- when "quote"
97
- NodeContentQuote.from_hash(hash)
98
- when "definition_list"
99
- NodeContentDefinitionList.from_hash(hash)
100
- when "definition_item"
101
- NodeContentDefinitionItem.from_hash(hash)
102
- when "raw_block"
103
- NodeContentRawBlock.from_hash(hash)
104
- when "metadata_block"
105
- NodeContentMetadataBlock.from_hash(hash)
106
- when "group"
107
- NodeContentGroup.from_hash(hash)
108
- else
109
- raise "Unknown discriminator: #{discriminator}"
78
+ when "heading" then NodeContentHeading.from_hash(hash)
79
+ when "paragraph" then NodeContentParagraph.from_hash(hash)
80
+ when "list" then NodeContentList.from_hash(hash)
81
+ when "list_item" then NodeContentListItem.from_hash(hash)
82
+ when "table" then NodeContentTable.from_hash(hash)
83
+ when "image" then NodeContentImage.from_hash(hash)
84
+ when "code" then NodeContentCode.from_hash(hash)
85
+ when "quote" then NodeContentQuote.from_hash(hash)
86
+ when "definition_list" then NodeContentDefinitionList.from_hash(hash)
87
+ when "definition_item" then NodeContentDefinitionItem.from_hash(hash)
88
+ when "raw_block" then NodeContentRawBlock.from_hash(hash)
89
+ when "metadata_block" then NodeContentMetadataBlock.from_hash(hash)
90
+ when "group" then NodeContentGroup.from_hash(hash)
91
+ else raise "Unknown discriminator: #{discriminator}"
110
92
  end
111
93
  end
112
94
  end
@@ -117,12 +99,10 @@ module HtmlToMarkdown
117
99
 
118
100
  # Heading level (1-6).
119
101
  sig { returns(Integer) }
120
- # rubocop:disable Lint/UselessMethodDefinition
121
- def level = super
102
+ def level = super # rubocop:disable Lint/UselessMethodDefinition
122
103
  # The heading text content.
123
104
  sig { returns(String) }
124
- # rubocop:disable Lint/UselessMethodDefinition
125
- def text = super
105
+ def text = super # rubocop:disable Lint/UselessMethodDefinition
126
106
  sig { returns(T::Boolean) }
127
107
  def heading? = true
128
108
  sig { returns(T::Boolean) }
@@ -163,8 +143,7 @@ module HtmlToMarkdown
163
143
 
164
144
  # The paragraph text content.
165
145
  sig { returns(String) }
166
- # rubocop:disable Lint/UselessMethodDefinition
167
- def text = super
146
+ def text = super # rubocop:disable Lint/UselessMethodDefinition
168
147
  sig { returns(T::Boolean) }
169
148
  def heading? = false
170
149
  sig { returns(T::Boolean) }
@@ -205,8 +184,7 @@ module HtmlToMarkdown
205
184
 
206
185
  # Whether this is an ordered list.
207
186
  sig { returns(T::Boolean) }
208
- # rubocop:disable Lint/UselessMethodDefinition
209
- def ordered = super
187
+ def ordered = super # rubocop:disable Lint/UselessMethodDefinition
210
188
  sig { returns(T::Boolean) }
211
189
  def heading? = false
212
190
  sig { returns(T::Boolean) }
@@ -247,8 +225,7 @@ module HtmlToMarkdown
247
225
 
248
226
  # The list item text content.
249
227
  sig { returns(String) }
250
- # rubocop:disable Lint/UselessMethodDefinition
251
- def text = super
228
+ def text = super # rubocop:disable Lint/UselessMethodDefinition
252
229
  sig { returns(T::Boolean) }
253
230
  def heading? = false
254
231
  sig { returns(T::Boolean) }
@@ -289,8 +266,7 @@ module HtmlToMarkdown
289
266
 
290
267
  # The table grid structure.
291
268
  sig { returns(TableGrid) }
292
- # rubocop:disable Lint/UselessMethodDefinition
293
- def grid = super
269
+ def grid = super # rubocop:disable Lint/UselessMethodDefinition
294
270
  sig { returns(T::Boolean) }
295
271
  def heading? = false
296
272
  sig { returns(T::Boolean) }
@@ -331,16 +307,13 @@ module HtmlToMarkdown
331
307
 
332
308
  # Alt text or caption.
333
309
  sig { returns(T.nilable(String)) }
334
- # rubocop:disable Lint/UselessMethodDefinition
335
- def description = super
310
+ def description = super # rubocop:disable Lint/UselessMethodDefinition
336
311
  # Image source URL.
337
312
  sig { returns(T.nilable(String)) }
338
- # rubocop:disable Lint/UselessMethodDefinition
339
- def src = super
313
+ def src = super # rubocop:disable Lint/UselessMethodDefinition
340
314
  # Index into `ConversionResult.images` when image extraction is enabled.
341
315
  sig { returns(T.nilable(Integer)) }
342
- # rubocop:disable Lint/UselessMethodDefinition
343
- def image_index = super
316
+ def image_index = super # rubocop:disable Lint/UselessMethodDefinition
344
317
  sig { returns(T::Boolean) }
345
318
  def heading? = false
346
319
  sig { returns(T::Boolean) }
@@ -371,11 +344,7 @@ module HtmlToMarkdown
371
344
  # @return [self]
372
345
  sig { params(hash: T::Hash[T.untyped, T.untyped]).returns(T.attached_class) }
373
346
  def self.from_hash(hash)
374
- new(
375
- description: hash[:description] || hash["description"],
376
- src: hash[:src] || hash["src"],
377
- image_index: hash[:image_index] || hash["image_index"]
378
- )
347
+ new(description: hash[:description] || hash["description"], src: hash[:src] || hash["src"], image_index: hash[:image_index] || hash["image_index"])
379
348
  end
380
349
  end
381
350
  ## A code block or inline code.
@@ -385,12 +354,10 @@ module HtmlToMarkdown
385
354
 
386
355
  # The code text content.
387
356
  sig { returns(String) }
388
- # rubocop:disable Lint/UselessMethodDefinition
389
- def text = super
357
+ def text = super # rubocop:disable Lint/UselessMethodDefinition
390
358
  # Programming language (from class="language-*" or similar).
391
359
  sig { returns(T.nilable(String)) }
392
- # rubocop:disable Lint/UselessMethodDefinition
393
- def language = super
360
+ def language = super # rubocop:disable Lint/UselessMethodDefinition
394
361
  sig { returns(T::Boolean) }
395
362
  def heading? = false
396
363
  sig { returns(T::Boolean) }
@@ -507,12 +474,10 @@ module HtmlToMarkdown
507
474
 
508
475
  # The term being defined.
509
476
  sig { returns(String) }
510
- # rubocop:disable Lint/UselessMethodDefinition
511
- def term = super
477
+ def term = super # rubocop:disable Lint/UselessMethodDefinition
512
478
  # The definition text.
513
479
  sig { returns(String) }
514
- # rubocop:disable Lint/UselessMethodDefinition
515
- def definition = super
480
+ def definition = super # rubocop:disable Lint/UselessMethodDefinition
516
481
  sig { returns(T::Boolean) }
517
482
  def heading? = false
518
483
  sig { returns(T::Boolean) }
@@ -553,12 +518,10 @@ module HtmlToMarkdown
553
518
 
554
519
  # The format of the raw content (e.g. "html", "css", "javascript").
555
520
  sig { returns(String) }
556
- # rubocop:disable Lint/UselessMethodDefinition
557
- def format = super
521
+ def format = super # rubocop:disable Lint/UselessMethodDefinition
558
522
  # The raw content.
559
523
  sig { returns(String) }
560
- # rubocop:disable Lint/UselessMethodDefinition
561
- def content = super
524
+ def content = super # rubocop:disable Lint/UselessMethodDefinition
562
525
  sig { returns(T::Boolean) }
563
526
  def heading? = false
564
527
  sig { returns(T::Boolean) }
@@ -599,8 +562,7 @@ module HtmlToMarkdown
599
562
 
600
563
  # Key-value metadata pairs.
601
564
  sig { returns(T::Array[MetadataEntry]) }
602
- # rubocop:disable Lint/UselessMethodDefinition
603
- def entries = super
565
+ def entries = super # rubocop:disable Lint/UselessMethodDefinition
604
566
  sig { returns(T::Boolean) }
605
567
  def heading? = false
606
568
  sig { returns(T::Boolean) }
@@ -641,16 +603,13 @@ module HtmlToMarkdown
641
603
 
642
604
  # Optional section label.
643
605
  sig { returns(T.nilable(String)) }
644
- # rubocop:disable Lint/UselessMethodDefinition
645
- def label = super
606
+ def label = super # rubocop:disable Lint/UselessMethodDefinition
646
607
  # The heading level that created this group.
647
608
  sig { returns(T.nilable(Integer)) }
648
- # rubocop:disable Lint/UselessMethodDefinition
649
- def heading_level = super
609
+ def heading_level = super # rubocop:disable Lint/UselessMethodDefinition
650
610
  # The heading text that created this group.
651
611
  sig { returns(T.nilable(String)) }
652
- # rubocop:disable Lint/UselessMethodDefinition
653
- def heading_text = super
612
+ def heading_text = super # rubocop:disable Lint/UselessMethodDefinition
654
613
  sig { returns(T::Boolean) }
655
614
  def heading? = false
656
615
  sig { returns(T::Boolean) }
@@ -681,11 +640,7 @@ module HtmlToMarkdown
681
640
  # @return [self]
682
641
  sig { params(hash: T::Hash[T.untyped, T.untyped]).returns(T.attached_class) }
683
642
  def self.from_hash(hash)
684
- new(
685
- label: hash[:label] || hash["label"],
686
- heading_level: hash[:heading_level] || hash["heading_level"],
687
- heading_text: hash[:heading_text] || hash["heading_text"]
688
- )
643
+ new(label: hash[:label] || hash["label"], heading_level: hash[:heading_level] || hash["heading_level"], heading_text: hash[:heading_text] || hash["heading_text"])
689
644
  end
690
645
  end
691
646
  end
@@ -707,26 +662,16 @@ module HtmlToMarkdown
707
662
  def self.from_hash(hash)
708
663
  discriminator = hash[:annotation_type] || hash["annotation_type"]
709
664
  case discriminator
710
- when "bold"
711
- AnnotationKindBold.from_hash(hash)
712
- when "italic"
713
- AnnotationKindItalic.from_hash(hash)
714
- when "underline"
715
- AnnotationKindUnderline.from_hash(hash)
716
- when "strikethrough"
717
- AnnotationKindStrikethrough.from_hash(hash)
718
- when "code"
719
- AnnotationKindCode.from_hash(hash)
720
- when "subscript"
721
- AnnotationKindSubscript.from_hash(hash)
722
- when "superscript"
723
- AnnotationKindSuperscript.from_hash(hash)
724
- when "highlight"
725
- AnnotationKindHighlight.from_hash(hash)
726
- when "link"
727
- AnnotationKindLink.from_hash(hash)
728
- else
729
- raise "Unknown discriminator: #{discriminator}"
665
+ when "bold" then AnnotationKindBold.from_hash(hash)
666
+ when "italic" then AnnotationKindItalic.from_hash(hash)
667
+ when "underline" then AnnotationKindUnderline.from_hash(hash)
668
+ when "strikethrough" then AnnotationKindStrikethrough.from_hash(hash)
669
+ when "code" then AnnotationKindCode.from_hash(hash)
670
+ when "subscript" then AnnotationKindSubscript.from_hash(hash)
671
+ when "superscript" then AnnotationKindSuperscript.from_hash(hash)
672
+ when "highlight" then AnnotationKindHighlight.from_hash(hash)
673
+ when "link" then AnnotationKindLink.from_hash(hash)
674
+ else raise "Unknown discriminator: #{discriminator}"
730
675
  end
731
676
  end
732
677
  end
@@ -982,15 +927,13 @@ module HtmlToMarkdown
982
927
  # written in the source. Callers that need an absolute URL must resolve it against the
983
928
  # document base URL themselves.
984
929
  sig { returns(String) }
985
- # rubocop:disable Lint/UselessMethodDefinition
986
- def url = super
930
+ def url = super # rubocop:disable Lint/UselessMethodDefinition
987
931
  # The `title` attribute of the `<a>` element, if present.
988
932
  #
989
933
  # `None` when the `<a>` tag has no `title="..."` attribute. When present, the value
990
934
  # is copied verbatim — HTML entities within the title are not decoded.
991
935
  sig { returns(T.nilable(String)) }
992
- # rubocop:disable Lint/UselessMethodDefinition
993
- def title = super
936
+ def title = super # rubocop:disable Lint/UselessMethodDefinition
994
937
  sig { returns(T::Boolean) }
995
938
  def bold? = false
996
939
  sig { returns(T::Boolean) }
@@ -1017,3 +960,158 @@ module HtmlToMarkdown
1017
960
  end
1018
961
  end
1019
962
  end
963
+
964
+ module HtmlToMarkdown
965
+ # Result of a visitor callback.
966
+ #
967
+ # Allows visitors to control the conversion flow by either proceeding
968
+ # with default behavior, providing custom output, skipping elements,
969
+ # preserving HTML, or signaling errors.
970
+ module VisitResult
971
+ extend T::Helpers
972
+ extend T::Sig
973
+
974
+ interface!
975
+
976
+ # Dispatch from a Hash to the appropriate variant constructor.
977
+ # @param hash [Hash] with discriminator field and variant-specific fields
978
+ # @return [variant_class] an instance of the appropriate variant
979
+ sig { params(hash: T::Hash[T.untyped, T.untyped]).returns(T.untyped) }
980
+ def self.from_hash(hash)
981
+ discriminator = hash[:type] || hash["type"]
982
+ case discriminator
983
+ when "continue" then VisitResultContinue.from_hash(hash)
984
+ when "custom" then VisitResultCustom.from_hash(hash)
985
+ when "skip" then VisitResultSkip.from_hash(hash)
986
+ when "preserve_html" then VisitResultPreserveHtml.from_hash(hash)
987
+ when "error" then VisitResultError.from_hash(hash)
988
+ else raise "Unknown discriminator: #{discriminator}"
989
+ end
990
+ end
991
+ end
992
+ ## Continue with default conversion behavior
993
+ VisitResultContinue = Data.define do
994
+ include VisitResult
995
+ extend T::Sig
996
+
997
+ sig { returns(T::Boolean) }
998
+ def continue? = true
999
+ sig { returns(T::Boolean) }
1000
+ def custom? = false
1001
+ sig { returns(T::Boolean) }
1002
+ def skip? = false
1003
+ sig { returns(T::Boolean) }
1004
+ def preserve_html? = false
1005
+ sig { returns(T::Boolean) }
1006
+ def error? = false
1007
+ # @param hash [Hash] deserialized from the native extension
1008
+ # @return [self]
1009
+ sig { params(hash: T::Hash[T.untyped, T.untyped]).returns(T.attached_class) }
1010
+ def self.from_hash(hash)
1011
+ new
1012
+ end
1013
+ end
1014
+ ## Replace default output with custom markdown
1015
+ ##
1016
+ ## The visitor takes full responsibility for the markdown output
1017
+ ## of this node and its children.
1018
+ VisitResultCustom = Data.define(:value) do
1019
+ include VisitResult
1020
+ extend T::Sig
1021
+
1022
+ # @return [String]
1023
+ sig { returns(String) }
1024
+ def value = super # rubocop:disable Lint/UselessMethodDefinition
1025
+ sig { returns(T::Boolean) }
1026
+ def continue? = false
1027
+ sig { returns(T::Boolean) }
1028
+ def custom? = true
1029
+ sig { returns(T::Boolean) }
1030
+ def skip? = false
1031
+ sig { returns(T::Boolean) }
1032
+ def preserve_html? = false
1033
+ sig { returns(T::Boolean) }
1034
+ def error? = false
1035
+ # @param hash [Hash] deserialized from the native extension
1036
+ # @return [self]
1037
+ sig { params(hash: T::Hash[T.untyped, T.untyped]).returns(T.attached_class) }
1038
+ def self.from_hash(hash)
1039
+ new(value: hash[:_0] || hash["_0"])
1040
+ end
1041
+ end
1042
+ ## Skip this element entirely (don't output anything)
1043
+ ##
1044
+ ## The element and all its children are ignored in the output.
1045
+ VisitResultSkip = Data.define do
1046
+ include VisitResult
1047
+ extend T::Sig
1048
+
1049
+ sig { returns(T::Boolean) }
1050
+ def continue? = false
1051
+ sig { returns(T::Boolean) }
1052
+ def custom? = false
1053
+ sig { returns(T::Boolean) }
1054
+ def skip? = true
1055
+ sig { returns(T::Boolean) }
1056
+ def preserve_html? = false
1057
+ sig { returns(T::Boolean) }
1058
+ def error? = false
1059
+ # @param hash [Hash] deserialized from the native extension
1060
+ # @return [self]
1061
+ sig { params(hash: T::Hash[T.untyped, T.untyped]).returns(T.attached_class) }
1062
+ def self.from_hash(hash)
1063
+ new
1064
+ end
1065
+ end
1066
+ ## Preserve original HTML (don't convert to markdown)
1067
+ ##
1068
+ ## The element's raw HTML is included verbatim in the output.
1069
+ VisitResultPreserveHtml = Data.define do
1070
+ include VisitResult
1071
+ extend T::Sig
1072
+
1073
+ sig { returns(T::Boolean) }
1074
+ def continue? = false
1075
+ sig { returns(T::Boolean) }
1076
+ def custom? = false
1077
+ sig { returns(T::Boolean) }
1078
+ def skip? = false
1079
+ sig { returns(T::Boolean) }
1080
+ def preserve_html? = true
1081
+ sig { returns(T::Boolean) }
1082
+ def error? = false
1083
+ # @param hash [Hash] deserialized from the native extension
1084
+ # @return [self]
1085
+ sig { params(hash: T::Hash[T.untyped, T.untyped]).returns(T.attached_class) }
1086
+ def self.from_hash(hash)
1087
+ new
1088
+ end
1089
+ end
1090
+ ## Stop conversion with an error
1091
+ ##
1092
+ ## The conversion process halts and returns this error message.
1093
+ VisitResultError = Data.define(:value) do
1094
+ include VisitResult
1095
+ extend T::Sig
1096
+
1097
+ # @return [String]
1098
+ sig { returns(String) }
1099
+ def value = super # rubocop:disable Lint/UselessMethodDefinition
1100
+ sig { returns(T::Boolean) }
1101
+ def continue? = false
1102
+ sig { returns(T::Boolean) }
1103
+ def custom? = false
1104
+ sig { returns(T::Boolean) }
1105
+ def skip? = false
1106
+ sig { returns(T::Boolean) }
1107
+ def preserve_html? = false
1108
+ sig { returns(T::Boolean) }
1109
+ def error? = true
1110
+ # @param hash [Hash] deserialized from the native extension
1111
+ # @return [self]
1112
+ sig { params(hash: T::Hash[T.untyped, T.untyped]).returns(T.attached_class) }
1113
+ def self.from_hash(hash)
1114
+ new(value: hash[:_0] || hash["_0"])
1115
+ end
1116
+ end
1117
+ end
@@ -1,10 +1,10 @@
1
1
  # This file is auto-generated by alef — DO NOT EDIT.
2
- # alef:hash:f44000653901d10b61e9069d2e901a11b70b0e643ba63d75f2222729c924ae82
2
+ # alef:hash:b91f80d853da057a497660797e08ed766f3540e488f2c58b16c5f100dd6d8f04
3
3
  # To regenerate: alef generate
4
- # To verify freshness: alef verify --exit-code
4
+ # To verify freshness: alef verify
5
5
  # frozen_string_literal: true
6
6
 
7
7
  module HtmlToMarkdown
8
8
  ## The version string for this package.
9
- VERSION = "3.10.6"
9
+ VERSION = "3.11.2"
10
10
  end
@@ -1,7 +1,7 @@
1
1
  # This file is auto-generated by alef — DO NOT EDIT.
2
- # alef:hash:f44000653901d10b61e9069d2e901a11b70b0e643ba63d75f2222729c924ae82
2
+ # alef:hash:cc885f84ff886e0b8811b1fd3b76314a149b879662c55f3a50a694f4126c029f
3
3
  # To regenerate: alef generate
4
- # To verify freshness: alef verify --exit-code
4
+ # To verify freshness: alef verify
5
5
  # frozen_string_literal: true
6
6
 
7
7
  require_relative "html_to_markdown/version"
Binary file