commonmarker 2.10.1 → 3.0.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.
@@ -1,20 +1,28 @@
1
1
  use crate::rctree::Node;
2
2
  use comrak::arena_tree::Node as ComrakNode;
3
3
  use comrak::nodes::{
4
- AlertType, Ast as ComrakAst, AstNode as ComrakAstNode, ListDelimType, ListType, NodeAlert,
5
- NodeCode, NodeCodeBlock, NodeDescriptionItem, NodeFootnoteDefinition, NodeFootnoteReference,
6
- NodeHeading, NodeHtmlBlock, NodeLink, NodeList, NodeMath, NodeMultilineBlockQuote,
7
- NodeShortCode, NodeTable, NodeTaskItem, NodeValue as ComrakNodeValue, NodeWikiLink,
8
- TableAlignment,
4
+ AlertType, Ast as ComrakAst, AstNode as ComrakAstNode, CalloutFold, ListDelimType, NodeAlert,
5
+ NodeBlockId, NodeCallout, NodeCode, NodeCodeBlock, NodeComment, NodeCommentBlock,
6
+ NodeDescriptionItem, NodeEmph, NodeFootnoteDefinition, NodeFootnoteReference, NodeHeading,
7
+ NodeHtmlBlock, NodeLink, NodeList, NodeMath, NodeMathBlock, NodeMultilineBlockQuote,
8
+ NodeShortCode, NodeStrikethrough, NodeStrong, NodeTable, NodeTableRow, NodeTaskItem,
9
+ NodeThematicBreak, NodeValue as ComrakNodeValue, NodeWikiLink, TableAlignment,
10
+ };
11
+ use magnus::r_hash::ForEach;
12
+ use magnus::value::ReprValue;
13
+ use magnus::{
14
+ function, method, scan_args, Module, Object, RClass, RHash, Symbol, TryConvert, Value,
9
15
  };
10
- use magnus::{function, method, scan_args, Module, Object, RHash, RModule, Symbol, Value};
11
16
  use magnus::{RArray, Ruby};
17
+ use std::sync::Arc;
12
18
  use typed_arena::Arena;
13
19
 
14
20
  use std::cell::RefCell;
15
21
 
16
- use crate::options::{iterate_extension_options, iterate_parse_options, iterate_render_options};
22
+ use crate::options::{format_options, Options};
17
23
  use crate::plugins::syntax_highlighting::construct_syntax_highlighter_from_plugin;
24
+ use crate::plugins::{comrak_plugins, format_plugins};
25
+ use comrak::plugins::syntect::SyntectAdapter;
18
26
 
19
27
  #[derive(Debug, Clone)]
20
28
  #[magnus::wrap(class = "Commonmarker::Node::Ast", size, mark)]
@@ -51,13 +59,17 @@ fn value_supports(value: &ComrakNodeValue, property: &str) -> Option<bool> {
51
59
  | ComrakNodeValue::HtmlInline(_)
52
60
  | ComrakNodeValue::Raw(_)
53
61
  | ComrakNodeValue::Math(_)
62
+ | ComrakNodeValue::MathBlock(_)
54
63
  | ComrakNodeValue::FrontMatter(_)
64
+ | ComrakNodeValue::CommentInline(_)
65
+ | ComrakNodeValue::MultilineComment(_)
55
66
  ),
56
67
  "url" | "title" => matches!(value, ComrakNodeValue::Link(_) | ComrakNodeValue::Image(_)),
57
68
  "header_level" => matches!(value, ComrakNodeValue::Heading(_)),
58
69
  "list_type" | "list_start" | "list_tight" => matches!(value, ComrakNodeValue::List(_)),
59
70
  "fenced" | "fence_info" => matches!(value, ComrakNodeValue::CodeBlock(_)),
60
71
  "alert_type" => matches!(value, ComrakNodeValue::Alert(_)),
72
+ "callout_type" => matches!(value, ComrakNodeValue::Callout(_)),
61
73
  _ => return None,
62
74
  };
63
75
 
@@ -93,12 +105,11 @@ impl CommonmarkerNode {
93
105
  ));
94
106
  };
95
107
 
96
- ComrakNodeValue::FootnoteDefinition(NodeFootnoteDefinition {
97
- // The name of the footnote.
98
- name,
99
- // Total number of references to this footnote
100
- total_references,
101
- })
108
+ let mut footnote_definition = NodeFootnoteDefinition::new(name);
109
+ // Total number of references to this footnote
110
+ footnote_definition.total_references = total_references;
111
+
112
+ ComrakNodeValue::FootnoteDefinition(footnote_definition)
102
113
  }
103
114
  "list" => {
104
115
  let kwargs = scan_args::get_kwargs::<
@@ -141,35 +152,30 @@ impl CommonmarkerNode {
141
152
  ));
142
153
  }
143
154
 
144
- let comrak_list_type = if commonmark_list_type == "ordered" {
145
- ListType::Ordered
146
- } else {
147
- ListType::Bullet
148
- };
149
-
155
+ // For ordered lists, the delimiter after each number.
150
156
  let comrak_delimiter = match delimiter.unwrap_or("".to_string()).as_str() {
151
157
  ")" => ListDelimType::Paren,
152
158
  _ => ListDelimType::Period,
153
159
  };
154
160
 
155
- ComrakNodeValue::List(NodeList {
156
- // The kind of list (bullet (unordered) or ordered).
157
- list_type: comrak_list_type,
158
- // Number of spaces before the list marker.
159
- marker_offset: marker_offset.unwrap_or(0),
160
- // Number of characters between the start of the list marker and the item text (including the list marker(s)).
161
- padding: padding.unwrap_or(0),
161
+ // Whether the list is [tight](https://github.github.com/gfm/#tight), i.e. whether the
162
+ // paragraphs are wrapped in `<p>` tags when formatted as HTML.
163
+ let tight = tight.unwrap_or(false);
164
+
165
+ let mut list = if commonmark_list_type == "ordered" {
162
166
  // For ordered lists, the ordinal the list starts at.
163
- start: start.unwrap_or(0),
164
- // For ordered lists, the delimiter after each number.
165
- delimiter: comrak_delimiter,
167
+ NodeList::ordered(start.unwrap_or(0), comrak_delimiter, tight)
168
+ } else {
166
169
  // For bullet lists, the character used for each bullet.
167
- bullet_char: bullet_char.unwrap_or(0),
168
- // Whether the list is [tight](https://github.github.com/gfm/#tight), i.e. whether the
169
- // paragraphs are wrapped in `<p>` tags when formatted as HTML.
170
- tight: tight.unwrap_or(false),
171
- is_task_list: task_list.unwrap_or(false),
172
- })
170
+ NodeList::bullet(bullet_char.unwrap_or(0), tight)
171
+ };
172
+ // Number of spaces before the list marker.
173
+ list.marker_offset = marker_offset.unwrap_or(0);
174
+ // Number of characters between the start of the list marker and the item text (including the list marker(s)).
175
+ list.padding = padding.unwrap_or(0);
176
+ list.is_task_list = task_list.unwrap_or(false);
177
+
178
+ ComrakNodeValue::List(list)
173
179
  }
174
180
  "description_list" => ComrakNodeValue::DescriptionList,
175
181
  "description_item" => {
@@ -184,15 +190,15 @@ impl CommonmarkerNode {
184
190
 
185
191
  let (marker_offset, padding, tight) = kwargs.optional;
186
192
 
187
- ComrakNodeValue::DescriptionItem(NodeDescriptionItem {
188
- // Number of spaces before the list marker.
189
- marker_offset: marker_offset.unwrap_or(0),
190
- // Number of characters between the start of the list marker and the item text (including the list marker(s)).
191
- padding: padding.unwrap_or(0),
192
- // Whether the list is [tight](https://github.github.com/gfm/#tight), i.e. whether the
193
- // paragraphs are wrapped in `<p>` tags when formatted as HTML.
194
- tight: tight.unwrap_or(false),
195
- })
193
+ // Whether the list is [tight](https://github.github.com/gfm/#tight), i.e. whether the
194
+ // paragraphs are wrapped in `<p>` tags when formatted as HTML.
195
+ let mut description_item = NodeDescriptionItem::new(tight.unwrap_or(false));
196
+ // Number of spaces before the list marker.
197
+ description_item.marker_offset = marker_offset.unwrap_or(0);
198
+ // Number of characters between the start of the list marker and the item text (including the list marker(s)).
199
+ description_item.padding = padding.unwrap_or(0);
200
+
201
+ ComrakNodeValue::DescriptionItem(description_item)
196
202
  }
197
203
  "description_term" => ComrakNodeValue::DescriptionTerm,
198
204
  "description_details" => ComrakNodeValue::DescriptionDetails,
@@ -225,30 +231,30 @@ impl CommonmarkerNode {
225
231
  let (fence_char, fence_length, fence_offset, info, literal, closed) =
226
232
  kwargs.optional;
227
233
 
228
- ComrakNodeValue::CodeBlock(Box::new(NodeCodeBlock {
229
- // Whether the code block is fenced.
230
- fenced,
231
- // For fenced code blocks, the fence character itself (`` ` `` or `~`).
232
- fence_char: fence_char.unwrap_or(b'`'),
233
- // For fenced code blocks, the length of the fence.
234
- fence_length: fence_length.unwrap_or(0),
235
- // For fenced code blocks, the indentation level of the code within the block.
236
- fence_offset: fence_offset.unwrap_or(0),
234
+ // The literal contents of the code block. As the contents are not interpreted as Markdown at
235
+ // all, they are contained within this structure, rather than inserted into a child inline of
236
+ // any kind.
237
+ let literal = literal.unwrap_or_default();
237
238
 
239
+ let mut code_block = if fenced {
238
240
  // For fenced code blocks, the [info string](https://github.github.com/gfm/#info-string) after
239
241
  // the opening fence, if any.
240
- info: info.unwrap_or(String::with_capacity(10)),
241
-
242
- // The literal contents of the code block. As the contents are not interpreted as Markdown at
243
- // all, they are contained within this structure, rather than inserted into a child inline of
244
- // any kind.
245
- literal: literal.unwrap_or(String::new()),
246
-
247
- // For fenced code blocks, whether the code block is closed. (If not, it was terminated by
248
- // some other condition, like the end of the document, or the end of the indentation level the
249
- // code block was introduced at.)
250
- closed: closed.unwrap_or(true),
251
- }))
242
+ NodeCodeBlock::fenced(info.unwrap_or_default(), literal)
243
+ } else {
244
+ NodeCodeBlock::indented(literal)
245
+ };
246
+ // For fenced code blocks, the fence character itself (`` ` `` or `~`).
247
+ code_block.fence_char = fence_char.unwrap_or(b'`');
248
+ // For fenced code blocks, the length of the fence.
249
+ code_block.fence_length = fence_length.unwrap_or(0);
250
+ // For fenced code blocks, the indentation level of the code within the block.
251
+ code_block.fence_offset = fence_offset.unwrap_or(0);
252
+ // For fenced code blocks, whether the code block is closed. (If not, it was terminated by
253
+ // some other condition, like the end of the document, or the end of the indentation level the
254
+ // code block was introduced at.)
255
+ code_block.closed = closed.unwrap_or(true);
256
+
257
+ ComrakNodeValue::CodeBlock(Box::new(code_block))
252
258
  }
253
259
  "html_block" => {
254
260
  let kwargs = scan_args::get_kwargs::<_, (), (Option<u8>, Option<String>), ()>(
@@ -259,12 +265,12 @@ impl CommonmarkerNode {
259
265
 
260
266
  let (block_type, literal) = kwargs.optional;
261
267
 
262
- ComrakNodeValue::HtmlBlock(NodeHtmlBlock {
263
- // Number of spaces before the list marker.
264
- block_type: block_type.unwrap_or(0),
265
- // Number of characters between the start of the list marker and the item text (including the list marker(s)).
266
- literal: literal.unwrap_or(String::new()),
267
- })
268
+ // The literal contents of the HTML block.
269
+ let mut html_block = NodeHtmlBlock::new(literal.unwrap_or_default());
270
+ // The HTML block's type.
271
+ html_block.block_type = block_type.unwrap_or(0);
272
+
273
+ ComrakNodeValue::HtmlBlock(html_block)
268
274
  }
269
275
  "paragraph" => ComrakNodeValue::Paragraph,
270
276
  "heading" => {
@@ -277,18 +283,18 @@ impl CommonmarkerNode {
277
283
  let (level,) = kwargs.required;
278
284
  let (setext, closed) = kwargs.optional;
279
285
 
280
- ComrakNodeValue::Heading(NodeHeading {
281
- // The heading level. For setext headings, an underline made of "=" characters is level 1, and made of
282
- // "-" is level 2. For ATX headings, the number of leading "#" characters (from 1 to 6) is its level.
283
- level,
284
- // Whether the heading is setext style (marked by an underline). If not, it is ATX style (marked by leading,
285
- // and possibly trailing, "#" characters).
286
- setext: setext.unwrap_or(false),
287
- // For ATX headings, whether the the leading "#" are terminated by a sequence of closing "#" characters.
288
- closed: closed.unwrap_or(false),
289
- })
286
+ // The heading level. For setext headings, an underline made of "=" characters is level 1, and made of
287
+ // "-" is level 2. For ATX headings, the number of leading "#" characters (from 1 to 6) is its level.
288
+ let mut heading = NodeHeading::new(level);
289
+ // Whether the heading is setext style (marked by an underline). If not, it is ATX style (marked by leading,
290
+ // and possibly trailing, "#" characters).
291
+ heading.setext = setext.unwrap_or(false);
292
+ // For ATX headings, whether the the leading "#" are terminated by a sequence of closing "#" characters.
293
+ heading.closed = closed.unwrap_or(false);
294
+
295
+ ComrakNodeValue::Heading(heading)
290
296
  }
291
- "thematic_break" => ComrakNodeValue::ThematicBreak,
297
+ "thematic_break" => ComrakNodeValue::ThematicBreak(NodeThematicBreak::default()),
292
298
  "table" => {
293
299
  let kwargs = scan_args::get_kwargs::<_, (RArray, usize, usize, usize), (), ()>(
294
300
  args.keywords,
@@ -320,19 +326,16 @@ impl CommonmarkerNode {
320
326
  comrak_alignments.push(TableAlignment::None);
321
327
  }
322
328
  });
323
- ComrakNodeValue::Table(Box::new(NodeTable {
324
- // The table alignments
325
- alignments: comrak_alignments,
326
-
327
- // Number of columns of the table
328
- num_columns,
329
-
330
- // Number of rows of the table
331
- num_rows,
332
-
333
- // Number of non-empty, non-autocompleted cells
334
- num_nonempty_cells,
335
- }))
329
+ // The table alignments
330
+ let mut table = NodeTable::new(comrak_alignments);
331
+ // Number of columns of the table
332
+ table.num_columns = num_columns;
333
+ // Number of rows of the table
334
+ table.num_rows = num_rows;
335
+ // Number of non-empty, non-autocompleted cells
336
+ table.num_nonempty_cells = num_nonempty_cells;
337
+
338
+ ComrakNodeValue::Table(Box::new(table))
336
339
  }
337
340
  "table_row" => {
338
341
  let kwargs =
@@ -340,7 +343,7 @@ impl CommonmarkerNode {
340
343
 
341
344
  let (header,) = kwargs.required;
342
345
 
343
- ComrakNodeValue::TableRow(header)
346
+ ComrakNodeValue::TableRow(NodeTableRow::new(header))
344
347
  }
345
348
  "table_cell" => ComrakNodeValue::TableCell,
346
349
  "text" => {
@@ -363,10 +366,7 @@ impl CommonmarkerNode {
363
366
 
364
367
  let (mark,) = kwargs.optional;
365
368
 
366
- ComrakNodeValue::TaskItem(NodeTaskItem {
367
- symbol: mark,
368
- symbol_sourcepos: (0, 0, 0, 0).into(),
369
- })
369
+ ComrakNodeValue::TaskItem(NodeTaskItem::new(mark))
370
370
  }
371
371
  "softbreak" => ComrakNodeValue::SoftBreak,
372
372
  "linebreak" => ComrakNodeValue::LineBreak,
@@ -379,15 +379,15 @@ impl CommonmarkerNode {
379
379
 
380
380
  let (num_backticks, literal) = kwargs.optional;
381
381
 
382
- ComrakNodeValue::Code(NodeCode {
383
- // The number of backticks
384
- num_backticks: num_backticks.unwrap_or(1),
385
- // The content of the inline code span.
386
- // As the contents are not interpreted as Markdown at all,
387
- // they are contained within this structure,
388
- // rather than inserted into a child inline of any kind
389
- literal: literal.unwrap_or_default(),
390
- })
382
+ // The content of the inline code span.
383
+ // As the contents are not interpreted as Markdown at all,
384
+ // they are contained within this structure,
385
+ // rather than inserted into a child inline of any kind
386
+ let mut code = NodeCode::new(literal.unwrap_or_default());
387
+ // The number of backticks
388
+ code.num_backticks = num_backticks.unwrap_or(1);
389
+
390
+ ComrakNodeValue::Code(code)
391
391
  }
392
392
  "html_inline" => {
393
393
  let kwargs = scan_args::get_kwargs::<_, (), (Option<String>,), ()>(
@@ -400,9 +400,9 @@ impl CommonmarkerNode {
400
400
 
401
401
  ComrakNodeValue::HtmlInline(content.unwrap_or_default())
402
402
  }
403
- "emph" => ComrakNodeValue::Emph,
404
- "strong" => ComrakNodeValue::Strong,
405
- "strikethrough" => ComrakNodeValue::Strikethrough,
403
+ "emph" => ComrakNodeValue::Emph(NodeEmph::default()),
404
+ "strong" => ComrakNodeValue::Strong(NodeStrong::default()),
405
+ "strikethrough" => ComrakNodeValue::Strikethrough(NodeStrikethrough::default()),
406
406
  "superscript" => ComrakNodeValue::Superscript,
407
407
  "subscript" => ComrakNodeValue::Subscript,
408
408
  "link" => {
@@ -415,15 +415,8 @@ impl CommonmarkerNode {
415
415
  let (url,) = kwargs.required;
416
416
  let (title,) = kwargs.optional;
417
417
 
418
- ComrakNodeValue::Link(Box::new(NodeLink {
419
- // The URL for the link destination or image source.
420
- url,
421
- // The title for the link or image.
422
- //
423
- // Note this field is used for the `title` attribute by the HTML formatter even for images;
424
- // `alt` text is supplied in the image inline text.
425
- title: title.unwrap_or_default(),
426
- }))
418
+ // The URL for the link destination, and the title for the link.
419
+ ComrakNodeValue::Link(Box::new(NodeLink::new(url, title.unwrap_or_default())))
427
420
  }
428
421
  "image" => {
429
422
  let kwargs = scan_args::get_kwargs::<_, (String,), (Option<String>,), ()>(
@@ -435,15 +428,11 @@ impl CommonmarkerNode {
435
428
  let (url,) = kwargs.required;
436
429
  let (title,) = kwargs.optional;
437
430
 
438
- ComrakNodeValue::Image(Box::new(NodeLink {
439
- // The URL for the link destination or image source.
440
- url,
441
- // The title for the link or image.
442
- //
443
- // Note this field is used for the `title` attribute by the HTML formatter even for images;
444
- // `alt` text is supplied in the image inline text.
445
- title: title.unwrap_or_default(),
446
- }))
431
+ // The URL for the image source, and the title for the image.
432
+ //
433
+ // Note the title is used for the `title` attribute by the HTML formatter even for images;
434
+ // `alt` text is supplied in the image inline text.
435
+ ComrakNodeValue::Image(Box::new(NodeLink::new(url, title.unwrap_or_default())))
447
436
  }
448
437
  "footnote_reference" => {
449
438
  let kwargs = scan_args::get_kwargs::<_, (String,), (Option<u32>, Option<u32>), ()>(
@@ -455,16 +444,14 @@ impl CommonmarkerNode {
455
444
  let (name,) = kwargs.required;
456
445
  let (ref_num, ix) = kwargs.optional;
457
446
 
458
- ComrakNodeValue::FootnoteReference(Box::new(NodeFootnoteReference {
459
- // The name of the footnote.
460
- name,
461
- // The original text and sourcepos column spans that comprised the footnote ref.
462
- texts: vec![],
463
- // The index of reference to the same footnote
464
- ref_num: ref_num.unwrap_or(0),
465
- // The index of the footnote in the document.
466
- ix: ix.unwrap_or(0),
467
- }))
447
+ // The name of the footnote.
448
+ let mut footnote_reference = NodeFootnoteReference::new(name);
449
+ // The index of reference to the same footnote
450
+ footnote_reference.ref_num = ref_num.unwrap_or(0);
451
+ // The index of the footnote in the document.
452
+ footnote_reference.ix = ix.unwrap_or(0);
453
+
454
+ ComrakNodeValue::FootnoteReference(Box::new(footnote_reference))
468
455
  }
469
456
  // #[cfg(feature = "shortcodes")]
470
457
  "shortcode" => {
@@ -492,20 +479,18 @@ impl CommonmarkerNode {
492
479
 
493
480
  let (dollar_math, display_math, literal) = kwargs.required;
494
481
 
495
- ComrakNodeValue::Math(NodeMath {
496
- // Whether this is dollar math (`$` or `$$`).
497
- // `false` indicates it is code math
498
- dollar_math,
499
-
500
- // Whether this is display math (using `$$`)
501
- display_math,
502
-
503
- // The literal contents of the math span.
504
- // As the contents are not interpreted as Markdown at all,
505
- // they are contained within this structure,
506
- // rather than inserted into a child inline of any kind.
507
- literal,
508
- })
482
+ // The literal contents of the math span.
483
+ // As the contents are not interpreted as Markdown at all,
484
+ // they are contained within this structure,
485
+ // rather than inserted into a child inline of any kind.
486
+ //
487
+ // Whether this is display math (using `$$`)
488
+ let mut math = NodeMath::new(literal, display_math);
489
+ // Whether this is dollar math (`$` or `$$`).
490
+ // `false` indicates it is code math
491
+ math.dollar_math = dollar_math;
492
+
493
+ ComrakNodeValue::Math(math)
509
494
  }
510
495
  "multiline_block_quote" => {
511
496
  let kwargs = scan_args::get_kwargs::<_, (usize, usize), (), ()>(
@@ -516,23 +501,30 @@ impl CommonmarkerNode {
516
501
 
517
502
  let (fence_length, fence_offset) = kwargs.required;
518
503
 
519
- ComrakNodeValue::MultilineBlockQuote(NodeMultilineBlockQuote {
520
- // The length of the fence.
521
- fence_length,
522
- // The indentation level of the fence marker.
523
- fence_offset,
524
- })
504
+ let mut multiline_block_quote = NodeMultilineBlockQuote::default();
505
+ // The length of the fence.
506
+ multiline_block_quote.fence_length = fence_length;
507
+ // The indentation level of the fence marker.
508
+ multiline_block_quote.fence_offset = fence_offset;
509
+
510
+ ComrakNodeValue::MultilineBlockQuote(multiline_block_quote)
525
511
  }
526
512
 
527
513
  "escaped" => ComrakNodeValue::Escaped,
528
514
 
529
515
  "wikilink" => {
530
- let kwargs =
531
- scan_args::get_kwargs::<_, (String,), (), ()>(args.keywords, &["url"], &[])?;
516
+ let kwargs = scan_args::get_kwargs::<_, (String,), (Option<bool>,), ()>(
517
+ args.keywords,
518
+ &["url"],
519
+ &["embed"],
520
+ )?;
532
521
 
533
522
  let (url,) = kwargs.required;
523
+ let (embed,) = kwargs.optional;
534
524
 
535
- ComrakNodeValue::WikiLink(NodeWikiLink { url })
525
+ // The URL for the link destination, and whether this is an
526
+ // embed (`![[embed]]`) rather than a normal link (`[[link]]`).
527
+ ComrakNodeValue::WikiLink(NodeWikiLink::new(url, embed.unwrap_or(false)))
536
528
  }
537
529
 
538
530
  "raw" => {
@@ -576,20 +568,114 @@ impl CommonmarkerNode {
576
568
  }
577
569
  };
578
570
 
579
- ComrakNodeValue::Alert(Box::new(NodeAlert {
580
- alert_type,
581
- // Overridden title. If None, then use the default title.
582
- title,
583
- // Originated from a multiline blockquote.
584
- multiline: multiline.unwrap_or(false),
585
- // The length of the fence (multiline only).
586
- fence_length: fence_length.unwrap_or(0),
587
- // The indentation level of the fence marker (multiline only)
588
- fence_offset: fence_offset.unwrap_or(0),
589
- }))
571
+ // Overridden title. If None, then use the default title.
572
+ let mut alert = NodeAlert::new(alert_type, title);
573
+ // Originated from a multiline blockquote.
574
+ alert.multiline = multiline.unwrap_or(false);
575
+ // The length of the fence (multiline only).
576
+ alert.fence_length = fence_length.unwrap_or(0);
577
+ // The indentation level of the fence marker (multiline only)
578
+ alert.fence_offset = fence_offset.unwrap_or(0);
579
+
580
+ ComrakNodeValue::Alert(Box::new(alert))
581
+ }
582
+
583
+ "math_block" => {
584
+ let kwargs =
585
+ scan_args::get_kwargs::<_, (String,), (Option<usize>, Option<bool>), ()>(
586
+ args.keywords,
587
+ &["literal"],
588
+ &["fence_offset", "closed"],
589
+ )?;
590
+
591
+ let (literal,) = kwargs.required;
592
+ let (fence_offset, closed) = kwargs.optional;
593
+
594
+ // The literal contents of the math block, excluding the `$$` delimiter lines.
595
+ let mut math_block = NodeMathBlock::new(literal);
596
+ // The indentation level of the opening fence marker.
597
+ math_block.fence_offset = fence_offset.unwrap_or(0);
598
+ // Whether the math block was explicitly closed by a closing fence.
599
+ math_block.closed = closed.unwrap_or(true);
600
+
601
+ ComrakNodeValue::MathBlock(Box::new(math_block))
602
+ }
603
+
604
+ "callout" => {
605
+ let kwargs = scan_args::get_kwargs::<
606
+ _,
607
+ (Symbol,),
608
+ (Option<String>, Option<Symbol>),
609
+ (),
610
+ >(args.keywords, &["type"], &["metadata", "fold"])?;
611
+
612
+ let (callout_type,) = kwargs.required;
613
+ let (metadata, fold) = kwargs.optional;
614
+
615
+ // The initial fold state: not foldable, or foldable and initially expanded or collapsed.
616
+ let fold = match fold.map(|fold| fold.to_string()).as_deref() {
617
+ None | Some("none") => CalloutFold::None,
618
+ Some("expanded") => CalloutFold::Expanded,
619
+ Some("collapsed") => CalloutFold::Collapsed,
620
+ Some(_) => {
621
+ return Err(magnus::Error::new(
622
+ ruby.exception_arg_error(),
623
+ "callout fold must be `none`, `expanded`, or `collapsed`",
624
+ ));
625
+ }
626
+ };
627
+
628
+ // The callout type, plus the raw metadata after the `|` separator, if any.
629
+ ComrakNodeValue::Callout(Box::new(NodeCallout::new(
630
+ callout_type.to_string(),
631
+ metadata,
632
+ fold,
633
+ )))
634
+ }
635
+ "callout_title" => ComrakNodeValue::CalloutTitle,
636
+
637
+ "block_id" => {
638
+ let kwargs =
639
+ scan_args::get_kwargs::<_, (String,), (), ()>(args.keywords, &["name"], &[])?;
640
+
641
+ let (name,) = kwargs.required;
642
+
643
+ // The identifier itself, without the leading `^`.
644
+ ComrakNodeValue::BlockId(Box::new(NodeBlockId::new(name)))
590
645
  }
591
646
 
592
- _ => panic!("unknown node type {}", node_type),
647
+ "comment" => {
648
+ let kwargs = scan_args::get_kwargs::<
649
+ _,
650
+ (),
651
+ (Option<String>, Option<bool>, Option<bool>),
652
+ (),
653
+ >(
654
+ args.keywords, &[], &["literal", "multiline", "closed"]
655
+ )?;
656
+
657
+ let (literal, multiline, closed) = kwargs.optional;
658
+
659
+ // The literal contents of the comment, without the `%%` markers.
660
+ let literal = literal.unwrap_or_default();
661
+
662
+ if multiline.unwrap_or(false) {
663
+ let mut comment = NodeCommentBlock::new(literal);
664
+ // Whether the comment block was explicitly closed by a closing `%%`.
665
+ comment.closed = closed.unwrap_or(true);
666
+
667
+ ComrakNodeValue::MultilineComment(comment)
668
+ } else {
669
+ ComrakNodeValue::CommentInline(NodeComment::new(literal))
670
+ }
671
+ }
672
+
673
+ _ => {
674
+ return Err(magnus::Error::new(
675
+ ruby.exception_arg_error(),
676
+ format!("unknown node type {node_type}"),
677
+ ));
678
+ }
593
679
  };
594
680
 
595
681
  Ok(CommonmarkerNode {
@@ -847,6 +933,9 @@ impl CommonmarkerNode {
847
933
  ComrakNodeValue::HtmlInline(html_inline) => Ok(html_inline.to_string()),
848
934
  ComrakNodeValue::Raw(raw) => Ok(raw.to_string()),
849
935
  ComrakNodeValue::Math(math) => Ok(math.literal.to_string()),
936
+ ComrakNodeValue::MathBlock(math_block) => Ok(math_block.literal.to_string()),
937
+ ComrakNodeValue::CommentInline(comment) => Ok(comment.literal.to_string()),
938
+ ComrakNodeValue::MultilineComment(comment) => Ok(comment.literal.to_string()),
850
939
  ComrakNodeValue::FrontMatter(front_matter) => Ok(front_matter.to_string()),
851
940
  _ => Err(magnus::Error::new(
852
941
  ruby.exception_type_error(),
@@ -870,6 +959,9 @@ impl CommonmarkerNode {
870
959
  ComrakNodeValue::HtmlInline(ref mut html_inline) => *html_inline = new_literal,
871
960
  ComrakNodeValue::Raw(ref mut raw) => *raw = new_literal,
872
961
  ComrakNodeValue::Math(ref mut math) => math.literal = new_literal,
962
+ ComrakNodeValue::MathBlock(ref mut math_block) => math_block.literal = new_literal,
963
+ ComrakNodeValue::CommentInline(ref mut comment) => comment.literal = new_literal,
964
+ ComrakNodeValue::MultilineComment(ref mut comment) => comment.literal = new_literal,
873
965
  ComrakNodeValue::FrontMatter(ref mut front_matter) => *front_matter = new_literal,
874
966
  _ => {
875
967
  return Err(magnus::Error::new(
@@ -964,7 +1056,12 @@ impl CommonmarkerNode {
964
1056
  match new_type.to_string().as_str() {
965
1057
  "bullet" => list.list_type = comrak::nodes::ListType::Bullet,
966
1058
  "ordered" => list.list_type = comrak::nodes::ListType::Ordered,
967
- _ => return Ok(false),
1059
+ _ => {
1060
+ return Err(magnus::Error::new(
1061
+ ruby.exception_arg_error(),
1062
+ "list type must be `bullet` or `ordered`",
1063
+ ));
1064
+ }
968
1065
  }
969
1066
  Ok(true)
970
1067
  }
@@ -1091,6 +1188,112 @@ impl CommonmarkerNode {
1091
1188
  }
1092
1189
  }
1093
1190
 
1191
+ /// The node's parsed attributes (`{#id .class key=value}`), as a Hash of
1192
+ /// `id`, `classes` and `pairs`, or `nil` when the node has none.
1193
+ fn get_attributes(ruby: &Ruby, rb_self: &Self) -> Result<Option<RHash>, magnus::Error> {
1194
+ let node = rb_self.inner.borrow();
1195
+
1196
+ let Some(attrs) = &node.data.attrs else {
1197
+ return Ok(None);
1198
+ };
1199
+
1200
+ let pairs = ruby.hash_new();
1201
+ for (key, value) in &attrs.pairs {
1202
+ pairs.aset(key.as_str(), value.as_str())?;
1203
+ }
1204
+
1205
+ let result = ruby.hash_new();
1206
+ result.aset(ruby.to_symbol("id"), attrs.id.as_deref())?;
1207
+ result.aset(ruby.to_symbol("classes"), attrs.classes.clone())?;
1208
+ result.aset(ruby.to_symbol("pairs"), pairs)?;
1209
+
1210
+ Ok(Some(result))
1211
+ }
1212
+
1213
+ /// Replaces the node's attributes. Accepts `nil` to clear them, or a Hash
1214
+ /// with any of `id` (String), `classes` (Array) and `pairs` (Hash). Strings
1215
+ /// and Symbols are both accepted for names and values.
1216
+ fn set_attributes(ruby: &Ruby, rb_self: &Self, value: Value) -> Result<bool, magnus::Error> {
1217
+ fn as_string(ruby: &Ruby, value: Value, what: &str) -> Result<String, magnus::Error> {
1218
+ if let Some(symbol) = Symbol::from_value(value) {
1219
+ return Ok(symbol.name()?.into_owned());
1220
+ }
1221
+ String::try_convert(value).map_err(|_| {
1222
+ magnus::Error::new(
1223
+ ruby.exception_type_error(),
1224
+ format!(
1225
+ "{} must be a String or Symbol; got {}",
1226
+ what,
1227
+ crate::utils::get_classname(value)
1228
+ ),
1229
+ )
1230
+ })
1231
+ }
1232
+
1233
+ let mut node = rb_self.inner.borrow_mut();
1234
+
1235
+ if value.is_nil() {
1236
+ node.data.attrs = None;
1237
+ return Ok(true);
1238
+ }
1239
+
1240
+ let hash: RHash = TryConvert::try_convert(value).map_err(|_| {
1241
+ magnus::Error::new(
1242
+ ruby.exception_type_error(),
1243
+ format!(
1244
+ "attributes must be a Hash or nil; got {}",
1245
+ crate::utils::get_classname(value)
1246
+ ),
1247
+ )
1248
+ })?;
1249
+
1250
+ let mut attrs = comrak::nodes::Attributes::default();
1251
+
1252
+ if let Some(id) = hash.get(ruby.to_symbol("id")).filter(|id| !id.is_nil()) {
1253
+ attrs.id = Some(as_string(ruby, id, "attribute id")?);
1254
+ }
1255
+
1256
+ if let Some(classes) = hash.get(ruby.to_symbol("classes")).filter(|c| !c.is_nil()) {
1257
+ let classes: RArray = TryConvert::try_convert(classes).map_err(|_| {
1258
+ magnus::Error::new(
1259
+ ruby.exception_type_error(),
1260
+ format!(
1261
+ "attribute classes must be an Array; got {}",
1262
+ crate::utils::get_classname(classes)
1263
+ ),
1264
+ )
1265
+ })?;
1266
+ for class in classes.into_iter() {
1267
+ attrs
1268
+ .classes
1269
+ .push(as_string(ruby, class, "attribute class")?);
1270
+ }
1271
+ }
1272
+
1273
+ if let Some(pairs) = hash.get(ruby.to_symbol("pairs")).filter(|p| !p.is_nil()) {
1274
+ let pairs: RHash = TryConvert::try_convert(pairs).map_err(|_| {
1275
+ magnus::Error::new(
1276
+ ruby.exception_type_error(),
1277
+ format!(
1278
+ "attribute pairs must be a Hash; got {}",
1279
+ crate::utils::get_classname(pairs)
1280
+ ),
1281
+ )
1282
+ })?;
1283
+ pairs.foreach(|key: Value, value: Value| {
1284
+ attrs.pairs.push((
1285
+ as_string(ruby, key, "attribute name")?,
1286
+ as_string(ruby, value, "attribute value")?,
1287
+ ));
1288
+ Ok(ForEach::Continue)
1289
+ })?;
1290
+ }
1291
+
1292
+ node.data.attrs = Some(Box::new(attrs));
1293
+
1294
+ Ok(true)
1295
+ }
1296
+
1094
1297
  fn get_alert_type(ruby: &Ruby, rb_self: &Self) -> Result<Symbol, magnus::Error> {
1095
1298
  let node = rb_self.inner.borrow();
1096
1299
 
@@ -1101,6 +1304,10 @@ impl CommonmarkerNode {
1101
1304
  AlertType::Important => Ok(ruby.to_symbol("important")),
1102
1305
  AlertType::Warning => Ok(ruby.to_symbol("warning")),
1103
1306
  AlertType::Caution => Ok(ruby.to_symbol("caution")),
1307
+ _ => Err(magnus::Error::new(
1308
+ ruby.exception_type_error(),
1309
+ "node has an unknown alert type",
1310
+ )),
1104
1311
  },
1105
1312
  _ => Err(magnus::Error::new(
1106
1313
  ruby.exception_type_error(),
@@ -1124,7 +1331,12 @@ impl CommonmarkerNode {
1124
1331
  "important" => alert.alert_type = AlertType::Important,
1125
1332
  "warning" => alert.alert_type = AlertType::Warning,
1126
1333
  "caution" => alert.alert_type = AlertType::Caution,
1127
- _ => return Ok(false),
1334
+ _ => {
1335
+ return Err(magnus::Error::new(
1336
+ ruby.exception_arg_error(),
1337
+ "alert type must be `note`, `tip`, `important`, `warning`, or `caution`",
1338
+ ));
1339
+ }
1128
1340
  }
1129
1341
  Ok(true)
1130
1342
  }
@@ -1135,6 +1347,37 @@ impl CommonmarkerNode {
1135
1347
  }
1136
1348
  }
1137
1349
 
1350
+ fn get_callout_type(ruby: &Ruby, rb_self: &Self) -> Result<Symbol, magnus::Error> {
1351
+ let node = rb_self.inner.borrow();
1352
+
1353
+ match &node.data.value {
1354
+ ComrakNodeValue::Callout(callout) => Ok(ruby.to_symbol(callout.callout_type.as_str())),
1355
+ _ => Err(magnus::Error::new(
1356
+ ruby.exception_type_error(),
1357
+ "node is not a callout node",
1358
+ )),
1359
+ }
1360
+ }
1361
+
1362
+ fn set_callout_type(
1363
+ ruby: &Ruby,
1364
+ rb_self: &Self,
1365
+ new_type: Symbol,
1366
+ ) -> Result<bool, magnus::Error> {
1367
+ let mut node = rb_self.inner.borrow_mut();
1368
+
1369
+ match node.data.value {
1370
+ ComrakNodeValue::Callout(ref mut callout) => {
1371
+ callout.callout_type = new_type.to_string();
1372
+ Ok(true)
1373
+ }
1374
+ _ => Err(magnus::Error::new(
1375
+ ruby.exception_type_error(),
1376
+ "node is not a callout node",
1377
+ )),
1378
+ }
1379
+ }
1380
+
1138
1381
  /// Copies this node and its descendants into `arena` as a comrak tree so that
1139
1382
  /// comrak's formatters can render it.
1140
1383
  ///
@@ -1168,153 +1411,96 @@ impl CommonmarkerNode {
1168
1411
  comrak_root_node
1169
1412
  }
1170
1413
 
1171
- fn to_html(ruby: &Ruby, rb_self: &Self, args: &[Value]) -> Result<String, magnus::Error> {
1414
+ /// Reads the `options:` and `plugins:` keyword arguments shared by
1415
+ /// `to_html` and `to_commonmark`.
1416
+ fn render_args(
1417
+ ruby: &Ruby,
1418
+ args: &[Value],
1419
+ ) -> Result<(Options, Option<Arc<SyntectAdapter>>), magnus::Error> {
1172
1420
  let args = scan_args::scan_args::<(), (), (), (), _, ()>(args)?;
1173
1421
 
1174
- let kwargs = scan_args::get_kwargs::<
1175
- _,
1176
- (),
1177
- (Option<RHash>, Option<RHash>, Option<RHash>, Option<RHash>),
1178
- (),
1179
- >(
1422
+ let kwargs = scan_args::get_kwargs::<_, (), (Option<Value>, Option<Value>), ()>(
1180
1423
  args.keywords,
1181
1424
  &[],
1182
- &["parse", "render", "extension", "plugins"],
1425
+ &["options", "plugins"],
1183
1426
  )?;
1184
- let (rb_parse, rb_render, rb_extension, rb_plugins) = kwargs.optional;
1427
+ let (rb_options, rb_plugins) = kwargs.optional;
1185
1428
 
1186
- let mut comrak_parse_options = comrak::options::Parse::default();
1187
- let mut comrak_render_options = comrak::options::Render::default();
1188
- let mut comrak_extension_options = comrak::options::Extension::default();
1429
+ let options = format_options(ruby, rb_options)?;
1430
+ let formatted_plugins = format_plugins(ruby, rb_plugins)?;
1431
+ let syntect_adapter = construct_syntax_highlighter_from_plugin(ruby, formatted_plugins)?;
1189
1432
 
1190
- if let Some(rb_parse) = rb_parse {
1191
- iterate_parse_options(&mut comrak_parse_options, rb_parse);
1192
- }
1193
- if let Some(rb_render) = rb_render {
1194
- iterate_render_options(&mut comrak_render_options, rb_render);
1195
- }
1196
- if let Some(rb_extension) = rb_extension {
1197
- iterate_extension_options(&mut comrak_extension_options, rb_extension);
1198
- }
1433
+ Ok((options, syntect_adapter))
1434
+ }
1199
1435
 
1200
- let comrak_options = comrak::Options {
1201
- parse: comrak_parse_options,
1202
- render: comrak_render_options,
1203
- extension: comrak_extension_options,
1204
- };
1436
+ /// Renders this node and its descendants as HTML.
1437
+ pub fn render_html(
1438
+ &self,
1439
+ ruby: &Ruby,
1440
+ options: &Options,
1441
+ plugins: &comrak::options::Plugins,
1442
+ ) -> Result<String, magnus::Error> {
1443
+ let arena: Arena<ComrakAstNode> = Arena::new();
1444
+ let comrak_root_node = self.to_comrak_node(&arena);
1205
1445
 
1206
- let mut comrak_plugins = comrak::options::Plugins::default();
1446
+ crate::nesting::check(ruby, comrak_root_node, options.max_nesting_depth)?;
1207
1447
 
1208
- let syntect_adapter = match construct_syntax_highlighter_from_plugin(ruby, rb_plugins) {
1209
- Ok(Some(adapter)) => Some(adapter),
1210
- Ok(None) => None,
1211
- Err(err) => return Err(err),
1212
- };
1448
+ let mut output = String::new();
1449
+ comrak::format_html_with_plugins(comrak_root_node, &options.comrak, &mut output, plugins)
1450
+ .map_err(|e| {
1451
+ magnus::Error::new(
1452
+ ruby.exception_runtime_error(),
1453
+ format!("cannot convert into html: {e}"),
1454
+ )
1455
+ })?;
1213
1456
 
1214
- match syntect_adapter {
1215
- Some(ref adapter) => {
1216
- comrak_plugins.render.codefence_syntax_highlighter = Some(adapter.as_ref())
1217
- }
1218
- None => comrak_plugins.render.codefence_syntax_highlighter = None,
1219
- }
1457
+ Ok(output)
1458
+ }
1220
1459
 
1460
+ /// Renders this node and its descendants as CommonMark.
1461
+ pub fn render_commonmark(
1462
+ &self,
1463
+ ruby: &Ruby,
1464
+ options: &Options,
1465
+ plugins: &comrak::options::Plugins,
1466
+ ) -> Result<String, magnus::Error> {
1221
1467
  let arena: Arena<ComrakAstNode> = Arena::new();
1222
- let comrak_root_node = rb_self.to_comrak_node(&arena);
1468
+ let comrak_root_node = self.to_comrak_node(&arena);
1469
+
1470
+ crate::nesting::check(ruby, comrak_root_node, options.max_nesting_depth)?;
1223
1471
 
1224
1472
  let mut output = String::new();
1225
- match comrak::format_html_with_plugins(
1473
+ comrak::format_commonmark_with_plugins(
1226
1474
  comrak_root_node,
1227
- &comrak_options,
1475
+ &options.comrak,
1228
1476
  &mut output,
1229
- &comrak_plugins,
1230
- ) {
1231
- Ok(_) => {}
1232
- Err(e) => {
1233
- return Err(magnus::Error::new(
1234
- ruby.exception_runtime_error(),
1235
- format!("cannot convert into html: {}", e),
1236
- ));
1237
- }
1238
- }
1477
+ plugins,
1478
+ )
1479
+ .map_err(|e| {
1480
+ magnus::Error::new(
1481
+ ruby.exception_runtime_error(),
1482
+ format!("cannot convert into commonmark: {e}"),
1483
+ )
1484
+ })?;
1239
1485
 
1240
1486
  Ok(output)
1241
1487
  }
1242
1488
 
1243
- fn to_commonmark(ruby: &Ruby, rb_self: &Self, args: &[Value]) -> Result<String, magnus::Error> {
1244
- let args = scan_args::scan_args::<(), (), (), (), _, ()>(args)?;
1245
-
1246
- let kwargs = scan_args::get_kwargs::<
1247
- _,
1248
- (),
1249
- (Option<RHash>, Option<RHash>, Option<RHash>, Option<RHash>),
1250
- (),
1251
- >(
1252
- args.keywords,
1253
- &[],
1254
- &["render", "parse", "extension", "plugins"],
1255
- )?;
1256
- let (rb_render, rb_parse, rb_extension, rb_plugins) = kwargs.optional;
1257
-
1258
- let mut comrak_parse_options = comrak::options::Parse::default();
1259
- let mut comrak_render_options = comrak::options::Render::default();
1260
- let mut comrak_extension_options = comrak::options::Extension::default();
1261
-
1262
- if let Some(rb_parse) = rb_parse {
1263
- iterate_parse_options(&mut comrak_parse_options, rb_parse);
1264
- }
1265
- if let Some(rb_render) = rb_render {
1266
- iterate_render_options(&mut comrak_render_options, rb_render);
1267
- }
1268
- if let Some(rb_extension) = rb_extension {
1269
- iterate_extension_options(&mut comrak_extension_options, rb_extension);
1270
- }
1271
-
1272
- let comrak_options = comrak::Options {
1273
- parse: comrak_parse_options,
1274
- render: comrak_render_options,
1275
- extension: comrak_extension_options,
1276
- };
1277
-
1278
- let mut comrak_plugins = comrak::options::Plugins::default();
1279
-
1280
- let syntect_adapter = match construct_syntax_highlighter_from_plugin(ruby, rb_plugins) {
1281
- Ok(Some(adapter)) => Some(adapter),
1282
- Ok(None) => None,
1283
- Err(err) => return Err(err),
1284
- };
1285
-
1286
- match syntect_adapter {
1287
- Some(ref adapter) => {
1288
- comrak_plugins.render.codefence_syntax_highlighter = Some(adapter.as_ref())
1289
- }
1290
- None => comrak_plugins.render.codefence_syntax_highlighter = None,
1291
- }
1489
+ fn to_html(ruby: &Ruby, rb_self: &Self, args: &[Value]) -> Result<String, magnus::Error> {
1490
+ let (options, syntect_adapter) = Self::render_args(ruby, args)?;
1292
1491
 
1293
- let arena: Arena<ComrakAstNode> = Arena::new();
1294
- let comrak_root_node = rb_self.to_comrak_node(&arena);
1492
+ rb_self.render_html(ruby, &options, &comrak_plugins(syntect_adapter.as_deref()))
1493
+ }
1295
1494
 
1296
- let mut output = String::new();
1297
- match comrak::format_commonmark_with_plugins(
1298
- comrak_root_node,
1299
- &comrak_options,
1300
- &mut output,
1301
- &comrak_plugins,
1302
- ) {
1303
- Ok(_) => {}
1304
- Err(e) => {
1305
- return Err(magnus::Error::new(
1306
- ruby.exception_runtime_error(),
1307
- format!("cannot convert into commonmark: {}", e),
1308
- ));
1309
- }
1310
- }
1495
+ fn to_commonmark(ruby: &Ruby, rb_self: &Self, args: &[Value]) -> Result<String, magnus::Error> {
1496
+ let (options, syntect_adapter) = Self::render_args(ruby, args)?;
1311
1497
 
1312
- Ok(output)
1498
+ rb_self.render_commonmark(ruby, &options, &comrak_plugins(syntect_adapter.as_deref()))
1313
1499
  }
1314
1500
  }
1315
1501
 
1316
- pub fn init(ruby: &Ruby, m_commonmarker: RModule) -> Result<(), magnus::Error> {
1317
- let c_node = m_commonmarker
1502
+ pub fn init(ruby: &Ruby, c_commonmarker: RClass) -> Result<(), magnus::Error> {
1503
+ let c_node = c_commonmarker
1318
1504
  .define_class("Node", ruby.class_object())
1319
1505
  .expect("cannot define class Commonmarker::Node");
1320
1506
 
@@ -1406,8 +1592,18 @@ pub fn init(ruby: &Ruby, m_commonmarker: RModule) -> Result<(), magnus::Error> {
1406
1592
  c_node.define_method("fenced=", method!(CommonmarkerNode::set_fenced, 1))?;
1407
1593
  c_node.define_method("fence_info", method!(CommonmarkerNode::get_fence_info, 0))?;
1408
1594
  c_node.define_method("fence_info=", method!(CommonmarkerNode::set_fence_info, 1))?;
1595
+ c_node.define_method("attributes", method!(CommonmarkerNode::get_attributes, 0))?;
1596
+ c_node.define_method("attributes=", method!(CommonmarkerNode::set_attributes, 1))?;
1409
1597
  c_node.define_method("alert_type", method!(CommonmarkerNode::get_alert_type, 0))?;
1410
1598
  c_node.define_method("alert_type=", method!(CommonmarkerNode::set_alert_type, 1))?;
1599
+ c_node.define_method(
1600
+ "callout_type",
1601
+ method!(CommonmarkerNode::get_callout_type, 0),
1602
+ )?;
1603
+ c_node.define_method(
1604
+ "callout_type=",
1605
+ method!(CommonmarkerNode::set_callout_type, 1),
1606
+ )?;
1411
1607
 
1412
1608
  Ok(())
1413
1609
  }