html-to-markdown 3.1.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +42 -12
- data/Gemfile +1 -0
- data/Gemfile.lock +27 -55
- data/README.md +9 -10
- data/Rakefile +4 -10
- data/ext/html-to-markdown_rb/Cargo.toml +14 -0
- data/ext/html_to_markdown_rb/Cargo.toml +16 -0
- data/ext/html_to_markdown_rb/extconf.rb +10 -0
- data/ext/html_to_markdown_rb/src/html_to_markdown_rs/version.rb +6 -0
- data/ext/html_to_markdown_rb/src/html_to_markdown_rs.rb +9 -0
- data/ext/html_to_markdown_rb/src/lib.rs +3941 -0
- data/html-to-markdown-rb.gemspec +1 -1
- data/lib/html_to_markdown/version.rb +1 -1
- data/lib/html_to_markdown.rb +31 -21
- data/{ext/html-to-markdown-rb/native/extconf.rb → lib/html_to_markdown_rs.rb} +1 -1
- data/sig/html_to_markdown.rbs +17 -5
- data/vendor/Cargo.toml +4 -4
- data/vendor/html-to-markdown-rs/Cargo.toml +2 -2
- data/vendor/html-to-markdown-rs/examples/test_deser.rs +12 -0
- data/vendor/html-to-markdown-rs/src/converter/block/mod.rs +1 -1
- data/vendor/html-to-markdown-rs/src/converter/block/table/mod.rs +1 -1
- data/vendor/html-to-markdown-rs/src/converter/form/mod.rs +1 -1
- data/vendor/html-to-markdown-rs/src/converter/inline/mod.rs +1 -1
- data/vendor/html-to-markdown-rs/src/converter/list/item.rs +10 -2
- data/vendor/html-to-markdown-rs/src/converter/mod.rs +2 -2
- data/vendor/html-to-markdown-rs/src/converter/semantic/mod.rs +1 -1
- data/vendor/html-to-markdown-rs/src/converter/utility/content.rs +1 -1
- data/vendor/html-to-markdown-rs/src/exports.rs +3 -3
- data/vendor/html-to-markdown-rs/src/inline_images.rs +1 -1
- data/vendor/html-to-markdown-rs/src/lib.rs +1 -2
- data/vendor/html-to-markdown-rs/src/metadata/config.rs +1 -1
- data/vendor/html-to-markdown-rs/src/metadata/mod.rs +5 -5
- data/vendor/html-to-markdown-rs/src/options/conversion.rs +6 -12
- data/vendor/html-to-markdown-rs/src/options/mod.rs +1 -1
- data/vendor/html-to-markdown-rs/src/options/preprocessing.rs +3 -9
- data/vendor/html-to-markdown-rs/src/options/validation.rs +3 -3
- data/vendor/html-to-markdown-rs/src/types/document.rs +11 -0
- data/vendor/html-to-markdown-rs/src/types/result.rs +5 -2
- data/vendor/html-to-markdown-rs/src/types/tables.rs +1 -1
- data/vendor/html-to-markdown-rs/src/visitor/mod.rs +1 -1
- data/vendor/html-to-markdown-rs/src/visitor_helpers/helpers/state.rs +1 -1
- data/vendor/html-to-markdown-rs/src/visitor_helpers/helpers/traversal.rs +1 -1
- data/vendor/html-to-markdown-rs/src/visitor_helpers.rs +8 -8
- data/vendor/html-to-markdown-rs/tests/commonmark_compliance_test.rs +6 -0
- data/vendor/html-to-markdown-rs/tests/integration_test.rs +3 -3
- data/vendor/html-to-markdown-rs/tests/issue_140_regressions.rs +8 -2
- data/vendor/html-to-markdown-rs/tests/lists_test.rs +4 -4
- metadata +11 -18
- data/ext/html-to-markdown-rb/extconf.rb +0 -41
- data/ext/html-to-markdown-rb/native/Cargo.lock +0 -934
- data/ext/html-to-markdown-rb/native/Cargo.toml +0 -48
- data/ext/html-to-markdown-rb/native/README.md +0 -215
- data/ext/html-to-markdown-rb/native/src/conversion/inline_images.rs +0 -54
- data/ext/html-to-markdown-rb/native/src/conversion/metadata.rs +0 -158
- data/ext/html-to-markdown-rb/native/src/conversion/mod.rs +0 -11
- data/ext/html-to-markdown-rb/native/src/lib.rs +0 -128
- data/ext/html-to-markdown-rb/native/src/options.rs +0 -238
- data/ext/html-to-markdown-rb/native/src/types.rs +0 -24
- data/lib/html_to_markdown/cli.rb +0 -21
- data/lib/html_to_markdown/cli_proxy.rb +0 -74
- data/spec/cli_proxy_spec.rb +0 -42
- data/spec/spec_helper.rb +0 -10
|
@@ -0,0 +1,3941 @@
|
|
|
1
|
+
// This file is auto-generated by alef. DO NOT EDIT.
|
|
2
|
+
// Re-generate with: alef generate
|
|
3
|
+
#![allow(dead_code)]
|
|
4
|
+
|
|
5
|
+
use magnus::{Error, IntoValueFromNative, Ruby, function, method, prelude::*, try_convert::TryConvertOwned};
|
|
6
|
+
use std::collections::HashMap;
|
|
7
|
+
use std::sync::Arc;
|
|
8
|
+
|
|
9
|
+
fn json_to_ruby(handle: &Ruby, val: serde_json::Value) -> magnus::Value {
|
|
10
|
+
use magnus::IntoValue;
|
|
11
|
+
match val {
|
|
12
|
+
serde_json::Value::Null => handle.qnil().into_value_with(handle),
|
|
13
|
+
serde_json::Value::Bool(b) => b.into_value_with(handle),
|
|
14
|
+
serde_json::Value::Number(n) => {
|
|
15
|
+
if let Some(i) = n.as_i64() {
|
|
16
|
+
i.into_value_with(handle)
|
|
17
|
+
} else if let Some(f) = n.as_f64() {
|
|
18
|
+
f.into_value_with(handle)
|
|
19
|
+
} else {
|
|
20
|
+
handle.qnil().into_value_with(handle)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
serde_json::Value::String(s) => s.into_value_with(handle),
|
|
24
|
+
serde_json::Value::Array(arr) => {
|
|
25
|
+
let ruby_arr = handle.ary_new_capa(arr.len());
|
|
26
|
+
for item in arr {
|
|
27
|
+
let _ = ruby_arr.push(json_to_ruby(handle, item));
|
|
28
|
+
}
|
|
29
|
+
ruby_arr.into_value_with(handle)
|
|
30
|
+
}
|
|
31
|
+
serde_json::Value::Object(map) => {
|
|
32
|
+
let hash = handle.hash_new();
|
|
33
|
+
for (k, v) in map {
|
|
34
|
+
let key = handle.to_symbol(&k);
|
|
35
|
+
let val = json_to_ruby(handle, v);
|
|
36
|
+
let _ = hash.aset(key, val);
|
|
37
|
+
}
|
|
38
|
+
hash.into_value_with(handle)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
|
44
|
+
#[magnus::wrap(class = "HtmlToMarkdownRs::MetadataConfig")]
|
|
45
|
+
#[serde(default)]
|
|
46
|
+
pub struct MetadataConfig {
|
|
47
|
+
pub extract_document: bool,
|
|
48
|
+
pub extract_headers: bool,
|
|
49
|
+
pub extract_links: bool,
|
|
50
|
+
pub extract_images: bool,
|
|
51
|
+
pub extract_structured_data: bool,
|
|
52
|
+
pub max_structured_data_size: usize,
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
unsafe impl IntoValueFromNative for MetadataConfig {}
|
|
56
|
+
|
|
57
|
+
impl magnus::TryConvert for MetadataConfig {
|
|
58
|
+
fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
|
|
59
|
+
let r: &MetadataConfig = magnus::TryConvert::try_convert(val)?;
|
|
60
|
+
Ok(r.clone())
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
unsafe impl TryConvertOwned for MetadataConfig {}
|
|
64
|
+
|
|
65
|
+
impl Default for MetadataConfig {
|
|
66
|
+
fn default() -> Self {
|
|
67
|
+
Self {
|
|
68
|
+
extract_document: Default::default(),
|
|
69
|
+
extract_headers: Default::default(),
|
|
70
|
+
extract_links: Default::default(),
|
|
71
|
+
extract_images: Default::default(),
|
|
72
|
+
extract_structured_data: Default::default(),
|
|
73
|
+
max_structured_data_size: Default::default(),
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
impl MetadataConfig {
|
|
79
|
+
fn new(
|
|
80
|
+
extract_document: Option<bool>,
|
|
81
|
+
extract_headers: Option<bool>,
|
|
82
|
+
extract_links: Option<bool>,
|
|
83
|
+
extract_images: Option<bool>,
|
|
84
|
+
extract_structured_data: Option<bool>,
|
|
85
|
+
max_structured_data_size: Option<usize>,
|
|
86
|
+
) -> Self {
|
|
87
|
+
Self {
|
|
88
|
+
extract_document: extract_document.unwrap_or(true),
|
|
89
|
+
extract_headers: extract_headers.unwrap_or(true),
|
|
90
|
+
extract_links: extract_links.unwrap_or(true),
|
|
91
|
+
extract_images: extract_images.unwrap_or(true),
|
|
92
|
+
extract_structured_data: extract_structured_data.unwrap_or(true),
|
|
93
|
+
max_structured_data_size: max_structured_data_size.unwrap_or_default(),
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
fn extract_document(&self) -> bool {
|
|
98
|
+
self.extract_document
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
fn extract_headers(&self) -> bool {
|
|
102
|
+
self.extract_headers
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
fn extract_links(&self) -> bool {
|
|
106
|
+
self.extract_links
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
fn extract_images(&self) -> bool {
|
|
110
|
+
self.extract_images
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
fn extract_structured_data(&self) -> bool {
|
|
114
|
+
self.extract_structured_data
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
fn max_structured_data_size(&self) -> usize {
|
|
118
|
+
self.max_structured_data_size
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
fn any_enabled(&self) -> bool {
|
|
122
|
+
let core_self = html_to_markdown_rs::metadata::MetadataConfig {
|
|
123
|
+
extract_document: self.extract_document,
|
|
124
|
+
extract_headers: self.extract_headers,
|
|
125
|
+
extract_links: self.extract_links,
|
|
126
|
+
extract_images: self.extract_images,
|
|
127
|
+
extract_structured_data: self.extract_structured_data,
|
|
128
|
+
max_structured_data_size: self.max_structured_data_size,
|
|
129
|
+
};
|
|
130
|
+
core_self.any_enabled()
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
|
135
|
+
#[magnus::wrap(class = "HtmlToMarkdownRs::MetadataConfigUpdate")]
|
|
136
|
+
#[serde(default)]
|
|
137
|
+
pub struct MetadataConfigUpdate {
|
|
138
|
+
pub extract_document: Option<bool>,
|
|
139
|
+
pub extract_headers: Option<bool>,
|
|
140
|
+
pub extract_links: Option<bool>,
|
|
141
|
+
pub extract_images: Option<bool>,
|
|
142
|
+
pub extract_structured_data: Option<bool>,
|
|
143
|
+
pub max_structured_data_size: Option<usize>,
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
unsafe impl IntoValueFromNative for MetadataConfigUpdate {}
|
|
147
|
+
|
|
148
|
+
impl magnus::TryConvert for MetadataConfigUpdate {
|
|
149
|
+
fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
|
|
150
|
+
let r: &MetadataConfigUpdate = magnus::TryConvert::try_convert(val)?;
|
|
151
|
+
Ok(r.clone())
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
unsafe impl TryConvertOwned for MetadataConfigUpdate {}
|
|
155
|
+
|
|
156
|
+
impl Default for MetadataConfigUpdate {
|
|
157
|
+
fn default() -> Self {
|
|
158
|
+
Self {
|
|
159
|
+
extract_document: Default::default(),
|
|
160
|
+
extract_headers: Default::default(),
|
|
161
|
+
extract_links: Default::default(),
|
|
162
|
+
extract_images: Default::default(),
|
|
163
|
+
extract_structured_data: Default::default(),
|
|
164
|
+
max_structured_data_size: Default::default(),
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
impl MetadataConfigUpdate {
|
|
170
|
+
fn new(
|
|
171
|
+
extract_document: Option<bool>,
|
|
172
|
+
extract_headers: Option<bool>,
|
|
173
|
+
extract_links: Option<bool>,
|
|
174
|
+
extract_images: Option<bool>,
|
|
175
|
+
extract_structured_data: Option<bool>,
|
|
176
|
+
max_structured_data_size: Option<usize>,
|
|
177
|
+
) -> Self {
|
|
178
|
+
Self {
|
|
179
|
+
extract_document,
|
|
180
|
+
extract_headers,
|
|
181
|
+
extract_links,
|
|
182
|
+
extract_images,
|
|
183
|
+
extract_structured_data,
|
|
184
|
+
max_structured_data_size,
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
fn extract_document(&self) -> Option<bool> {
|
|
189
|
+
self.extract_document
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
fn extract_headers(&self) -> Option<bool> {
|
|
193
|
+
self.extract_headers
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
fn extract_links(&self) -> Option<bool> {
|
|
197
|
+
self.extract_links
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
fn extract_images(&self) -> Option<bool> {
|
|
201
|
+
self.extract_images
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
fn extract_structured_data(&self) -> Option<bool> {
|
|
205
|
+
self.extract_structured_data
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
fn max_structured_data_size(&self) -> Option<usize> {
|
|
209
|
+
self.max_structured_data_size
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
|
214
|
+
#[magnus::wrap(class = "HtmlToMarkdownRs::DocumentMetadata")]
|
|
215
|
+
#[serde(default)]
|
|
216
|
+
pub struct DocumentMetadata {
|
|
217
|
+
pub title: Option<String>,
|
|
218
|
+
pub description: Option<String>,
|
|
219
|
+
pub keywords: Vec<String>,
|
|
220
|
+
pub author: Option<String>,
|
|
221
|
+
pub canonical_url: Option<String>,
|
|
222
|
+
pub base_href: Option<String>,
|
|
223
|
+
pub language: Option<String>,
|
|
224
|
+
pub text_direction: Option<TextDirection>,
|
|
225
|
+
pub open_graph: HashMap<String, String>,
|
|
226
|
+
pub twitter_card: HashMap<String, String>,
|
|
227
|
+
pub meta_tags: HashMap<String, String>,
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
unsafe impl IntoValueFromNative for DocumentMetadata {}
|
|
231
|
+
|
|
232
|
+
impl magnus::TryConvert for DocumentMetadata {
|
|
233
|
+
fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
|
|
234
|
+
let r: &DocumentMetadata = magnus::TryConvert::try_convert(val)?;
|
|
235
|
+
Ok(r.clone())
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
unsafe impl TryConvertOwned for DocumentMetadata {}
|
|
239
|
+
|
|
240
|
+
impl Default for DocumentMetadata {
|
|
241
|
+
fn default() -> Self {
|
|
242
|
+
Self {
|
|
243
|
+
title: Default::default(),
|
|
244
|
+
description: Default::default(),
|
|
245
|
+
keywords: Default::default(),
|
|
246
|
+
author: Default::default(),
|
|
247
|
+
canonical_url: Default::default(),
|
|
248
|
+
base_href: Default::default(),
|
|
249
|
+
language: Default::default(),
|
|
250
|
+
text_direction: Default::default(),
|
|
251
|
+
open_graph: Default::default(),
|
|
252
|
+
twitter_card: Default::default(),
|
|
253
|
+
meta_tags: Default::default(),
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
impl DocumentMetadata {
|
|
259
|
+
fn new(
|
|
260
|
+
title: Option<String>,
|
|
261
|
+
description: Option<String>,
|
|
262
|
+
keywords: Option<Vec<String>>,
|
|
263
|
+
author: Option<String>,
|
|
264
|
+
canonical_url: Option<String>,
|
|
265
|
+
base_href: Option<String>,
|
|
266
|
+
language: Option<String>,
|
|
267
|
+
text_direction: Option<TextDirection>,
|
|
268
|
+
open_graph: Option<HashMap<String, String>>,
|
|
269
|
+
twitter_card: Option<HashMap<String, String>>,
|
|
270
|
+
meta_tags: Option<HashMap<String, String>>,
|
|
271
|
+
) -> Self {
|
|
272
|
+
Self {
|
|
273
|
+
title,
|
|
274
|
+
description,
|
|
275
|
+
keywords: keywords.unwrap_or_default(),
|
|
276
|
+
author,
|
|
277
|
+
canonical_url,
|
|
278
|
+
base_href,
|
|
279
|
+
language,
|
|
280
|
+
text_direction,
|
|
281
|
+
open_graph: open_graph.unwrap_or_default(),
|
|
282
|
+
twitter_card: twitter_card.unwrap_or_default(),
|
|
283
|
+
meta_tags: meta_tags.unwrap_or_default(),
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
fn title(&self) -> Option<String> {
|
|
288
|
+
self.title.clone()
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
fn description(&self) -> Option<String> {
|
|
292
|
+
self.description.clone()
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
fn keywords(&self) -> Vec<String> {
|
|
296
|
+
self.keywords.clone()
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
fn author(&self) -> Option<String> {
|
|
300
|
+
self.author.clone()
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
fn canonical_url(&self) -> Option<String> {
|
|
304
|
+
self.canonical_url.clone()
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
fn base_href(&self) -> Option<String> {
|
|
308
|
+
self.base_href.clone()
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
fn language(&self) -> Option<String> {
|
|
312
|
+
self.language.clone()
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
fn text_direction(&self) -> Option<TextDirection> {
|
|
316
|
+
self.text_direction.clone()
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
fn open_graph(&self) -> HashMap<String, String> {
|
|
320
|
+
self.open_graph.clone()
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
fn twitter_card(&self) -> HashMap<String, String> {
|
|
324
|
+
self.twitter_card.clone()
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
fn meta_tags(&self) -> HashMap<String, String> {
|
|
328
|
+
self.meta_tags.clone()
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
|
333
|
+
#[magnus::wrap(class = "HtmlToMarkdownRs::HeaderMetadata")]
|
|
334
|
+
pub struct HeaderMetadata {
|
|
335
|
+
pub level: u8,
|
|
336
|
+
pub text: String,
|
|
337
|
+
pub id: Option<String>,
|
|
338
|
+
pub depth: usize,
|
|
339
|
+
pub html_offset: usize,
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
unsafe impl IntoValueFromNative for HeaderMetadata {}
|
|
343
|
+
|
|
344
|
+
impl magnus::TryConvert for HeaderMetadata {
|
|
345
|
+
fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
|
|
346
|
+
let r: &HeaderMetadata = magnus::TryConvert::try_convert(val)?;
|
|
347
|
+
Ok(r.clone())
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
unsafe impl TryConvertOwned for HeaderMetadata {}
|
|
351
|
+
|
|
352
|
+
impl HeaderMetadata {
|
|
353
|
+
fn new(level: u8, text: String, depth: usize, html_offset: usize, id: Option<String>) -> Self {
|
|
354
|
+
Self {
|
|
355
|
+
level,
|
|
356
|
+
text,
|
|
357
|
+
id,
|
|
358
|
+
depth,
|
|
359
|
+
html_offset,
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
fn level(&self) -> u8 {
|
|
364
|
+
self.level
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
fn text(&self) -> String {
|
|
368
|
+
self.text.clone()
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
fn id(&self) -> Option<String> {
|
|
372
|
+
self.id.clone()
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
fn depth(&self) -> usize {
|
|
376
|
+
self.depth
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
fn html_offset(&self) -> usize {
|
|
380
|
+
self.html_offset
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
fn is_valid(&self) -> bool {
|
|
384
|
+
let core_self = html_to_markdown_rs::metadata::HeaderMetadata {
|
|
385
|
+
level: self.level,
|
|
386
|
+
text: self.text.clone(),
|
|
387
|
+
id: self.id.clone(),
|
|
388
|
+
depth: self.depth,
|
|
389
|
+
html_offset: self.html_offset,
|
|
390
|
+
};
|
|
391
|
+
core_self.is_valid()
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
|
396
|
+
#[magnus::wrap(class = "HtmlToMarkdownRs::LinkMetadata")]
|
|
397
|
+
pub struct LinkMetadata {
|
|
398
|
+
pub href: String,
|
|
399
|
+
pub text: String,
|
|
400
|
+
pub title: Option<String>,
|
|
401
|
+
pub link_type: LinkType,
|
|
402
|
+
pub rel: Vec<String>,
|
|
403
|
+
pub attributes: HashMap<String, String>,
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
unsafe impl IntoValueFromNative for LinkMetadata {}
|
|
407
|
+
|
|
408
|
+
impl magnus::TryConvert for LinkMetadata {
|
|
409
|
+
fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
|
|
410
|
+
let r: &LinkMetadata = magnus::TryConvert::try_convert(val)?;
|
|
411
|
+
Ok(r.clone())
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
unsafe impl TryConvertOwned for LinkMetadata {}
|
|
415
|
+
|
|
416
|
+
impl LinkMetadata {
|
|
417
|
+
fn new(
|
|
418
|
+
href: String,
|
|
419
|
+
text: String,
|
|
420
|
+
link_type: LinkType,
|
|
421
|
+
rel: Vec<String>,
|
|
422
|
+
attributes: HashMap<String, String>,
|
|
423
|
+
title: Option<String>,
|
|
424
|
+
) -> Self {
|
|
425
|
+
Self {
|
|
426
|
+
href,
|
|
427
|
+
text,
|
|
428
|
+
title,
|
|
429
|
+
link_type,
|
|
430
|
+
rel,
|
|
431
|
+
attributes,
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
fn href(&self) -> String {
|
|
436
|
+
self.href.clone()
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
fn text(&self) -> String {
|
|
440
|
+
self.text.clone()
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
fn title(&self) -> Option<String> {
|
|
444
|
+
self.title.clone()
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
fn link_type(&self) -> LinkType {
|
|
448
|
+
self.link_type.clone()
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
fn rel(&self) -> Vec<String> {
|
|
452
|
+
self.rel.clone()
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
fn attributes(&self) -> HashMap<String, String> {
|
|
456
|
+
self.attributes.clone()
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
|
461
|
+
#[magnus::wrap(class = "HtmlToMarkdownRs::ImageMetadata")]
|
|
462
|
+
pub struct ImageMetadata {
|
|
463
|
+
pub src: String,
|
|
464
|
+
pub alt: Option<String>,
|
|
465
|
+
pub title: Option<String>,
|
|
466
|
+
pub dimensions: Option<String>,
|
|
467
|
+
pub image_type: ImageType,
|
|
468
|
+
pub attributes: HashMap<String, String>,
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
unsafe impl IntoValueFromNative for ImageMetadata {}
|
|
472
|
+
|
|
473
|
+
impl magnus::TryConvert for ImageMetadata {
|
|
474
|
+
fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
|
|
475
|
+
let r: &ImageMetadata = magnus::TryConvert::try_convert(val)?;
|
|
476
|
+
Ok(r.clone())
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
unsafe impl TryConvertOwned for ImageMetadata {}
|
|
480
|
+
|
|
481
|
+
impl ImageMetadata {
|
|
482
|
+
fn new(
|
|
483
|
+
src: String,
|
|
484
|
+
image_type: ImageType,
|
|
485
|
+
attributes: HashMap<String, String>,
|
|
486
|
+
alt: Option<String>,
|
|
487
|
+
title: Option<String>,
|
|
488
|
+
dimensions: Option<String>,
|
|
489
|
+
) -> Self {
|
|
490
|
+
Self {
|
|
491
|
+
src,
|
|
492
|
+
alt,
|
|
493
|
+
title,
|
|
494
|
+
dimensions,
|
|
495
|
+
image_type,
|
|
496
|
+
attributes,
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
fn src(&self) -> String {
|
|
501
|
+
self.src.clone()
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
fn alt(&self) -> Option<String> {
|
|
505
|
+
self.alt.clone()
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
fn title(&self) -> Option<String> {
|
|
509
|
+
self.title.clone()
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
fn dimensions(&self) -> Option<String> {
|
|
513
|
+
self.dimensions.clone()
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
fn image_type(&self) -> ImageType {
|
|
517
|
+
self.image_type.clone()
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
fn attributes(&self) -> HashMap<String, String> {
|
|
521
|
+
self.attributes.clone()
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
|
526
|
+
#[magnus::wrap(class = "HtmlToMarkdownRs::StructuredData")]
|
|
527
|
+
pub struct StructuredData {
|
|
528
|
+
pub data_type: StructuredDataType,
|
|
529
|
+
pub raw_json: String,
|
|
530
|
+
pub schema_type: Option<String>,
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
unsafe impl IntoValueFromNative for StructuredData {}
|
|
534
|
+
|
|
535
|
+
impl magnus::TryConvert for StructuredData {
|
|
536
|
+
fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
|
|
537
|
+
let r: &StructuredData = magnus::TryConvert::try_convert(val)?;
|
|
538
|
+
Ok(r.clone())
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
unsafe impl TryConvertOwned for StructuredData {}
|
|
542
|
+
|
|
543
|
+
impl StructuredData {
|
|
544
|
+
fn new(data_type: StructuredDataType, raw_json: String, schema_type: Option<String>) -> Self {
|
|
545
|
+
Self {
|
|
546
|
+
data_type,
|
|
547
|
+
raw_json,
|
|
548
|
+
schema_type,
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
fn data_type(&self) -> StructuredDataType {
|
|
553
|
+
self.data_type.clone()
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
fn raw_json(&self) -> String {
|
|
557
|
+
self.raw_json.clone()
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
fn schema_type(&self) -> Option<String> {
|
|
561
|
+
self.schema_type.clone()
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
|
566
|
+
#[magnus::wrap(class = "HtmlToMarkdownRs::HtmlMetadata")]
|
|
567
|
+
#[serde(default)]
|
|
568
|
+
pub struct HtmlMetadata {
|
|
569
|
+
pub document: DocumentMetadata,
|
|
570
|
+
pub headers: Vec<HeaderMetadata>,
|
|
571
|
+
pub links: Vec<LinkMetadata>,
|
|
572
|
+
pub images: Vec<ImageMetadata>,
|
|
573
|
+
pub structured_data: Vec<StructuredData>,
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
unsafe impl IntoValueFromNative for HtmlMetadata {}
|
|
577
|
+
|
|
578
|
+
impl magnus::TryConvert for HtmlMetadata {
|
|
579
|
+
fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
|
|
580
|
+
let r: &HtmlMetadata = magnus::TryConvert::try_convert(val)?;
|
|
581
|
+
Ok(r.clone())
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
unsafe impl TryConvertOwned for HtmlMetadata {}
|
|
585
|
+
|
|
586
|
+
impl Default for HtmlMetadata {
|
|
587
|
+
fn default() -> Self {
|
|
588
|
+
Self {
|
|
589
|
+
document: Default::default(),
|
|
590
|
+
headers: Default::default(),
|
|
591
|
+
links: Default::default(),
|
|
592
|
+
images: Default::default(),
|
|
593
|
+
structured_data: Default::default(),
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
impl HtmlMetadata {
|
|
599
|
+
fn new(
|
|
600
|
+
document: Option<DocumentMetadata>,
|
|
601
|
+
headers: Option<Vec<HeaderMetadata>>,
|
|
602
|
+
links: Option<Vec<LinkMetadata>>,
|
|
603
|
+
images: Option<Vec<ImageMetadata>>,
|
|
604
|
+
structured_data: Option<Vec<StructuredData>>,
|
|
605
|
+
) -> Self {
|
|
606
|
+
Self {
|
|
607
|
+
document: document.unwrap_or_default(),
|
|
608
|
+
headers: headers.unwrap_or_default(),
|
|
609
|
+
links: links.unwrap_or_default(),
|
|
610
|
+
images: images.unwrap_or_default(),
|
|
611
|
+
structured_data: structured_data.unwrap_or_default(),
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
fn document(&self) -> DocumentMetadata {
|
|
616
|
+
self.document.clone()
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
fn headers(&self) -> Vec<HeaderMetadata> {
|
|
620
|
+
self.headers.clone()
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
fn links(&self) -> Vec<LinkMetadata> {
|
|
624
|
+
self.links.clone()
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
fn images(&self) -> Vec<ImageMetadata> {
|
|
628
|
+
self.images.clone()
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
fn structured_data(&self) -> Vec<StructuredData> {
|
|
632
|
+
self.structured_data.clone()
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
|
637
|
+
#[magnus::wrap(class = "HtmlToMarkdownRs::ConversionOptions")]
|
|
638
|
+
#[serde(default)]
|
|
639
|
+
pub struct ConversionOptions {
|
|
640
|
+
pub heading_style: HeadingStyle,
|
|
641
|
+
pub list_indent_type: ListIndentType,
|
|
642
|
+
pub list_indent_width: usize,
|
|
643
|
+
pub bullets: String,
|
|
644
|
+
pub strong_em_symbol: String,
|
|
645
|
+
pub escape_asterisks: bool,
|
|
646
|
+
pub escape_underscores: bool,
|
|
647
|
+
pub escape_misc: bool,
|
|
648
|
+
pub escape_ascii: bool,
|
|
649
|
+
pub code_language: String,
|
|
650
|
+
pub autolinks: bool,
|
|
651
|
+
pub default_title: bool,
|
|
652
|
+
pub br_in_tables: bool,
|
|
653
|
+
pub highlight_style: HighlightStyle,
|
|
654
|
+
pub extract_metadata: bool,
|
|
655
|
+
pub whitespace_mode: WhitespaceMode,
|
|
656
|
+
pub strip_newlines: bool,
|
|
657
|
+
pub wrap: bool,
|
|
658
|
+
pub wrap_width: usize,
|
|
659
|
+
pub convert_as_inline: bool,
|
|
660
|
+
pub sub_symbol: String,
|
|
661
|
+
pub sup_symbol: String,
|
|
662
|
+
pub newline_style: NewlineStyle,
|
|
663
|
+
pub code_block_style: CodeBlockStyle,
|
|
664
|
+
pub keep_inline_images_in: Vec<String>,
|
|
665
|
+
pub preprocessing: PreprocessingOptions,
|
|
666
|
+
pub encoding: String,
|
|
667
|
+
pub debug: bool,
|
|
668
|
+
pub strip_tags: Vec<String>,
|
|
669
|
+
pub preserve_tags: Vec<String>,
|
|
670
|
+
pub skip_images: bool,
|
|
671
|
+
pub link_style: LinkStyle,
|
|
672
|
+
pub output_format: OutputFormat,
|
|
673
|
+
pub include_document_structure: bool,
|
|
674
|
+
pub extract_images: bool,
|
|
675
|
+
pub max_image_size: u64,
|
|
676
|
+
pub capture_svg: bool,
|
|
677
|
+
pub infer_dimensions: bool,
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
unsafe impl IntoValueFromNative for ConversionOptions {}
|
|
681
|
+
|
|
682
|
+
impl magnus::TryConvert for ConversionOptions {
|
|
683
|
+
fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
|
|
684
|
+
let r: &ConversionOptions = magnus::TryConvert::try_convert(val)?;
|
|
685
|
+
Ok(r.clone())
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
unsafe impl TryConvertOwned for ConversionOptions {}
|
|
689
|
+
|
|
690
|
+
impl Default for ConversionOptions {
|
|
691
|
+
fn default() -> Self {
|
|
692
|
+
Self {
|
|
693
|
+
heading_style: Default::default(),
|
|
694
|
+
list_indent_type: Default::default(),
|
|
695
|
+
list_indent_width: Default::default(),
|
|
696
|
+
bullets: Default::default(),
|
|
697
|
+
strong_em_symbol: Default::default(),
|
|
698
|
+
escape_asterisks: Default::default(),
|
|
699
|
+
escape_underscores: Default::default(),
|
|
700
|
+
escape_misc: Default::default(),
|
|
701
|
+
escape_ascii: Default::default(),
|
|
702
|
+
code_language: Default::default(),
|
|
703
|
+
autolinks: Default::default(),
|
|
704
|
+
default_title: Default::default(),
|
|
705
|
+
br_in_tables: Default::default(),
|
|
706
|
+
highlight_style: Default::default(),
|
|
707
|
+
extract_metadata: Default::default(),
|
|
708
|
+
whitespace_mode: Default::default(),
|
|
709
|
+
strip_newlines: Default::default(),
|
|
710
|
+
wrap: Default::default(),
|
|
711
|
+
wrap_width: Default::default(),
|
|
712
|
+
convert_as_inline: Default::default(),
|
|
713
|
+
sub_symbol: Default::default(),
|
|
714
|
+
sup_symbol: Default::default(),
|
|
715
|
+
newline_style: Default::default(),
|
|
716
|
+
code_block_style: Default::default(),
|
|
717
|
+
keep_inline_images_in: Default::default(),
|
|
718
|
+
preprocessing: Default::default(),
|
|
719
|
+
encoding: Default::default(),
|
|
720
|
+
debug: Default::default(),
|
|
721
|
+
strip_tags: Default::default(),
|
|
722
|
+
preserve_tags: Default::default(),
|
|
723
|
+
skip_images: Default::default(),
|
|
724
|
+
link_style: Default::default(),
|
|
725
|
+
output_format: Default::default(),
|
|
726
|
+
include_document_structure: Default::default(),
|
|
727
|
+
extract_images: Default::default(),
|
|
728
|
+
max_image_size: Default::default(),
|
|
729
|
+
capture_svg: Default::default(),
|
|
730
|
+
infer_dimensions: Default::default(),
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
impl ConversionOptions {
|
|
736
|
+
fn new(kwargs: magnus::RHash) -> Result<Self, magnus::Error> {
|
|
737
|
+
let ruby = unsafe { magnus::Ruby::get_unchecked() };
|
|
738
|
+
Ok(Self {
|
|
739
|
+
heading_style: kwargs
|
|
740
|
+
.get(ruby.to_symbol("heading_style"))
|
|
741
|
+
.and_then(|v| HeadingStyle::try_convert(v).ok())
|
|
742
|
+
.unwrap_or_default(),
|
|
743
|
+
list_indent_type: kwargs
|
|
744
|
+
.get(ruby.to_symbol("list_indent_type"))
|
|
745
|
+
.and_then(|v| ListIndentType::try_convert(v).ok())
|
|
746
|
+
.unwrap_or_default(),
|
|
747
|
+
list_indent_width: kwargs
|
|
748
|
+
.get(ruby.to_symbol("list_indent_width"))
|
|
749
|
+
.and_then(|v| usize::try_convert(v).ok())
|
|
750
|
+
.unwrap_or(2),
|
|
751
|
+
bullets: kwargs
|
|
752
|
+
.get(ruby.to_symbol("bullets"))
|
|
753
|
+
.and_then(|v| String::try_convert(v).ok())
|
|
754
|
+
.unwrap_or("-*+".to_string()),
|
|
755
|
+
strong_em_symbol: kwargs
|
|
756
|
+
.get(ruby.to_symbol("strong_em_symbol"))
|
|
757
|
+
.and_then(|v| String::try_convert(v).ok())
|
|
758
|
+
.unwrap_or("*".to_string()),
|
|
759
|
+
escape_asterisks: kwargs
|
|
760
|
+
.get(ruby.to_symbol("escape_asterisks"))
|
|
761
|
+
.and_then(|v| bool::try_convert(v).ok())
|
|
762
|
+
.unwrap_or(false),
|
|
763
|
+
escape_underscores: kwargs
|
|
764
|
+
.get(ruby.to_symbol("escape_underscores"))
|
|
765
|
+
.and_then(|v| bool::try_convert(v).ok())
|
|
766
|
+
.unwrap_or(false),
|
|
767
|
+
escape_misc: kwargs
|
|
768
|
+
.get(ruby.to_symbol("escape_misc"))
|
|
769
|
+
.and_then(|v| bool::try_convert(v).ok())
|
|
770
|
+
.unwrap_or(false),
|
|
771
|
+
escape_ascii: kwargs
|
|
772
|
+
.get(ruby.to_symbol("escape_ascii"))
|
|
773
|
+
.and_then(|v| bool::try_convert(v).ok())
|
|
774
|
+
.unwrap_or(false),
|
|
775
|
+
code_language: kwargs
|
|
776
|
+
.get(ruby.to_symbol("code_language"))
|
|
777
|
+
.and_then(|v| String::try_convert(v).ok())
|
|
778
|
+
.unwrap_or("".to_string()),
|
|
779
|
+
autolinks: kwargs
|
|
780
|
+
.get(ruby.to_symbol("autolinks"))
|
|
781
|
+
.and_then(|v| bool::try_convert(v).ok())
|
|
782
|
+
.unwrap_or(true),
|
|
783
|
+
default_title: kwargs
|
|
784
|
+
.get(ruby.to_symbol("default_title"))
|
|
785
|
+
.and_then(|v| bool::try_convert(v).ok())
|
|
786
|
+
.unwrap_or(false),
|
|
787
|
+
br_in_tables: kwargs
|
|
788
|
+
.get(ruby.to_symbol("br_in_tables"))
|
|
789
|
+
.and_then(|v| bool::try_convert(v).ok())
|
|
790
|
+
.unwrap_or(false),
|
|
791
|
+
highlight_style: kwargs
|
|
792
|
+
.get(ruby.to_symbol("highlight_style"))
|
|
793
|
+
.and_then(|v| HighlightStyle::try_convert(v).ok())
|
|
794
|
+
.unwrap_or_default(),
|
|
795
|
+
extract_metadata: kwargs
|
|
796
|
+
.get(ruby.to_symbol("extract_metadata"))
|
|
797
|
+
.and_then(|v| bool::try_convert(v).ok())
|
|
798
|
+
.unwrap_or(true),
|
|
799
|
+
whitespace_mode: kwargs
|
|
800
|
+
.get(ruby.to_symbol("whitespace_mode"))
|
|
801
|
+
.and_then(|v| WhitespaceMode::try_convert(v).ok())
|
|
802
|
+
.unwrap_or_default(),
|
|
803
|
+
strip_newlines: kwargs
|
|
804
|
+
.get(ruby.to_symbol("strip_newlines"))
|
|
805
|
+
.and_then(|v| bool::try_convert(v).ok())
|
|
806
|
+
.unwrap_or(false),
|
|
807
|
+
wrap: kwargs
|
|
808
|
+
.get(ruby.to_symbol("wrap"))
|
|
809
|
+
.and_then(|v| bool::try_convert(v).ok())
|
|
810
|
+
.unwrap_or(false),
|
|
811
|
+
wrap_width: kwargs
|
|
812
|
+
.get(ruby.to_symbol("wrap_width"))
|
|
813
|
+
.and_then(|v| usize::try_convert(v).ok())
|
|
814
|
+
.unwrap_or(80),
|
|
815
|
+
convert_as_inline: kwargs
|
|
816
|
+
.get(ruby.to_symbol("convert_as_inline"))
|
|
817
|
+
.and_then(|v| bool::try_convert(v).ok())
|
|
818
|
+
.unwrap_or(false),
|
|
819
|
+
sub_symbol: kwargs
|
|
820
|
+
.get(ruby.to_symbol("sub_symbol"))
|
|
821
|
+
.and_then(|v| String::try_convert(v).ok())
|
|
822
|
+
.unwrap_or("".to_string()),
|
|
823
|
+
sup_symbol: kwargs
|
|
824
|
+
.get(ruby.to_symbol("sup_symbol"))
|
|
825
|
+
.and_then(|v| String::try_convert(v).ok())
|
|
826
|
+
.unwrap_or("".to_string()),
|
|
827
|
+
newline_style: kwargs
|
|
828
|
+
.get(ruby.to_symbol("newline_style"))
|
|
829
|
+
.and_then(|v| NewlineStyle::try_convert(v).ok())
|
|
830
|
+
.unwrap_or(NewlineStyle::Spaces),
|
|
831
|
+
code_block_style: kwargs
|
|
832
|
+
.get(ruby.to_symbol("code_block_style"))
|
|
833
|
+
.and_then(|v| CodeBlockStyle::try_convert(v).ok())
|
|
834
|
+
.unwrap_or_default(),
|
|
835
|
+
keep_inline_images_in: kwargs
|
|
836
|
+
.get(ruby.to_symbol("keep_inline_images_in"))
|
|
837
|
+
.and_then(|v| <Vec<String>>::try_convert(v).ok())
|
|
838
|
+
.unwrap_or_default(),
|
|
839
|
+
preprocessing: kwargs
|
|
840
|
+
.get(ruby.to_symbol("preprocessing"))
|
|
841
|
+
.and_then(|v| PreprocessingOptions::try_convert(v).ok())
|
|
842
|
+
.unwrap_or_default(),
|
|
843
|
+
encoding: kwargs
|
|
844
|
+
.get(ruby.to_symbol("encoding"))
|
|
845
|
+
.and_then(|v| String::try_convert(v).ok())
|
|
846
|
+
.unwrap_or("utf-8".to_string()),
|
|
847
|
+
debug: kwargs
|
|
848
|
+
.get(ruby.to_symbol("debug"))
|
|
849
|
+
.and_then(|v| bool::try_convert(v).ok())
|
|
850
|
+
.unwrap_or(false),
|
|
851
|
+
strip_tags: kwargs
|
|
852
|
+
.get(ruby.to_symbol("strip_tags"))
|
|
853
|
+
.and_then(|v| <Vec<String>>::try_convert(v).ok())
|
|
854
|
+
.unwrap_or_default(),
|
|
855
|
+
preserve_tags: kwargs
|
|
856
|
+
.get(ruby.to_symbol("preserve_tags"))
|
|
857
|
+
.and_then(|v| <Vec<String>>::try_convert(v).ok())
|
|
858
|
+
.unwrap_or_default(),
|
|
859
|
+
skip_images: kwargs
|
|
860
|
+
.get(ruby.to_symbol("skip_images"))
|
|
861
|
+
.and_then(|v| bool::try_convert(v).ok())
|
|
862
|
+
.unwrap_or(false),
|
|
863
|
+
link_style: kwargs
|
|
864
|
+
.get(ruby.to_symbol("link_style"))
|
|
865
|
+
.and_then(|v| LinkStyle::try_convert(v).ok())
|
|
866
|
+
.unwrap_or_default(),
|
|
867
|
+
output_format: kwargs
|
|
868
|
+
.get(ruby.to_symbol("output_format"))
|
|
869
|
+
.and_then(|v| OutputFormat::try_convert(v).ok())
|
|
870
|
+
.unwrap_or_default(),
|
|
871
|
+
include_document_structure: kwargs
|
|
872
|
+
.get(ruby.to_symbol("include_document_structure"))
|
|
873
|
+
.and_then(|v| bool::try_convert(v).ok())
|
|
874
|
+
.unwrap_or(false),
|
|
875
|
+
extract_images: kwargs
|
|
876
|
+
.get(ruby.to_symbol("extract_images"))
|
|
877
|
+
.and_then(|v| bool::try_convert(v).ok())
|
|
878
|
+
.unwrap_or(false),
|
|
879
|
+
max_image_size: kwargs
|
|
880
|
+
.get(ruby.to_symbol("max_image_size"))
|
|
881
|
+
.and_then(|v| u64::try_convert(v).ok())
|
|
882
|
+
.unwrap_or(5242880),
|
|
883
|
+
capture_svg: kwargs
|
|
884
|
+
.get(ruby.to_symbol("capture_svg"))
|
|
885
|
+
.and_then(|v| bool::try_convert(v).ok())
|
|
886
|
+
.unwrap_or(false),
|
|
887
|
+
infer_dimensions: kwargs
|
|
888
|
+
.get(ruby.to_symbol("infer_dimensions"))
|
|
889
|
+
.and_then(|v| bool::try_convert(v).ok())
|
|
890
|
+
.unwrap_or(true),
|
|
891
|
+
})
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
fn heading_style(&self) -> HeadingStyle {
|
|
895
|
+
self.heading_style.clone()
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
fn list_indent_type(&self) -> ListIndentType {
|
|
899
|
+
self.list_indent_type.clone()
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
fn list_indent_width(&self) -> usize {
|
|
903
|
+
self.list_indent_width
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
fn bullets(&self) -> String {
|
|
907
|
+
self.bullets.clone()
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
fn strong_em_symbol(&self) -> String {
|
|
911
|
+
self.strong_em_symbol.clone()
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
fn escape_asterisks(&self) -> bool {
|
|
915
|
+
self.escape_asterisks
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
fn escape_underscores(&self) -> bool {
|
|
919
|
+
self.escape_underscores
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
fn escape_misc(&self) -> bool {
|
|
923
|
+
self.escape_misc
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
fn escape_ascii(&self) -> bool {
|
|
927
|
+
self.escape_ascii
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
fn code_language(&self) -> String {
|
|
931
|
+
self.code_language.clone()
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
fn autolinks(&self) -> bool {
|
|
935
|
+
self.autolinks
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
fn default_title(&self) -> bool {
|
|
939
|
+
self.default_title
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
fn br_in_tables(&self) -> bool {
|
|
943
|
+
self.br_in_tables
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
fn highlight_style(&self) -> HighlightStyle {
|
|
947
|
+
self.highlight_style.clone()
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
fn extract_metadata(&self) -> bool {
|
|
951
|
+
self.extract_metadata
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
fn whitespace_mode(&self) -> WhitespaceMode {
|
|
955
|
+
self.whitespace_mode.clone()
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
fn strip_newlines(&self) -> bool {
|
|
959
|
+
self.strip_newlines
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
fn wrap(&self) -> bool {
|
|
963
|
+
self.wrap
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
fn wrap_width(&self) -> usize {
|
|
967
|
+
self.wrap_width
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
fn convert_as_inline(&self) -> bool {
|
|
971
|
+
self.convert_as_inline
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
fn sub_symbol(&self) -> String {
|
|
975
|
+
self.sub_symbol.clone()
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
fn sup_symbol(&self) -> String {
|
|
979
|
+
self.sup_symbol.clone()
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
fn newline_style(&self) -> NewlineStyle {
|
|
983
|
+
self.newline_style.clone()
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
fn code_block_style(&self) -> CodeBlockStyle {
|
|
987
|
+
self.code_block_style.clone()
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
fn keep_inline_images_in(&self) -> Vec<String> {
|
|
991
|
+
self.keep_inline_images_in.clone()
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
fn preprocessing(&self) -> PreprocessingOptions {
|
|
995
|
+
self.preprocessing.clone()
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
fn encoding(&self) -> String {
|
|
999
|
+
self.encoding.clone()
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
fn debug(&self) -> bool {
|
|
1003
|
+
self.debug
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
fn strip_tags(&self) -> Vec<String> {
|
|
1007
|
+
self.strip_tags.clone()
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
fn preserve_tags(&self) -> Vec<String> {
|
|
1011
|
+
self.preserve_tags.clone()
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
fn skip_images(&self) -> bool {
|
|
1015
|
+
self.skip_images
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
fn link_style(&self) -> LinkStyle {
|
|
1019
|
+
self.link_style.clone()
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
fn output_format(&self) -> OutputFormat {
|
|
1023
|
+
self.output_format.clone()
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
fn include_document_structure(&self) -> bool {
|
|
1027
|
+
self.include_document_structure
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
fn extract_images(&self) -> bool {
|
|
1031
|
+
self.extract_images
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
fn max_image_size(&self) -> u64 {
|
|
1035
|
+
self.max_image_size
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
fn capture_svg(&self) -> bool {
|
|
1039
|
+
self.capture_svg
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
fn infer_dimensions(&self) -> bool {
|
|
1043
|
+
self.infer_dimensions
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
#[derive(Clone)]
|
|
1048
|
+
#[magnus::wrap(class = "HtmlToMarkdownRs::ConversionOptionsBuilder")]
|
|
1049
|
+
pub struct ConversionOptionsBuilder {
|
|
1050
|
+
inner: Arc<html_to_markdown_rs::options::ConversionOptionsBuilder>,
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
unsafe impl IntoValueFromNative for ConversionOptionsBuilder {}
|
|
1054
|
+
|
|
1055
|
+
impl magnus::TryConvert for ConversionOptionsBuilder {
|
|
1056
|
+
fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
|
|
1057
|
+
let r: &ConversionOptionsBuilder = magnus::TryConvert::try_convert(val)?;
|
|
1058
|
+
Ok(r.clone())
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
unsafe impl TryConvertOwned for ConversionOptionsBuilder {}
|
|
1062
|
+
|
|
1063
|
+
impl ConversionOptionsBuilder {
|
|
1064
|
+
fn strip_tags(&self, tags: Vec<String>) -> ConversionOptionsBuilder {
|
|
1065
|
+
Self {
|
|
1066
|
+
inner: Arc::new(self.inner.as_ref().clone().strip_tags(tags)),
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
fn preserve_tags(&self, tags: Vec<String>) -> ConversionOptionsBuilder {
|
|
1071
|
+
Self {
|
|
1072
|
+
inner: Arc::new(self.inner.as_ref().clone().preserve_tags(tags)),
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
fn keep_inline_images_in(&self, tags: Vec<String>) -> ConversionOptionsBuilder {
|
|
1077
|
+
Self {
|
|
1078
|
+
inner: Arc::new(self.inner.as_ref().clone().keep_inline_images_in(tags)),
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
fn preprocessing(&self, preprocessing: PreprocessingOptions) -> ConversionOptionsBuilder {
|
|
1083
|
+
Self {
|
|
1084
|
+
inner: Arc::new(self.inner.as_ref().clone().preprocessing(preprocessing.into())),
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
fn build(&self) -> ConversionOptions {
|
|
1089
|
+
self.inner.as_ref().clone().build().into()
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
|
1094
|
+
#[magnus::wrap(class = "HtmlToMarkdownRs::ConversionOptionsUpdate")]
|
|
1095
|
+
#[serde(default)]
|
|
1096
|
+
pub struct ConversionOptionsUpdate {
|
|
1097
|
+
pub heading_style: Option<HeadingStyle>,
|
|
1098
|
+
pub list_indent_type: Option<ListIndentType>,
|
|
1099
|
+
pub list_indent_width: Option<usize>,
|
|
1100
|
+
pub bullets: Option<String>,
|
|
1101
|
+
pub strong_em_symbol: Option<String>,
|
|
1102
|
+
pub escape_asterisks: Option<bool>,
|
|
1103
|
+
pub escape_underscores: Option<bool>,
|
|
1104
|
+
pub escape_misc: Option<bool>,
|
|
1105
|
+
pub escape_ascii: Option<bool>,
|
|
1106
|
+
pub code_language: Option<String>,
|
|
1107
|
+
pub autolinks: Option<bool>,
|
|
1108
|
+
pub default_title: Option<bool>,
|
|
1109
|
+
pub br_in_tables: Option<bool>,
|
|
1110
|
+
pub highlight_style: Option<HighlightStyle>,
|
|
1111
|
+
pub extract_metadata: Option<bool>,
|
|
1112
|
+
pub whitespace_mode: Option<WhitespaceMode>,
|
|
1113
|
+
pub strip_newlines: Option<bool>,
|
|
1114
|
+
pub wrap: Option<bool>,
|
|
1115
|
+
pub wrap_width: Option<usize>,
|
|
1116
|
+
pub convert_as_inline: Option<bool>,
|
|
1117
|
+
pub sub_symbol: Option<String>,
|
|
1118
|
+
pub sup_symbol: Option<String>,
|
|
1119
|
+
pub newline_style: Option<NewlineStyle>,
|
|
1120
|
+
pub code_block_style: Option<CodeBlockStyle>,
|
|
1121
|
+
pub keep_inline_images_in: Option<Vec<String>>,
|
|
1122
|
+
pub preprocessing: Option<PreprocessingOptionsUpdate>,
|
|
1123
|
+
pub encoding: Option<String>,
|
|
1124
|
+
pub debug: Option<bool>,
|
|
1125
|
+
pub strip_tags: Option<Vec<String>>,
|
|
1126
|
+
pub preserve_tags: Option<Vec<String>>,
|
|
1127
|
+
pub skip_images: Option<bool>,
|
|
1128
|
+
pub link_style: Option<LinkStyle>,
|
|
1129
|
+
pub output_format: Option<OutputFormat>,
|
|
1130
|
+
pub include_document_structure: Option<bool>,
|
|
1131
|
+
pub extract_images: Option<bool>,
|
|
1132
|
+
pub max_image_size: Option<u64>,
|
|
1133
|
+
pub capture_svg: Option<bool>,
|
|
1134
|
+
pub infer_dimensions: Option<bool>,
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
unsafe impl IntoValueFromNative for ConversionOptionsUpdate {}
|
|
1138
|
+
|
|
1139
|
+
impl magnus::TryConvert for ConversionOptionsUpdate {
|
|
1140
|
+
fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
|
|
1141
|
+
let r: &ConversionOptionsUpdate = magnus::TryConvert::try_convert(val)?;
|
|
1142
|
+
Ok(r.clone())
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
unsafe impl TryConvertOwned for ConversionOptionsUpdate {}
|
|
1146
|
+
|
|
1147
|
+
impl Default for ConversionOptionsUpdate {
|
|
1148
|
+
fn default() -> Self {
|
|
1149
|
+
Self {
|
|
1150
|
+
heading_style: Default::default(),
|
|
1151
|
+
list_indent_type: Default::default(),
|
|
1152
|
+
list_indent_width: Default::default(),
|
|
1153
|
+
bullets: Default::default(),
|
|
1154
|
+
strong_em_symbol: Default::default(),
|
|
1155
|
+
escape_asterisks: Default::default(),
|
|
1156
|
+
escape_underscores: Default::default(),
|
|
1157
|
+
escape_misc: Default::default(),
|
|
1158
|
+
escape_ascii: Default::default(),
|
|
1159
|
+
code_language: Default::default(),
|
|
1160
|
+
autolinks: Default::default(),
|
|
1161
|
+
default_title: Default::default(),
|
|
1162
|
+
br_in_tables: Default::default(),
|
|
1163
|
+
highlight_style: Default::default(),
|
|
1164
|
+
extract_metadata: Default::default(),
|
|
1165
|
+
whitespace_mode: Default::default(),
|
|
1166
|
+
strip_newlines: Default::default(),
|
|
1167
|
+
wrap: Default::default(),
|
|
1168
|
+
wrap_width: Default::default(),
|
|
1169
|
+
convert_as_inline: Default::default(),
|
|
1170
|
+
sub_symbol: Default::default(),
|
|
1171
|
+
sup_symbol: Default::default(),
|
|
1172
|
+
newline_style: Default::default(),
|
|
1173
|
+
code_block_style: Default::default(),
|
|
1174
|
+
keep_inline_images_in: Default::default(),
|
|
1175
|
+
preprocessing: Default::default(),
|
|
1176
|
+
encoding: Default::default(),
|
|
1177
|
+
debug: Default::default(),
|
|
1178
|
+
strip_tags: Default::default(),
|
|
1179
|
+
preserve_tags: Default::default(),
|
|
1180
|
+
skip_images: Default::default(),
|
|
1181
|
+
link_style: Default::default(),
|
|
1182
|
+
output_format: Default::default(),
|
|
1183
|
+
include_document_structure: Default::default(),
|
|
1184
|
+
extract_images: Default::default(),
|
|
1185
|
+
max_image_size: Default::default(),
|
|
1186
|
+
capture_svg: Default::default(),
|
|
1187
|
+
infer_dimensions: Default::default(),
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
impl ConversionOptionsUpdate {
|
|
1193
|
+
fn new(kwargs: magnus::RHash) -> Result<Self, magnus::Error> {
|
|
1194
|
+
let ruby = unsafe { magnus::Ruby::get_unchecked() };
|
|
1195
|
+
Ok(Self {
|
|
1196
|
+
heading_style: kwargs
|
|
1197
|
+
.get(ruby.to_symbol("heading_style"))
|
|
1198
|
+
.and_then(|v| HeadingStyle::try_convert(v).ok()),
|
|
1199
|
+
list_indent_type: kwargs
|
|
1200
|
+
.get(ruby.to_symbol("list_indent_type"))
|
|
1201
|
+
.and_then(|v| ListIndentType::try_convert(v).ok()),
|
|
1202
|
+
list_indent_width: kwargs
|
|
1203
|
+
.get(ruby.to_symbol("list_indent_width"))
|
|
1204
|
+
.and_then(|v| usize::try_convert(v).ok()),
|
|
1205
|
+
bullets: kwargs
|
|
1206
|
+
.get(ruby.to_symbol("bullets"))
|
|
1207
|
+
.and_then(|v| String::try_convert(v).ok()),
|
|
1208
|
+
strong_em_symbol: kwargs
|
|
1209
|
+
.get(ruby.to_symbol("strong_em_symbol"))
|
|
1210
|
+
.and_then(|v| String::try_convert(v).ok()),
|
|
1211
|
+
escape_asterisks: kwargs
|
|
1212
|
+
.get(ruby.to_symbol("escape_asterisks"))
|
|
1213
|
+
.and_then(|v| bool::try_convert(v).ok()),
|
|
1214
|
+
escape_underscores: kwargs
|
|
1215
|
+
.get(ruby.to_symbol("escape_underscores"))
|
|
1216
|
+
.and_then(|v| bool::try_convert(v).ok()),
|
|
1217
|
+
escape_misc: kwargs
|
|
1218
|
+
.get(ruby.to_symbol("escape_misc"))
|
|
1219
|
+
.and_then(|v| bool::try_convert(v).ok()),
|
|
1220
|
+
escape_ascii: kwargs
|
|
1221
|
+
.get(ruby.to_symbol("escape_ascii"))
|
|
1222
|
+
.and_then(|v| bool::try_convert(v).ok()),
|
|
1223
|
+
code_language: kwargs
|
|
1224
|
+
.get(ruby.to_symbol("code_language"))
|
|
1225
|
+
.and_then(|v| String::try_convert(v).ok()),
|
|
1226
|
+
autolinks: kwargs
|
|
1227
|
+
.get(ruby.to_symbol("autolinks"))
|
|
1228
|
+
.and_then(|v| bool::try_convert(v).ok()),
|
|
1229
|
+
default_title: kwargs
|
|
1230
|
+
.get(ruby.to_symbol("default_title"))
|
|
1231
|
+
.and_then(|v| bool::try_convert(v).ok()),
|
|
1232
|
+
br_in_tables: kwargs
|
|
1233
|
+
.get(ruby.to_symbol("br_in_tables"))
|
|
1234
|
+
.and_then(|v| bool::try_convert(v).ok()),
|
|
1235
|
+
highlight_style: kwargs
|
|
1236
|
+
.get(ruby.to_symbol("highlight_style"))
|
|
1237
|
+
.and_then(|v| HighlightStyle::try_convert(v).ok()),
|
|
1238
|
+
extract_metadata: kwargs
|
|
1239
|
+
.get(ruby.to_symbol("extract_metadata"))
|
|
1240
|
+
.and_then(|v| bool::try_convert(v).ok()),
|
|
1241
|
+
whitespace_mode: kwargs
|
|
1242
|
+
.get(ruby.to_symbol("whitespace_mode"))
|
|
1243
|
+
.and_then(|v| WhitespaceMode::try_convert(v).ok()),
|
|
1244
|
+
strip_newlines: kwargs
|
|
1245
|
+
.get(ruby.to_symbol("strip_newlines"))
|
|
1246
|
+
.and_then(|v| bool::try_convert(v).ok()),
|
|
1247
|
+
wrap: kwargs
|
|
1248
|
+
.get(ruby.to_symbol("wrap"))
|
|
1249
|
+
.and_then(|v| bool::try_convert(v).ok()),
|
|
1250
|
+
wrap_width: kwargs
|
|
1251
|
+
.get(ruby.to_symbol("wrap_width"))
|
|
1252
|
+
.and_then(|v| usize::try_convert(v).ok()),
|
|
1253
|
+
convert_as_inline: kwargs
|
|
1254
|
+
.get(ruby.to_symbol("convert_as_inline"))
|
|
1255
|
+
.and_then(|v| bool::try_convert(v).ok()),
|
|
1256
|
+
sub_symbol: kwargs
|
|
1257
|
+
.get(ruby.to_symbol("sub_symbol"))
|
|
1258
|
+
.and_then(|v| String::try_convert(v).ok()),
|
|
1259
|
+
sup_symbol: kwargs
|
|
1260
|
+
.get(ruby.to_symbol("sup_symbol"))
|
|
1261
|
+
.and_then(|v| String::try_convert(v).ok()),
|
|
1262
|
+
newline_style: kwargs
|
|
1263
|
+
.get(ruby.to_symbol("newline_style"))
|
|
1264
|
+
.and_then(|v| NewlineStyle::try_convert(v).ok()),
|
|
1265
|
+
code_block_style: kwargs
|
|
1266
|
+
.get(ruby.to_symbol("code_block_style"))
|
|
1267
|
+
.and_then(|v| CodeBlockStyle::try_convert(v).ok()),
|
|
1268
|
+
keep_inline_images_in: kwargs
|
|
1269
|
+
.get(ruby.to_symbol("keep_inline_images_in"))
|
|
1270
|
+
.and_then(|v| <Vec<String>>::try_convert(v).ok()),
|
|
1271
|
+
preprocessing: kwargs
|
|
1272
|
+
.get(ruby.to_symbol("preprocessing"))
|
|
1273
|
+
.and_then(|v| PreprocessingOptionsUpdate::try_convert(v).ok()),
|
|
1274
|
+
encoding: kwargs
|
|
1275
|
+
.get(ruby.to_symbol("encoding"))
|
|
1276
|
+
.and_then(|v| String::try_convert(v).ok()),
|
|
1277
|
+
debug: kwargs
|
|
1278
|
+
.get(ruby.to_symbol("debug"))
|
|
1279
|
+
.and_then(|v| bool::try_convert(v).ok()),
|
|
1280
|
+
strip_tags: kwargs
|
|
1281
|
+
.get(ruby.to_symbol("strip_tags"))
|
|
1282
|
+
.and_then(|v| <Vec<String>>::try_convert(v).ok()),
|
|
1283
|
+
preserve_tags: kwargs
|
|
1284
|
+
.get(ruby.to_symbol("preserve_tags"))
|
|
1285
|
+
.and_then(|v| <Vec<String>>::try_convert(v).ok()),
|
|
1286
|
+
skip_images: kwargs
|
|
1287
|
+
.get(ruby.to_symbol("skip_images"))
|
|
1288
|
+
.and_then(|v| bool::try_convert(v).ok()),
|
|
1289
|
+
link_style: kwargs
|
|
1290
|
+
.get(ruby.to_symbol("link_style"))
|
|
1291
|
+
.and_then(|v| LinkStyle::try_convert(v).ok()),
|
|
1292
|
+
output_format: kwargs
|
|
1293
|
+
.get(ruby.to_symbol("output_format"))
|
|
1294
|
+
.and_then(|v| OutputFormat::try_convert(v).ok()),
|
|
1295
|
+
include_document_structure: kwargs
|
|
1296
|
+
.get(ruby.to_symbol("include_document_structure"))
|
|
1297
|
+
.and_then(|v| bool::try_convert(v).ok()),
|
|
1298
|
+
extract_images: kwargs
|
|
1299
|
+
.get(ruby.to_symbol("extract_images"))
|
|
1300
|
+
.and_then(|v| bool::try_convert(v).ok()),
|
|
1301
|
+
max_image_size: kwargs
|
|
1302
|
+
.get(ruby.to_symbol("max_image_size"))
|
|
1303
|
+
.and_then(|v| u64::try_convert(v).ok()),
|
|
1304
|
+
capture_svg: kwargs
|
|
1305
|
+
.get(ruby.to_symbol("capture_svg"))
|
|
1306
|
+
.and_then(|v| bool::try_convert(v).ok()),
|
|
1307
|
+
infer_dimensions: kwargs
|
|
1308
|
+
.get(ruby.to_symbol("infer_dimensions"))
|
|
1309
|
+
.and_then(|v| bool::try_convert(v).ok()),
|
|
1310
|
+
})
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
fn heading_style(&self) -> Option<HeadingStyle> {
|
|
1314
|
+
self.heading_style.clone()
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
fn list_indent_type(&self) -> Option<ListIndentType> {
|
|
1318
|
+
self.list_indent_type.clone()
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
fn list_indent_width(&self) -> Option<usize> {
|
|
1322
|
+
self.list_indent_width
|
|
1323
|
+
}
|
|
1324
|
+
|
|
1325
|
+
fn bullets(&self) -> Option<String> {
|
|
1326
|
+
self.bullets.clone()
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
fn strong_em_symbol(&self) -> Option<String> {
|
|
1330
|
+
self.strong_em_symbol.clone()
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1333
|
+
fn escape_asterisks(&self) -> Option<bool> {
|
|
1334
|
+
self.escape_asterisks
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
fn escape_underscores(&self) -> Option<bool> {
|
|
1338
|
+
self.escape_underscores
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
fn escape_misc(&self) -> Option<bool> {
|
|
1342
|
+
self.escape_misc
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
fn escape_ascii(&self) -> Option<bool> {
|
|
1346
|
+
self.escape_ascii
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
fn code_language(&self) -> Option<String> {
|
|
1350
|
+
self.code_language.clone()
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1353
|
+
fn autolinks(&self) -> Option<bool> {
|
|
1354
|
+
self.autolinks
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
fn default_title(&self) -> Option<bool> {
|
|
1358
|
+
self.default_title
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1361
|
+
fn br_in_tables(&self) -> Option<bool> {
|
|
1362
|
+
self.br_in_tables
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
fn highlight_style(&self) -> Option<HighlightStyle> {
|
|
1366
|
+
self.highlight_style.clone()
|
|
1367
|
+
}
|
|
1368
|
+
|
|
1369
|
+
fn extract_metadata(&self) -> Option<bool> {
|
|
1370
|
+
self.extract_metadata
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1373
|
+
fn whitespace_mode(&self) -> Option<WhitespaceMode> {
|
|
1374
|
+
self.whitespace_mode.clone()
|
|
1375
|
+
}
|
|
1376
|
+
|
|
1377
|
+
fn strip_newlines(&self) -> Option<bool> {
|
|
1378
|
+
self.strip_newlines
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
fn wrap(&self) -> Option<bool> {
|
|
1382
|
+
self.wrap
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1385
|
+
fn wrap_width(&self) -> Option<usize> {
|
|
1386
|
+
self.wrap_width
|
|
1387
|
+
}
|
|
1388
|
+
|
|
1389
|
+
fn convert_as_inline(&self) -> Option<bool> {
|
|
1390
|
+
self.convert_as_inline
|
|
1391
|
+
}
|
|
1392
|
+
|
|
1393
|
+
fn sub_symbol(&self) -> Option<String> {
|
|
1394
|
+
self.sub_symbol.clone()
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
fn sup_symbol(&self) -> Option<String> {
|
|
1398
|
+
self.sup_symbol.clone()
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
fn newline_style(&self) -> Option<NewlineStyle> {
|
|
1402
|
+
self.newline_style.clone()
|
|
1403
|
+
}
|
|
1404
|
+
|
|
1405
|
+
fn code_block_style(&self) -> Option<CodeBlockStyle> {
|
|
1406
|
+
self.code_block_style.clone()
|
|
1407
|
+
}
|
|
1408
|
+
|
|
1409
|
+
fn keep_inline_images_in(&self) -> Option<Vec<String>> {
|
|
1410
|
+
self.keep_inline_images_in.clone()
|
|
1411
|
+
}
|
|
1412
|
+
|
|
1413
|
+
fn preprocessing(&self) -> Option<PreprocessingOptionsUpdate> {
|
|
1414
|
+
self.preprocessing.clone()
|
|
1415
|
+
}
|
|
1416
|
+
|
|
1417
|
+
fn encoding(&self) -> Option<String> {
|
|
1418
|
+
self.encoding.clone()
|
|
1419
|
+
}
|
|
1420
|
+
|
|
1421
|
+
fn debug(&self) -> Option<bool> {
|
|
1422
|
+
self.debug
|
|
1423
|
+
}
|
|
1424
|
+
|
|
1425
|
+
fn strip_tags(&self) -> Option<Vec<String>> {
|
|
1426
|
+
self.strip_tags.clone()
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
fn preserve_tags(&self) -> Option<Vec<String>> {
|
|
1430
|
+
self.preserve_tags.clone()
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
fn skip_images(&self) -> Option<bool> {
|
|
1434
|
+
self.skip_images
|
|
1435
|
+
}
|
|
1436
|
+
|
|
1437
|
+
fn link_style(&self) -> Option<LinkStyle> {
|
|
1438
|
+
self.link_style.clone()
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
fn output_format(&self) -> Option<OutputFormat> {
|
|
1442
|
+
self.output_format.clone()
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
fn include_document_structure(&self) -> Option<bool> {
|
|
1446
|
+
self.include_document_structure
|
|
1447
|
+
}
|
|
1448
|
+
|
|
1449
|
+
fn extract_images(&self) -> Option<bool> {
|
|
1450
|
+
self.extract_images
|
|
1451
|
+
}
|
|
1452
|
+
|
|
1453
|
+
fn max_image_size(&self) -> Option<u64> {
|
|
1454
|
+
self.max_image_size
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1457
|
+
fn capture_svg(&self) -> Option<bool> {
|
|
1458
|
+
self.capture_svg
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
fn infer_dimensions(&self) -> Option<bool> {
|
|
1462
|
+
self.infer_dimensions
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1465
|
+
|
|
1466
|
+
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
|
1467
|
+
#[magnus::wrap(class = "HtmlToMarkdownRs::PreprocessingOptions")]
|
|
1468
|
+
#[serde(default)]
|
|
1469
|
+
pub struct PreprocessingOptions {
|
|
1470
|
+
pub enabled: bool,
|
|
1471
|
+
pub preset: PreprocessingPreset,
|
|
1472
|
+
pub remove_navigation: bool,
|
|
1473
|
+
pub remove_forms: bool,
|
|
1474
|
+
}
|
|
1475
|
+
|
|
1476
|
+
unsafe impl IntoValueFromNative for PreprocessingOptions {}
|
|
1477
|
+
|
|
1478
|
+
impl magnus::TryConvert for PreprocessingOptions {
|
|
1479
|
+
fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
|
|
1480
|
+
let r: &PreprocessingOptions = magnus::TryConvert::try_convert(val)?;
|
|
1481
|
+
Ok(r.clone())
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
unsafe impl TryConvertOwned for PreprocessingOptions {}
|
|
1485
|
+
|
|
1486
|
+
impl Default for PreprocessingOptions {
|
|
1487
|
+
fn default() -> Self {
|
|
1488
|
+
Self {
|
|
1489
|
+
enabled: Default::default(),
|
|
1490
|
+
preset: Default::default(),
|
|
1491
|
+
remove_navigation: Default::default(),
|
|
1492
|
+
remove_forms: Default::default(),
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
|
|
1497
|
+
impl PreprocessingOptions {
|
|
1498
|
+
fn new(
|
|
1499
|
+
enabled: Option<bool>,
|
|
1500
|
+
preset: Option<PreprocessingPreset>,
|
|
1501
|
+
remove_navigation: Option<bool>,
|
|
1502
|
+
remove_forms: Option<bool>,
|
|
1503
|
+
) -> Self {
|
|
1504
|
+
Self {
|
|
1505
|
+
enabled: enabled.unwrap_or(true),
|
|
1506
|
+
preset: preset.unwrap_or_default(),
|
|
1507
|
+
remove_navigation: remove_navigation.unwrap_or(true),
|
|
1508
|
+
remove_forms: remove_forms.unwrap_or(true),
|
|
1509
|
+
}
|
|
1510
|
+
}
|
|
1511
|
+
|
|
1512
|
+
fn enabled(&self) -> bool {
|
|
1513
|
+
self.enabled
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
fn preset(&self) -> PreprocessingPreset {
|
|
1517
|
+
self.preset.clone()
|
|
1518
|
+
}
|
|
1519
|
+
|
|
1520
|
+
fn remove_navigation(&self) -> bool {
|
|
1521
|
+
self.remove_navigation
|
|
1522
|
+
}
|
|
1523
|
+
|
|
1524
|
+
fn remove_forms(&self) -> bool {
|
|
1525
|
+
self.remove_forms
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
|
|
1529
|
+
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
|
1530
|
+
#[magnus::wrap(class = "HtmlToMarkdownRs::PreprocessingOptionsUpdate")]
|
|
1531
|
+
#[serde(default)]
|
|
1532
|
+
pub struct PreprocessingOptionsUpdate {
|
|
1533
|
+
pub enabled: Option<bool>,
|
|
1534
|
+
pub preset: Option<PreprocessingPreset>,
|
|
1535
|
+
pub remove_navigation: Option<bool>,
|
|
1536
|
+
pub remove_forms: Option<bool>,
|
|
1537
|
+
}
|
|
1538
|
+
|
|
1539
|
+
unsafe impl IntoValueFromNative for PreprocessingOptionsUpdate {}
|
|
1540
|
+
|
|
1541
|
+
impl magnus::TryConvert for PreprocessingOptionsUpdate {
|
|
1542
|
+
fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
|
|
1543
|
+
let r: &PreprocessingOptionsUpdate = magnus::TryConvert::try_convert(val)?;
|
|
1544
|
+
Ok(r.clone())
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
unsafe impl TryConvertOwned for PreprocessingOptionsUpdate {}
|
|
1548
|
+
|
|
1549
|
+
impl Default for PreprocessingOptionsUpdate {
|
|
1550
|
+
fn default() -> Self {
|
|
1551
|
+
Self {
|
|
1552
|
+
enabled: Default::default(),
|
|
1553
|
+
preset: Default::default(),
|
|
1554
|
+
remove_navigation: Default::default(),
|
|
1555
|
+
remove_forms: Default::default(),
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
}
|
|
1559
|
+
|
|
1560
|
+
impl PreprocessingOptionsUpdate {
|
|
1561
|
+
fn new(
|
|
1562
|
+
enabled: Option<bool>,
|
|
1563
|
+
preset: Option<PreprocessingPreset>,
|
|
1564
|
+
remove_navigation: Option<bool>,
|
|
1565
|
+
remove_forms: Option<bool>,
|
|
1566
|
+
) -> Self {
|
|
1567
|
+
Self {
|
|
1568
|
+
enabled,
|
|
1569
|
+
preset,
|
|
1570
|
+
remove_navigation,
|
|
1571
|
+
remove_forms,
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1574
|
+
|
|
1575
|
+
fn enabled(&self) -> Option<bool> {
|
|
1576
|
+
self.enabled
|
|
1577
|
+
}
|
|
1578
|
+
|
|
1579
|
+
fn preset(&self) -> Option<PreprocessingPreset> {
|
|
1580
|
+
self.preset.clone()
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
fn remove_navigation(&self) -> Option<bool> {
|
|
1584
|
+
self.remove_navigation
|
|
1585
|
+
}
|
|
1586
|
+
|
|
1587
|
+
fn remove_forms(&self) -> Option<bool> {
|
|
1588
|
+
self.remove_forms
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
|
|
1592
|
+
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
|
1593
|
+
#[magnus::wrap(class = "HtmlToMarkdownRs::DocumentStructure")]
|
|
1594
|
+
pub struct DocumentStructure {
|
|
1595
|
+
pub nodes: Vec<DocumentNode>,
|
|
1596
|
+
pub source_format: Option<String>,
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1599
|
+
unsafe impl IntoValueFromNative for DocumentStructure {}
|
|
1600
|
+
|
|
1601
|
+
impl magnus::TryConvert for DocumentStructure {
|
|
1602
|
+
fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
|
|
1603
|
+
let r: &DocumentStructure = magnus::TryConvert::try_convert(val)?;
|
|
1604
|
+
Ok(r.clone())
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
unsafe impl TryConvertOwned for DocumentStructure {}
|
|
1608
|
+
|
|
1609
|
+
impl DocumentStructure {
|
|
1610
|
+
fn new(nodes: Vec<DocumentNode>, source_format: Option<String>) -> Self {
|
|
1611
|
+
Self { nodes, source_format }
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1614
|
+
fn nodes(&self) -> Vec<DocumentNode> {
|
|
1615
|
+
self.nodes.clone()
|
|
1616
|
+
}
|
|
1617
|
+
|
|
1618
|
+
fn source_format(&self) -> Option<String> {
|
|
1619
|
+
self.source_format.clone()
|
|
1620
|
+
}
|
|
1621
|
+
}
|
|
1622
|
+
|
|
1623
|
+
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
|
1624
|
+
#[magnus::wrap(class = "HtmlToMarkdownRs::DocumentNode")]
|
|
1625
|
+
pub struct DocumentNode {
|
|
1626
|
+
pub id: String,
|
|
1627
|
+
pub content: NodeContent,
|
|
1628
|
+
pub parent: Option<u32>,
|
|
1629
|
+
pub children: Vec<u32>,
|
|
1630
|
+
pub annotations: Vec<TextAnnotation>,
|
|
1631
|
+
pub attributes: Option<HashMap<String, String>>,
|
|
1632
|
+
}
|
|
1633
|
+
|
|
1634
|
+
unsafe impl IntoValueFromNative for DocumentNode {}
|
|
1635
|
+
|
|
1636
|
+
impl magnus::TryConvert for DocumentNode {
|
|
1637
|
+
fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
|
|
1638
|
+
let r: &DocumentNode = magnus::TryConvert::try_convert(val)?;
|
|
1639
|
+
Ok(r.clone())
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
unsafe impl TryConvertOwned for DocumentNode {}
|
|
1643
|
+
|
|
1644
|
+
impl DocumentNode {
|
|
1645
|
+
fn new(
|
|
1646
|
+
id: String,
|
|
1647
|
+
content: NodeContent,
|
|
1648
|
+
children: Vec<u32>,
|
|
1649
|
+
annotations: Vec<TextAnnotation>,
|
|
1650
|
+
parent: Option<u32>,
|
|
1651
|
+
attributes: Option<HashMap<String, String>>,
|
|
1652
|
+
) -> Self {
|
|
1653
|
+
Self {
|
|
1654
|
+
id,
|
|
1655
|
+
content,
|
|
1656
|
+
parent,
|
|
1657
|
+
children,
|
|
1658
|
+
annotations,
|
|
1659
|
+
attributes,
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
|
|
1663
|
+
fn id(&self) -> String {
|
|
1664
|
+
self.id.clone()
|
|
1665
|
+
}
|
|
1666
|
+
|
|
1667
|
+
fn content(&self) -> NodeContent {
|
|
1668
|
+
self.content.clone()
|
|
1669
|
+
}
|
|
1670
|
+
|
|
1671
|
+
fn parent(&self) -> Option<u32> {
|
|
1672
|
+
self.parent
|
|
1673
|
+
}
|
|
1674
|
+
|
|
1675
|
+
fn children(&self) -> Vec<u32> {
|
|
1676
|
+
self.children.clone()
|
|
1677
|
+
}
|
|
1678
|
+
|
|
1679
|
+
fn annotations(&self) -> Vec<TextAnnotation> {
|
|
1680
|
+
self.annotations.clone()
|
|
1681
|
+
}
|
|
1682
|
+
|
|
1683
|
+
fn attributes(&self) -> Option<HashMap<String, String>> {
|
|
1684
|
+
self.attributes.clone()
|
|
1685
|
+
}
|
|
1686
|
+
}
|
|
1687
|
+
|
|
1688
|
+
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
|
1689
|
+
#[magnus::wrap(class = "HtmlToMarkdownRs::TextAnnotation")]
|
|
1690
|
+
pub struct TextAnnotation {
|
|
1691
|
+
pub start: u32,
|
|
1692
|
+
pub end: u32,
|
|
1693
|
+
pub kind: AnnotationKind,
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1696
|
+
unsafe impl IntoValueFromNative for TextAnnotation {}
|
|
1697
|
+
|
|
1698
|
+
impl magnus::TryConvert for TextAnnotation {
|
|
1699
|
+
fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
|
|
1700
|
+
let r: &TextAnnotation = magnus::TryConvert::try_convert(val)?;
|
|
1701
|
+
Ok(r.clone())
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
unsafe impl TryConvertOwned for TextAnnotation {}
|
|
1705
|
+
|
|
1706
|
+
impl TextAnnotation {
|
|
1707
|
+
fn new(start: u32, end: u32, kind: AnnotationKind) -> Self {
|
|
1708
|
+
Self { start, end, kind }
|
|
1709
|
+
}
|
|
1710
|
+
|
|
1711
|
+
fn start(&self) -> u32 {
|
|
1712
|
+
self.start
|
|
1713
|
+
}
|
|
1714
|
+
|
|
1715
|
+
fn end(&self) -> u32 {
|
|
1716
|
+
self.end
|
|
1717
|
+
}
|
|
1718
|
+
|
|
1719
|
+
fn kind(&self) -> AnnotationKind {
|
|
1720
|
+
self.kind.clone()
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1723
|
+
|
|
1724
|
+
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
|
1725
|
+
#[magnus::wrap(class = "HtmlToMarkdownRs::ConversionResult")]
|
|
1726
|
+
#[serde(default)]
|
|
1727
|
+
pub struct ConversionResult {
|
|
1728
|
+
pub content: Option<String>,
|
|
1729
|
+
pub document: Option<DocumentStructure>,
|
|
1730
|
+
pub metadata: HtmlMetadata,
|
|
1731
|
+
pub tables: Vec<TableData>,
|
|
1732
|
+
pub images: Vec<String>,
|
|
1733
|
+
pub warnings: Vec<ProcessingWarning>,
|
|
1734
|
+
}
|
|
1735
|
+
|
|
1736
|
+
unsafe impl IntoValueFromNative for ConversionResult {}
|
|
1737
|
+
|
|
1738
|
+
impl magnus::TryConvert for ConversionResult {
|
|
1739
|
+
fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
|
|
1740
|
+
let r: &ConversionResult = magnus::TryConvert::try_convert(val)?;
|
|
1741
|
+
Ok(r.clone())
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
unsafe impl TryConvertOwned for ConversionResult {}
|
|
1745
|
+
|
|
1746
|
+
impl Default for ConversionResult {
|
|
1747
|
+
fn default() -> Self {
|
|
1748
|
+
Self {
|
|
1749
|
+
content: Default::default(),
|
|
1750
|
+
document: Default::default(),
|
|
1751
|
+
metadata: Default::default(),
|
|
1752
|
+
tables: Default::default(),
|
|
1753
|
+
images: Default::default(),
|
|
1754
|
+
warnings: Default::default(),
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1758
|
+
|
|
1759
|
+
impl ConversionResult {
|
|
1760
|
+
fn new(
|
|
1761
|
+
content: Option<String>,
|
|
1762
|
+
document: Option<DocumentStructure>,
|
|
1763
|
+
metadata: Option<HtmlMetadata>,
|
|
1764
|
+
tables: Option<Vec<TableData>>,
|
|
1765
|
+
images: Option<Vec<String>>,
|
|
1766
|
+
warnings: Option<Vec<ProcessingWarning>>,
|
|
1767
|
+
) -> Self {
|
|
1768
|
+
Self {
|
|
1769
|
+
content,
|
|
1770
|
+
document,
|
|
1771
|
+
metadata: metadata.unwrap_or_default(),
|
|
1772
|
+
tables: tables.unwrap_or_default(),
|
|
1773
|
+
images: images.unwrap_or_default(),
|
|
1774
|
+
warnings: warnings.unwrap_or_default(),
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1777
|
+
|
|
1778
|
+
fn content(&self) -> Option<String> {
|
|
1779
|
+
self.content.clone()
|
|
1780
|
+
}
|
|
1781
|
+
|
|
1782
|
+
fn document(&self) -> Option<DocumentStructure> {
|
|
1783
|
+
self.document.clone()
|
|
1784
|
+
}
|
|
1785
|
+
|
|
1786
|
+
fn metadata(&self) -> HtmlMetadata {
|
|
1787
|
+
self.metadata.clone()
|
|
1788
|
+
}
|
|
1789
|
+
|
|
1790
|
+
fn tables(&self) -> Vec<TableData> {
|
|
1791
|
+
self.tables.clone()
|
|
1792
|
+
}
|
|
1793
|
+
|
|
1794
|
+
fn images(&self) -> Vec<String> {
|
|
1795
|
+
self.images.clone()
|
|
1796
|
+
}
|
|
1797
|
+
|
|
1798
|
+
fn warnings(&self) -> Vec<ProcessingWarning> {
|
|
1799
|
+
self.warnings.clone()
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1802
|
+
|
|
1803
|
+
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
|
1804
|
+
#[magnus::wrap(class = "HtmlToMarkdownRs::TableGrid")]
|
|
1805
|
+
#[serde(default)]
|
|
1806
|
+
pub struct TableGrid {
|
|
1807
|
+
pub rows: u32,
|
|
1808
|
+
pub cols: u32,
|
|
1809
|
+
pub cells: Vec<GridCell>,
|
|
1810
|
+
}
|
|
1811
|
+
|
|
1812
|
+
unsafe impl IntoValueFromNative for TableGrid {}
|
|
1813
|
+
|
|
1814
|
+
impl magnus::TryConvert for TableGrid {
|
|
1815
|
+
fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
|
|
1816
|
+
let r: &TableGrid = magnus::TryConvert::try_convert(val)?;
|
|
1817
|
+
Ok(r.clone())
|
|
1818
|
+
}
|
|
1819
|
+
}
|
|
1820
|
+
unsafe impl TryConvertOwned for TableGrid {}
|
|
1821
|
+
|
|
1822
|
+
impl Default for TableGrid {
|
|
1823
|
+
fn default() -> Self {
|
|
1824
|
+
Self {
|
|
1825
|
+
rows: Default::default(),
|
|
1826
|
+
cols: Default::default(),
|
|
1827
|
+
cells: Default::default(),
|
|
1828
|
+
}
|
|
1829
|
+
}
|
|
1830
|
+
}
|
|
1831
|
+
|
|
1832
|
+
impl TableGrid {
|
|
1833
|
+
fn new(rows: Option<u32>, cols: Option<u32>, cells: Option<Vec<GridCell>>) -> Self {
|
|
1834
|
+
Self {
|
|
1835
|
+
rows: rows.unwrap_or_default(),
|
|
1836
|
+
cols: cols.unwrap_or_default(),
|
|
1837
|
+
cells: cells.unwrap_or_default(),
|
|
1838
|
+
}
|
|
1839
|
+
}
|
|
1840
|
+
|
|
1841
|
+
fn rows(&self) -> u32 {
|
|
1842
|
+
self.rows
|
|
1843
|
+
}
|
|
1844
|
+
|
|
1845
|
+
fn cols(&self) -> u32 {
|
|
1846
|
+
self.cols
|
|
1847
|
+
}
|
|
1848
|
+
|
|
1849
|
+
fn cells(&self) -> Vec<GridCell> {
|
|
1850
|
+
self.cells.clone()
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
|
|
1854
|
+
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
|
1855
|
+
#[magnus::wrap(class = "HtmlToMarkdownRs::GridCell")]
|
|
1856
|
+
pub struct GridCell {
|
|
1857
|
+
pub content: String,
|
|
1858
|
+
pub row: u32,
|
|
1859
|
+
pub col: u32,
|
|
1860
|
+
pub row_span: u32,
|
|
1861
|
+
pub col_span: u32,
|
|
1862
|
+
pub is_header: bool,
|
|
1863
|
+
}
|
|
1864
|
+
|
|
1865
|
+
unsafe impl IntoValueFromNative for GridCell {}
|
|
1866
|
+
|
|
1867
|
+
impl magnus::TryConvert for GridCell {
|
|
1868
|
+
fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
|
|
1869
|
+
let r: &GridCell = magnus::TryConvert::try_convert(val)?;
|
|
1870
|
+
Ok(r.clone())
|
|
1871
|
+
}
|
|
1872
|
+
}
|
|
1873
|
+
unsafe impl TryConvertOwned for GridCell {}
|
|
1874
|
+
|
|
1875
|
+
impl GridCell {
|
|
1876
|
+
fn new(content: String, row: u32, col: u32, row_span: u32, col_span: u32, is_header: bool) -> Self {
|
|
1877
|
+
Self {
|
|
1878
|
+
content,
|
|
1879
|
+
row,
|
|
1880
|
+
col,
|
|
1881
|
+
row_span,
|
|
1882
|
+
col_span,
|
|
1883
|
+
is_header,
|
|
1884
|
+
}
|
|
1885
|
+
}
|
|
1886
|
+
|
|
1887
|
+
fn content(&self) -> String {
|
|
1888
|
+
self.content.clone()
|
|
1889
|
+
}
|
|
1890
|
+
|
|
1891
|
+
fn row(&self) -> u32 {
|
|
1892
|
+
self.row
|
|
1893
|
+
}
|
|
1894
|
+
|
|
1895
|
+
fn col(&self) -> u32 {
|
|
1896
|
+
self.col
|
|
1897
|
+
}
|
|
1898
|
+
|
|
1899
|
+
fn row_span(&self) -> u32 {
|
|
1900
|
+
self.row_span
|
|
1901
|
+
}
|
|
1902
|
+
|
|
1903
|
+
fn col_span(&self) -> u32 {
|
|
1904
|
+
self.col_span
|
|
1905
|
+
}
|
|
1906
|
+
|
|
1907
|
+
fn is_header(&self) -> bool {
|
|
1908
|
+
self.is_header
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
|
|
1912
|
+
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
|
1913
|
+
#[magnus::wrap(class = "HtmlToMarkdownRs::TableData")]
|
|
1914
|
+
pub struct TableData {
|
|
1915
|
+
pub grid: TableGrid,
|
|
1916
|
+
pub markdown: String,
|
|
1917
|
+
}
|
|
1918
|
+
|
|
1919
|
+
unsafe impl IntoValueFromNative for TableData {}
|
|
1920
|
+
|
|
1921
|
+
impl magnus::TryConvert for TableData {
|
|
1922
|
+
fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
|
|
1923
|
+
let r: &TableData = magnus::TryConvert::try_convert(val)?;
|
|
1924
|
+
Ok(r.clone())
|
|
1925
|
+
}
|
|
1926
|
+
}
|
|
1927
|
+
unsafe impl TryConvertOwned for TableData {}
|
|
1928
|
+
|
|
1929
|
+
impl TableData {
|
|
1930
|
+
fn new(grid: TableGrid, markdown: String) -> Self {
|
|
1931
|
+
Self { grid, markdown }
|
|
1932
|
+
}
|
|
1933
|
+
|
|
1934
|
+
fn grid(&self) -> TableGrid {
|
|
1935
|
+
self.grid.clone()
|
|
1936
|
+
}
|
|
1937
|
+
|
|
1938
|
+
fn markdown(&self) -> String {
|
|
1939
|
+
self.markdown.clone()
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
|
|
1943
|
+
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
|
1944
|
+
#[magnus::wrap(class = "HtmlToMarkdownRs::ProcessingWarning")]
|
|
1945
|
+
pub struct ProcessingWarning {
|
|
1946
|
+
pub message: String,
|
|
1947
|
+
pub kind: WarningKind,
|
|
1948
|
+
}
|
|
1949
|
+
|
|
1950
|
+
unsafe impl IntoValueFromNative for ProcessingWarning {}
|
|
1951
|
+
|
|
1952
|
+
impl magnus::TryConvert for ProcessingWarning {
|
|
1953
|
+
fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
|
|
1954
|
+
let r: &ProcessingWarning = magnus::TryConvert::try_convert(val)?;
|
|
1955
|
+
Ok(r.clone())
|
|
1956
|
+
}
|
|
1957
|
+
}
|
|
1958
|
+
unsafe impl TryConvertOwned for ProcessingWarning {}
|
|
1959
|
+
|
|
1960
|
+
impl ProcessingWarning {
|
|
1961
|
+
fn new(message: String, kind: WarningKind) -> Self {
|
|
1962
|
+
Self { message, kind }
|
|
1963
|
+
}
|
|
1964
|
+
|
|
1965
|
+
fn message(&self) -> String {
|
|
1966
|
+
self.message.clone()
|
|
1967
|
+
}
|
|
1968
|
+
|
|
1969
|
+
fn kind(&self) -> WarningKind {
|
|
1970
|
+
self.kind.clone()
|
|
1971
|
+
}
|
|
1972
|
+
}
|
|
1973
|
+
|
|
1974
|
+
#[derive(Clone, Copy, PartialEq, Eq, Debug, serde::Serialize, serde::Deserialize)]
|
|
1975
|
+
pub enum TextDirection {
|
|
1976
|
+
#[serde(rename = "ltr")]
|
|
1977
|
+
LeftToRight,
|
|
1978
|
+
#[serde(rename = "rtl")]
|
|
1979
|
+
RightToLeft,
|
|
1980
|
+
#[serde(rename = "auto")]
|
|
1981
|
+
Auto,
|
|
1982
|
+
}
|
|
1983
|
+
|
|
1984
|
+
impl Default for TextDirection {
|
|
1985
|
+
fn default() -> Self {
|
|
1986
|
+
Self::LeftToRight
|
|
1987
|
+
}
|
|
1988
|
+
}
|
|
1989
|
+
|
|
1990
|
+
impl magnus::IntoValue for TextDirection {
|
|
1991
|
+
fn into_value_with(self, handle: &Ruby) -> magnus::Value {
|
|
1992
|
+
let sym = match self {
|
|
1993
|
+
TextDirection::LeftToRight => "left_to_right",
|
|
1994
|
+
TextDirection::RightToLeft => "right_to_left",
|
|
1995
|
+
TextDirection::Auto => "auto",
|
|
1996
|
+
};
|
|
1997
|
+
handle.to_symbol(sym).into_value_with(handle)
|
|
1998
|
+
}
|
|
1999
|
+
}
|
|
2000
|
+
|
|
2001
|
+
impl magnus::TryConvert for TextDirection {
|
|
2002
|
+
fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
|
|
2003
|
+
let s: String = magnus::TryConvert::try_convert(val)?;
|
|
2004
|
+
match s.as_str() {
|
|
2005
|
+
"left_to_right" => Ok(TextDirection::LeftToRight),
|
|
2006
|
+
"right_to_left" => Ok(TextDirection::RightToLeft),
|
|
2007
|
+
"auto" => Ok(TextDirection::Auto),
|
|
2008
|
+
other => Err(magnus::Error::new(
|
|
2009
|
+
unsafe { Ruby::get_unchecked() }.exception_arg_error(),
|
|
2010
|
+
format!("invalid TextDirection value: {other}"),
|
|
2011
|
+
)),
|
|
2012
|
+
}
|
|
2013
|
+
}
|
|
2014
|
+
}
|
|
2015
|
+
|
|
2016
|
+
unsafe impl IntoValueFromNative for TextDirection {}
|
|
2017
|
+
unsafe impl TryConvertOwned for TextDirection {}
|
|
2018
|
+
|
|
2019
|
+
#[derive(Clone, Copy, PartialEq, Eq, Debug, serde::Serialize, serde::Deserialize)]
|
|
2020
|
+
pub enum LinkType {
|
|
2021
|
+
Anchor,
|
|
2022
|
+
Internal,
|
|
2023
|
+
External,
|
|
2024
|
+
Email,
|
|
2025
|
+
Phone,
|
|
2026
|
+
Other,
|
|
2027
|
+
}
|
|
2028
|
+
|
|
2029
|
+
impl Default for LinkType {
|
|
2030
|
+
fn default() -> Self {
|
|
2031
|
+
Self::Anchor
|
|
2032
|
+
}
|
|
2033
|
+
}
|
|
2034
|
+
|
|
2035
|
+
impl magnus::IntoValue for LinkType {
|
|
2036
|
+
fn into_value_with(self, handle: &Ruby) -> magnus::Value {
|
|
2037
|
+
let sym = match self {
|
|
2038
|
+
LinkType::Anchor => "anchor",
|
|
2039
|
+
LinkType::Internal => "internal",
|
|
2040
|
+
LinkType::External => "external",
|
|
2041
|
+
LinkType::Email => "email",
|
|
2042
|
+
LinkType::Phone => "phone",
|
|
2043
|
+
LinkType::Other => "other",
|
|
2044
|
+
};
|
|
2045
|
+
handle.to_symbol(sym).into_value_with(handle)
|
|
2046
|
+
}
|
|
2047
|
+
}
|
|
2048
|
+
|
|
2049
|
+
impl magnus::TryConvert for LinkType {
|
|
2050
|
+
fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
|
|
2051
|
+
let s: String = magnus::TryConvert::try_convert(val)?;
|
|
2052
|
+
match s.as_str() {
|
|
2053
|
+
"anchor" => Ok(LinkType::Anchor),
|
|
2054
|
+
"internal" => Ok(LinkType::Internal),
|
|
2055
|
+
"external" => Ok(LinkType::External),
|
|
2056
|
+
"email" => Ok(LinkType::Email),
|
|
2057
|
+
"phone" => Ok(LinkType::Phone),
|
|
2058
|
+
"other" => Ok(LinkType::Other),
|
|
2059
|
+
other => Err(magnus::Error::new(
|
|
2060
|
+
unsafe { Ruby::get_unchecked() }.exception_arg_error(),
|
|
2061
|
+
format!("invalid LinkType value: {other}"),
|
|
2062
|
+
)),
|
|
2063
|
+
}
|
|
2064
|
+
}
|
|
2065
|
+
}
|
|
2066
|
+
|
|
2067
|
+
unsafe impl IntoValueFromNative for LinkType {}
|
|
2068
|
+
unsafe impl TryConvertOwned for LinkType {}
|
|
2069
|
+
|
|
2070
|
+
#[derive(Clone, Copy, PartialEq, Eq, Debug, serde::Serialize, serde::Deserialize)]
|
|
2071
|
+
pub enum ImageType {
|
|
2072
|
+
DataUri,
|
|
2073
|
+
InlineSvg,
|
|
2074
|
+
External,
|
|
2075
|
+
Relative,
|
|
2076
|
+
}
|
|
2077
|
+
|
|
2078
|
+
impl Default for ImageType {
|
|
2079
|
+
fn default() -> Self {
|
|
2080
|
+
Self::DataUri
|
|
2081
|
+
}
|
|
2082
|
+
}
|
|
2083
|
+
|
|
2084
|
+
impl magnus::IntoValue for ImageType {
|
|
2085
|
+
fn into_value_with(self, handle: &Ruby) -> magnus::Value {
|
|
2086
|
+
let sym = match self {
|
|
2087
|
+
ImageType::DataUri => "data_uri",
|
|
2088
|
+
ImageType::InlineSvg => "inline_svg",
|
|
2089
|
+
ImageType::External => "external",
|
|
2090
|
+
ImageType::Relative => "relative",
|
|
2091
|
+
};
|
|
2092
|
+
handle.to_symbol(sym).into_value_with(handle)
|
|
2093
|
+
}
|
|
2094
|
+
}
|
|
2095
|
+
|
|
2096
|
+
impl magnus::TryConvert for ImageType {
|
|
2097
|
+
fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
|
|
2098
|
+
let s: String = magnus::TryConvert::try_convert(val)?;
|
|
2099
|
+
match s.as_str() {
|
|
2100
|
+
"data_uri" => Ok(ImageType::DataUri),
|
|
2101
|
+
"inline_svg" => Ok(ImageType::InlineSvg),
|
|
2102
|
+
"external" => Ok(ImageType::External),
|
|
2103
|
+
"relative" => Ok(ImageType::Relative),
|
|
2104
|
+
other => Err(magnus::Error::new(
|
|
2105
|
+
unsafe { Ruby::get_unchecked() }.exception_arg_error(),
|
|
2106
|
+
format!("invalid ImageType value: {other}"),
|
|
2107
|
+
)),
|
|
2108
|
+
}
|
|
2109
|
+
}
|
|
2110
|
+
}
|
|
2111
|
+
|
|
2112
|
+
unsafe impl IntoValueFromNative for ImageType {}
|
|
2113
|
+
unsafe impl TryConvertOwned for ImageType {}
|
|
2114
|
+
|
|
2115
|
+
#[derive(Clone, Copy, PartialEq, Eq, Debug, serde::Serialize, serde::Deserialize)]
|
|
2116
|
+
pub enum StructuredDataType {
|
|
2117
|
+
#[serde(rename = "json_ld")]
|
|
2118
|
+
JsonLd,
|
|
2119
|
+
Microdata,
|
|
2120
|
+
#[serde(rename = "rdfa")]
|
|
2121
|
+
RDFa,
|
|
2122
|
+
}
|
|
2123
|
+
|
|
2124
|
+
impl Default for StructuredDataType {
|
|
2125
|
+
fn default() -> Self {
|
|
2126
|
+
Self::JsonLd
|
|
2127
|
+
}
|
|
2128
|
+
}
|
|
2129
|
+
|
|
2130
|
+
impl magnus::IntoValue for StructuredDataType {
|
|
2131
|
+
fn into_value_with(self, handle: &Ruby) -> magnus::Value {
|
|
2132
|
+
let sym = match self {
|
|
2133
|
+
StructuredDataType::JsonLd => "json_ld",
|
|
2134
|
+
StructuredDataType::Microdata => "microdata",
|
|
2135
|
+
StructuredDataType::RDFa => "r_d_fa",
|
|
2136
|
+
};
|
|
2137
|
+
handle.to_symbol(sym).into_value_with(handle)
|
|
2138
|
+
}
|
|
2139
|
+
}
|
|
2140
|
+
|
|
2141
|
+
impl magnus::TryConvert for StructuredDataType {
|
|
2142
|
+
fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
|
|
2143
|
+
let s: String = magnus::TryConvert::try_convert(val)?;
|
|
2144
|
+
match s.as_str() {
|
|
2145
|
+
"json_ld" => Ok(StructuredDataType::JsonLd),
|
|
2146
|
+
"microdata" => Ok(StructuredDataType::Microdata),
|
|
2147
|
+
"r_d_fa" => Ok(StructuredDataType::RDFa),
|
|
2148
|
+
other => Err(magnus::Error::new(
|
|
2149
|
+
unsafe { Ruby::get_unchecked() }.exception_arg_error(),
|
|
2150
|
+
format!("invalid StructuredDataType value: {other}"),
|
|
2151
|
+
)),
|
|
2152
|
+
}
|
|
2153
|
+
}
|
|
2154
|
+
}
|
|
2155
|
+
|
|
2156
|
+
unsafe impl IntoValueFromNative for StructuredDataType {}
|
|
2157
|
+
unsafe impl TryConvertOwned for StructuredDataType {}
|
|
2158
|
+
|
|
2159
|
+
#[derive(Clone, Copy, PartialEq, Eq, Debug, serde::Serialize, serde::Deserialize)]
|
|
2160
|
+
pub enum PreprocessingPreset {
|
|
2161
|
+
Minimal,
|
|
2162
|
+
Standard,
|
|
2163
|
+
Aggressive,
|
|
2164
|
+
}
|
|
2165
|
+
|
|
2166
|
+
impl Default for PreprocessingPreset {
|
|
2167
|
+
fn default() -> Self {
|
|
2168
|
+
Self::Minimal
|
|
2169
|
+
}
|
|
2170
|
+
}
|
|
2171
|
+
|
|
2172
|
+
impl magnus::IntoValue for PreprocessingPreset {
|
|
2173
|
+
fn into_value_with(self, handle: &Ruby) -> magnus::Value {
|
|
2174
|
+
let sym = match self {
|
|
2175
|
+
PreprocessingPreset::Minimal => "minimal",
|
|
2176
|
+
PreprocessingPreset::Standard => "standard",
|
|
2177
|
+
PreprocessingPreset::Aggressive => "aggressive",
|
|
2178
|
+
};
|
|
2179
|
+
handle.to_symbol(sym).into_value_with(handle)
|
|
2180
|
+
}
|
|
2181
|
+
}
|
|
2182
|
+
|
|
2183
|
+
impl magnus::TryConvert for PreprocessingPreset {
|
|
2184
|
+
fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
|
|
2185
|
+
let s: String = magnus::TryConvert::try_convert(val)?;
|
|
2186
|
+
match s.as_str() {
|
|
2187
|
+
"minimal" => Ok(PreprocessingPreset::Minimal),
|
|
2188
|
+
"standard" => Ok(PreprocessingPreset::Standard),
|
|
2189
|
+
"aggressive" => Ok(PreprocessingPreset::Aggressive),
|
|
2190
|
+
other => Err(magnus::Error::new(
|
|
2191
|
+
unsafe { Ruby::get_unchecked() }.exception_arg_error(),
|
|
2192
|
+
format!("invalid PreprocessingPreset value: {other}"),
|
|
2193
|
+
)),
|
|
2194
|
+
}
|
|
2195
|
+
}
|
|
2196
|
+
}
|
|
2197
|
+
|
|
2198
|
+
unsafe impl IntoValueFromNative for PreprocessingPreset {}
|
|
2199
|
+
unsafe impl TryConvertOwned for PreprocessingPreset {}
|
|
2200
|
+
|
|
2201
|
+
#[derive(Clone, Copy, PartialEq, Eq, Debug, serde::Serialize, serde::Deserialize)]
|
|
2202
|
+
pub enum HeadingStyle {
|
|
2203
|
+
Underlined,
|
|
2204
|
+
Atx,
|
|
2205
|
+
AtxClosed,
|
|
2206
|
+
}
|
|
2207
|
+
|
|
2208
|
+
impl Default for HeadingStyle {
|
|
2209
|
+
fn default() -> Self {
|
|
2210
|
+
Self::Underlined
|
|
2211
|
+
}
|
|
2212
|
+
}
|
|
2213
|
+
|
|
2214
|
+
impl magnus::IntoValue for HeadingStyle {
|
|
2215
|
+
fn into_value_with(self, handle: &Ruby) -> magnus::Value {
|
|
2216
|
+
let sym = match self {
|
|
2217
|
+
HeadingStyle::Underlined => "underlined",
|
|
2218
|
+
HeadingStyle::Atx => "atx",
|
|
2219
|
+
HeadingStyle::AtxClosed => "atx_closed",
|
|
2220
|
+
};
|
|
2221
|
+
handle.to_symbol(sym).into_value_with(handle)
|
|
2222
|
+
}
|
|
2223
|
+
}
|
|
2224
|
+
|
|
2225
|
+
impl magnus::TryConvert for HeadingStyle {
|
|
2226
|
+
fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
|
|
2227
|
+
let s: String = magnus::TryConvert::try_convert(val)?;
|
|
2228
|
+
match s.as_str() {
|
|
2229
|
+
"underlined" => Ok(HeadingStyle::Underlined),
|
|
2230
|
+
"atx" => Ok(HeadingStyle::Atx),
|
|
2231
|
+
"atx_closed" => Ok(HeadingStyle::AtxClosed),
|
|
2232
|
+
other => Err(magnus::Error::new(
|
|
2233
|
+
unsafe { Ruby::get_unchecked() }.exception_arg_error(),
|
|
2234
|
+
format!("invalid HeadingStyle value: {other}"),
|
|
2235
|
+
)),
|
|
2236
|
+
}
|
|
2237
|
+
}
|
|
2238
|
+
}
|
|
2239
|
+
|
|
2240
|
+
unsafe impl IntoValueFromNative for HeadingStyle {}
|
|
2241
|
+
unsafe impl TryConvertOwned for HeadingStyle {}
|
|
2242
|
+
|
|
2243
|
+
#[derive(Clone, Copy, PartialEq, Eq, Debug, serde::Serialize, serde::Deserialize)]
|
|
2244
|
+
pub enum ListIndentType {
|
|
2245
|
+
Spaces,
|
|
2246
|
+
Tabs,
|
|
2247
|
+
}
|
|
2248
|
+
|
|
2249
|
+
impl Default for ListIndentType {
|
|
2250
|
+
fn default() -> Self {
|
|
2251
|
+
Self::Spaces
|
|
2252
|
+
}
|
|
2253
|
+
}
|
|
2254
|
+
|
|
2255
|
+
impl magnus::IntoValue for ListIndentType {
|
|
2256
|
+
fn into_value_with(self, handle: &Ruby) -> magnus::Value {
|
|
2257
|
+
let sym = match self {
|
|
2258
|
+
ListIndentType::Spaces => "spaces",
|
|
2259
|
+
ListIndentType::Tabs => "tabs",
|
|
2260
|
+
};
|
|
2261
|
+
handle.to_symbol(sym).into_value_with(handle)
|
|
2262
|
+
}
|
|
2263
|
+
}
|
|
2264
|
+
|
|
2265
|
+
impl magnus::TryConvert for ListIndentType {
|
|
2266
|
+
fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
|
|
2267
|
+
let s: String = magnus::TryConvert::try_convert(val)?;
|
|
2268
|
+
match s.as_str() {
|
|
2269
|
+
"spaces" => Ok(ListIndentType::Spaces),
|
|
2270
|
+
"tabs" => Ok(ListIndentType::Tabs),
|
|
2271
|
+
other => Err(magnus::Error::new(
|
|
2272
|
+
unsafe { Ruby::get_unchecked() }.exception_arg_error(),
|
|
2273
|
+
format!("invalid ListIndentType value: {other}"),
|
|
2274
|
+
)),
|
|
2275
|
+
}
|
|
2276
|
+
}
|
|
2277
|
+
}
|
|
2278
|
+
|
|
2279
|
+
unsafe impl IntoValueFromNative for ListIndentType {}
|
|
2280
|
+
unsafe impl TryConvertOwned for ListIndentType {}
|
|
2281
|
+
|
|
2282
|
+
#[derive(Clone, Copy, PartialEq, Eq, Debug, serde::Serialize, serde::Deserialize)]
|
|
2283
|
+
pub enum WhitespaceMode {
|
|
2284
|
+
Normalized,
|
|
2285
|
+
Strict,
|
|
2286
|
+
}
|
|
2287
|
+
|
|
2288
|
+
impl Default for WhitespaceMode {
|
|
2289
|
+
fn default() -> Self {
|
|
2290
|
+
Self::Normalized
|
|
2291
|
+
}
|
|
2292
|
+
}
|
|
2293
|
+
|
|
2294
|
+
impl magnus::IntoValue for WhitespaceMode {
|
|
2295
|
+
fn into_value_with(self, handle: &Ruby) -> magnus::Value {
|
|
2296
|
+
let sym = match self {
|
|
2297
|
+
WhitespaceMode::Normalized => "normalized",
|
|
2298
|
+
WhitespaceMode::Strict => "strict",
|
|
2299
|
+
};
|
|
2300
|
+
handle.to_symbol(sym).into_value_with(handle)
|
|
2301
|
+
}
|
|
2302
|
+
}
|
|
2303
|
+
|
|
2304
|
+
impl magnus::TryConvert for WhitespaceMode {
|
|
2305
|
+
fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
|
|
2306
|
+
let s: String = magnus::TryConvert::try_convert(val)?;
|
|
2307
|
+
match s.as_str() {
|
|
2308
|
+
"normalized" => Ok(WhitespaceMode::Normalized),
|
|
2309
|
+
"strict" => Ok(WhitespaceMode::Strict),
|
|
2310
|
+
other => Err(magnus::Error::new(
|
|
2311
|
+
unsafe { Ruby::get_unchecked() }.exception_arg_error(),
|
|
2312
|
+
format!("invalid WhitespaceMode value: {other}"),
|
|
2313
|
+
)),
|
|
2314
|
+
}
|
|
2315
|
+
}
|
|
2316
|
+
}
|
|
2317
|
+
|
|
2318
|
+
unsafe impl IntoValueFromNative for WhitespaceMode {}
|
|
2319
|
+
unsafe impl TryConvertOwned for WhitespaceMode {}
|
|
2320
|
+
|
|
2321
|
+
#[derive(Clone, Copy, PartialEq, Eq, Debug, serde::Serialize, serde::Deserialize)]
|
|
2322
|
+
pub enum NewlineStyle {
|
|
2323
|
+
Spaces,
|
|
2324
|
+
Backslash,
|
|
2325
|
+
}
|
|
2326
|
+
|
|
2327
|
+
impl Default for NewlineStyle {
|
|
2328
|
+
fn default() -> Self {
|
|
2329
|
+
Self::Spaces
|
|
2330
|
+
}
|
|
2331
|
+
}
|
|
2332
|
+
|
|
2333
|
+
impl magnus::IntoValue for NewlineStyle {
|
|
2334
|
+
fn into_value_with(self, handle: &Ruby) -> magnus::Value {
|
|
2335
|
+
let sym = match self {
|
|
2336
|
+
NewlineStyle::Spaces => "spaces",
|
|
2337
|
+
NewlineStyle::Backslash => "backslash",
|
|
2338
|
+
};
|
|
2339
|
+
handle.to_symbol(sym).into_value_with(handle)
|
|
2340
|
+
}
|
|
2341
|
+
}
|
|
2342
|
+
|
|
2343
|
+
impl magnus::TryConvert for NewlineStyle {
|
|
2344
|
+
fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
|
|
2345
|
+
let s: String = magnus::TryConvert::try_convert(val)?;
|
|
2346
|
+
match s.as_str() {
|
|
2347
|
+
"spaces" => Ok(NewlineStyle::Spaces),
|
|
2348
|
+
"backslash" => Ok(NewlineStyle::Backslash),
|
|
2349
|
+
other => Err(magnus::Error::new(
|
|
2350
|
+
unsafe { Ruby::get_unchecked() }.exception_arg_error(),
|
|
2351
|
+
format!("invalid NewlineStyle value: {other}"),
|
|
2352
|
+
)),
|
|
2353
|
+
}
|
|
2354
|
+
}
|
|
2355
|
+
}
|
|
2356
|
+
|
|
2357
|
+
unsafe impl IntoValueFromNative for NewlineStyle {}
|
|
2358
|
+
unsafe impl TryConvertOwned for NewlineStyle {}
|
|
2359
|
+
|
|
2360
|
+
#[derive(Clone, Copy, PartialEq, Eq, Debug, serde::Serialize, serde::Deserialize)]
|
|
2361
|
+
pub enum CodeBlockStyle {
|
|
2362
|
+
Indented,
|
|
2363
|
+
Backticks,
|
|
2364
|
+
Tildes,
|
|
2365
|
+
}
|
|
2366
|
+
|
|
2367
|
+
impl Default for CodeBlockStyle {
|
|
2368
|
+
fn default() -> Self {
|
|
2369
|
+
Self::Indented
|
|
2370
|
+
}
|
|
2371
|
+
}
|
|
2372
|
+
|
|
2373
|
+
impl magnus::IntoValue for CodeBlockStyle {
|
|
2374
|
+
fn into_value_with(self, handle: &Ruby) -> magnus::Value {
|
|
2375
|
+
let sym = match self {
|
|
2376
|
+
CodeBlockStyle::Indented => "indented",
|
|
2377
|
+
CodeBlockStyle::Backticks => "backticks",
|
|
2378
|
+
CodeBlockStyle::Tildes => "tildes",
|
|
2379
|
+
};
|
|
2380
|
+
handle.to_symbol(sym).into_value_with(handle)
|
|
2381
|
+
}
|
|
2382
|
+
}
|
|
2383
|
+
|
|
2384
|
+
impl magnus::TryConvert for CodeBlockStyle {
|
|
2385
|
+
fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
|
|
2386
|
+
let s: String = magnus::TryConvert::try_convert(val)?;
|
|
2387
|
+
match s.as_str() {
|
|
2388
|
+
"indented" => Ok(CodeBlockStyle::Indented),
|
|
2389
|
+
"backticks" => Ok(CodeBlockStyle::Backticks),
|
|
2390
|
+
"tildes" => Ok(CodeBlockStyle::Tildes),
|
|
2391
|
+
other => Err(magnus::Error::new(
|
|
2392
|
+
unsafe { Ruby::get_unchecked() }.exception_arg_error(),
|
|
2393
|
+
format!("invalid CodeBlockStyle value: {other}"),
|
|
2394
|
+
)),
|
|
2395
|
+
}
|
|
2396
|
+
}
|
|
2397
|
+
}
|
|
2398
|
+
|
|
2399
|
+
unsafe impl IntoValueFromNative for CodeBlockStyle {}
|
|
2400
|
+
unsafe impl TryConvertOwned for CodeBlockStyle {}
|
|
2401
|
+
|
|
2402
|
+
#[derive(Clone, Copy, PartialEq, Eq, Debug, serde::Serialize, serde::Deserialize)]
|
|
2403
|
+
pub enum HighlightStyle {
|
|
2404
|
+
DoubleEqual,
|
|
2405
|
+
Html,
|
|
2406
|
+
Bold,
|
|
2407
|
+
None,
|
|
2408
|
+
}
|
|
2409
|
+
|
|
2410
|
+
impl Default for HighlightStyle {
|
|
2411
|
+
fn default() -> Self {
|
|
2412
|
+
Self::DoubleEqual
|
|
2413
|
+
}
|
|
2414
|
+
}
|
|
2415
|
+
|
|
2416
|
+
impl magnus::IntoValue for HighlightStyle {
|
|
2417
|
+
fn into_value_with(self, handle: &Ruby) -> magnus::Value {
|
|
2418
|
+
let sym = match self {
|
|
2419
|
+
HighlightStyle::DoubleEqual => "double_equal",
|
|
2420
|
+
HighlightStyle::Html => "html",
|
|
2421
|
+
HighlightStyle::Bold => "bold",
|
|
2422
|
+
HighlightStyle::None => "none",
|
|
2423
|
+
};
|
|
2424
|
+
handle.to_symbol(sym).into_value_with(handle)
|
|
2425
|
+
}
|
|
2426
|
+
}
|
|
2427
|
+
|
|
2428
|
+
impl magnus::TryConvert for HighlightStyle {
|
|
2429
|
+
fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
|
|
2430
|
+
let s: String = magnus::TryConvert::try_convert(val)?;
|
|
2431
|
+
match s.as_str() {
|
|
2432
|
+
"double_equal" => Ok(HighlightStyle::DoubleEqual),
|
|
2433
|
+
"html" => Ok(HighlightStyle::Html),
|
|
2434
|
+
"bold" => Ok(HighlightStyle::Bold),
|
|
2435
|
+
"none" => Ok(HighlightStyle::None),
|
|
2436
|
+
other => Err(magnus::Error::new(
|
|
2437
|
+
unsafe { Ruby::get_unchecked() }.exception_arg_error(),
|
|
2438
|
+
format!("invalid HighlightStyle value: {other}"),
|
|
2439
|
+
)),
|
|
2440
|
+
}
|
|
2441
|
+
}
|
|
2442
|
+
}
|
|
2443
|
+
|
|
2444
|
+
unsafe impl IntoValueFromNative for HighlightStyle {}
|
|
2445
|
+
unsafe impl TryConvertOwned for HighlightStyle {}
|
|
2446
|
+
|
|
2447
|
+
#[derive(Clone, Copy, PartialEq, Eq, Debug, serde::Serialize, serde::Deserialize)]
|
|
2448
|
+
pub enum LinkStyle {
|
|
2449
|
+
Inline,
|
|
2450
|
+
Reference,
|
|
2451
|
+
}
|
|
2452
|
+
|
|
2453
|
+
impl Default for LinkStyle {
|
|
2454
|
+
fn default() -> Self {
|
|
2455
|
+
Self::Inline
|
|
2456
|
+
}
|
|
2457
|
+
}
|
|
2458
|
+
|
|
2459
|
+
impl magnus::IntoValue for LinkStyle {
|
|
2460
|
+
fn into_value_with(self, handle: &Ruby) -> magnus::Value {
|
|
2461
|
+
let sym = match self {
|
|
2462
|
+
LinkStyle::Inline => "inline",
|
|
2463
|
+
LinkStyle::Reference => "reference",
|
|
2464
|
+
};
|
|
2465
|
+
handle.to_symbol(sym).into_value_with(handle)
|
|
2466
|
+
}
|
|
2467
|
+
}
|
|
2468
|
+
|
|
2469
|
+
impl magnus::TryConvert for LinkStyle {
|
|
2470
|
+
fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
|
|
2471
|
+
let s: String = magnus::TryConvert::try_convert(val)?;
|
|
2472
|
+
match s.as_str() {
|
|
2473
|
+
"inline" => Ok(LinkStyle::Inline),
|
|
2474
|
+
"reference" => Ok(LinkStyle::Reference),
|
|
2475
|
+
other => Err(magnus::Error::new(
|
|
2476
|
+
unsafe { Ruby::get_unchecked() }.exception_arg_error(),
|
|
2477
|
+
format!("invalid LinkStyle value: {other}"),
|
|
2478
|
+
)),
|
|
2479
|
+
}
|
|
2480
|
+
}
|
|
2481
|
+
}
|
|
2482
|
+
|
|
2483
|
+
unsafe impl IntoValueFromNative for LinkStyle {}
|
|
2484
|
+
unsafe impl TryConvertOwned for LinkStyle {}
|
|
2485
|
+
|
|
2486
|
+
#[derive(Clone, Copy, PartialEq, Eq, Debug, serde::Serialize, serde::Deserialize)]
|
|
2487
|
+
pub enum OutputFormat {
|
|
2488
|
+
Markdown,
|
|
2489
|
+
Djot,
|
|
2490
|
+
Plain,
|
|
2491
|
+
}
|
|
2492
|
+
|
|
2493
|
+
impl Default for OutputFormat {
|
|
2494
|
+
fn default() -> Self {
|
|
2495
|
+
Self::Markdown
|
|
2496
|
+
}
|
|
2497
|
+
}
|
|
2498
|
+
|
|
2499
|
+
impl magnus::IntoValue for OutputFormat {
|
|
2500
|
+
fn into_value_with(self, handle: &Ruby) -> magnus::Value {
|
|
2501
|
+
let sym = match self {
|
|
2502
|
+
OutputFormat::Markdown => "markdown",
|
|
2503
|
+
OutputFormat::Djot => "djot",
|
|
2504
|
+
OutputFormat::Plain => "plain",
|
|
2505
|
+
};
|
|
2506
|
+
handle.to_symbol(sym).into_value_with(handle)
|
|
2507
|
+
}
|
|
2508
|
+
}
|
|
2509
|
+
|
|
2510
|
+
impl magnus::TryConvert for OutputFormat {
|
|
2511
|
+
fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
|
|
2512
|
+
let s: String = magnus::TryConvert::try_convert(val)?;
|
|
2513
|
+
match s.as_str() {
|
|
2514
|
+
"markdown" => Ok(OutputFormat::Markdown),
|
|
2515
|
+
"djot" => Ok(OutputFormat::Djot),
|
|
2516
|
+
"plain" => Ok(OutputFormat::Plain),
|
|
2517
|
+
other => Err(magnus::Error::new(
|
|
2518
|
+
unsafe { Ruby::get_unchecked() }.exception_arg_error(),
|
|
2519
|
+
format!("invalid OutputFormat value: {other}"),
|
|
2520
|
+
)),
|
|
2521
|
+
}
|
|
2522
|
+
}
|
|
2523
|
+
}
|
|
2524
|
+
|
|
2525
|
+
unsafe impl IntoValueFromNative for OutputFormat {}
|
|
2526
|
+
unsafe impl TryConvertOwned for OutputFormat {}
|
|
2527
|
+
|
|
2528
|
+
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
|
2529
|
+
#[serde(tag = "node_type")]
|
|
2530
|
+
pub enum NodeContent {
|
|
2531
|
+
Heading {
|
|
2532
|
+
level: u8,
|
|
2533
|
+
text: String,
|
|
2534
|
+
},
|
|
2535
|
+
Paragraph {
|
|
2536
|
+
text: String,
|
|
2537
|
+
},
|
|
2538
|
+
List {
|
|
2539
|
+
ordered: bool,
|
|
2540
|
+
},
|
|
2541
|
+
ListItem {
|
|
2542
|
+
text: String,
|
|
2543
|
+
},
|
|
2544
|
+
Table {
|
|
2545
|
+
grid: TableGrid,
|
|
2546
|
+
},
|
|
2547
|
+
Image {
|
|
2548
|
+
description: Option<String>,
|
|
2549
|
+
src: Option<String>,
|
|
2550
|
+
image_index: Option<u32>,
|
|
2551
|
+
},
|
|
2552
|
+
Code {
|
|
2553
|
+
text: String,
|
|
2554
|
+
language: Option<String>,
|
|
2555
|
+
},
|
|
2556
|
+
Quote,
|
|
2557
|
+
DefinitionList,
|
|
2558
|
+
DefinitionItem {
|
|
2559
|
+
term: String,
|
|
2560
|
+
definition: String,
|
|
2561
|
+
},
|
|
2562
|
+
RawBlock {
|
|
2563
|
+
format: String,
|
|
2564
|
+
content: String,
|
|
2565
|
+
},
|
|
2566
|
+
MetadataBlock {
|
|
2567
|
+
entries: String,
|
|
2568
|
+
},
|
|
2569
|
+
Group {
|
|
2570
|
+
label: Option<String>,
|
|
2571
|
+
heading_level: Option<u8>,
|
|
2572
|
+
heading_text: Option<String>,
|
|
2573
|
+
},
|
|
2574
|
+
}
|
|
2575
|
+
|
|
2576
|
+
impl Default for NodeContent {
|
|
2577
|
+
fn default() -> Self {
|
|
2578
|
+
Self::Heading {
|
|
2579
|
+
level: Default::default(),
|
|
2580
|
+
text: Default::default(),
|
|
2581
|
+
}
|
|
2582
|
+
}
|
|
2583
|
+
}
|
|
2584
|
+
|
|
2585
|
+
impl magnus::IntoValue for NodeContent {
|
|
2586
|
+
fn into_value_with(self, handle: &Ruby) -> magnus::Value {
|
|
2587
|
+
match serde_json::to_value(&self) {
|
|
2588
|
+
Ok(v) => json_to_ruby(handle, v),
|
|
2589
|
+
Err(_) => handle.qnil().into_value_with(handle),
|
|
2590
|
+
}
|
|
2591
|
+
}
|
|
2592
|
+
}
|
|
2593
|
+
|
|
2594
|
+
impl magnus::TryConvert for NodeContent {
|
|
2595
|
+
fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
|
|
2596
|
+
let s: String = magnus::TryConvert::try_convert(val)?;
|
|
2597
|
+
serde_json::from_str(&s).map_err(|e| magnus::Error::new(magnus::exception::type_error(), e.to_string()))
|
|
2598
|
+
}
|
|
2599
|
+
}
|
|
2600
|
+
|
|
2601
|
+
unsafe impl IntoValueFromNative for NodeContent {}
|
|
2602
|
+
unsafe impl TryConvertOwned for NodeContent {}
|
|
2603
|
+
|
|
2604
|
+
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
|
2605
|
+
#[serde(tag = "annotation_type")]
|
|
2606
|
+
pub enum AnnotationKind {
|
|
2607
|
+
Bold,
|
|
2608
|
+
Italic,
|
|
2609
|
+
Underline,
|
|
2610
|
+
Strikethrough,
|
|
2611
|
+
Code,
|
|
2612
|
+
Subscript,
|
|
2613
|
+
Superscript,
|
|
2614
|
+
Highlight,
|
|
2615
|
+
Link { url: String, title: Option<String> },
|
|
2616
|
+
}
|
|
2617
|
+
|
|
2618
|
+
impl Default for AnnotationKind {
|
|
2619
|
+
fn default() -> Self {
|
|
2620
|
+
Self::Bold
|
|
2621
|
+
}
|
|
2622
|
+
}
|
|
2623
|
+
|
|
2624
|
+
impl magnus::IntoValue for AnnotationKind {
|
|
2625
|
+
fn into_value_with(self, handle: &Ruby) -> magnus::Value {
|
|
2626
|
+
match serde_json::to_value(&self) {
|
|
2627
|
+
Ok(v) => json_to_ruby(handle, v),
|
|
2628
|
+
Err(_) => handle.qnil().into_value_with(handle),
|
|
2629
|
+
}
|
|
2630
|
+
}
|
|
2631
|
+
}
|
|
2632
|
+
|
|
2633
|
+
impl magnus::TryConvert for AnnotationKind {
|
|
2634
|
+
fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
|
|
2635
|
+
let s: String = magnus::TryConvert::try_convert(val)?;
|
|
2636
|
+
serde_json::from_str(&s).map_err(|e| magnus::Error::new(magnus::exception::type_error(), e.to_string()))
|
|
2637
|
+
}
|
|
2638
|
+
}
|
|
2639
|
+
|
|
2640
|
+
unsafe impl IntoValueFromNative for AnnotationKind {}
|
|
2641
|
+
unsafe impl TryConvertOwned for AnnotationKind {}
|
|
2642
|
+
|
|
2643
|
+
#[derive(Clone, Copy, PartialEq, Eq, Debug, serde::Serialize, serde::Deserialize)]
|
|
2644
|
+
pub enum WarningKind {
|
|
2645
|
+
ImageExtractionFailed,
|
|
2646
|
+
EncodingFallback,
|
|
2647
|
+
TruncatedInput,
|
|
2648
|
+
MalformedHtml,
|
|
2649
|
+
SanitizationApplied,
|
|
2650
|
+
}
|
|
2651
|
+
|
|
2652
|
+
impl Default for WarningKind {
|
|
2653
|
+
fn default() -> Self {
|
|
2654
|
+
Self::ImageExtractionFailed
|
|
2655
|
+
}
|
|
2656
|
+
}
|
|
2657
|
+
|
|
2658
|
+
impl magnus::IntoValue for WarningKind {
|
|
2659
|
+
fn into_value_with(self, handle: &Ruby) -> magnus::Value {
|
|
2660
|
+
let sym = match self {
|
|
2661
|
+
WarningKind::ImageExtractionFailed => "image_extraction_failed",
|
|
2662
|
+
WarningKind::EncodingFallback => "encoding_fallback",
|
|
2663
|
+
WarningKind::TruncatedInput => "truncated_input",
|
|
2664
|
+
WarningKind::MalformedHtml => "malformed_html",
|
|
2665
|
+
WarningKind::SanitizationApplied => "sanitization_applied",
|
|
2666
|
+
};
|
|
2667
|
+
handle.to_symbol(sym).into_value_with(handle)
|
|
2668
|
+
}
|
|
2669
|
+
}
|
|
2670
|
+
|
|
2671
|
+
impl magnus::TryConvert for WarningKind {
|
|
2672
|
+
fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
|
|
2673
|
+
let s: String = magnus::TryConvert::try_convert(val)?;
|
|
2674
|
+
match s.as_str() {
|
|
2675
|
+
"image_extraction_failed" => Ok(WarningKind::ImageExtractionFailed),
|
|
2676
|
+
"encoding_fallback" => Ok(WarningKind::EncodingFallback),
|
|
2677
|
+
"truncated_input" => Ok(WarningKind::TruncatedInput),
|
|
2678
|
+
"malformed_html" => Ok(WarningKind::MalformedHtml),
|
|
2679
|
+
"sanitization_applied" => Ok(WarningKind::SanitizationApplied),
|
|
2680
|
+
other => Err(magnus::Error::new(
|
|
2681
|
+
unsafe { Ruby::get_unchecked() }.exception_arg_error(),
|
|
2682
|
+
format!("invalid WarningKind value: {other}"),
|
|
2683
|
+
)),
|
|
2684
|
+
}
|
|
2685
|
+
}
|
|
2686
|
+
}
|
|
2687
|
+
|
|
2688
|
+
unsafe impl IntoValueFromNative for WarningKind {}
|
|
2689
|
+
unsafe impl TryConvertOwned for WarningKind {}
|
|
2690
|
+
|
|
2691
|
+
fn convert(html: String, options: Option<String>) -> Result<ConversionResult, Error> {
|
|
2692
|
+
let options: Option<ConversionOptions> = options
|
|
2693
|
+
.as_deref()
|
|
2694
|
+
.filter(|s| *s != "nil")
|
|
2695
|
+
.map(|s| {
|
|
2696
|
+
let core: html_to_markdown_rs::ConversionOptions = serde_json::from_str(s)
|
|
2697
|
+
.map_err(|e| magnus::Error::new(magnus::exception::type_error(), e.to_string()))?;
|
|
2698
|
+
Ok::<_, magnus::Error>(core.into())
|
|
2699
|
+
})
|
|
2700
|
+
.transpose()?;
|
|
2701
|
+
let result = html_to_markdown_rs::convert(&html, options.map(Into::into))
|
|
2702
|
+
.map_err(|e| magnus::Error::new(magnus::exception::runtime_error(), e.to_string()))?;
|
|
2703
|
+
Ok(result.into())
|
|
2704
|
+
}
|
|
2705
|
+
|
|
2706
|
+
impl From<MetadataConfig> for html_to_markdown_rs::metadata::MetadataConfig {
|
|
2707
|
+
fn from(val: MetadataConfig) -> Self {
|
|
2708
|
+
Self {
|
|
2709
|
+
extract_document: val.extract_document,
|
|
2710
|
+
extract_headers: val.extract_headers,
|
|
2711
|
+
extract_links: val.extract_links,
|
|
2712
|
+
extract_images: val.extract_images,
|
|
2713
|
+
extract_structured_data: val.extract_structured_data,
|
|
2714
|
+
max_structured_data_size: val.max_structured_data_size,
|
|
2715
|
+
}
|
|
2716
|
+
}
|
|
2717
|
+
}
|
|
2718
|
+
|
|
2719
|
+
impl From<html_to_markdown_rs::metadata::MetadataConfig> for MetadataConfig {
|
|
2720
|
+
fn from(val: html_to_markdown_rs::metadata::MetadataConfig) -> Self {
|
|
2721
|
+
Self {
|
|
2722
|
+
extract_document: val.extract_document,
|
|
2723
|
+
extract_headers: val.extract_headers,
|
|
2724
|
+
extract_links: val.extract_links,
|
|
2725
|
+
extract_images: val.extract_images,
|
|
2726
|
+
extract_structured_data: val.extract_structured_data,
|
|
2727
|
+
max_structured_data_size: val.max_structured_data_size,
|
|
2728
|
+
}
|
|
2729
|
+
}
|
|
2730
|
+
}
|
|
2731
|
+
|
|
2732
|
+
impl From<html_to_markdown_rs::metadata::MetadataConfigUpdate> for MetadataConfigUpdate {
|
|
2733
|
+
fn from(val: html_to_markdown_rs::metadata::MetadataConfigUpdate) -> Self {
|
|
2734
|
+
Self {
|
|
2735
|
+
extract_document: val.extract_document,
|
|
2736
|
+
extract_headers: val.extract_headers,
|
|
2737
|
+
extract_links: val.extract_links,
|
|
2738
|
+
extract_images: val.extract_images,
|
|
2739
|
+
extract_structured_data: val.extract_structured_data,
|
|
2740
|
+
max_structured_data_size: val.max_structured_data_size,
|
|
2741
|
+
}
|
|
2742
|
+
}
|
|
2743
|
+
}
|
|
2744
|
+
|
|
2745
|
+
impl From<DocumentMetadata> for html_to_markdown_rs::metadata::DocumentMetadata {
|
|
2746
|
+
fn from(val: DocumentMetadata) -> Self {
|
|
2747
|
+
Self {
|
|
2748
|
+
title: val.title,
|
|
2749
|
+
description: val.description,
|
|
2750
|
+
keywords: val.keywords,
|
|
2751
|
+
author: val.author,
|
|
2752
|
+
canonical_url: val.canonical_url,
|
|
2753
|
+
base_href: val.base_href,
|
|
2754
|
+
language: val.language,
|
|
2755
|
+
text_direction: val.text_direction.map(Into::into),
|
|
2756
|
+
open_graph: val.open_graph.into_iter().collect(),
|
|
2757
|
+
twitter_card: val.twitter_card.into_iter().collect(),
|
|
2758
|
+
meta_tags: val.meta_tags.into_iter().collect(),
|
|
2759
|
+
}
|
|
2760
|
+
}
|
|
2761
|
+
}
|
|
2762
|
+
|
|
2763
|
+
impl From<html_to_markdown_rs::metadata::DocumentMetadata> for DocumentMetadata {
|
|
2764
|
+
fn from(val: html_to_markdown_rs::metadata::DocumentMetadata) -> Self {
|
|
2765
|
+
Self {
|
|
2766
|
+
title: val.title,
|
|
2767
|
+
description: val.description,
|
|
2768
|
+
keywords: val.keywords,
|
|
2769
|
+
author: val.author,
|
|
2770
|
+
canonical_url: val.canonical_url,
|
|
2771
|
+
base_href: val.base_href,
|
|
2772
|
+
language: val.language,
|
|
2773
|
+
text_direction: val.text_direction.map(Into::into),
|
|
2774
|
+
open_graph: val.open_graph.into_iter().collect(),
|
|
2775
|
+
twitter_card: val.twitter_card.into_iter().collect(),
|
|
2776
|
+
meta_tags: val.meta_tags.into_iter().collect(),
|
|
2777
|
+
}
|
|
2778
|
+
}
|
|
2779
|
+
}
|
|
2780
|
+
|
|
2781
|
+
impl From<HeaderMetadata> for html_to_markdown_rs::metadata::HeaderMetadata {
|
|
2782
|
+
fn from(val: HeaderMetadata) -> Self {
|
|
2783
|
+
Self {
|
|
2784
|
+
level: val.level,
|
|
2785
|
+
text: val.text,
|
|
2786
|
+
id: val.id,
|
|
2787
|
+
depth: val.depth,
|
|
2788
|
+
html_offset: val.html_offset,
|
|
2789
|
+
}
|
|
2790
|
+
}
|
|
2791
|
+
}
|
|
2792
|
+
|
|
2793
|
+
impl From<html_to_markdown_rs::metadata::HeaderMetadata> for HeaderMetadata {
|
|
2794
|
+
fn from(val: html_to_markdown_rs::metadata::HeaderMetadata) -> Self {
|
|
2795
|
+
Self {
|
|
2796
|
+
level: val.level,
|
|
2797
|
+
text: val.text,
|
|
2798
|
+
id: val.id,
|
|
2799
|
+
depth: val.depth,
|
|
2800
|
+
html_offset: val.html_offset,
|
|
2801
|
+
}
|
|
2802
|
+
}
|
|
2803
|
+
}
|
|
2804
|
+
|
|
2805
|
+
impl From<LinkMetadata> for html_to_markdown_rs::metadata::LinkMetadata {
|
|
2806
|
+
fn from(val: LinkMetadata) -> Self {
|
|
2807
|
+
Self {
|
|
2808
|
+
href: val.href,
|
|
2809
|
+
text: val.text,
|
|
2810
|
+
title: val.title,
|
|
2811
|
+
link_type: val.link_type.into(),
|
|
2812
|
+
rel: val.rel,
|
|
2813
|
+
attributes: val.attributes.into_iter().collect(),
|
|
2814
|
+
}
|
|
2815
|
+
}
|
|
2816
|
+
}
|
|
2817
|
+
|
|
2818
|
+
impl From<html_to_markdown_rs::metadata::LinkMetadata> for LinkMetadata {
|
|
2819
|
+
fn from(val: html_to_markdown_rs::metadata::LinkMetadata) -> Self {
|
|
2820
|
+
Self {
|
|
2821
|
+
href: val.href,
|
|
2822
|
+
text: val.text,
|
|
2823
|
+
title: val.title,
|
|
2824
|
+
link_type: val.link_type.into(),
|
|
2825
|
+
rel: val.rel,
|
|
2826
|
+
attributes: val.attributes.into_iter().collect(),
|
|
2827
|
+
}
|
|
2828
|
+
}
|
|
2829
|
+
}
|
|
2830
|
+
|
|
2831
|
+
impl From<ImageMetadata> for html_to_markdown_rs::metadata::ImageMetadata {
|
|
2832
|
+
fn from(val: ImageMetadata) -> Self {
|
|
2833
|
+
Self {
|
|
2834
|
+
src: val.src,
|
|
2835
|
+
alt: val.alt,
|
|
2836
|
+
title: val.title,
|
|
2837
|
+
dimensions: Default::default(),
|
|
2838
|
+
image_type: val.image_type.into(),
|
|
2839
|
+
attributes: val.attributes.into_iter().collect(),
|
|
2840
|
+
}
|
|
2841
|
+
}
|
|
2842
|
+
}
|
|
2843
|
+
|
|
2844
|
+
impl From<html_to_markdown_rs::metadata::ImageMetadata> for ImageMetadata {
|
|
2845
|
+
fn from(val: html_to_markdown_rs::metadata::ImageMetadata) -> Self {
|
|
2846
|
+
Self {
|
|
2847
|
+
src: val.src,
|
|
2848
|
+
alt: val.alt,
|
|
2849
|
+
title: val.title,
|
|
2850
|
+
dimensions: val.dimensions.as_ref().map(|v| format!("{:?}", v)),
|
|
2851
|
+
image_type: val.image_type.into(),
|
|
2852
|
+
attributes: val.attributes.into_iter().collect(),
|
|
2853
|
+
}
|
|
2854
|
+
}
|
|
2855
|
+
}
|
|
2856
|
+
|
|
2857
|
+
impl From<StructuredData> for html_to_markdown_rs::metadata::StructuredData {
|
|
2858
|
+
fn from(val: StructuredData) -> Self {
|
|
2859
|
+
Self {
|
|
2860
|
+
data_type: val.data_type.into(),
|
|
2861
|
+
raw_json: val.raw_json,
|
|
2862
|
+
schema_type: val.schema_type,
|
|
2863
|
+
}
|
|
2864
|
+
}
|
|
2865
|
+
}
|
|
2866
|
+
|
|
2867
|
+
impl From<html_to_markdown_rs::metadata::StructuredData> for StructuredData {
|
|
2868
|
+
fn from(val: html_to_markdown_rs::metadata::StructuredData) -> Self {
|
|
2869
|
+
Self {
|
|
2870
|
+
data_type: val.data_type.into(),
|
|
2871
|
+
raw_json: val.raw_json,
|
|
2872
|
+
schema_type: val.schema_type,
|
|
2873
|
+
}
|
|
2874
|
+
}
|
|
2875
|
+
}
|
|
2876
|
+
|
|
2877
|
+
impl From<HtmlMetadata> for html_to_markdown_rs::metadata::HtmlMetadata {
|
|
2878
|
+
fn from(val: HtmlMetadata) -> Self {
|
|
2879
|
+
Self {
|
|
2880
|
+
document: val.document.into(),
|
|
2881
|
+
headers: val.headers.into_iter().map(Into::into).collect(),
|
|
2882
|
+
links: val.links.into_iter().map(Into::into).collect(),
|
|
2883
|
+
images: val.images.into_iter().map(Into::into).collect(),
|
|
2884
|
+
structured_data: val.structured_data.into_iter().map(Into::into).collect(),
|
|
2885
|
+
}
|
|
2886
|
+
}
|
|
2887
|
+
}
|
|
2888
|
+
|
|
2889
|
+
impl From<html_to_markdown_rs::metadata::HtmlMetadata> for HtmlMetadata {
|
|
2890
|
+
fn from(val: html_to_markdown_rs::metadata::HtmlMetadata) -> Self {
|
|
2891
|
+
Self {
|
|
2892
|
+
document: val.document.into(),
|
|
2893
|
+
headers: val.headers.into_iter().map(Into::into).collect(),
|
|
2894
|
+
links: val.links.into_iter().map(Into::into).collect(),
|
|
2895
|
+
images: val.images.into_iter().map(Into::into).collect(),
|
|
2896
|
+
structured_data: val.structured_data.into_iter().map(Into::into).collect(),
|
|
2897
|
+
}
|
|
2898
|
+
}
|
|
2899
|
+
}
|
|
2900
|
+
|
|
2901
|
+
impl From<ConversionOptions> for html_to_markdown_rs::options::ConversionOptions {
|
|
2902
|
+
fn from(val: ConversionOptions) -> Self {
|
|
2903
|
+
Self {
|
|
2904
|
+
heading_style: val.heading_style.into(),
|
|
2905
|
+
list_indent_type: val.list_indent_type.into(),
|
|
2906
|
+
list_indent_width: val.list_indent_width,
|
|
2907
|
+
bullets: val.bullets,
|
|
2908
|
+
strong_em_symbol: val.strong_em_symbol.chars().next().unwrap_or('*'),
|
|
2909
|
+
escape_asterisks: val.escape_asterisks,
|
|
2910
|
+
escape_underscores: val.escape_underscores,
|
|
2911
|
+
escape_misc: val.escape_misc,
|
|
2912
|
+
escape_ascii: val.escape_ascii,
|
|
2913
|
+
code_language: val.code_language,
|
|
2914
|
+
autolinks: val.autolinks,
|
|
2915
|
+
default_title: val.default_title,
|
|
2916
|
+
br_in_tables: val.br_in_tables,
|
|
2917
|
+
highlight_style: val.highlight_style.into(),
|
|
2918
|
+
extract_metadata: val.extract_metadata,
|
|
2919
|
+
whitespace_mode: val.whitespace_mode.into(),
|
|
2920
|
+
strip_newlines: val.strip_newlines,
|
|
2921
|
+
wrap: val.wrap,
|
|
2922
|
+
wrap_width: val.wrap_width,
|
|
2923
|
+
convert_as_inline: val.convert_as_inline,
|
|
2924
|
+
sub_symbol: val.sub_symbol,
|
|
2925
|
+
sup_symbol: val.sup_symbol,
|
|
2926
|
+
newline_style: val.newline_style.into(),
|
|
2927
|
+
code_block_style: val.code_block_style.into(),
|
|
2928
|
+
keep_inline_images_in: val.keep_inline_images_in,
|
|
2929
|
+
preprocessing: val.preprocessing.into(),
|
|
2930
|
+
encoding: val.encoding,
|
|
2931
|
+
debug: val.debug,
|
|
2932
|
+
strip_tags: val.strip_tags,
|
|
2933
|
+
preserve_tags: val.preserve_tags,
|
|
2934
|
+
skip_images: val.skip_images,
|
|
2935
|
+
link_style: val.link_style.into(),
|
|
2936
|
+
output_format: val.output_format.into(),
|
|
2937
|
+
include_document_structure: val.include_document_structure,
|
|
2938
|
+
extract_images: val.extract_images,
|
|
2939
|
+
max_image_size: val.max_image_size,
|
|
2940
|
+
capture_svg: val.capture_svg,
|
|
2941
|
+
infer_dimensions: val.infer_dimensions,
|
|
2942
|
+
}
|
|
2943
|
+
}
|
|
2944
|
+
}
|
|
2945
|
+
|
|
2946
|
+
impl From<html_to_markdown_rs::options::ConversionOptions> for ConversionOptions {
|
|
2947
|
+
fn from(val: html_to_markdown_rs::options::ConversionOptions) -> Self {
|
|
2948
|
+
Self {
|
|
2949
|
+
heading_style: val.heading_style.into(),
|
|
2950
|
+
list_indent_type: val.list_indent_type.into(),
|
|
2951
|
+
list_indent_width: val.list_indent_width,
|
|
2952
|
+
bullets: val.bullets,
|
|
2953
|
+
strong_em_symbol: val.strong_em_symbol.to_string(),
|
|
2954
|
+
escape_asterisks: val.escape_asterisks,
|
|
2955
|
+
escape_underscores: val.escape_underscores,
|
|
2956
|
+
escape_misc: val.escape_misc,
|
|
2957
|
+
escape_ascii: val.escape_ascii,
|
|
2958
|
+
code_language: val.code_language,
|
|
2959
|
+
autolinks: val.autolinks,
|
|
2960
|
+
default_title: val.default_title,
|
|
2961
|
+
br_in_tables: val.br_in_tables,
|
|
2962
|
+
highlight_style: val.highlight_style.into(),
|
|
2963
|
+
extract_metadata: val.extract_metadata,
|
|
2964
|
+
whitespace_mode: val.whitespace_mode.into(),
|
|
2965
|
+
strip_newlines: val.strip_newlines,
|
|
2966
|
+
wrap: val.wrap,
|
|
2967
|
+
wrap_width: val.wrap_width,
|
|
2968
|
+
convert_as_inline: val.convert_as_inline,
|
|
2969
|
+
sub_symbol: val.sub_symbol,
|
|
2970
|
+
sup_symbol: val.sup_symbol,
|
|
2971
|
+
newline_style: val.newline_style.into(),
|
|
2972
|
+
code_block_style: val.code_block_style.into(),
|
|
2973
|
+
keep_inline_images_in: val.keep_inline_images_in,
|
|
2974
|
+
preprocessing: val.preprocessing.into(),
|
|
2975
|
+
encoding: val.encoding,
|
|
2976
|
+
debug: val.debug,
|
|
2977
|
+
strip_tags: val.strip_tags,
|
|
2978
|
+
preserve_tags: val.preserve_tags,
|
|
2979
|
+
skip_images: val.skip_images,
|
|
2980
|
+
link_style: val.link_style.into(),
|
|
2981
|
+
output_format: val.output_format.into(),
|
|
2982
|
+
include_document_structure: val.include_document_structure,
|
|
2983
|
+
extract_images: val.extract_images,
|
|
2984
|
+
max_image_size: val.max_image_size,
|
|
2985
|
+
capture_svg: val.capture_svg,
|
|
2986
|
+
infer_dimensions: val.infer_dimensions,
|
|
2987
|
+
}
|
|
2988
|
+
}
|
|
2989
|
+
}
|
|
2990
|
+
|
|
2991
|
+
impl From<html_to_markdown_rs::options::ConversionOptionsUpdate> for ConversionOptionsUpdate {
|
|
2992
|
+
fn from(val: html_to_markdown_rs::options::ConversionOptionsUpdate) -> Self {
|
|
2993
|
+
Self {
|
|
2994
|
+
heading_style: val.heading_style.map(Into::into),
|
|
2995
|
+
list_indent_type: val.list_indent_type.map(Into::into),
|
|
2996
|
+
list_indent_width: val.list_indent_width,
|
|
2997
|
+
bullets: val.bullets,
|
|
2998
|
+
strong_em_symbol: val.strong_em_symbol.map(|c| c.to_string()),
|
|
2999
|
+
escape_asterisks: val.escape_asterisks,
|
|
3000
|
+
escape_underscores: val.escape_underscores,
|
|
3001
|
+
escape_misc: val.escape_misc,
|
|
3002
|
+
escape_ascii: val.escape_ascii,
|
|
3003
|
+
code_language: val.code_language,
|
|
3004
|
+
autolinks: val.autolinks,
|
|
3005
|
+
default_title: val.default_title,
|
|
3006
|
+
br_in_tables: val.br_in_tables,
|
|
3007
|
+
highlight_style: val.highlight_style.map(Into::into),
|
|
3008
|
+
extract_metadata: val.extract_metadata,
|
|
3009
|
+
whitespace_mode: val.whitespace_mode.map(Into::into),
|
|
3010
|
+
strip_newlines: val.strip_newlines,
|
|
3011
|
+
wrap: val.wrap,
|
|
3012
|
+
wrap_width: val.wrap_width,
|
|
3013
|
+
convert_as_inline: val.convert_as_inline,
|
|
3014
|
+
sub_symbol: val.sub_symbol,
|
|
3015
|
+
sup_symbol: val.sup_symbol,
|
|
3016
|
+
newline_style: val.newline_style.map(Into::into),
|
|
3017
|
+
code_block_style: val.code_block_style.map(Into::into),
|
|
3018
|
+
keep_inline_images_in: val.keep_inline_images_in,
|
|
3019
|
+
preprocessing: val.preprocessing.map(Into::into),
|
|
3020
|
+
encoding: val.encoding,
|
|
3021
|
+
debug: val.debug,
|
|
3022
|
+
strip_tags: val.strip_tags,
|
|
3023
|
+
preserve_tags: val.preserve_tags,
|
|
3024
|
+
skip_images: val.skip_images,
|
|
3025
|
+
link_style: val.link_style.map(Into::into),
|
|
3026
|
+
output_format: val.output_format.map(Into::into),
|
|
3027
|
+
include_document_structure: val.include_document_structure,
|
|
3028
|
+
extract_images: val.extract_images,
|
|
3029
|
+
max_image_size: val.max_image_size,
|
|
3030
|
+
capture_svg: val.capture_svg,
|
|
3031
|
+
infer_dimensions: val.infer_dimensions,
|
|
3032
|
+
}
|
|
3033
|
+
}
|
|
3034
|
+
}
|
|
3035
|
+
|
|
3036
|
+
impl From<PreprocessingOptions> for html_to_markdown_rs::options::PreprocessingOptions {
|
|
3037
|
+
fn from(val: PreprocessingOptions) -> Self {
|
|
3038
|
+
Self {
|
|
3039
|
+
enabled: val.enabled,
|
|
3040
|
+
preset: val.preset.into(),
|
|
3041
|
+
remove_navigation: val.remove_navigation,
|
|
3042
|
+
remove_forms: val.remove_forms,
|
|
3043
|
+
}
|
|
3044
|
+
}
|
|
3045
|
+
}
|
|
3046
|
+
|
|
3047
|
+
impl From<html_to_markdown_rs::options::PreprocessingOptions> for PreprocessingOptions {
|
|
3048
|
+
fn from(val: html_to_markdown_rs::options::PreprocessingOptions) -> Self {
|
|
3049
|
+
Self {
|
|
3050
|
+
enabled: val.enabled,
|
|
3051
|
+
preset: val.preset.into(),
|
|
3052
|
+
remove_navigation: val.remove_navigation,
|
|
3053
|
+
remove_forms: val.remove_forms,
|
|
3054
|
+
}
|
|
3055
|
+
}
|
|
3056
|
+
}
|
|
3057
|
+
|
|
3058
|
+
impl From<html_to_markdown_rs::options::PreprocessingOptionsUpdate> for PreprocessingOptionsUpdate {
|
|
3059
|
+
fn from(val: html_to_markdown_rs::options::PreprocessingOptionsUpdate) -> Self {
|
|
3060
|
+
Self {
|
|
3061
|
+
enabled: val.enabled,
|
|
3062
|
+
preset: val.preset.map(Into::into),
|
|
3063
|
+
remove_navigation: val.remove_navigation,
|
|
3064
|
+
remove_forms: val.remove_forms,
|
|
3065
|
+
}
|
|
3066
|
+
}
|
|
3067
|
+
}
|
|
3068
|
+
|
|
3069
|
+
impl From<DocumentStructure> for html_to_markdown_rs::DocumentStructure {
|
|
3070
|
+
fn from(val: DocumentStructure) -> Self {
|
|
3071
|
+
Self {
|
|
3072
|
+
nodes: val.nodes.into_iter().map(Into::into).collect(),
|
|
3073
|
+
source_format: val.source_format,
|
|
3074
|
+
}
|
|
3075
|
+
}
|
|
3076
|
+
}
|
|
3077
|
+
|
|
3078
|
+
impl From<html_to_markdown_rs::DocumentStructure> for DocumentStructure {
|
|
3079
|
+
fn from(val: html_to_markdown_rs::DocumentStructure) -> Self {
|
|
3080
|
+
Self {
|
|
3081
|
+
nodes: val.nodes.into_iter().map(Into::into).collect(),
|
|
3082
|
+
source_format: val.source_format,
|
|
3083
|
+
}
|
|
3084
|
+
}
|
|
3085
|
+
}
|
|
3086
|
+
|
|
3087
|
+
impl From<DocumentNode> for html_to_markdown_rs::DocumentNode {
|
|
3088
|
+
fn from(val: DocumentNode) -> Self {
|
|
3089
|
+
Self {
|
|
3090
|
+
id: val.id,
|
|
3091
|
+
content: val.content.into(),
|
|
3092
|
+
parent: val.parent,
|
|
3093
|
+
children: val.children,
|
|
3094
|
+
annotations: val.annotations.into_iter().map(Into::into).collect(),
|
|
3095
|
+
attributes: val.attributes.map(|m| m.into_iter().collect()),
|
|
3096
|
+
}
|
|
3097
|
+
}
|
|
3098
|
+
}
|
|
3099
|
+
|
|
3100
|
+
impl From<html_to_markdown_rs::DocumentNode> for DocumentNode {
|
|
3101
|
+
fn from(val: html_to_markdown_rs::DocumentNode) -> Self {
|
|
3102
|
+
Self {
|
|
3103
|
+
id: val.id,
|
|
3104
|
+
content: val.content.into(),
|
|
3105
|
+
parent: val.parent,
|
|
3106
|
+
children: val.children,
|
|
3107
|
+
annotations: val.annotations.into_iter().map(Into::into).collect(),
|
|
3108
|
+
attributes: val.attributes.map(|m| m.into_iter().collect()),
|
|
3109
|
+
}
|
|
3110
|
+
}
|
|
3111
|
+
}
|
|
3112
|
+
|
|
3113
|
+
impl From<TextAnnotation> for html_to_markdown_rs::TextAnnotation {
|
|
3114
|
+
fn from(val: TextAnnotation) -> Self {
|
|
3115
|
+
Self {
|
|
3116
|
+
start: val.start,
|
|
3117
|
+
end: val.end,
|
|
3118
|
+
kind: val.kind.into(),
|
|
3119
|
+
}
|
|
3120
|
+
}
|
|
3121
|
+
}
|
|
3122
|
+
|
|
3123
|
+
impl From<html_to_markdown_rs::TextAnnotation> for TextAnnotation {
|
|
3124
|
+
fn from(val: html_to_markdown_rs::TextAnnotation) -> Self {
|
|
3125
|
+
Self {
|
|
3126
|
+
start: val.start,
|
|
3127
|
+
end: val.end,
|
|
3128
|
+
kind: val.kind.into(),
|
|
3129
|
+
}
|
|
3130
|
+
}
|
|
3131
|
+
}
|
|
3132
|
+
|
|
3133
|
+
#[allow(clippy::needless_update)]
|
|
3134
|
+
impl From<ConversionResult> for html_to_markdown_rs::ConversionResult {
|
|
3135
|
+
fn from(val: ConversionResult) -> Self {
|
|
3136
|
+
Self {
|
|
3137
|
+
content: val.content,
|
|
3138
|
+
document: val.document.map(Into::into),
|
|
3139
|
+
metadata: val.metadata.into(),
|
|
3140
|
+
tables: val.tables.into_iter().map(Into::into).collect(),
|
|
3141
|
+
images: Default::default(),
|
|
3142
|
+
warnings: val.warnings.into_iter().map(Into::into).collect(),
|
|
3143
|
+
..Default::default()
|
|
3144
|
+
}
|
|
3145
|
+
}
|
|
3146
|
+
}
|
|
3147
|
+
|
|
3148
|
+
impl From<html_to_markdown_rs::ConversionResult> for ConversionResult {
|
|
3149
|
+
fn from(val: html_to_markdown_rs::ConversionResult) -> Self {
|
|
3150
|
+
Self {
|
|
3151
|
+
content: val.content,
|
|
3152
|
+
document: val.document.map(Into::into),
|
|
3153
|
+
metadata: val.metadata.into(),
|
|
3154
|
+
tables: val.tables.into_iter().map(Into::into).collect(),
|
|
3155
|
+
images: val.images.iter().map(|i| format!("{:?}", i)).collect(),
|
|
3156
|
+
warnings: val.warnings.into_iter().map(Into::into).collect(),
|
|
3157
|
+
}
|
|
3158
|
+
}
|
|
3159
|
+
}
|
|
3160
|
+
|
|
3161
|
+
impl From<TableGrid> for html_to_markdown_rs::TableGrid {
|
|
3162
|
+
fn from(val: TableGrid) -> Self {
|
|
3163
|
+
Self {
|
|
3164
|
+
rows: val.rows,
|
|
3165
|
+
cols: val.cols,
|
|
3166
|
+
cells: val.cells.into_iter().map(Into::into).collect(),
|
|
3167
|
+
}
|
|
3168
|
+
}
|
|
3169
|
+
}
|
|
3170
|
+
|
|
3171
|
+
impl From<html_to_markdown_rs::TableGrid> for TableGrid {
|
|
3172
|
+
fn from(val: html_to_markdown_rs::TableGrid) -> Self {
|
|
3173
|
+
Self {
|
|
3174
|
+
rows: val.rows,
|
|
3175
|
+
cols: val.cols,
|
|
3176
|
+
cells: val.cells.into_iter().map(Into::into).collect(),
|
|
3177
|
+
}
|
|
3178
|
+
}
|
|
3179
|
+
}
|
|
3180
|
+
|
|
3181
|
+
impl From<GridCell> for html_to_markdown_rs::GridCell {
|
|
3182
|
+
fn from(val: GridCell) -> Self {
|
|
3183
|
+
Self {
|
|
3184
|
+
content: val.content,
|
|
3185
|
+
row: val.row,
|
|
3186
|
+
col: val.col,
|
|
3187
|
+
row_span: val.row_span,
|
|
3188
|
+
col_span: val.col_span,
|
|
3189
|
+
is_header: val.is_header,
|
|
3190
|
+
}
|
|
3191
|
+
}
|
|
3192
|
+
}
|
|
3193
|
+
|
|
3194
|
+
impl From<html_to_markdown_rs::GridCell> for GridCell {
|
|
3195
|
+
fn from(val: html_to_markdown_rs::GridCell) -> Self {
|
|
3196
|
+
Self {
|
|
3197
|
+
content: val.content,
|
|
3198
|
+
row: val.row,
|
|
3199
|
+
col: val.col,
|
|
3200
|
+
row_span: val.row_span,
|
|
3201
|
+
col_span: val.col_span,
|
|
3202
|
+
is_header: val.is_header,
|
|
3203
|
+
}
|
|
3204
|
+
}
|
|
3205
|
+
}
|
|
3206
|
+
|
|
3207
|
+
impl From<TableData> for html_to_markdown_rs::TableData {
|
|
3208
|
+
fn from(val: TableData) -> Self {
|
|
3209
|
+
Self {
|
|
3210
|
+
grid: val.grid.into(),
|
|
3211
|
+
markdown: val.markdown,
|
|
3212
|
+
}
|
|
3213
|
+
}
|
|
3214
|
+
}
|
|
3215
|
+
|
|
3216
|
+
impl From<html_to_markdown_rs::TableData> for TableData {
|
|
3217
|
+
fn from(val: html_to_markdown_rs::TableData) -> Self {
|
|
3218
|
+
Self {
|
|
3219
|
+
grid: val.grid.into(),
|
|
3220
|
+
markdown: val.markdown,
|
|
3221
|
+
}
|
|
3222
|
+
}
|
|
3223
|
+
}
|
|
3224
|
+
|
|
3225
|
+
impl From<ProcessingWarning> for html_to_markdown_rs::ProcessingWarning {
|
|
3226
|
+
fn from(val: ProcessingWarning) -> Self {
|
|
3227
|
+
Self {
|
|
3228
|
+
message: val.message,
|
|
3229
|
+
kind: val.kind.into(),
|
|
3230
|
+
}
|
|
3231
|
+
}
|
|
3232
|
+
}
|
|
3233
|
+
|
|
3234
|
+
impl From<html_to_markdown_rs::ProcessingWarning> for ProcessingWarning {
|
|
3235
|
+
fn from(val: html_to_markdown_rs::ProcessingWarning) -> Self {
|
|
3236
|
+
Self {
|
|
3237
|
+
message: val.message,
|
|
3238
|
+
kind: val.kind.into(),
|
|
3239
|
+
}
|
|
3240
|
+
}
|
|
3241
|
+
}
|
|
3242
|
+
|
|
3243
|
+
impl From<TextDirection> for html_to_markdown_rs::metadata::TextDirection {
|
|
3244
|
+
fn from(val: TextDirection) -> Self {
|
|
3245
|
+
match val {
|
|
3246
|
+
TextDirection::LeftToRight => Self::LeftToRight,
|
|
3247
|
+
TextDirection::RightToLeft => Self::RightToLeft,
|
|
3248
|
+
TextDirection::Auto => Self::Auto,
|
|
3249
|
+
}
|
|
3250
|
+
}
|
|
3251
|
+
}
|
|
3252
|
+
|
|
3253
|
+
impl From<html_to_markdown_rs::metadata::TextDirection> for TextDirection {
|
|
3254
|
+
fn from(val: html_to_markdown_rs::metadata::TextDirection) -> Self {
|
|
3255
|
+
match val {
|
|
3256
|
+
html_to_markdown_rs::metadata::TextDirection::LeftToRight => Self::LeftToRight,
|
|
3257
|
+
html_to_markdown_rs::metadata::TextDirection::RightToLeft => Self::RightToLeft,
|
|
3258
|
+
html_to_markdown_rs::metadata::TextDirection::Auto => Self::Auto,
|
|
3259
|
+
}
|
|
3260
|
+
}
|
|
3261
|
+
}
|
|
3262
|
+
|
|
3263
|
+
impl From<LinkType> for html_to_markdown_rs::metadata::LinkType {
|
|
3264
|
+
fn from(val: LinkType) -> Self {
|
|
3265
|
+
match val {
|
|
3266
|
+
LinkType::Anchor => Self::Anchor,
|
|
3267
|
+
LinkType::Internal => Self::Internal,
|
|
3268
|
+
LinkType::External => Self::External,
|
|
3269
|
+
LinkType::Email => Self::Email,
|
|
3270
|
+
LinkType::Phone => Self::Phone,
|
|
3271
|
+
LinkType::Other => Self::Other,
|
|
3272
|
+
}
|
|
3273
|
+
}
|
|
3274
|
+
}
|
|
3275
|
+
|
|
3276
|
+
impl From<html_to_markdown_rs::metadata::LinkType> for LinkType {
|
|
3277
|
+
fn from(val: html_to_markdown_rs::metadata::LinkType) -> Self {
|
|
3278
|
+
match val {
|
|
3279
|
+
html_to_markdown_rs::metadata::LinkType::Anchor => Self::Anchor,
|
|
3280
|
+
html_to_markdown_rs::metadata::LinkType::Internal => Self::Internal,
|
|
3281
|
+
html_to_markdown_rs::metadata::LinkType::External => Self::External,
|
|
3282
|
+
html_to_markdown_rs::metadata::LinkType::Email => Self::Email,
|
|
3283
|
+
html_to_markdown_rs::metadata::LinkType::Phone => Self::Phone,
|
|
3284
|
+
html_to_markdown_rs::metadata::LinkType::Other => Self::Other,
|
|
3285
|
+
}
|
|
3286
|
+
}
|
|
3287
|
+
}
|
|
3288
|
+
|
|
3289
|
+
impl From<ImageType> for html_to_markdown_rs::metadata::ImageType {
|
|
3290
|
+
fn from(val: ImageType) -> Self {
|
|
3291
|
+
match val {
|
|
3292
|
+
ImageType::DataUri => Self::DataUri,
|
|
3293
|
+
ImageType::InlineSvg => Self::InlineSvg,
|
|
3294
|
+
ImageType::External => Self::External,
|
|
3295
|
+
ImageType::Relative => Self::Relative,
|
|
3296
|
+
}
|
|
3297
|
+
}
|
|
3298
|
+
}
|
|
3299
|
+
|
|
3300
|
+
impl From<html_to_markdown_rs::metadata::ImageType> for ImageType {
|
|
3301
|
+
fn from(val: html_to_markdown_rs::metadata::ImageType) -> Self {
|
|
3302
|
+
match val {
|
|
3303
|
+
html_to_markdown_rs::metadata::ImageType::DataUri => Self::DataUri,
|
|
3304
|
+
html_to_markdown_rs::metadata::ImageType::InlineSvg => Self::InlineSvg,
|
|
3305
|
+
html_to_markdown_rs::metadata::ImageType::External => Self::External,
|
|
3306
|
+
html_to_markdown_rs::metadata::ImageType::Relative => Self::Relative,
|
|
3307
|
+
}
|
|
3308
|
+
}
|
|
3309
|
+
}
|
|
3310
|
+
|
|
3311
|
+
impl From<StructuredDataType> for html_to_markdown_rs::metadata::StructuredDataType {
|
|
3312
|
+
fn from(val: StructuredDataType) -> Self {
|
|
3313
|
+
match val {
|
|
3314
|
+
StructuredDataType::JsonLd => Self::JsonLd,
|
|
3315
|
+
StructuredDataType::Microdata => Self::Microdata,
|
|
3316
|
+
StructuredDataType::RDFa => Self::RDFa,
|
|
3317
|
+
}
|
|
3318
|
+
}
|
|
3319
|
+
}
|
|
3320
|
+
|
|
3321
|
+
impl From<html_to_markdown_rs::metadata::StructuredDataType> for StructuredDataType {
|
|
3322
|
+
fn from(val: html_to_markdown_rs::metadata::StructuredDataType) -> Self {
|
|
3323
|
+
match val {
|
|
3324
|
+
html_to_markdown_rs::metadata::StructuredDataType::JsonLd => Self::JsonLd,
|
|
3325
|
+
html_to_markdown_rs::metadata::StructuredDataType::Microdata => Self::Microdata,
|
|
3326
|
+
html_to_markdown_rs::metadata::StructuredDataType::RDFa => Self::RDFa,
|
|
3327
|
+
}
|
|
3328
|
+
}
|
|
3329
|
+
}
|
|
3330
|
+
|
|
3331
|
+
impl From<PreprocessingPreset> for html_to_markdown_rs::options::PreprocessingPreset {
|
|
3332
|
+
fn from(val: PreprocessingPreset) -> Self {
|
|
3333
|
+
match val {
|
|
3334
|
+
PreprocessingPreset::Minimal => Self::Minimal,
|
|
3335
|
+
PreprocessingPreset::Standard => Self::Standard,
|
|
3336
|
+
PreprocessingPreset::Aggressive => Self::Aggressive,
|
|
3337
|
+
}
|
|
3338
|
+
}
|
|
3339
|
+
}
|
|
3340
|
+
|
|
3341
|
+
impl From<html_to_markdown_rs::options::PreprocessingPreset> for PreprocessingPreset {
|
|
3342
|
+
fn from(val: html_to_markdown_rs::options::PreprocessingPreset) -> Self {
|
|
3343
|
+
match val {
|
|
3344
|
+
html_to_markdown_rs::options::PreprocessingPreset::Minimal => Self::Minimal,
|
|
3345
|
+
html_to_markdown_rs::options::PreprocessingPreset::Standard => Self::Standard,
|
|
3346
|
+
html_to_markdown_rs::options::PreprocessingPreset::Aggressive => Self::Aggressive,
|
|
3347
|
+
}
|
|
3348
|
+
}
|
|
3349
|
+
}
|
|
3350
|
+
|
|
3351
|
+
impl From<HeadingStyle> for html_to_markdown_rs::options::HeadingStyle {
|
|
3352
|
+
fn from(val: HeadingStyle) -> Self {
|
|
3353
|
+
match val {
|
|
3354
|
+
HeadingStyle::Underlined => Self::Underlined,
|
|
3355
|
+
HeadingStyle::Atx => Self::Atx,
|
|
3356
|
+
HeadingStyle::AtxClosed => Self::AtxClosed,
|
|
3357
|
+
}
|
|
3358
|
+
}
|
|
3359
|
+
}
|
|
3360
|
+
|
|
3361
|
+
impl From<html_to_markdown_rs::options::HeadingStyle> for HeadingStyle {
|
|
3362
|
+
fn from(val: html_to_markdown_rs::options::HeadingStyle) -> Self {
|
|
3363
|
+
match val {
|
|
3364
|
+
html_to_markdown_rs::options::HeadingStyle::Underlined => Self::Underlined,
|
|
3365
|
+
html_to_markdown_rs::options::HeadingStyle::Atx => Self::Atx,
|
|
3366
|
+
html_to_markdown_rs::options::HeadingStyle::AtxClosed => Self::AtxClosed,
|
|
3367
|
+
}
|
|
3368
|
+
}
|
|
3369
|
+
}
|
|
3370
|
+
|
|
3371
|
+
impl From<ListIndentType> for html_to_markdown_rs::options::ListIndentType {
|
|
3372
|
+
fn from(val: ListIndentType) -> Self {
|
|
3373
|
+
match val {
|
|
3374
|
+
ListIndentType::Spaces => Self::Spaces,
|
|
3375
|
+
ListIndentType::Tabs => Self::Tabs,
|
|
3376
|
+
}
|
|
3377
|
+
}
|
|
3378
|
+
}
|
|
3379
|
+
|
|
3380
|
+
impl From<html_to_markdown_rs::options::ListIndentType> for ListIndentType {
|
|
3381
|
+
fn from(val: html_to_markdown_rs::options::ListIndentType) -> Self {
|
|
3382
|
+
match val {
|
|
3383
|
+
html_to_markdown_rs::options::ListIndentType::Spaces => Self::Spaces,
|
|
3384
|
+
html_to_markdown_rs::options::ListIndentType::Tabs => Self::Tabs,
|
|
3385
|
+
}
|
|
3386
|
+
}
|
|
3387
|
+
}
|
|
3388
|
+
|
|
3389
|
+
impl From<WhitespaceMode> for html_to_markdown_rs::options::WhitespaceMode {
|
|
3390
|
+
fn from(val: WhitespaceMode) -> Self {
|
|
3391
|
+
match val {
|
|
3392
|
+
WhitespaceMode::Normalized => Self::Normalized,
|
|
3393
|
+
WhitespaceMode::Strict => Self::Strict,
|
|
3394
|
+
}
|
|
3395
|
+
}
|
|
3396
|
+
}
|
|
3397
|
+
|
|
3398
|
+
impl From<html_to_markdown_rs::options::WhitespaceMode> for WhitespaceMode {
|
|
3399
|
+
fn from(val: html_to_markdown_rs::options::WhitespaceMode) -> Self {
|
|
3400
|
+
match val {
|
|
3401
|
+
html_to_markdown_rs::options::WhitespaceMode::Normalized => Self::Normalized,
|
|
3402
|
+
html_to_markdown_rs::options::WhitespaceMode::Strict => Self::Strict,
|
|
3403
|
+
}
|
|
3404
|
+
}
|
|
3405
|
+
}
|
|
3406
|
+
|
|
3407
|
+
impl From<NewlineStyle> for html_to_markdown_rs::options::NewlineStyle {
|
|
3408
|
+
fn from(val: NewlineStyle) -> Self {
|
|
3409
|
+
match val {
|
|
3410
|
+
NewlineStyle::Spaces => Self::Spaces,
|
|
3411
|
+
NewlineStyle::Backslash => Self::Backslash,
|
|
3412
|
+
}
|
|
3413
|
+
}
|
|
3414
|
+
}
|
|
3415
|
+
|
|
3416
|
+
impl From<html_to_markdown_rs::options::NewlineStyle> for NewlineStyle {
|
|
3417
|
+
fn from(val: html_to_markdown_rs::options::NewlineStyle) -> Self {
|
|
3418
|
+
match val {
|
|
3419
|
+
html_to_markdown_rs::options::NewlineStyle::Spaces => Self::Spaces,
|
|
3420
|
+
html_to_markdown_rs::options::NewlineStyle::Backslash => Self::Backslash,
|
|
3421
|
+
}
|
|
3422
|
+
}
|
|
3423
|
+
}
|
|
3424
|
+
|
|
3425
|
+
impl From<CodeBlockStyle> for html_to_markdown_rs::options::CodeBlockStyle {
|
|
3426
|
+
fn from(val: CodeBlockStyle) -> Self {
|
|
3427
|
+
match val {
|
|
3428
|
+
CodeBlockStyle::Indented => Self::Indented,
|
|
3429
|
+
CodeBlockStyle::Backticks => Self::Backticks,
|
|
3430
|
+
CodeBlockStyle::Tildes => Self::Tildes,
|
|
3431
|
+
}
|
|
3432
|
+
}
|
|
3433
|
+
}
|
|
3434
|
+
|
|
3435
|
+
impl From<html_to_markdown_rs::options::CodeBlockStyle> for CodeBlockStyle {
|
|
3436
|
+
fn from(val: html_to_markdown_rs::options::CodeBlockStyle) -> Self {
|
|
3437
|
+
match val {
|
|
3438
|
+
html_to_markdown_rs::options::CodeBlockStyle::Indented => Self::Indented,
|
|
3439
|
+
html_to_markdown_rs::options::CodeBlockStyle::Backticks => Self::Backticks,
|
|
3440
|
+
html_to_markdown_rs::options::CodeBlockStyle::Tildes => Self::Tildes,
|
|
3441
|
+
}
|
|
3442
|
+
}
|
|
3443
|
+
}
|
|
3444
|
+
|
|
3445
|
+
impl From<HighlightStyle> for html_to_markdown_rs::options::HighlightStyle {
|
|
3446
|
+
fn from(val: HighlightStyle) -> Self {
|
|
3447
|
+
match val {
|
|
3448
|
+
HighlightStyle::DoubleEqual => Self::DoubleEqual,
|
|
3449
|
+
HighlightStyle::Html => Self::Html,
|
|
3450
|
+
HighlightStyle::Bold => Self::Bold,
|
|
3451
|
+
HighlightStyle::None => Self::None,
|
|
3452
|
+
}
|
|
3453
|
+
}
|
|
3454
|
+
}
|
|
3455
|
+
|
|
3456
|
+
impl From<html_to_markdown_rs::options::HighlightStyle> for HighlightStyle {
|
|
3457
|
+
fn from(val: html_to_markdown_rs::options::HighlightStyle) -> Self {
|
|
3458
|
+
match val {
|
|
3459
|
+
html_to_markdown_rs::options::HighlightStyle::DoubleEqual => Self::DoubleEqual,
|
|
3460
|
+
html_to_markdown_rs::options::HighlightStyle::Html => Self::Html,
|
|
3461
|
+
html_to_markdown_rs::options::HighlightStyle::Bold => Self::Bold,
|
|
3462
|
+
html_to_markdown_rs::options::HighlightStyle::None => Self::None,
|
|
3463
|
+
}
|
|
3464
|
+
}
|
|
3465
|
+
}
|
|
3466
|
+
|
|
3467
|
+
impl From<LinkStyle> for html_to_markdown_rs::options::LinkStyle {
|
|
3468
|
+
fn from(val: LinkStyle) -> Self {
|
|
3469
|
+
match val {
|
|
3470
|
+
LinkStyle::Inline => Self::Inline,
|
|
3471
|
+
LinkStyle::Reference => Self::Reference,
|
|
3472
|
+
}
|
|
3473
|
+
}
|
|
3474
|
+
}
|
|
3475
|
+
|
|
3476
|
+
impl From<html_to_markdown_rs::options::LinkStyle> for LinkStyle {
|
|
3477
|
+
fn from(val: html_to_markdown_rs::options::LinkStyle) -> Self {
|
|
3478
|
+
match val {
|
|
3479
|
+
html_to_markdown_rs::options::LinkStyle::Inline => Self::Inline,
|
|
3480
|
+
html_to_markdown_rs::options::LinkStyle::Reference => Self::Reference,
|
|
3481
|
+
}
|
|
3482
|
+
}
|
|
3483
|
+
}
|
|
3484
|
+
|
|
3485
|
+
impl From<OutputFormat> for html_to_markdown_rs::options::OutputFormat {
|
|
3486
|
+
fn from(val: OutputFormat) -> Self {
|
|
3487
|
+
match val {
|
|
3488
|
+
OutputFormat::Markdown => Self::Markdown,
|
|
3489
|
+
OutputFormat::Djot => Self::Djot,
|
|
3490
|
+
OutputFormat::Plain => Self::Plain,
|
|
3491
|
+
}
|
|
3492
|
+
}
|
|
3493
|
+
}
|
|
3494
|
+
|
|
3495
|
+
impl From<html_to_markdown_rs::options::OutputFormat> for OutputFormat {
|
|
3496
|
+
fn from(val: html_to_markdown_rs::options::OutputFormat) -> Self {
|
|
3497
|
+
match val {
|
|
3498
|
+
html_to_markdown_rs::options::OutputFormat::Markdown => Self::Markdown,
|
|
3499
|
+
html_to_markdown_rs::options::OutputFormat::Djot => Self::Djot,
|
|
3500
|
+
html_to_markdown_rs::options::OutputFormat::Plain => Self::Plain,
|
|
3501
|
+
}
|
|
3502
|
+
}
|
|
3503
|
+
}
|
|
3504
|
+
|
|
3505
|
+
impl From<NodeContent> for html_to_markdown_rs::NodeContent {
|
|
3506
|
+
fn from(val: NodeContent) -> Self {
|
|
3507
|
+
match val {
|
|
3508
|
+
NodeContent::Heading { level, text } => Self::Heading { level, text },
|
|
3509
|
+
NodeContent::Paragraph { text } => Self::Paragraph { text },
|
|
3510
|
+
NodeContent::List { ordered } => Self::List { ordered },
|
|
3511
|
+
NodeContent::ListItem { text } => Self::ListItem { text },
|
|
3512
|
+
NodeContent::Table { grid } => Self::Table { grid: grid.into() },
|
|
3513
|
+
NodeContent::Image {
|
|
3514
|
+
description,
|
|
3515
|
+
src,
|
|
3516
|
+
image_index,
|
|
3517
|
+
} => Self::Image {
|
|
3518
|
+
description,
|
|
3519
|
+
src,
|
|
3520
|
+
image_index,
|
|
3521
|
+
},
|
|
3522
|
+
NodeContent::Code { text, language } => Self::Code { text, language },
|
|
3523
|
+
NodeContent::Quote => Self::Quote,
|
|
3524
|
+
NodeContent::DefinitionList => Self::DefinitionList,
|
|
3525
|
+
NodeContent::DefinitionItem { term, definition } => Self::DefinitionItem { term, definition },
|
|
3526
|
+
NodeContent::RawBlock { format, content } => Self::RawBlock { format, content },
|
|
3527
|
+
NodeContent::MetadataBlock { entries } => Self::MetadataBlock {
|
|
3528
|
+
entries: serde_json::from_str(&entries).unwrap_or_default(),
|
|
3529
|
+
},
|
|
3530
|
+
NodeContent::Group {
|
|
3531
|
+
label,
|
|
3532
|
+
heading_level,
|
|
3533
|
+
heading_text,
|
|
3534
|
+
} => Self::Group {
|
|
3535
|
+
label,
|
|
3536
|
+
heading_level,
|
|
3537
|
+
heading_text,
|
|
3538
|
+
},
|
|
3539
|
+
}
|
|
3540
|
+
}
|
|
3541
|
+
}
|
|
3542
|
+
|
|
3543
|
+
impl From<html_to_markdown_rs::NodeContent> for NodeContent {
|
|
3544
|
+
fn from(val: html_to_markdown_rs::NodeContent) -> Self {
|
|
3545
|
+
match val {
|
|
3546
|
+
html_to_markdown_rs::NodeContent::Heading { level, text } => Self::Heading { level, text },
|
|
3547
|
+
html_to_markdown_rs::NodeContent::Paragraph { text } => Self::Paragraph { text },
|
|
3548
|
+
html_to_markdown_rs::NodeContent::List { ordered } => Self::List { ordered },
|
|
3549
|
+
html_to_markdown_rs::NodeContent::ListItem { text } => Self::ListItem { text },
|
|
3550
|
+
html_to_markdown_rs::NodeContent::Table { grid } => Self::Table { grid: grid.into() },
|
|
3551
|
+
html_to_markdown_rs::NodeContent::Image {
|
|
3552
|
+
description,
|
|
3553
|
+
src,
|
|
3554
|
+
image_index,
|
|
3555
|
+
} => Self::Image {
|
|
3556
|
+
description,
|
|
3557
|
+
src,
|
|
3558
|
+
image_index,
|
|
3559
|
+
},
|
|
3560
|
+
html_to_markdown_rs::NodeContent::Code { text, language } => Self::Code { text, language },
|
|
3561
|
+
html_to_markdown_rs::NodeContent::Quote => Self::Quote,
|
|
3562
|
+
html_to_markdown_rs::NodeContent::DefinitionList => Self::DefinitionList,
|
|
3563
|
+
html_to_markdown_rs::NodeContent::DefinitionItem { term, definition } => {
|
|
3564
|
+
Self::DefinitionItem { term, definition }
|
|
3565
|
+
}
|
|
3566
|
+
html_to_markdown_rs::NodeContent::RawBlock { format, content } => Self::RawBlock { format, content },
|
|
3567
|
+
html_to_markdown_rs::NodeContent::MetadataBlock { entries } => Self::MetadataBlock {
|
|
3568
|
+
entries: serde_json::to_string(&entries).unwrap_or_default(),
|
|
3569
|
+
},
|
|
3570
|
+
html_to_markdown_rs::NodeContent::Group {
|
|
3571
|
+
label,
|
|
3572
|
+
heading_level,
|
|
3573
|
+
heading_text,
|
|
3574
|
+
} => Self::Group {
|
|
3575
|
+
label,
|
|
3576
|
+
heading_level,
|
|
3577
|
+
heading_text,
|
|
3578
|
+
},
|
|
3579
|
+
}
|
|
3580
|
+
}
|
|
3581
|
+
}
|
|
3582
|
+
|
|
3583
|
+
impl From<AnnotationKind> for html_to_markdown_rs::AnnotationKind {
|
|
3584
|
+
fn from(val: AnnotationKind) -> Self {
|
|
3585
|
+
match val {
|
|
3586
|
+
AnnotationKind::Bold => Self::Bold,
|
|
3587
|
+
AnnotationKind::Italic => Self::Italic,
|
|
3588
|
+
AnnotationKind::Underline => Self::Underline,
|
|
3589
|
+
AnnotationKind::Strikethrough => Self::Strikethrough,
|
|
3590
|
+
AnnotationKind::Code => Self::Code,
|
|
3591
|
+
AnnotationKind::Subscript => Self::Subscript,
|
|
3592
|
+
AnnotationKind::Superscript => Self::Superscript,
|
|
3593
|
+
AnnotationKind::Highlight => Self::Highlight,
|
|
3594
|
+
AnnotationKind::Link { url, title } => Self::Link { url, title },
|
|
3595
|
+
}
|
|
3596
|
+
}
|
|
3597
|
+
}
|
|
3598
|
+
|
|
3599
|
+
impl From<html_to_markdown_rs::AnnotationKind> for AnnotationKind {
|
|
3600
|
+
fn from(val: html_to_markdown_rs::AnnotationKind) -> Self {
|
|
3601
|
+
match val {
|
|
3602
|
+
html_to_markdown_rs::AnnotationKind::Bold => Self::Bold,
|
|
3603
|
+
html_to_markdown_rs::AnnotationKind::Italic => Self::Italic,
|
|
3604
|
+
html_to_markdown_rs::AnnotationKind::Underline => Self::Underline,
|
|
3605
|
+
html_to_markdown_rs::AnnotationKind::Strikethrough => Self::Strikethrough,
|
|
3606
|
+
html_to_markdown_rs::AnnotationKind::Code => Self::Code,
|
|
3607
|
+
html_to_markdown_rs::AnnotationKind::Subscript => Self::Subscript,
|
|
3608
|
+
html_to_markdown_rs::AnnotationKind::Superscript => Self::Superscript,
|
|
3609
|
+
html_to_markdown_rs::AnnotationKind::Highlight => Self::Highlight,
|
|
3610
|
+
html_to_markdown_rs::AnnotationKind::Link { url, title } => Self::Link { url, title },
|
|
3611
|
+
}
|
|
3612
|
+
}
|
|
3613
|
+
}
|
|
3614
|
+
|
|
3615
|
+
impl From<WarningKind> for html_to_markdown_rs::WarningKind {
|
|
3616
|
+
fn from(val: WarningKind) -> Self {
|
|
3617
|
+
match val {
|
|
3618
|
+
WarningKind::ImageExtractionFailed => Self::ImageExtractionFailed,
|
|
3619
|
+
WarningKind::EncodingFallback => Self::EncodingFallback,
|
|
3620
|
+
WarningKind::TruncatedInput => Self::TruncatedInput,
|
|
3621
|
+
WarningKind::MalformedHtml => Self::MalformedHtml,
|
|
3622
|
+
WarningKind::SanitizationApplied => Self::SanitizationApplied,
|
|
3623
|
+
}
|
|
3624
|
+
}
|
|
3625
|
+
}
|
|
3626
|
+
|
|
3627
|
+
impl From<html_to_markdown_rs::WarningKind> for WarningKind {
|
|
3628
|
+
fn from(val: html_to_markdown_rs::WarningKind) -> Self {
|
|
3629
|
+
match val {
|
|
3630
|
+
html_to_markdown_rs::WarningKind::ImageExtractionFailed => Self::ImageExtractionFailed,
|
|
3631
|
+
html_to_markdown_rs::WarningKind::EncodingFallback => Self::EncodingFallback,
|
|
3632
|
+
html_to_markdown_rs::WarningKind::TruncatedInput => Self::TruncatedInput,
|
|
3633
|
+
html_to_markdown_rs::WarningKind::MalformedHtml => Self::MalformedHtml,
|
|
3634
|
+
html_to_markdown_rs::WarningKind::SanitizationApplied => Self::SanitizationApplied,
|
|
3635
|
+
}
|
|
3636
|
+
}
|
|
3637
|
+
}
|
|
3638
|
+
|
|
3639
|
+
/// Convert a `html_to_markdown_rs::error::ConversionError` error to a Magnus runtime error.
|
|
3640
|
+
#[allow(dead_code)]
|
|
3641
|
+
fn conversion_error_to_magnus_err(e: html_to_markdown_rs::error::ConversionError) -> magnus::Error {
|
|
3642
|
+
let msg = e.to_string();
|
|
3643
|
+
magnus::Error::new(magnus::exception::runtime_error(), msg)
|
|
3644
|
+
}
|
|
3645
|
+
|
|
3646
|
+
#[magnus::init]
|
|
3647
|
+
fn init(ruby: &Ruby) -> Result<(), Error> {
|
|
3648
|
+
let module = ruby.define_module("HtmlToMarkdownRs")?;
|
|
3649
|
+
|
|
3650
|
+
let class = module.define_class("MetadataConfig", ruby.class_object())?;
|
|
3651
|
+
class.define_singleton_method("new", function!(MetadataConfig::new, 6))?;
|
|
3652
|
+
class.define_method("extract_document", method!(MetadataConfig::extract_document, 0))?;
|
|
3653
|
+
class.define_method("extract_headers", method!(MetadataConfig::extract_headers, 0))?;
|
|
3654
|
+
class.define_method("extract_links", method!(MetadataConfig::extract_links, 0))?;
|
|
3655
|
+
class.define_method("extract_images", method!(MetadataConfig::extract_images, 0))?;
|
|
3656
|
+
class.define_method(
|
|
3657
|
+
"extract_structured_data",
|
|
3658
|
+
method!(MetadataConfig::extract_structured_data, 0),
|
|
3659
|
+
)?;
|
|
3660
|
+
class.define_method(
|
|
3661
|
+
"max_structured_data_size",
|
|
3662
|
+
method!(MetadataConfig::max_structured_data_size, 0),
|
|
3663
|
+
)?;
|
|
3664
|
+
class.define_method("any_enabled", method!(MetadataConfig::any_enabled, 0))?;
|
|
3665
|
+
|
|
3666
|
+
let class = module.define_class("MetadataConfigUpdate", ruby.class_object())?;
|
|
3667
|
+
class.define_singleton_method("new", function!(MetadataConfigUpdate::new, 6))?;
|
|
3668
|
+
class.define_method("extract_document", method!(MetadataConfigUpdate::extract_document, 0))?;
|
|
3669
|
+
class.define_method("extract_headers", method!(MetadataConfigUpdate::extract_headers, 0))?;
|
|
3670
|
+
class.define_method("extract_links", method!(MetadataConfigUpdate::extract_links, 0))?;
|
|
3671
|
+
class.define_method("extract_images", method!(MetadataConfigUpdate::extract_images, 0))?;
|
|
3672
|
+
class.define_method(
|
|
3673
|
+
"extract_structured_data",
|
|
3674
|
+
method!(MetadataConfigUpdate::extract_structured_data, 0),
|
|
3675
|
+
)?;
|
|
3676
|
+
class.define_method(
|
|
3677
|
+
"max_structured_data_size",
|
|
3678
|
+
method!(MetadataConfigUpdate::max_structured_data_size, 0),
|
|
3679
|
+
)?;
|
|
3680
|
+
|
|
3681
|
+
let class = module.define_class("DocumentMetadata", ruby.class_object())?;
|
|
3682
|
+
class.define_singleton_method("new", function!(DocumentMetadata::new, 11))?;
|
|
3683
|
+
class.define_method("title", method!(DocumentMetadata::title, 0))?;
|
|
3684
|
+
class.define_method("description", method!(DocumentMetadata::description, 0))?;
|
|
3685
|
+
class.define_method("keywords", method!(DocumentMetadata::keywords, 0))?;
|
|
3686
|
+
class.define_method("author", method!(DocumentMetadata::author, 0))?;
|
|
3687
|
+
class.define_method("canonical_url", method!(DocumentMetadata::canonical_url, 0))?;
|
|
3688
|
+
class.define_method("base_href", method!(DocumentMetadata::base_href, 0))?;
|
|
3689
|
+
class.define_method("language", method!(DocumentMetadata::language, 0))?;
|
|
3690
|
+
class.define_method("text_direction", method!(DocumentMetadata::text_direction, 0))?;
|
|
3691
|
+
class.define_method("open_graph", method!(DocumentMetadata::open_graph, 0))?;
|
|
3692
|
+
class.define_method("twitter_card", method!(DocumentMetadata::twitter_card, 0))?;
|
|
3693
|
+
class.define_method("meta_tags", method!(DocumentMetadata::meta_tags, 0))?;
|
|
3694
|
+
|
|
3695
|
+
let class = module.define_class("HeaderMetadata", ruby.class_object())?;
|
|
3696
|
+
class.define_singleton_method("new", function!(HeaderMetadata::new, 5))?;
|
|
3697
|
+
class.define_method("level", method!(HeaderMetadata::level, 0))?;
|
|
3698
|
+
class.define_method("text", method!(HeaderMetadata::text, 0))?;
|
|
3699
|
+
class.define_method("id", method!(HeaderMetadata::id, 0))?;
|
|
3700
|
+
class.define_method("depth", method!(HeaderMetadata::depth, 0))?;
|
|
3701
|
+
class.define_method("html_offset", method!(HeaderMetadata::html_offset, 0))?;
|
|
3702
|
+
class.define_method("is_valid", method!(HeaderMetadata::is_valid, 0))?;
|
|
3703
|
+
|
|
3704
|
+
let class = module.define_class("LinkMetadata", ruby.class_object())?;
|
|
3705
|
+
class.define_singleton_method("new", function!(LinkMetadata::new, 6))?;
|
|
3706
|
+
class.define_method("href", method!(LinkMetadata::href, 0))?;
|
|
3707
|
+
class.define_method("text", method!(LinkMetadata::text, 0))?;
|
|
3708
|
+
class.define_method("title", method!(LinkMetadata::title, 0))?;
|
|
3709
|
+
class.define_method("link_type", method!(LinkMetadata::link_type, 0))?;
|
|
3710
|
+
class.define_method("rel", method!(LinkMetadata::rel, 0))?;
|
|
3711
|
+
class.define_method("attributes", method!(LinkMetadata::attributes, 0))?;
|
|
3712
|
+
|
|
3713
|
+
let class = module.define_class("ImageMetadata", ruby.class_object())?;
|
|
3714
|
+
class.define_singleton_method("new", function!(ImageMetadata::new, 6))?;
|
|
3715
|
+
class.define_method("src", method!(ImageMetadata::src, 0))?;
|
|
3716
|
+
class.define_method("alt", method!(ImageMetadata::alt, 0))?;
|
|
3717
|
+
class.define_method("title", method!(ImageMetadata::title, 0))?;
|
|
3718
|
+
class.define_method("dimensions", method!(ImageMetadata::dimensions, 0))?;
|
|
3719
|
+
class.define_method("image_type", method!(ImageMetadata::image_type, 0))?;
|
|
3720
|
+
class.define_method("attributes", method!(ImageMetadata::attributes, 0))?;
|
|
3721
|
+
|
|
3722
|
+
let class = module.define_class("StructuredData", ruby.class_object())?;
|
|
3723
|
+
class.define_singleton_method("new", function!(StructuredData::new, 3))?;
|
|
3724
|
+
class.define_method("data_type", method!(StructuredData::data_type, 0))?;
|
|
3725
|
+
class.define_method("raw_json", method!(StructuredData::raw_json, 0))?;
|
|
3726
|
+
class.define_method("schema_type", method!(StructuredData::schema_type, 0))?;
|
|
3727
|
+
|
|
3728
|
+
let class = module.define_class("HtmlMetadata", ruby.class_object())?;
|
|
3729
|
+
class.define_singleton_method("new", function!(HtmlMetadata::new, 5))?;
|
|
3730
|
+
class.define_method("document", method!(HtmlMetadata::document, 0))?;
|
|
3731
|
+
class.define_method("headers", method!(HtmlMetadata::headers, 0))?;
|
|
3732
|
+
class.define_method("links", method!(HtmlMetadata::links, 0))?;
|
|
3733
|
+
class.define_method("images", method!(HtmlMetadata::images, 0))?;
|
|
3734
|
+
class.define_method("structured_data", method!(HtmlMetadata::structured_data, 0))?;
|
|
3735
|
+
|
|
3736
|
+
let class = module.define_class("ConversionOptions", ruby.class_object())?;
|
|
3737
|
+
class.define_singleton_method("new", function!(ConversionOptions::new, 1))?;
|
|
3738
|
+
class.define_method("heading_style", method!(ConversionOptions::heading_style, 0))?;
|
|
3739
|
+
class.define_method("list_indent_type", method!(ConversionOptions::list_indent_type, 0))?;
|
|
3740
|
+
class.define_method("list_indent_width", method!(ConversionOptions::list_indent_width, 0))?;
|
|
3741
|
+
class.define_method("bullets", method!(ConversionOptions::bullets, 0))?;
|
|
3742
|
+
class.define_method("strong_em_symbol", method!(ConversionOptions::strong_em_symbol, 0))?;
|
|
3743
|
+
class.define_method("escape_asterisks", method!(ConversionOptions::escape_asterisks, 0))?;
|
|
3744
|
+
class.define_method("escape_underscores", method!(ConversionOptions::escape_underscores, 0))?;
|
|
3745
|
+
class.define_method("escape_misc", method!(ConversionOptions::escape_misc, 0))?;
|
|
3746
|
+
class.define_method("escape_ascii", method!(ConversionOptions::escape_ascii, 0))?;
|
|
3747
|
+
class.define_method("code_language", method!(ConversionOptions::code_language, 0))?;
|
|
3748
|
+
class.define_method("autolinks", method!(ConversionOptions::autolinks, 0))?;
|
|
3749
|
+
class.define_method("default_title", method!(ConversionOptions::default_title, 0))?;
|
|
3750
|
+
class.define_method("br_in_tables", method!(ConversionOptions::br_in_tables, 0))?;
|
|
3751
|
+
class.define_method("highlight_style", method!(ConversionOptions::highlight_style, 0))?;
|
|
3752
|
+
class.define_method("extract_metadata", method!(ConversionOptions::extract_metadata, 0))?;
|
|
3753
|
+
class.define_method("whitespace_mode", method!(ConversionOptions::whitespace_mode, 0))?;
|
|
3754
|
+
class.define_method("strip_newlines", method!(ConversionOptions::strip_newlines, 0))?;
|
|
3755
|
+
class.define_method("wrap", method!(ConversionOptions::wrap, 0))?;
|
|
3756
|
+
class.define_method("wrap_width", method!(ConversionOptions::wrap_width, 0))?;
|
|
3757
|
+
class.define_method("convert_as_inline", method!(ConversionOptions::convert_as_inline, 0))?;
|
|
3758
|
+
class.define_method("sub_symbol", method!(ConversionOptions::sub_symbol, 0))?;
|
|
3759
|
+
class.define_method("sup_symbol", method!(ConversionOptions::sup_symbol, 0))?;
|
|
3760
|
+
class.define_method("newline_style", method!(ConversionOptions::newline_style, 0))?;
|
|
3761
|
+
class.define_method("code_block_style", method!(ConversionOptions::code_block_style, 0))?;
|
|
3762
|
+
class.define_method(
|
|
3763
|
+
"keep_inline_images_in",
|
|
3764
|
+
method!(ConversionOptions::keep_inline_images_in, 0),
|
|
3765
|
+
)?;
|
|
3766
|
+
class.define_method("preprocessing", method!(ConversionOptions::preprocessing, 0))?;
|
|
3767
|
+
class.define_method("encoding", method!(ConversionOptions::encoding, 0))?;
|
|
3768
|
+
class.define_method("debug", method!(ConversionOptions::debug, 0))?;
|
|
3769
|
+
class.define_method("strip_tags", method!(ConversionOptions::strip_tags, 0))?;
|
|
3770
|
+
class.define_method("preserve_tags", method!(ConversionOptions::preserve_tags, 0))?;
|
|
3771
|
+
class.define_method("skip_images", method!(ConversionOptions::skip_images, 0))?;
|
|
3772
|
+
class.define_method("link_style", method!(ConversionOptions::link_style, 0))?;
|
|
3773
|
+
class.define_method("output_format", method!(ConversionOptions::output_format, 0))?;
|
|
3774
|
+
class.define_method(
|
|
3775
|
+
"include_document_structure",
|
|
3776
|
+
method!(ConversionOptions::include_document_structure, 0),
|
|
3777
|
+
)?;
|
|
3778
|
+
class.define_method("extract_images", method!(ConversionOptions::extract_images, 0))?;
|
|
3779
|
+
class.define_method("max_image_size", method!(ConversionOptions::max_image_size, 0))?;
|
|
3780
|
+
class.define_method("capture_svg", method!(ConversionOptions::capture_svg, 0))?;
|
|
3781
|
+
class.define_method("infer_dimensions", method!(ConversionOptions::infer_dimensions, 0))?;
|
|
3782
|
+
|
|
3783
|
+
let class = module.define_class("ConversionOptionsBuilder", ruby.class_object())?;
|
|
3784
|
+
class.define_method("strip_tags", method!(ConversionOptionsBuilder::strip_tags, 1))?;
|
|
3785
|
+
class.define_method("preserve_tags", method!(ConversionOptionsBuilder::preserve_tags, 1))?;
|
|
3786
|
+
class.define_method(
|
|
3787
|
+
"keep_inline_images_in",
|
|
3788
|
+
method!(ConversionOptionsBuilder::keep_inline_images_in, 1),
|
|
3789
|
+
)?;
|
|
3790
|
+
class.define_method("preprocessing", method!(ConversionOptionsBuilder::preprocessing, 1))?;
|
|
3791
|
+
class.define_method("build", method!(ConversionOptionsBuilder::build, 0))?;
|
|
3792
|
+
|
|
3793
|
+
let class = module.define_class("ConversionOptionsUpdate", ruby.class_object())?;
|
|
3794
|
+
class.define_singleton_method("new", function!(ConversionOptionsUpdate::new, 1))?;
|
|
3795
|
+
class.define_method("heading_style", method!(ConversionOptionsUpdate::heading_style, 0))?;
|
|
3796
|
+
class.define_method(
|
|
3797
|
+
"list_indent_type",
|
|
3798
|
+
method!(ConversionOptionsUpdate::list_indent_type, 0),
|
|
3799
|
+
)?;
|
|
3800
|
+
class.define_method(
|
|
3801
|
+
"list_indent_width",
|
|
3802
|
+
method!(ConversionOptionsUpdate::list_indent_width, 0),
|
|
3803
|
+
)?;
|
|
3804
|
+
class.define_method("bullets", method!(ConversionOptionsUpdate::bullets, 0))?;
|
|
3805
|
+
class.define_method(
|
|
3806
|
+
"strong_em_symbol",
|
|
3807
|
+
method!(ConversionOptionsUpdate::strong_em_symbol, 0),
|
|
3808
|
+
)?;
|
|
3809
|
+
class.define_method(
|
|
3810
|
+
"escape_asterisks",
|
|
3811
|
+
method!(ConversionOptionsUpdate::escape_asterisks, 0),
|
|
3812
|
+
)?;
|
|
3813
|
+
class.define_method(
|
|
3814
|
+
"escape_underscores",
|
|
3815
|
+
method!(ConversionOptionsUpdate::escape_underscores, 0),
|
|
3816
|
+
)?;
|
|
3817
|
+
class.define_method("escape_misc", method!(ConversionOptionsUpdate::escape_misc, 0))?;
|
|
3818
|
+
class.define_method("escape_ascii", method!(ConversionOptionsUpdate::escape_ascii, 0))?;
|
|
3819
|
+
class.define_method("code_language", method!(ConversionOptionsUpdate::code_language, 0))?;
|
|
3820
|
+
class.define_method("autolinks", method!(ConversionOptionsUpdate::autolinks, 0))?;
|
|
3821
|
+
class.define_method("default_title", method!(ConversionOptionsUpdate::default_title, 0))?;
|
|
3822
|
+
class.define_method("br_in_tables", method!(ConversionOptionsUpdate::br_in_tables, 0))?;
|
|
3823
|
+
class.define_method("highlight_style", method!(ConversionOptionsUpdate::highlight_style, 0))?;
|
|
3824
|
+
class.define_method(
|
|
3825
|
+
"extract_metadata",
|
|
3826
|
+
method!(ConversionOptionsUpdate::extract_metadata, 0),
|
|
3827
|
+
)?;
|
|
3828
|
+
class.define_method("whitespace_mode", method!(ConversionOptionsUpdate::whitespace_mode, 0))?;
|
|
3829
|
+
class.define_method("strip_newlines", method!(ConversionOptionsUpdate::strip_newlines, 0))?;
|
|
3830
|
+
class.define_method("wrap", method!(ConversionOptionsUpdate::wrap, 0))?;
|
|
3831
|
+
class.define_method("wrap_width", method!(ConversionOptionsUpdate::wrap_width, 0))?;
|
|
3832
|
+
class.define_method(
|
|
3833
|
+
"convert_as_inline",
|
|
3834
|
+
method!(ConversionOptionsUpdate::convert_as_inline, 0),
|
|
3835
|
+
)?;
|
|
3836
|
+
class.define_method("sub_symbol", method!(ConversionOptionsUpdate::sub_symbol, 0))?;
|
|
3837
|
+
class.define_method("sup_symbol", method!(ConversionOptionsUpdate::sup_symbol, 0))?;
|
|
3838
|
+
class.define_method("newline_style", method!(ConversionOptionsUpdate::newline_style, 0))?;
|
|
3839
|
+
class.define_method(
|
|
3840
|
+
"code_block_style",
|
|
3841
|
+
method!(ConversionOptionsUpdate::code_block_style, 0),
|
|
3842
|
+
)?;
|
|
3843
|
+
class.define_method(
|
|
3844
|
+
"keep_inline_images_in",
|
|
3845
|
+
method!(ConversionOptionsUpdate::keep_inline_images_in, 0),
|
|
3846
|
+
)?;
|
|
3847
|
+
class.define_method("preprocessing", method!(ConversionOptionsUpdate::preprocessing, 0))?;
|
|
3848
|
+
class.define_method("encoding", method!(ConversionOptionsUpdate::encoding, 0))?;
|
|
3849
|
+
class.define_method("debug", method!(ConversionOptionsUpdate::debug, 0))?;
|
|
3850
|
+
class.define_method("strip_tags", method!(ConversionOptionsUpdate::strip_tags, 0))?;
|
|
3851
|
+
class.define_method("preserve_tags", method!(ConversionOptionsUpdate::preserve_tags, 0))?;
|
|
3852
|
+
class.define_method("skip_images", method!(ConversionOptionsUpdate::skip_images, 0))?;
|
|
3853
|
+
class.define_method("link_style", method!(ConversionOptionsUpdate::link_style, 0))?;
|
|
3854
|
+
class.define_method("output_format", method!(ConversionOptionsUpdate::output_format, 0))?;
|
|
3855
|
+
class.define_method(
|
|
3856
|
+
"include_document_structure",
|
|
3857
|
+
method!(ConversionOptionsUpdate::include_document_structure, 0),
|
|
3858
|
+
)?;
|
|
3859
|
+
class.define_method("extract_images", method!(ConversionOptionsUpdate::extract_images, 0))?;
|
|
3860
|
+
class.define_method("max_image_size", method!(ConversionOptionsUpdate::max_image_size, 0))?;
|
|
3861
|
+
class.define_method("capture_svg", method!(ConversionOptionsUpdate::capture_svg, 0))?;
|
|
3862
|
+
class.define_method(
|
|
3863
|
+
"infer_dimensions",
|
|
3864
|
+
method!(ConversionOptionsUpdate::infer_dimensions, 0),
|
|
3865
|
+
)?;
|
|
3866
|
+
|
|
3867
|
+
let class = module.define_class("PreprocessingOptions", ruby.class_object())?;
|
|
3868
|
+
class.define_singleton_method("new", function!(PreprocessingOptions::new, 4))?;
|
|
3869
|
+
class.define_method("enabled", method!(PreprocessingOptions::enabled, 0))?;
|
|
3870
|
+
class.define_method("preset", method!(PreprocessingOptions::preset, 0))?;
|
|
3871
|
+
class.define_method("remove_navigation", method!(PreprocessingOptions::remove_navigation, 0))?;
|
|
3872
|
+
class.define_method("remove_forms", method!(PreprocessingOptions::remove_forms, 0))?;
|
|
3873
|
+
|
|
3874
|
+
let class = module.define_class("PreprocessingOptionsUpdate", ruby.class_object())?;
|
|
3875
|
+
class.define_singleton_method("new", function!(PreprocessingOptionsUpdate::new, 4))?;
|
|
3876
|
+
class.define_method("enabled", method!(PreprocessingOptionsUpdate::enabled, 0))?;
|
|
3877
|
+
class.define_method("preset", method!(PreprocessingOptionsUpdate::preset, 0))?;
|
|
3878
|
+
class.define_method(
|
|
3879
|
+
"remove_navigation",
|
|
3880
|
+
method!(PreprocessingOptionsUpdate::remove_navigation, 0),
|
|
3881
|
+
)?;
|
|
3882
|
+
class.define_method("remove_forms", method!(PreprocessingOptionsUpdate::remove_forms, 0))?;
|
|
3883
|
+
|
|
3884
|
+
let class = module.define_class("DocumentStructure", ruby.class_object())?;
|
|
3885
|
+
class.define_singleton_method("new", function!(DocumentStructure::new, 2))?;
|
|
3886
|
+
class.define_method("nodes", method!(DocumentStructure::nodes, 0))?;
|
|
3887
|
+
class.define_method("source_format", method!(DocumentStructure::source_format, 0))?;
|
|
3888
|
+
|
|
3889
|
+
let class = module.define_class("DocumentNode", ruby.class_object())?;
|
|
3890
|
+
class.define_singleton_method("new", function!(DocumentNode::new, 6))?;
|
|
3891
|
+
class.define_method("id", method!(DocumentNode::id, 0))?;
|
|
3892
|
+
class.define_method("content", method!(DocumentNode::content, 0))?;
|
|
3893
|
+
class.define_method("parent", method!(DocumentNode::parent, 0))?;
|
|
3894
|
+
class.define_method("children", method!(DocumentNode::children, 0))?;
|
|
3895
|
+
class.define_method("annotations", method!(DocumentNode::annotations, 0))?;
|
|
3896
|
+
class.define_method("attributes", method!(DocumentNode::attributes, 0))?;
|
|
3897
|
+
|
|
3898
|
+
let class = module.define_class("TextAnnotation", ruby.class_object())?;
|
|
3899
|
+
class.define_singleton_method("new", function!(TextAnnotation::new, 3))?;
|
|
3900
|
+
class.define_method("start", method!(TextAnnotation::start, 0))?;
|
|
3901
|
+
class.define_method("end", method!(TextAnnotation::end, 0))?;
|
|
3902
|
+
class.define_method("kind", method!(TextAnnotation::kind, 0))?;
|
|
3903
|
+
|
|
3904
|
+
let class = module.define_class("ConversionResult", ruby.class_object())?;
|
|
3905
|
+
class.define_singleton_method("new", function!(ConversionResult::new, 6))?;
|
|
3906
|
+
class.define_method("content", method!(ConversionResult::content, 0))?;
|
|
3907
|
+
class.define_method("document", method!(ConversionResult::document, 0))?;
|
|
3908
|
+
class.define_method("metadata", method!(ConversionResult::metadata, 0))?;
|
|
3909
|
+
class.define_method("tables", method!(ConversionResult::tables, 0))?;
|
|
3910
|
+
class.define_method("images", method!(ConversionResult::images, 0))?;
|
|
3911
|
+
class.define_method("warnings", method!(ConversionResult::warnings, 0))?;
|
|
3912
|
+
|
|
3913
|
+
let class = module.define_class("TableGrid", ruby.class_object())?;
|
|
3914
|
+
class.define_singleton_method("new", function!(TableGrid::new, 3))?;
|
|
3915
|
+
class.define_method("rows", method!(TableGrid::rows, 0))?;
|
|
3916
|
+
class.define_method("cols", method!(TableGrid::cols, 0))?;
|
|
3917
|
+
class.define_method("cells", method!(TableGrid::cells, 0))?;
|
|
3918
|
+
|
|
3919
|
+
let class = module.define_class("GridCell", ruby.class_object())?;
|
|
3920
|
+
class.define_singleton_method("new", function!(GridCell::new, 6))?;
|
|
3921
|
+
class.define_method("content", method!(GridCell::content, 0))?;
|
|
3922
|
+
class.define_method("row", method!(GridCell::row, 0))?;
|
|
3923
|
+
class.define_method("col", method!(GridCell::col, 0))?;
|
|
3924
|
+
class.define_method("row_span", method!(GridCell::row_span, 0))?;
|
|
3925
|
+
class.define_method("col_span", method!(GridCell::col_span, 0))?;
|
|
3926
|
+
class.define_method("is_header", method!(GridCell::is_header, 0))?;
|
|
3927
|
+
|
|
3928
|
+
let class = module.define_class("TableData", ruby.class_object())?;
|
|
3929
|
+
class.define_singleton_method("new", function!(TableData::new, 2))?;
|
|
3930
|
+
class.define_method("grid", method!(TableData::grid, 0))?;
|
|
3931
|
+
class.define_method("markdown", method!(TableData::markdown, 0))?;
|
|
3932
|
+
|
|
3933
|
+
let class = module.define_class("ProcessingWarning", ruby.class_object())?;
|
|
3934
|
+
class.define_singleton_method("new", function!(ProcessingWarning::new, 2))?;
|
|
3935
|
+
class.define_method("message", method!(ProcessingWarning::message, 0))?;
|
|
3936
|
+
class.define_method("kind", method!(ProcessingWarning::kind, 0))?;
|
|
3937
|
+
|
|
3938
|
+
module.define_module_function("convert", function!(convert, 2))?;
|
|
3939
|
+
|
|
3940
|
+
Ok(())
|
|
3941
|
+
}
|