commonmarker 2.5.0 → 2.6.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.
@@ -5,15 +5,14 @@ use comrak::nodes::{
5
5
  NodeHeading, NodeHtmlBlock, NodeLink, NodeList, NodeMath, NodeMultilineBlockQuote,
6
6
  NodeShortCode, NodeTable, NodeValue as ComrakNodeValue, NodeWikiLink, TableAlignment,
7
7
  };
8
- use magnus::RArray;
9
8
  use magnus::{function, method, scan_args, Module, Object, RHash, RModule, Symbol, Value};
9
+ use magnus::{RArray, Ruby};
10
10
  use rctree::Node;
11
11
  use typed_arena::Arena;
12
12
 
13
13
  use std::cell::RefCell;
14
14
 
15
- use crate::format_options;
16
-
15
+ use crate::options::{iterate_extension_options, iterate_parse_options, iterate_render_options};
17
16
  use crate::plugins::syntax_highlighting::construct_syntax_highlighter_from_plugin;
18
17
 
19
18
  #[derive(Debug, Clone)]
@@ -32,8 +31,7 @@ pub struct CommonmarkerNode {
32
31
  unsafe impl Send for CommonmarkerNode {}
33
32
 
34
33
  impl CommonmarkerNode {
35
- pub fn new(args: &[Value]) -> Result<Self, magnus::Error> {
36
- let ruby = magnus::Ruby::get().unwrap();
34
+ pub fn new(ruby: &Ruby, args: &[Value]) -> Result<Self, magnus::Error> {
37
35
  let args = scan_args::scan_args::<_, (), (), (), _, ()>(args)?;
38
36
  let (node_type,): (Symbol,) = args.required;
39
37
 
@@ -162,6 +160,7 @@ impl CommonmarkerNode {
162
160
  Option<usize>,
163
161
  Option<String>,
164
162
  Option<String>,
163
+ Option<bool>,
165
164
  ),
166
165
  (),
167
166
  >(
@@ -173,12 +172,14 @@ impl CommonmarkerNode {
173
172
  "fence_offset",
174
173
  "info",
175
174
  "literal",
175
+ "closed",
176
176
  ],
177
177
  )?;
178
178
  let (fenced,) = kwargs.required;
179
- let (fence_char, fence_length, fence_offset, info, literal) = kwargs.optional;
179
+ let (fence_char, fence_length, fence_offset, info, literal, closed) =
180
+ kwargs.optional;
180
181
 
181
- ComrakNodeValue::CodeBlock(NodeCodeBlock {
182
+ ComrakNodeValue::CodeBlock(Box::new(NodeCodeBlock {
182
183
  // Whether the code block is fenced.
183
184
  fenced,
184
185
  // For fenced code blocks, the fence character itself (`` ` `` or `~`).
@@ -196,7 +197,12 @@ impl CommonmarkerNode {
196
197
  // all, they are contained within this structure, rather than inserted into a child inline of
197
198
  // any kind.
198
199
  literal: literal.unwrap_or(String::new()),
199
- })
200
+
201
+ // For fenced code blocks, whether the code block is closed. (If not, it was terminated by
202
+ // some other condition, like the end of the document, or the end of the indentation level the
203
+ // code block was introduced at.)
204
+ closed: closed.unwrap_or(true),
205
+ }))
200
206
  }
201
207
  "html_block" => {
202
208
  let kwargs = scan_args::get_kwargs::<_, (), (Option<u8>, Option<String>), ()>(
@@ -216,20 +222,24 @@ impl CommonmarkerNode {
216
222
  }
217
223
  "paragraph" => ComrakNodeValue::Paragraph,
218
224
  "heading" => {
219
- let kwargs = scan_args::get_kwargs::<_, (u8,), (Option<bool>,), ()>(
225
+ let kwargs = scan_args::get_kwargs::<_, (u8,), (Option<bool>, Option<bool>), ()>(
220
226
  args.keywords,
221
227
  &["level"],
222
- &["setext"],
228
+ &["setext", "closed"],
223
229
  )?;
224
230
 
225
231
  let (level,) = kwargs.required;
226
- let (setext,) = kwargs.optional;
232
+ let (setext, closed) = kwargs.optional;
227
233
 
228
234
  ComrakNodeValue::Heading(NodeHeading {
229
- // Number of spaces before the list marker.
235
+ // The heading level. For setext headings, an underline made of "=" characters is level 1, and made of
236
+ // "-" is level 2. For ATX headings, the number of leading "#" characters (from 1 to 6) is its level.
230
237
  level,
231
- // Number of characters between the start of the list marker and the item text (including the list marker(s)).
238
+ // Whether the heading is setext style (marked by an underline). If not, it is ATX style (marked by leading,
239
+ // and possibly trailing, "#" characters).
232
240
  setext: setext.unwrap_or(false),
241
+ // For ATX headings, whether the the leading "#" are terminated by a sequence of closing "#" characters.
242
+ closed: closed.unwrap_or(false),
233
243
  })
234
244
  }
235
245
  "thematic_break" => ComrakNodeValue::ThematicBreak,
@@ -264,7 +274,7 @@ impl CommonmarkerNode {
264
274
  comrak_alignments.push(TableAlignment::None);
265
275
  }
266
276
  });
267
- ComrakNodeValue::Table(NodeTable {
277
+ ComrakNodeValue::Table(Box::new(NodeTable {
268
278
  // The table alignments
269
279
  alignments: comrak_alignments,
270
280
 
@@ -276,7 +286,7 @@ impl CommonmarkerNode {
276
286
 
277
287
  // Number of non-empty, non-autocompleted cells
278
288
  num_nonempty_cells,
279
- })
289
+ }))
280
290
  }
281
291
  "table_row" => {
282
292
  let kwargs =
@@ -296,7 +306,7 @@ impl CommonmarkerNode {
296
306
 
297
307
  let (content,) = kwargs.optional;
298
308
 
299
- ComrakNodeValue::Text(content.unwrap_or("".to_string()))
309
+ ComrakNodeValue::Text(content.unwrap_or_default().into())
300
310
  }
301
311
  "taskitem" => {
302
312
  let kwargs = scan_args::get_kwargs::<_, (), (Option<char>,), ()>(
@@ -356,7 +366,7 @@ impl CommonmarkerNode {
356
366
  let (url,) = kwargs.required;
357
367
  let (title,) = kwargs.optional;
358
368
 
359
- ComrakNodeValue::Link(NodeLink {
369
+ ComrakNodeValue::Link(Box::new(NodeLink {
360
370
  // The URL for the link destination or image source.
361
371
  url,
362
372
  // The title for the link or image.
@@ -364,7 +374,7 @@ impl CommonmarkerNode {
364
374
  // Note this field is used for the `title` attribute by the HTML formatter even for images;
365
375
  // `alt` text is supplied in the image inline text.
366
376
  title: title.unwrap_or_default(),
367
- })
377
+ }))
368
378
  }
369
379
  "image" => {
370
380
  let kwargs = scan_args::get_kwargs::<_, (String,), (Option<String>,), ()>(
@@ -376,7 +386,7 @@ impl CommonmarkerNode {
376
386
  let (url,) = kwargs.required;
377
387
  let (title,) = kwargs.optional;
378
388
 
379
- ComrakNodeValue::Image(NodeLink {
389
+ ComrakNodeValue::Image(Box::new(NodeLink {
380
390
  // The URL for the link destination or image source.
381
391
  url,
382
392
  // The title for the link or image.
@@ -384,7 +394,7 @@ impl CommonmarkerNode {
384
394
  // Note this field is used for the `title` attribute by the HTML formatter even for images;
385
395
  // `alt` text is supplied in the image inline text.
386
396
  title: title.unwrap_or_default(),
387
- })
397
+ }))
388
398
  }
389
399
  "footnote_reference" => {
390
400
  let kwargs = scan_args::get_kwargs::<_, (String,), (Option<u32>, Option<u32>), ()>(
@@ -396,14 +406,16 @@ impl CommonmarkerNode {
396
406
  let (name,) = kwargs.required;
397
407
  let (ref_num, ix) = kwargs.optional;
398
408
 
399
- ComrakNodeValue::FootnoteReference(NodeFootnoteReference {
409
+ ComrakNodeValue::FootnoteReference(Box::new(NodeFootnoteReference {
400
410
  // The name of the footnote.
401
411
  name,
412
+ // The original text and sourcepos column spans that comprised the footnote ref.
413
+ texts: vec![],
402
414
  // The index of reference to the same footnote
403
415
  ref_num: ref_num.unwrap_or(0),
404
416
  // The index of the footnote in the document.
405
417
  ix: ix.unwrap_or(0),
406
- })
418
+ }))
407
419
  }
408
420
  // #[cfg(feature = "shortcodes")]
409
421
  "shortcode" => {
@@ -413,7 +425,7 @@ impl CommonmarkerNode {
413
425
  let (code,) = kwargs.required;
414
426
 
415
427
  match NodeShortCode::resolve(code.as_str()) {
416
- Some(shortcode) => ComrakNodeValue::ShortCode(shortcode),
428
+ Some(shortcode) => ComrakNodeValue::ShortCode(Box::new(shortcode)),
417
429
  None => {
418
430
  return Err(magnus::Error::new(
419
431
  ruby.exception_arg_error(),
@@ -514,7 +526,7 @@ impl CommonmarkerNode {
514
526
  }
515
527
  };
516
528
 
517
- ComrakNodeValue::Alert(NodeAlert {
529
+ ComrakNodeValue::Alert(Box::new(NodeAlert {
518
530
  alert_type,
519
531
  // Overridden title. If None, then use the default title.
520
532
  title,
@@ -524,7 +536,7 @@ impl CommonmarkerNode {
524
536
  fence_length: fence_length.unwrap_or(0),
525
537
  // The indentation level of the fence marker (multiline only)
526
538
  fence_offset: fence_offset.unwrap_or(0),
527
- })
539
+ }))
528
540
  }
529
541
 
530
542
  _ => panic!("unknown node type {}", node_type),
@@ -575,53 +587,9 @@ impl CommonmarkerNode {
575
587
  Ok(commonmarker_root_node)
576
588
  }
577
589
 
578
- fn type_to_symbol(&self) -> Symbol {
579
- let node = self.inner.borrow();
580
- let ruby = magnus::Ruby::get().unwrap();
581
- match node.data.value {
582
- ComrakNodeValue::Document => ruby.to_symbol("document"),
583
- ComrakNodeValue::BlockQuote => ruby.to_symbol("block_quote"),
584
- ComrakNodeValue::FootnoteDefinition(_) => ruby.to_symbol("footnote_definition"),
585
- ComrakNodeValue::List(..) => ruby.to_symbol("list"),
586
- ComrakNodeValue::DescriptionList => ruby.to_symbol("description_list"),
587
- ComrakNodeValue::DescriptionItem(_) => ruby.to_symbol("description_item"),
588
- ComrakNodeValue::DescriptionTerm => ruby.to_symbol("description_term"),
589
- ComrakNodeValue::DescriptionDetails => ruby.to_symbol("description_details"),
590
- ComrakNodeValue::Item(..) => ruby.to_symbol("item"),
591
- ComrakNodeValue::CodeBlock(..) => ruby.to_symbol("code_block"),
592
- ComrakNodeValue::HtmlBlock(..) => ruby.to_symbol("html_block"),
593
- ComrakNodeValue::Paragraph => ruby.to_symbol("paragraph"),
594
- ComrakNodeValue::Heading(..) => ruby.to_symbol("heading"),
595
- ComrakNodeValue::ThematicBreak => ruby.to_symbol("thematic_break"),
596
- ComrakNodeValue::Table(..) => ruby.to_symbol("table"),
597
- ComrakNodeValue::TableRow(..) => ruby.to_symbol("table_row"),
598
- ComrakNodeValue::TableCell => ruby.to_symbol("table_cell"),
599
- ComrakNodeValue::Text(..) => ruby.to_symbol("text"),
600
- ComrakNodeValue::SoftBreak => ruby.to_symbol("softbreak"),
601
- ComrakNodeValue::LineBreak => ruby.to_symbol("linebreak"),
602
- ComrakNodeValue::Image(..) => ruby.to_symbol("image"),
603
- ComrakNodeValue::Link(..) => ruby.to_symbol("link"),
604
- ComrakNodeValue::Emph => ruby.to_symbol("emph"),
605
- ComrakNodeValue::Raw(..) => ruby.to_symbol("raw"),
606
- ComrakNodeValue::Strong => ruby.to_symbol("strong"),
607
- ComrakNodeValue::Code(..) => ruby.to_symbol("code"),
608
- ComrakNodeValue::HtmlInline(..) => ruby.to_symbol("html_inline"),
609
- ComrakNodeValue::Strikethrough => ruby.to_symbol("strikethrough"),
610
- ComrakNodeValue::FrontMatter(_) => ruby.to_symbol("frontmatter"),
611
- ComrakNodeValue::TaskItem { .. } => ruby.to_symbol("taskitem"),
612
- ComrakNodeValue::Superscript => ruby.to_symbol("superscript"),
613
- ComrakNodeValue::FootnoteReference(..) => ruby.to_symbol("footnote_reference"),
614
- ComrakNodeValue::ShortCode(_) => ruby.to_symbol("shortcode"),
615
- ComrakNodeValue::MultilineBlockQuote(_) => ruby.to_symbol("multiline_block_quote"),
616
- ComrakNodeValue::Escaped => ruby.to_symbol("escaped"),
617
- ComrakNodeValue::Math(..) => ruby.to_symbol("math"),
618
- ComrakNodeValue::WikiLink(..) => ruby.to_symbol("wikilink"),
619
- ComrakNodeValue::Underline => ruby.to_symbol("underline"),
620
- ComrakNodeValue::Subscript => ruby.to_symbol("subscript"),
621
- ComrakNodeValue::SpoileredText => ruby.to_symbol("spoilered_text"),
622
- ComrakNodeValue::EscapedTag(_) => ruby.to_symbol("escaped_tag"),
623
- ComrakNodeValue::Alert(..) => ruby.to_symbol("alert"),
624
- }
590
+ fn type_to_symbol(ruby: &Ruby, rb_self: &Self) -> Symbol {
591
+ let node = rb_self.inner.borrow();
592
+ ruby.to_symbol(node.data.value.xml_node_name())
625
593
  }
626
594
 
627
595
  fn get_parent(&self) -> Option<CommonmarkerNode> {
@@ -677,10 +645,9 @@ impl CommonmarkerNode {
677
645
  })
678
646
  }
679
647
 
680
- fn get_sourcepos(&self) -> Result<RHash, magnus::Error> {
681
- let node = self.inner.borrow();
648
+ fn get_sourcepos(ruby: &Ruby, rb_self: &Self) -> Result<RHash, magnus::Error> {
649
+ let node = rb_self.inner.borrow();
682
650
 
683
- let ruby = magnus::Ruby::get().unwrap();
684
651
  let result = ruby.hash_new();
685
652
  result.aset(ruby.to_symbol("start_line"), node.data.sourcepos.start.line)?;
686
653
  result.aset(
@@ -717,9 +684,8 @@ impl CommonmarkerNode {
717
684
  Ok(true)
718
685
  }
719
686
 
720
- fn get_url(&self) -> Result<String, magnus::Error> {
721
- let ruby = magnus::Ruby::get().unwrap();
722
- let node = self.inner.borrow();
687
+ fn get_url(ruby: &Ruby, rb_self: &Self) -> Result<String, magnus::Error> {
688
+ let node = rb_self.inner.borrow();
723
689
 
724
690
  match &node.data.value {
725
691
  ComrakNodeValue::Link(link) => Ok(link.url.to_string()),
@@ -731,9 +697,8 @@ impl CommonmarkerNode {
731
697
  }
732
698
  }
733
699
 
734
- fn set_url(&self, new_url: String) -> Result<bool, magnus::Error> {
735
- let ruby = magnus::Ruby::get().unwrap();
736
- let mut node = self.inner.borrow_mut();
700
+ fn set_url(ruby: &Ruby, rb_self: &Self, new_url: String) -> Result<bool, magnus::Error> {
701
+ let mut node = rb_self.inner.borrow_mut();
737
702
 
738
703
  match node.data.value {
739
704
  ComrakNodeValue::Link(ref mut link) => {
@@ -751,9 +716,8 @@ impl CommonmarkerNode {
751
716
  }
752
717
  }
753
718
 
754
- fn get_string_content(&self) -> Result<String, magnus::Error> {
755
- let ruby = magnus::Ruby::get().unwrap();
756
- let node = self.inner.borrow();
719
+ fn get_string_content(ruby: &Ruby, rb_self: &Self) -> Result<String, magnus::Error> {
720
+ let node = rb_self.inner.borrow();
757
721
 
758
722
  match node.data.value {
759
723
  ComrakNodeValue::Code(ref code) => return Ok(code.literal.to_string()),
@@ -772,9 +736,12 @@ impl CommonmarkerNode {
772
736
  }
773
737
  }
774
738
 
775
- fn set_string_content(&self, new_content: String) -> Result<bool, magnus::Error> {
776
- let ruby = magnus::Ruby::get().unwrap();
777
- let mut node = self.inner.borrow_mut();
739
+ fn set_string_content(
740
+ ruby: &Ruby,
741
+ rb_self: &Self,
742
+ new_content: String,
743
+ ) -> Result<bool, magnus::Error> {
744
+ let mut node = rb_self.inner.borrow_mut();
778
745
 
779
746
  match node.data.value {
780
747
  ComrakNodeValue::Code(ref mut code) => {
@@ -790,7 +757,7 @@ impl CommonmarkerNode {
790
757
 
791
758
  match node.data.value.text_mut() {
792
759
  Some(s) => {
793
- *s = new_content;
760
+ *s = new_content.into();
794
761
  Ok(true)
795
762
  }
796
763
  None => Err(magnus::Error::new(
@@ -800,9 +767,8 @@ impl CommonmarkerNode {
800
767
  }
801
768
  }
802
769
 
803
- fn get_title(&self) -> Result<String, magnus::Error> {
804
- let ruby = magnus::Ruby::get().unwrap();
805
- let node = self.inner.borrow();
770
+ fn get_title(ruby: &Ruby, rb_self: &Self) -> Result<String, magnus::Error> {
771
+ let node = rb_self.inner.borrow();
806
772
 
807
773
  match &node.data.value {
808
774
  ComrakNodeValue::Link(link) => Ok(link.title.to_string()),
@@ -814,9 +780,8 @@ impl CommonmarkerNode {
814
780
  }
815
781
  }
816
782
 
817
- fn set_title(&self, new_title: String) -> Result<bool, magnus::Error> {
818
- let ruby = magnus::Ruby::get().unwrap();
819
- let mut node = self.inner.borrow_mut();
783
+ fn set_title(ruby: &Ruby, rb_self: &Self, new_title: String) -> Result<bool, magnus::Error> {
784
+ let mut node = rb_self.inner.borrow_mut();
820
785
 
821
786
  match node.data.value {
822
787
  ComrakNodeValue::Link(ref mut link) => {
@@ -834,9 +799,8 @@ impl CommonmarkerNode {
834
799
  }
835
800
  }
836
801
 
837
- fn get_header_level(&self) -> Result<u8, magnus::Error> {
838
- let ruby = magnus::Ruby::get().unwrap();
839
- let node = self.inner.borrow();
802
+ fn get_header_level(ruby: &Ruby, rb_self: &Self) -> Result<u8, magnus::Error> {
803
+ let node = rb_self.inner.borrow();
840
804
 
841
805
  match &node.data.value {
842
806
  ComrakNodeValue::Heading(heading) => Ok(heading.level),
@@ -847,9 +811,8 @@ impl CommonmarkerNode {
847
811
  }
848
812
  }
849
813
 
850
- fn set_header_level(&self, new_level: u8) -> Result<bool, magnus::Error> {
851
- let ruby = magnus::Ruby::get().unwrap();
852
- let mut node = self.inner.borrow_mut();
814
+ fn set_header_level(ruby: &Ruby, rb_self: &Self, new_level: u8) -> Result<bool, magnus::Error> {
815
+ let mut node = rb_self.inner.borrow_mut();
853
816
 
854
817
  match node.data.value {
855
818
  ComrakNodeValue::Heading(ref mut heading) => {
@@ -863,9 +826,8 @@ impl CommonmarkerNode {
863
826
  }
864
827
  }
865
828
 
866
- fn get_list_type(&self) -> Result<Symbol, magnus::Error> {
867
- let node = self.inner.borrow();
868
- let ruby = magnus::Ruby::get().unwrap();
829
+ fn get_list_type(ruby: &Ruby, rb_self: &Self) -> Result<Symbol, magnus::Error> {
830
+ let node = rb_self.inner.borrow();
869
831
 
870
832
  match &node.data.value {
871
833
  ComrakNodeValue::List(list) => match list.list_type {
@@ -879,9 +841,8 @@ impl CommonmarkerNode {
879
841
  }
880
842
  }
881
843
 
882
- fn set_list_type(&self, new_type: Symbol) -> Result<bool, magnus::Error> {
883
- let ruby = magnus::Ruby::get().unwrap();
884
- let mut node = self.inner.borrow_mut();
844
+ fn set_list_type(ruby: &Ruby, rb_self: &Self, new_type: Symbol) -> Result<bool, magnus::Error> {
845
+ let mut node = rb_self.inner.borrow_mut();
885
846
 
886
847
  match node.data.value {
887
848
  ComrakNodeValue::List(ref mut list) => {
@@ -899,9 +860,8 @@ impl CommonmarkerNode {
899
860
  }
900
861
  }
901
862
 
902
- fn get_list_start(&self) -> Result<usize, magnus::Error> {
903
- let ruby = magnus::Ruby::get().unwrap();
904
- let node = self.inner.borrow();
863
+ fn get_list_start(ruby: &Ruby, rb_self: &Self) -> Result<usize, magnus::Error> {
864
+ let node = rb_self.inner.borrow();
905
865
 
906
866
  match &node.data.value {
907
867
  ComrakNodeValue::List(list) => Ok(list.start),
@@ -912,9 +872,12 @@ impl CommonmarkerNode {
912
872
  }
913
873
  }
914
874
 
915
- fn set_list_start(&self, new_start: usize) -> Result<bool, magnus::Error> {
916
- let ruby = magnus::Ruby::get().unwrap();
917
- let mut node = self.inner.borrow_mut();
875
+ fn set_list_start(
876
+ ruby: &Ruby,
877
+ rb_self: &Self,
878
+ new_start: usize,
879
+ ) -> Result<bool, magnus::Error> {
880
+ let mut node = rb_self.inner.borrow_mut();
918
881
 
919
882
  match node.data.value {
920
883
  ComrakNodeValue::List(ref mut list) => {
@@ -928,9 +891,8 @@ impl CommonmarkerNode {
928
891
  }
929
892
  }
930
893
 
931
- fn get_list_tight(&self) -> Result<bool, magnus::Error> {
932
- let ruby = magnus::Ruby::get().unwrap();
933
- let node = self.inner.borrow();
894
+ fn get_list_tight(ruby: &Ruby, rb_self: &Self) -> Result<bool, magnus::Error> {
895
+ let node = rb_self.inner.borrow();
934
896
 
935
897
  match &node.data.value {
936
898
  ComrakNodeValue::List(list) => Ok(list.tight),
@@ -941,9 +903,8 @@ impl CommonmarkerNode {
941
903
  }
942
904
  }
943
905
 
944
- fn set_list_tight(&self, new_tight: bool) -> Result<bool, magnus::Error> {
945
- let ruby = magnus::Ruby::get().unwrap();
946
- let mut node = self.inner.borrow_mut();
906
+ fn set_list_tight(ruby: &Ruby, rb_self: &Self, new_tight: bool) -> Result<bool, magnus::Error> {
907
+ let mut node = rb_self.inner.borrow_mut();
947
908
 
948
909
  match node.data.value {
949
910
  ComrakNodeValue::List(ref mut list) => {
@@ -957,9 +918,8 @@ impl CommonmarkerNode {
957
918
  }
958
919
  }
959
920
 
960
- fn get_fence_info(&self) -> Result<String, magnus::Error> {
961
- let ruby = magnus::Ruby::get().unwrap();
962
- let node = self.inner.borrow();
921
+ fn get_fence_info(ruby: &Ruby, rb_self: &Self) -> Result<String, magnus::Error> {
922
+ let node = rb_self.inner.borrow();
963
923
 
964
924
  match &node.data.value {
965
925
  ComrakNodeValue::CodeBlock(code_block) => Ok(code_block.info.to_string()),
@@ -970,9 +930,12 @@ impl CommonmarkerNode {
970
930
  }
971
931
  }
972
932
 
973
- fn set_fence_info(&self, new_info: String) -> Result<bool, magnus::Error> {
974
- let ruby = magnus::Ruby::get().unwrap();
975
- let mut node = self.inner.borrow_mut();
933
+ fn set_fence_info(
934
+ ruby: &Ruby,
935
+ rb_self: &Self,
936
+ new_info: String,
937
+ ) -> Result<bool, magnus::Error> {
938
+ let mut node = rb_self.inner.borrow_mut();
976
939
 
977
940
  match node.data.value {
978
941
  ComrakNodeValue::CodeBlock(ref mut code_block) => {
@@ -986,25 +949,44 @@ impl CommonmarkerNode {
986
949
  }
987
950
  }
988
951
 
989
- fn to_html(&self, args: &[Value]) -> Result<String, magnus::Error> {
990
- let ruby = magnus::Ruby::get().unwrap();
952
+ fn to_html(ruby: &Ruby, rb_self: &Self, args: &[Value]) -> Result<String, magnus::Error> {
991
953
  let args = scan_args::scan_args::<(), (), (), (), _, ()>(args)?;
992
954
 
993
- let kwargs = scan_args::get_kwargs::<_, (), (Option<RHash>, Option<RHash>), ()>(
955
+ let kwargs = scan_args::get_kwargs::<
956
+ _,
957
+ (),
958
+ (Option<RHash>, Option<RHash>, Option<RHash>, Option<RHash>),
959
+ (),
960
+ >(
994
961
  args.keywords,
995
962
  &[],
996
- &["options", "plugins"],
963
+ &["parse", "render", "extension", "plugins"],
997
964
  )?;
998
- let (rb_options, rb_plugins) = kwargs.optional;
965
+ let (rb_parse, rb_render, rb_extension, rb_plugins) = kwargs.optional;
999
966
 
1000
- let comrak_options = match format_options(rb_options) {
1001
- Ok(options) => options,
1002
- Err(err) => return Err(err),
967
+ let mut comrak_parse_options = comrak::options::Parse::default();
968
+ let mut comrak_render_options = comrak::options::Render::default();
969
+ let mut comrak_extension_options = comrak::options::Extension::default();
970
+
971
+ if let Some(rb_parse) = rb_parse {
972
+ iterate_parse_options(&mut comrak_parse_options, rb_parse);
973
+ }
974
+ if let Some(rb_render) = rb_render {
975
+ iterate_render_options(&mut comrak_render_options, rb_render);
976
+ }
977
+ if let Some(rb_extension) = rb_extension {
978
+ iterate_extension_options(&mut comrak_extension_options, rb_extension);
979
+ }
980
+
981
+ let comrak_options = comrak::Options {
982
+ parse: comrak_parse_options,
983
+ render: comrak_render_options,
984
+ extension: comrak_extension_options,
1003
985
  };
1004
986
 
1005
- let mut comrak_plugins = comrak::Plugins::default();
987
+ let mut comrak_plugins = comrak::options::Plugins::default();
1006
988
 
1007
- let syntect_adapter = match construct_syntax_highlighter_from_plugin(rb_plugins) {
989
+ let syntect_adapter = match construct_syntax_highlighter_from_plugin(ruby, rb_plugins) {
1008
990
  Ok(Some(adapter)) => Some(adapter),
1009
991
  Ok(None) => None,
1010
992
  Err(err) => return Err(err),
@@ -1034,9 +1016,9 @@ impl CommonmarkerNode {
1034
1016
  }
1035
1017
 
1036
1018
  let comrak_root_node: ComrakNode<RefCell<ComrakAst>> =
1037
- ComrakNode::new(RefCell::new(self.inner.borrow().data.clone()));
1019
+ ComrakNode::new(RefCell::new(rb_self.inner.borrow().data.clone()));
1038
1020
 
1039
- for c in self.inner.children() {
1021
+ for c in rb_self.inner.children() {
1040
1022
  let child = CommonmarkerNode { inner: c };
1041
1023
 
1042
1024
  let new_child = iter_nodes(&arena, &child);
@@ -1063,23 +1045,44 @@ impl CommonmarkerNode {
1063
1045
  Ok(output)
1064
1046
  }
1065
1047
 
1066
- fn to_commonmark(&self, args: &[Value]) -> Result<String, magnus::Error> {
1067
- let ruby = magnus::Ruby::get().unwrap();
1048
+ fn to_commonmark(ruby: &Ruby, rb_self: &Self, args: &[Value]) -> Result<String, magnus::Error> {
1068
1049
  let args = scan_args::scan_args::<(), (), (), (), _, ()>(args)?;
1069
1050
 
1070
- let kwargs = scan_args::get_kwargs::<_, (), (Option<RHash>, Option<RHash>), ()>(
1051
+ let kwargs = scan_args::get_kwargs::<
1052
+ _,
1053
+ (),
1054
+ (Option<RHash>, Option<RHash>, Option<RHash>, Option<RHash>),
1055
+ (),
1056
+ >(
1071
1057
  args.keywords,
1072
1058
  &[],
1073
- &["options", "plugins"],
1059
+ &["render", "parse", "extension", "plugins"],
1074
1060
  )?;
1075
- let (rb_options, rb_plugins) = kwargs.optional;
1061
+ let (rb_render, rb_parse, rb_extension, rb_plugins) = kwargs.optional;
1076
1062
 
1077
- let _comrak_options = format_options(rb_options);
1078
- let comrak_options = format_options(rb_options)?;
1063
+ let mut comrak_parse_options = comrak::options::Parse::default();
1064
+ let mut comrak_render_options = comrak::options::Render::default();
1065
+ let mut comrak_extension_options = comrak::options::Extension::default();
1066
+
1067
+ if let Some(rb_parse) = rb_parse {
1068
+ iterate_parse_options(&mut comrak_parse_options, rb_parse);
1069
+ }
1070
+ if let Some(rb_render) = rb_render {
1071
+ iterate_render_options(&mut comrak_render_options, rb_render);
1072
+ }
1073
+ if let Some(rb_extension) = rb_extension {
1074
+ iterate_extension_options(&mut comrak_extension_options, rb_extension);
1075
+ }
1076
+
1077
+ let comrak_options = comrak::Options {
1078
+ parse: comrak_parse_options,
1079
+ render: comrak_render_options,
1080
+ extension: comrak_extension_options,
1081
+ };
1079
1082
 
1080
- let mut comrak_plugins = comrak::Plugins::default();
1083
+ let mut comrak_plugins = comrak::options::Plugins::default();
1081
1084
 
1082
- let syntect_adapter = match construct_syntax_highlighter_from_plugin(rb_plugins) {
1085
+ let syntect_adapter = match construct_syntax_highlighter_from_plugin(ruby, rb_plugins) {
1083
1086
  Ok(Some(adapter)) => Some(adapter),
1084
1087
  Ok(None) => None,
1085
1088
  Err(err) => return Err(err),
@@ -1109,9 +1112,9 @@ impl CommonmarkerNode {
1109
1112
  }
1110
1113
 
1111
1114
  let comrak_root_node: ComrakNode<RefCell<ComrakAst>> =
1112
- ComrakNode::new(RefCell::new(self.inner.borrow().data.clone()));
1115
+ ComrakNode::new(RefCell::new(rb_self.inner.borrow().data.clone()));
1113
1116
 
1114
- for c in self.inner.children() {
1117
+ for c in rb_self.inner.children() {
1115
1118
  let child = CommonmarkerNode { inner: c };
1116
1119
 
1117
1120
  let new_child = iter_nodes(&arena, &child);
@@ -1139,8 +1142,7 @@ impl CommonmarkerNode {
1139
1142
  }
1140
1143
  }
1141
1144
 
1142
- pub fn init(m_commonmarker: RModule) -> Result<(), magnus::Error> {
1143
- let ruby = magnus::Ruby::get().unwrap();
1145
+ pub fn init(ruby: &Ruby, m_commonmarker: RModule) -> Result<(), magnus::Error> {
1144
1146
  let c_node = m_commonmarker
1145
1147
  .define_class("Node", ruby.class_object())
1146
1148
  .expect("cannot define class Commonmarker::Node");