commonmarker 2.5.0 → 2.6.1

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.
@@ -3,17 +3,17 @@ use comrak::nodes::{
3
3
  AlertType, Ast as ComrakAst, AstNode as ComrakAstNode, ListDelimType, ListType, NodeAlert,
4
4
  NodeCode, NodeCodeBlock, NodeDescriptionItem, NodeFootnoteDefinition, NodeFootnoteReference,
5
5
  NodeHeading, NodeHtmlBlock, NodeLink, NodeList, NodeMath, NodeMultilineBlockQuote,
6
- NodeShortCode, NodeTable, NodeValue as ComrakNodeValue, NodeWikiLink, TableAlignment,
6
+ NodeShortCode, NodeTable, NodeTaskItem, NodeValue as ComrakNodeValue, NodeWikiLink,
7
+ TableAlignment,
7
8
  };
8
- use magnus::RArray;
9
9
  use magnus::{function, method, scan_args, Module, Object, RHash, RModule, Symbol, Value};
10
+ use magnus::{RArray, Ruby};
10
11
  use rctree::Node;
11
12
  use typed_arena::Arena;
12
13
 
13
14
  use std::cell::RefCell;
14
15
 
15
- use crate::format_options;
16
-
16
+ use crate::options::{iterate_extension_options, iterate_parse_options, iterate_render_options};
17
17
  use crate::plugins::syntax_highlighting::construct_syntax_highlighter_from_plugin;
18
18
 
19
19
  #[derive(Debug, Clone)]
@@ -32,8 +32,7 @@ pub struct CommonmarkerNode {
32
32
  unsafe impl Send for CommonmarkerNode {}
33
33
 
34
34
  impl CommonmarkerNode {
35
- pub fn new(args: &[Value]) -> Result<Self, magnus::Error> {
36
- let ruby = magnus::Ruby::get().unwrap();
35
+ pub fn new(ruby: &Ruby, args: &[Value]) -> Result<Self, magnus::Error> {
37
36
  let args = scan_args::scan_args::<_, (), (), (), _, ()>(args)?;
38
37
  let (node_type,): (Symbol,) = args.required;
39
38
 
@@ -162,6 +161,7 @@ impl CommonmarkerNode {
162
161
  Option<usize>,
163
162
  Option<String>,
164
163
  Option<String>,
164
+ Option<bool>,
165
165
  ),
166
166
  (),
167
167
  >(
@@ -173,12 +173,14 @@ impl CommonmarkerNode {
173
173
  "fence_offset",
174
174
  "info",
175
175
  "literal",
176
+ "closed",
176
177
  ],
177
178
  )?;
178
179
  let (fenced,) = kwargs.required;
179
- let (fence_char, fence_length, fence_offset, info, literal) = kwargs.optional;
180
+ let (fence_char, fence_length, fence_offset, info, literal, closed) =
181
+ kwargs.optional;
180
182
 
181
- ComrakNodeValue::CodeBlock(NodeCodeBlock {
183
+ ComrakNodeValue::CodeBlock(Box::new(NodeCodeBlock {
182
184
  // Whether the code block is fenced.
183
185
  fenced,
184
186
  // For fenced code blocks, the fence character itself (`` ` `` or `~`).
@@ -196,7 +198,12 @@ impl CommonmarkerNode {
196
198
  // all, they are contained within this structure, rather than inserted into a child inline of
197
199
  // any kind.
198
200
  literal: literal.unwrap_or(String::new()),
199
- })
201
+
202
+ // For fenced code blocks, whether the code block is closed. (If not, it was terminated by
203
+ // some other condition, like the end of the document, or the end of the indentation level the
204
+ // code block was introduced at.)
205
+ closed: closed.unwrap_or(true),
206
+ }))
200
207
  }
201
208
  "html_block" => {
202
209
  let kwargs = scan_args::get_kwargs::<_, (), (Option<u8>, Option<String>), ()>(
@@ -216,20 +223,24 @@ impl CommonmarkerNode {
216
223
  }
217
224
  "paragraph" => ComrakNodeValue::Paragraph,
218
225
  "heading" => {
219
- let kwargs = scan_args::get_kwargs::<_, (u8,), (Option<bool>,), ()>(
226
+ let kwargs = scan_args::get_kwargs::<_, (u8,), (Option<bool>, Option<bool>), ()>(
220
227
  args.keywords,
221
228
  &["level"],
222
- &["setext"],
229
+ &["setext", "closed"],
223
230
  )?;
224
231
 
225
232
  let (level,) = kwargs.required;
226
- let (setext,) = kwargs.optional;
233
+ let (setext, closed) = kwargs.optional;
227
234
 
228
235
  ComrakNodeValue::Heading(NodeHeading {
229
- // Number of spaces before the list marker.
236
+ // The heading level. For setext headings, an underline made of "=" characters is level 1, and made of
237
+ // "-" is level 2. For ATX headings, the number of leading "#" characters (from 1 to 6) is its level.
230
238
  level,
231
- // Number of characters between the start of the list marker and the item text (including the list marker(s)).
239
+ // Whether the heading is setext style (marked by an underline). If not, it is ATX style (marked by leading,
240
+ // and possibly trailing, "#" characters).
232
241
  setext: setext.unwrap_or(false),
242
+ // For ATX headings, whether the the leading "#" are terminated by a sequence of closing "#" characters.
243
+ closed: closed.unwrap_or(false),
233
244
  })
234
245
  }
235
246
  "thematic_break" => ComrakNodeValue::ThematicBreak,
@@ -264,7 +275,7 @@ impl CommonmarkerNode {
264
275
  comrak_alignments.push(TableAlignment::None);
265
276
  }
266
277
  });
267
- ComrakNodeValue::Table(NodeTable {
278
+ ComrakNodeValue::Table(Box::new(NodeTable {
268
279
  // The table alignments
269
280
  alignments: comrak_alignments,
270
281
 
@@ -276,7 +287,7 @@ impl CommonmarkerNode {
276
287
 
277
288
  // Number of non-empty, non-autocompleted cells
278
289
  num_nonempty_cells,
279
- })
290
+ }))
280
291
  }
281
292
  "table_row" => {
282
293
  let kwargs =
@@ -296,7 +307,7 @@ impl CommonmarkerNode {
296
307
 
297
308
  let (content,) = kwargs.optional;
298
309
 
299
- ComrakNodeValue::Text(content.unwrap_or("".to_string()))
310
+ ComrakNodeValue::Text(content.unwrap_or_default().into())
300
311
  }
301
312
  "taskitem" => {
302
313
  let kwargs = scan_args::get_kwargs::<_, (), (Option<char>,), ()>(
@@ -307,7 +318,10 @@ impl CommonmarkerNode {
307
318
 
308
319
  let (mark,) = kwargs.optional;
309
320
 
310
- ComrakNodeValue::TaskItem(mark)
321
+ ComrakNodeValue::TaskItem(NodeTaskItem {
322
+ symbol: mark,
323
+ symbol_sourcepos: (0, 0, 0, 0).into(),
324
+ })
311
325
  }
312
326
  "softbreak" => ComrakNodeValue::SoftBreak,
313
327
  "linebreak" => ComrakNodeValue::LineBreak,
@@ -356,7 +370,7 @@ impl CommonmarkerNode {
356
370
  let (url,) = kwargs.required;
357
371
  let (title,) = kwargs.optional;
358
372
 
359
- ComrakNodeValue::Link(NodeLink {
373
+ ComrakNodeValue::Link(Box::new(NodeLink {
360
374
  // The URL for the link destination or image source.
361
375
  url,
362
376
  // The title for the link or image.
@@ -364,7 +378,7 @@ impl CommonmarkerNode {
364
378
  // Note this field is used for the `title` attribute by the HTML formatter even for images;
365
379
  // `alt` text is supplied in the image inline text.
366
380
  title: title.unwrap_or_default(),
367
- })
381
+ }))
368
382
  }
369
383
  "image" => {
370
384
  let kwargs = scan_args::get_kwargs::<_, (String,), (Option<String>,), ()>(
@@ -376,7 +390,7 @@ impl CommonmarkerNode {
376
390
  let (url,) = kwargs.required;
377
391
  let (title,) = kwargs.optional;
378
392
 
379
- ComrakNodeValue::Image(NodeLink {
393
+ ComrakNodeValue::Image(Box::new(NodeLink {
380
394
  // The URL for the link destination or image source.
381
395
  url,
382
396
  // The title for the link or image.
@@ -384,7 +398,7 @@ impl CommonmarkerNode {
384
398
  // Note this field is used for the `title` attribute by the HTML formatter even for images;
385
399
  // `alt` text is supplied in the image inline text.
386
400
  title: title.unwrap_or_default(),
387
- })
401
+ }))
388
402
  }
389
403
  "footnote_reference" => {
390
404
  let kwargs = scan_args::get_kwargs::<_, (String,), (Option<u32>, Option<u32>), ()>(
@@ -396,14 +410,16 @@ impl CommonmarkerNode {
396
410
  let (name,) = kwargs.required;
397
411
  let (ref_num, ix) = kwargs.optional;
398
412
 
399
- ComrakNodeValue::FootnoteReference(NodeFootnoteReference {
413
+ ComrakNodeValue::FootnoteReference(Box::new(NodeFootnoteReference {
400
414
  // The name of the footnote.
401
415
  name,
416
+ // The original text and sourcepos column spans that comprised the footnote ref.
417
+ texts: vec![],
402
418
  // The index of reference to the same footnote
403
419
  ref_num: ref_num.unwrap_or(0),
404
420
  // The index of the footnote in the document.
405
421
  ix: ix.unwrap_or(0),
406
- })
422
+ }))
407
423
  }
408
424
  // #[cfg(feature = "shortcodes")]
409
425
  "shortcode" => {
@@ -413,7 +429,7 @@ impl CommonmarkerNode {
413
429
  let (code,) = kwargs.required;
414
430
 
415
431
  match NodeShortCode::resolve(code.as_str()) {
416
- Some(shortcode) => ComrakNodeValue::ShortCode(shortcode),
432
+ Some(shortcode) => ComrakNodeValue::ShortCode(Box::new(shortcode)),
417
433
  None => {
418
434
  return Err(magnus::Error::new(
419
435
  ruby.exception_arg_error(),
@@ -514,7 +530,7 @@ impl CommonmarkerNode {
514
530
  }
515
531
  };
516
532
 
517
- ComrakNodeValue::Alert(NodeAlert {
533
+ ComrakNodeValue::Alert(Box::new(NodeAlert {
518
534
  alert_type,
519
535
  // Overridden title. If None, then use the default title.
520
536
  title,
@@ -524,7 +540,7 @@ impl CommonmarkerNode {
524
540
  fence_length: fence_length.unwrap_or(0),
525
541
  // The indentation level of the fence marker (multiline only)
526
542
  fence_offset: fence_offset.unwrap_or(0),
527
- })
543
+ }))
528
544
  }
529
545
 
530
546
  _ => panic!("unknown node type {}", node_type),
@@ -575,53 +591,9 @@ impl CommonmarkerNode {
575
591
  Ok(commonmarker_root_node)
576
592
  }
577
593
 
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
- }
594
+ fn type_to_symbol(ruby: &Ruby, rb_self: &Self) -> Symbol {
595
+ let node = rb_self.inner.borrow();
596
+ ruby.to_symbol(node.data.value.xml_node_name())
625
597
  }
626
598
 
627
599
  fn get_parent(&self) -> Option<CommonmarkerNode> {
@@ -677,10 +649,9 @@ impl CommonmarkerNode {
677
649
  })
678
650
  }
679
651
 
680
- fn get_sourcepos(&self) -> Result<RHash, magnus::Error> {
681
- let node = self.inner.borrow();
652
+ fn get_sourcepos(ruby: &Ruby, rb_self: &Self) -> Result<RHash, magnus::Error> {
653
+ let node = rb_self.inner.borrow();
682
654
 
683
- let ruby = magnus::Ruby::get().unwrap();
684
655
  let result = ruby.hash_new();
685
656
  result.aset(ruby.to_symbol("start_line"), node.data.sourcepos.start.line)?;
686
657
  result.aset(
@@ -717,9 +688,8 @@ impl CommonmarkerNode {
717
688
  Ok(true)
718
689
  }
719
690
 
720
- fn get_url(&self) -> Result<String, magnus::Error> {
721
- let ruby = magnus::Ruby::get().unwrap();
722
- let node = self.inner.borrow();
691
+ fn get_url(ruby: &Ruby, rb_self: &Self) -> Result<String, magnus::Error> {
692
+ let node = rb_self.inner.borrow();
723
693
 
724
694
  match &node.data.value {
725
695
  ComrakNodeValue::Link(link) => Ok(link.url.to_string()),
@@ -731,9 +701,8 @@ impl CommonmarkerNode {
731
701
  }
732
702
  }
733
703
 
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();
704
+ fn set_url(ruby: &Ruby, rb_self: &Self, new_url: String) -> Result<bool, magnus::Error> {
705
+ let mut node = rb_self.inner.borrow_mut();
737
706
 
738
707
  match node.data.value {
739
708
  ComrakNodeValue::Link(ref mut link) => {
@@ -751,9 +720,8 @@ impl CommonmarkerNode {
751
720
  }
752
721
  }
753
722
 
754
- fn get_string_content(&self) -> Result<String, magnus::Error> {
755
- let ruby = magnus::Ruby::get().unwrap();
756
- let node = self.inner.borrow();
723
+ fn get_string_content(ruby: &Ruby, rb_self: &Self) -> Result<String, magnus::Error> {
724
+ let node = rb_self.inner.borrow();
757
725
 
758
726
  match node.data.value {
759
727
  ComrakNodeValue::Code(ref code) => return Ok(code.literal.to_string()),
@@ -772,9 +740,12 @@ impl CommonmarkerNode {
772
740
  }
773
741
  }
774
742
 
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();
743
+ fn set_string_content(
744
+ ruby: &Ruby,
745
+ rb_self: &Self,
746
+ new_content: String,
747
+ ) -> Result<bool, magnus::Error> {
748
+ let mut node = rb_self.inner.borrow_mut();
778
749
 
779
750
  match node.data.value {
780
751
  ComrakNodeValue::Code(ref mut code) => {
@@ -790,7 +761,7 @@ impl CommonmarkerNode {
790
761
 
791
762
  match node.data.value.text_mut() {
792
763
  Some(s) => {
793
- *s = new_content;
764
+ *s = new_content.into();
794
765
  Ok(true)
795
766
  }
796
767
  None => Err(magnus::Error::new(
@@ -800,9 +771,8 @@ impl CommonmarkerNode {
800
771
  }
801
772
  }
802
773
 
803
- fn get_title(&self) -> Result<String, magnus::Error> {
804
- let ruby = magnus::Ruby::get().unwrap();
805
- let node = self.inner.borrow();
774
+ fn get_title(ruby: &Ruby, rb_self: &Self) -> Result<String, magnus::Error> {
775
+ let node = rb_self.inner.borrow();
806
776
 
807
777
  match &node.data.value {
808
778
  ComrakNodeValue::Link(link) => Ok(link.title.to_string()),
@@ -814,9 +784,8 @@ impl CommonmarkerNode {
814
784
  }
815
785
  }
816
786
 
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();
787
+ fn set_title(ruby: &Ruby, rb_self: &Self, new_title: String) -> Result<bool, magnus::Error> {
788
+ let mut node = rb_self.inner.borrow_mut();
820
789
 
821
790
  match node.data.value {
822
791
  ComrakNodeValue::Link(ref mut link) => {
@@ -834,9 +803,8 @@ impl CommonmarkerNode {
834
803
  }
835
804
  }
836
805
 
837
- fn get_header_level(&self) -> Result<u8, magnus::Error> {
838
- let ruby = magnus::Ruby::get().unwrap();
839
- let node = self.inner.borrow();
806
+ fn get_header_level(ruby: &Ruby, rb_self: &Self) -> Result<u8, magnus::Error> {
807
+ let node = rb_self.inner.borrow();
840
808
 
841
809
  match &node.data.value {
842
810
  ComrakNodeValue::Heading(heading) => Ok(heading.level),
@@ -847,9 +815,8 @@ impl CommonmarkerNode {
847
815
  }
848
816
  }
849
817
 
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();
818
+ fn set_header_level(ruby: &Ruby, rb_self: &Self, new_level: u8) -> Result<bool, magnus::Error> {
819
+ let mut node = rb_self.inner.borrow_mut();
853
820
 
854
821
  match node.data.value {
855
822
  ComrakNodeValue::Heading(ref mut heading) => {
@@ -863,9 +830,8 @@ impl CommonmarkerNode {
863
830
  }
864
831
  }
865
832
 
866
- fn get_list_type(&self) -> Result<Symbol, magnus::Error> {
867
- let node = self.inner.borrow();
868
- let ruby = magnus::Ruby::get().unwrap();
833
+ fn get_list_type(ruby: &Ruby, rb_self: &Self) -> Result<Symbol, magnus::Error> {
834
+ let node = rb_self.inner.borrow();
869
835
 
870
836
  match &node.data.value {
871
837
  ComrakNodeValue::List(list) => match list.list_type {
@@ -879,9 +845,8 @@ impl CommonmarkerNode {
879
845
  }
880
846
  }
881
847
 
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();
848
+ fn set_list_type(ruby: &Ruby, rb_self: &Self, new_type: Symbol) -> Result<bool, magnus::Error> {
849
+ let mut node = rb_self.inner.borrow_mut();
885
850
 
886
851
  match node.data.value {
887
852
  ComrakNodeValue::List(ref mut list) => {
@@ -899,9 +864,8 @@ impl CommonmarkerNode {
899
864
  }
900
865
  }
901
866
 
902
- fn get_list_start(&self) -> Result<usize, magnus::Error> {
903
- let ruby = magnus::Ruby::get().unwrap();
904
- let node = self.inner.borrow();
867
+ fn get_list_start(ruby: &Ruby, rb_self: &Self) -> Result<usize, magnus::Error> {
868
+ let node = rb_self.inner.borrow();
905
869
 
906
870
  match &node.data.value {
907
871
  ComrakNodeValue::List(list) => Ok(list.start),
@@ -912,9 +876,12 @@ impl CommonmarkerNode {
912
876
  }
913
877
  }
914
878
 
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();
879
+ fn set_list_start(
880
+ ruby: &Ruby,
881
+ rb_self: &Self,
882
+ new_start: usize,
883
+ ) -> Result<bool, magnus::Error> {
884
+ let mut node = rb_self.inner.borrow_mut();
918
885
 
919
886
  match node.data.value {
920
887
  ComrakNodeValue::List(ref mut list) => {
@@ -928,9 +895,8 @@ impl CommonmarkerNode {
928
895
  }
929
896
  }
930
897
 
931
- fn get_list_tight(&self) -> Result<bool, magnus::Error> {
932
- let ruby = magnus::Ruby::get().unwrap();
933
- let node = self.inner.borrow();
898
+ fn get_list_tight(ruby: &Ruby, rb_self: &Self) -> Result<bool, magnus::Error> {
899
+ let node = rb_self.inner.borrow();
934
900
 
935
901
  match &node.data.value {
936
902
  ComrakNodeValue::List(list) => Ok(list.tight),
@@ -941,9 +907,8 @@ impl CommonmarkerNode {
941
907
  }
942
908
  }
943
909
 
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();
910
+ fn set_list_tight(ruby: &Ruby, rb_self: &Self, new_tight: bool) -> Result<bool, magnus::Error> {
911
+ let mut node = rb_self.inner.borrow_mut();
947
912
 
948
913
  match node.data.value {
949
914
  ComrakNodeValue::List(ref mut list) => {
@@ -957,9 +922,8 @@ impl CommonmarkerNode {
957
922
  }
958
923
  }
959
924
 
960
- fn get_fence_info(&self) -> Result<String, magnus::Error> {
961
- let ruby = magnus::Ruby::get().unwrap();
962
- let node = self.inner.borrow();
925
+ fn get_fence_info(ruby: &Ruby, rb_self: &Self) -> Result<String, magnus::Error> {
926
+ let node = rb_self.inner.borrow();
963
927
 
964
928
  match &node.data.value {
965
929
  ComrakNodeValue::CodeBlock(code_block) => Ok(code_block.info.to_string()),
@@ -970,9 +934,12 @@ impl CommonmarkerNode {
970
934
  }
971
935
  }
972
936
 
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();
937
+ fn set_fence_info(
938
+ ruby: &Ruby,
939
+ rb_self: &Self,
940
+ new_info: String,
941
+ ) -> Result<bool, magnus::Error> {
942
+ let mut node = rb_self.inner.borrow_mut();
976
943
 
977
944
  match node.data.value {
978
945
  ComrakNodeValue::CodeBlock(ref mut code_block) => {
@@ -986,25 +953,44 @@ impl CommonmarkerNode {
986
953
  }
987
954
  }
988
955
 
989
- fn to_html(&self, args: &[Value]) -> Result<String, magnus::Error> {
990
- let ruby = magnus::Ruby::get().unwrap();
956
+ fn to_html(ruby: &Ruby, rb_self: &Self, args: &[Value]) -> Result<String, magnus::Error> {
991
957
  let args = scan_args::scan_args::<(), (), (), (), _, ()>(args)?;
992
958
 
993
- let kwargs = scan_args::get_kwargs::<_, (), (Option<RHash>, Option<RHash>), ()>(
959
+ let kwargs = scan_args::get_kwargs::<
960
+ _,
961
+ (),
962
+ (Option<RHash>, Option<RHash>, Option<RHash>, Option<RHash>),
963
+ (),
964
+ >(
994
965
  args.keywords,
995
966
  &[],
996
- &["options", "plugins"],
967
+ &["parse", "render", "extension", "plugins"],
997
968
  )?;
998
- let (rb_options, rb_plugins) = kwargs.optional;
969
+ let (rb_parse, rb_render, rb_extension, rb_plugins) = kwargs.optional;
999
970
 
1000
- let comrak_options = match format_options(rb_options) {
1001
- Ok(options) => options,
1002
- Err(err) => return Err(err),
971
+ let mut comrak_parse_options = comrak::options::Parse::default();
972
+ let mut comrak_render_options = comrak::options::Render::default();
973
+ let mut comrak_extension_options = comrak::options::Extension::default();
974
+
975
+ if let Some(rb_parse) = rb_parse {
976
+ iterate_parse_options(&mut comrak_parse_options, rb_parse);
977
+ }
978
+ if let Some(rb_render) = rb_render {
979
+ iterate_render_options(&mut comrak_render_options, rb_render);
980
+ }
981
+ if let Some(rb_extension) = rb_extension {
982
+ iterate_extension_options(&mut comrak_extension_options, rb_extension);
983
+ }
984
+
985
+ let comrak_options = comrak::Options {
986
+ parse: comrak_parse_options,
987
+ render: comrak_render_options,
988
+ extension: comrak_extension_options,
1003
989
  };
1004
990
 
1005
- let mut comrak_plugins = comrak::Plugins::default();
991
+ let mut comrak_plugins = comrak::options::Plugins::default();
1006
992
 
1007
- let syntect_adapter = match construct_syntax_highlighter_from_plugin(rb_plugins) {
993
+ let syntect_adapter = match construct_syntax_highlighter_from_plugin(ruby, rb_plugins) {
1008
994
  Ok(Some(adapter)) => Some(adapter),
1009
995
  Ok(None) => None,
1010
996
  Err(err) => return Err(err),
@@ -1034,9 +1020,9 @@ impl CommonmarkerNode {
1034
1020
  }
1035
1021
 
1036
1022
  let comrak_root_node: ComrakNode<RefCell<ComrakAst>> =
1037
- ComrakNode::new(RefCell::new(self.inner.borrow().data.clone()));
1023
+ ComrakNode::new(RefCell::new(rb_self.inner.borrow().data.clone()));
1038
1024
 
1039
- for c in self.inner.children() {
1025
+ for c in rb_self.inner.children() {
1040
1026
  let child = CommonmarkerNode { inner: c };
1041
1027
 
1042
1028
  let new_child = iter_nodes(&arena, &child);
@@ -1063,23 +1049,44 @@ impl CommonmarkerNode {
1063
1049
  Ok(output)
1064
1050
  }
1065
1051
 
1066
- fn to_commonmark(&self, args: &[Value]) -> Result<String, magnus::Error> {
1067
- let ruby = magnus::Ruby::get().unwrap();
1052
+ fn to_commonmark(ruby: &Ruby, rb_self: &Self, args: &[Value]) -> Result<String, magnus::Error> {
1068
1053
  let args = scan_args::scan_args::<(), (), (), (), _, ()>(args)?;
1069
1054
 
1070
- let kwargs = scan_args::get_kwargs::<_, (), (Option<RHash>, Option<RHash>), ()>(
1055
+ let kwargs = scan_args::get_kwargs::<
1056
+ _,
1057
+ (),
1058
+ (Option<RHash>, Option<RHash>, Option<RHash>, Option<RHash>),
1059
+ (),
1060
+ >(
1071
1061
  args.keywords,
1072
1062
  &[],
1073
- &["options", "plugins"],
1063
+ &["render", "parse", "extension", "plugins"],
1074
1064
  )?;
1075
- let (rb_options, rb_plugins) = kwargs.optional;
1065
+ let (rb_render, rb_parse, rb_extension, rb_plugins) = kwargs.optional;
1076
1066
 
1077
- let _comrak_options = format_options(rb_options);
1078
- let comrak_options = format_options(rb_options)?;
1067
+ let mut comrak_parse_options = comrak::options::Parse::default();
1068
+ let mut comrak_render_options = comrak::options::Render::default();
1069
+ let mut comrak_extension_options = comrak::options::Extension::default();
1070
+
1071
+ if let Some(rb_parse) = rb_parse {
1072
+ iterate_parse_options(&mut comrak_parse_options, rb_parse);
1073
+ }
1074
+ if let Some(rb_render) = rb_render {
1075
+ iterate_render_options(&mut comrak_render_options, rb_render);
1076
+ }
1077
+ if let Some(rb_extension) = rb_extension {
1078
+ iterate_extension_options(&mut comrak_extension_options, rb_extension);
1079
+ }
1080
+
1081
+ let comrak_options = comrak::Options {
1082
+ parse: comrak_parse_options,
1083
+ render: comrak_render_options,
1084
+ extension: comrak_extension_options,
1085
+ };
1079
1086
 
1080
- let mut comrak_plugins = comrak::Plugins::default();
1087
+ let mut comrak_plugins = comrak::options::Plugins::default();
1081
1088
 
1082
- let syntect_adapter = match construct_syntax_highlighter_from_plugin(rb_plugins) {
1089
+ let syntect_adapter = match construct_syntax_highlighter_from_plugin(ruby, rb_plugins) {
1083
1090
  Ok(Some(adapter)) => Some(adapter),
1084
1091
  Ok(None) => None,
1085
1092
  Err(err) => return Err(err),
@@ -1109,9 +1116,9 @@ impl CommonmarkerNode {
1109
1116
  }
1110
1117
 
1111
1118
  let comrak_root_node: ComrakNode<RefCell<ComrakAst>> =
1112
- ComrakNode::new(RefCell::new(self.inner.borrow().data.clone()));
1119
+ ComrakNode::new(RefCell::new(rb_self.inner.borrow().data.clone()));
1113
1120
 
1114
- for c in self.inner.children() {
1121
+ for c in rb_self.inner.children() {
1115
1122
  let child = CommonmarkerNode { inner: c };
1116
1123
 
1117
1124
  let new_child = iter_nodes(&arena, &child);
@@ -1139,8 +1146,7 @@ impl CommonmarkerNode {
1139
1146
  }
1140
1147
  }
1141
1148
 
1142
- pub fn init(m_commonmarker: RModule) -> Result<(), magnus::Error> {
1143
- let ruby = magnus::Ruby::get().unwrap();
1149
+ pub fn init(ruby: &Ruby, m_commonmarker: RModule) -> Result<(), magnus::Error> {
1144
1150
  let c_node = m_commonmarker
1145
1151
  .define_class("Node", ruby.class_object())
1146
1152
  .expect("cannot define class Commonmarker::Node");