commonmarker 2.3.2 → 2.4.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.
@@ -6,11 +6,11 @@ rust-version = "1.75.0"
6
6
  publish = false
7
7
 
8
8
  [dependencies]
9
- magnus = { version = "0.7", features = ["rb-sys"] }
9
+ magnus = { version = "0.8", features = ["rb-sys"] }
10
10
  rb-sys = { version = "*", default-features = false, features = [
11
11
  "stable-api-compiled-fallback",
12
12
  ] }
13
- comrak = { version = "0.41", features = ["shortcodes"] }
13
+ comrak = { version = "0.43", features = ["shortcodes"] }
14
14
  syntect = { version = "5.2", features = ["plist-load"] }
15
15
  typed-arena = "2.0"
16
16
  rctree = "0.6"
@@ -1,7 +1,7 @@
1
1
  extern crate core;
2
2
 
3
3
  use comrak::{markdown_to_html_with_plugins, parse_document, ComrakOptions};
4
- use magnus::{define_module, function, r_hash::ForEach, scan_args, Error, RHash, Symbol, Value};
4
+ use magnus::{function, r_hash::ForEach, scan_args, Error, RHash, Symbol, Value};
5
5
  use node::CommonmarkerNode;
6
6
  use plugins::syntax_highlighting::construct_syntax_highlighter_from_plugin;
7
7
 
@@ -51,10 +51,7 @@ fn commonmark_to_html(args: &[Value]) -> Result<String, magnus::Error> {
51
51
  )?;
52
52
  let (rb_options, rb_plugins) = kwargs.optional;
53
53
 
54
- let comrak_options = match format_options(rb_options) {
55
- Ok(options) => options,
56
- Err(err) => return Err(err),
57
- };
54
+ let comrak_options = format_options(rb_options)?;
58
55
 
59
56
  let mut comrak_plugins = comrak::Plugins::default();
60
57
 
@@ -91,7 +88,8 @@ fn format_options<'c>(rb_options: Option<RHash>) -> Result<comrak::Options<'c>,
91
88
 
92
89
  #[magnus::init]
93
90
  fn init() -> Result<(), Error> {
94
- let m_commonmarker = define_module("Commonmarker")?;
91
+ let ruby = magnus::Ruby::get().unwrap();
92
+ let m_commonmarker = ruby.define_module("Commonmarker")?;
95
93
 
96
94
  m_commonmarker.define_module_function("commonmark_parse", function!(commonmark_parse, -1))?;
97
95
  m_commonmarker
@@ -33,6 +33,7 @@ unsafe impl Send for CommonmarkerNode {}
33
33
 
34
34
  impl CommonmarkerNode {
35
35
  pub fn new(args: &[Value]) -> Result<Self, magnus::Error> {
36
+ let ruby = magnus::Ruby::get().unwrap();
36
37
  let args = scan_args::scan_args::<_, (), (), (), _, ()>(args)?;
37
38
  let (node_type,): (Symbol,) = args.required;
38
39
 
@@ -91,7 +92,7 @@ impl CommonmarkerNode {
91
92
 
92
93
  if commonmark_list_type != "bullet" && commonmark_list_type != "ordered" {
93
94
  return Err(magnus::Error::new(
94
- magnus::exception::arg_error(),
95
+ ruby.exception_arg_error(),
95
96
  "list type must be `bullet` or `ordered`",
96
97
  ));
97
98
  }
@@ -415,7 +416,7 @@ impl CommonmarkerNode {
415
416
  Some(shortcode) => ComrakNodeValue::ShortCode(shortcode),
416
417
  None => {
417
418
  return Err(magnus::Error::new(
418
- magnus::exception::arg_error(),
419
+ ruby.exception_arg_error(),
419
420
  "could not resolve shortcode",
420
421
  ));
421
422
  }
@@ -507,7 +508,7 @@ impl CommonmarkerNode {
507
508
  "warning" => AlertType::Warning,
508
509
  _ => {
509
510
  return Err(magnus::Error::new(
510
- magnus::exception::arg_error(),
511
+ ruby.exception_arg_error(),
511
512
  "alert type must be `note`, `tip`, `important`, or `warning`",
512
513
  ));
513
514
  }
@@ -576,49 +577,50 @@ impl CommonmarkerNode {
576
577
 
577
578
  fn type_to_symbol(&self) -> Symbol {
578
579
  let node = self.inner.borrow();
580
+ let ruby = magnus::Ruby::get().unwrap();
579
581
  match node.data.value {
580
- ComrakNodeValue::Document => Symbol::new("document"),
581
- ComrakNodeValue::BlockQuote => Symbol::new("block_quote"),
582
- ComrakNodeValue::FootnoteDefinition(_) => Symbol::new("footnote_definition"),
583
- ComrakNodeValue::List(..) => Symbol::new("list"),
584
- ComrakNodeValue::DescriptionList => Symbol::new("description_list"),
585
- ComrakNodeValue::DescriptionItem(_) => Symbol::new("description_item"),
586
- ComrakNodeValue::DescriptionTerm => Symbol::new("description_term"),
587
- ComrakNodeValue::DescriptionDetails => Symbol::new("description_details"),
588
- ComrakNodeValue::Item(..) => Symbol::new("item"),
589
- ComrakNodeValue::CodeBlock(..) => Symbol::new("code_block"),
590
- ComrakNodeValue::HtmlBlock(..) => Symbol::new("html_block"),
591
- ComrakNodeValue::Paragraph => Symbol::new("paragraph"),
592
- ComrakNodeValue::Heading(..) => Symbol::new("heading"),
593
- ComrakNodeValue::ThematicBreak => Symbol::new("thematic_break"),
594
- ComrakNodeValue::Table(..) => Symbol::new("table"),
595
- ComrakNodeValue::TableRow(..) => Symbol::new("table_row"),
596
- ComrakNodeValue::TableCell => Symbol::new("table_cell"),
597
- ComrakNodeValue::Text(..) => Symbol::new("text"),
598
- ComrakNodeValue::SoftBreak => Symbol::new("softbreak"),
599
- ComrakNodeValue::LineBreak => Symbol::new("linebreak"),
600
- ComrakNodeValue::Image(..) => Symbol::new("image"),
601
- ComrakNodeValue::Link(..) => Symbol::new("link"),
602
- ComrakNodeValue::Emph => Symbol::new("emph"),
603
- ComrakNodeValue::Raw(..) => Symbol::new("raw"),
604
- ComrakNodeValue::Strong => Symbol::new("strong"),
605
- ComrakNodeValue::Code(..) => Symbol::new("code"),
606
- ComrakNodeValue::HtmlInline(..) => Symbol::new("html_inline"),
607
- ComrakNodeValue::Strikethrough => Symbol::new("strikethrough"),
608
- ComrakNodeValue::FrontMatter(_) => Symbol::new("frontmatter"),
609
- ComrakNodeValue::TaskItem { .. } => Symbol::new("taskitem"),
610
- ComrakNodeValue::Superscript => Symbol::new("superscript"),
611
- ComrakNodeValue::FootnoteReference(..) => Symbol::new("footnote_reference"),
612
- ComrakNodeValue::ShortCode(_) => Symbol::new("shortcode"),
613
- ComrakNodeValue::MultilineBlockQuote(_) => Symbol::new("multiline_block_quote"),
614
- ComrakNodeValue::Escaped => Symbol::new("escaped"),
615
- ComrakNodeValue::Math(..) => Symbol::new("math"),
616
- ComrakNodeValue::WikiLink(..) => Symbol::new("wikilink"),
617
- ComrakNodeValue::Underline => Symbol::new("underline"),
618
- ComrakNodeValue::Subscript => Symbol::new("subscript"),
619
- ComrakNodeValue::SpoileredText => Symbol::new("spoilered_text"),
620
- ComrakNodeValue::EscapedTag(_) => Symbol::new("escaped_tag"),
621
- ComrakNodeValue::Alert(..) => Symbol::new("alert"),
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"),
622
624
  }
623
625
  }
624
626
 
@@ -678,14 +680,15 @@ impl CommonmarkerNode {
678
680
  fn get_sourcepos(&self) -> Result<RHash, magnus::Error> {
679
681
  let node = self.inner.borrow();
680
682
 
681
- let result = RHash::new();
682
- result.aset(Symbol::new("start_line"), node.data.sourcepos.start.line)?;
683
+ let ruby = magnus::Ruby::get().unwrap();
684
+ let result = ruby.hash_new();
685
+ result.aset(ruby.to_symbol("start_line"), node.data.sourcepos.start.line)?;
683
686
  result.aset(
684
- Symbol::new("start_column"),
687
+ ruby.to_symbol("start_column"),
685
688
  node.data.sourcepos.start.column,
686
689
  )?;
687
- result.aset(Symbol::new("end_line"), node.data.sourcepos.end.line)?;
688
- result.aset(Symbol::new("end_column"), node.data.sourcepos.end.column)?;
690
+ result.aset(ruby.to_symbol("end_line"), node.data.sourcepos.end.line)?;
691
+ result.aset(ruby.to_symbol("end_column"), node.data.sourcepos.end.column)?;
689
692
 
690
693
  Ok(result)
691
694
  }
@@ -715,19 +718,21 @@ impl CommonmarkerNode {
715
718
  }
716
719
 
717
720
  fn get_url(&self) -> Result<String, magnus::Error> {
721
+ let ruby = magnus::Ruby::get().unwrap();
718
722
  let node = self.inner.borrow();
719
723
 
720
724
  match &node.data.value {
721
725
  ComrakNodeValue::Link(link) => Ok(link.url.to_string()),
722
726
  ComrakNodeValue::Image(image) => Ok(image.url.to_string()),
723
727
  _ => Err(magnus::Error::new(
724
- magnus::exception::type_error(),
728
+ ruby.exception_type_error(),
725
729
  "node is not an image or link node",
726
730
  )),
727
731
  }
728
732
  }
729
733
 
730
734
  fn set_url(&self, new_url: String) -> Result<bool, magnus::Error> {
735
+ let ruby = magnus::Ruby::get().unwrap();
731
736
  let mut node = self.inner.borrow_mut();
732
737
 
733
738
  match node.data.value {
@@ -740,13 +745,14 @@ impl CommonmarkerNode {
740
745
  Ok(true)
741
746
  }
742
747
  _ => Err(magnus::Error::new(
743
- magnus::exception::type_error(),
748
+ ruby.exception_type_error(),
744
749
  "node is not an image or link node",
745
750
  )),
746
751
  }
747
752
  }
748
753
 
749
754
  fn get_string_content(&self) -> Result<String, magnus::Error> {
755
+ let ruby = magnus::Ruby::get().unwrap();
750
756
  let node = self.inner.borrow();
751
757
 
752
758
  match node.data.value {
@@ -760,13 +766,14 @@ impl CommonmarkerNode {
760
766
  match node.data.value.text() {
761
767
  Some(s) => Ok(s.to_string()),
762
768
  None => Err(magnus::Error::new(
763
- magnus::exception::type_error(),
769
+ ruby.exception_type_error(),
764
770
  "node does not have string content",
765
771
  )),
766
772
  }
767
773
  }
768
774
 
769
775
  fn set_string_content(&self, new_content: String) -> Result<bool, magnus::Error> {
776
+ let ruby = magnus::Ruby::get().unwrap();
770
777
  let mut node = self.inner.borrow_mut();
771
778
 
772
779
  match node.data.value {
@@ -787,26 +794,28 @@ impl CommonmarkerNode {
787
794
  Ok(true)
788
795
  }
789
796
  None => Err(magnus::Error::new(
790
- magnus::exception::type_error(),
797
+ ruby.exception_type_error(),
791
798
  "node does not have string content",
792
799
  )),
793
800
  }
794
801
  }
795
802
 
796
803
  fn get_title(&self) -> Result<String, magnus::Error> {
804
+ let ruby = magnus::Ruby::get().unwrap();
797
805
  let node = self.inner.borrow();
798
806
 
799
807
  match &node.data.value {
800
808
  ComrakNodeValue::Link(link) => Ok(link.title.to_string()),
801
809
  ComrakNodeValue::Image(image) => Ok(image.title.to_string()),
802
810
  _ => Err(magnus::Error::new(
803
- magnus::exception::type_error(),
811
+ ruby.exception_type_error(),
804
812
  "node is not an image or link node",
805
813
  )),
806
814
  }
807
815
  }
808
816
 
809
817
  fn set_title(&self, new_title: String) -> Result<bool, magnus::Error> {
818
+ let ruby = magnus::Ruby::get().unwrap();
810
819
  let mut node = self.inner.borrow_mut();
811
820
 
812
821
  match node.data.value {
@@ -819,25 +828,27 @@ impl CommonmarkerNode {
819
828
  Ok(true)
820
829
  }
821
830
  _ => Err(magnus::Error::new(
822
- magnus::exception::type_error(),
831
+ ruby.exception_type_error(),
823
832
  "node is not an image or link node",
824
833
  )),
825
834
  }
826
835
  }
827
836
 
828
837
  fn get_header_level(&self) -> Result<u8, magnus::Error> {
838
+ let ruby = magnus::Ruby::get().unwrap();
829
839
  let node = self.inner.borrow();
830
840
 
831
841
  match &node.data.value {
832
842
  ComrakNodeValue::Heading(heading) => Ok(heading.level),
833
843
  _ => Err(magnus::Error::new(
834
- magnus::exception::type_error(),
844
+ ruby.exception_type_error(),
835
845
  "node is not a heading node",
836
846
  )),
837
847
  }
838
848
  }
839
849
 
840
850
  fn set_header_level(&self, new_level: u8) -> Result<bool, magnus::Error> {
851
+ let ruby = magnus::Ruby::get().unwrap();
841
852
  let mut node = self.inner.borrow_mut();
842
853
 
843
854
  match node.data.value {
@@ -846,7 +857,7 @@ impl CommonmarkerNode {
846
857
  Ok(true)
847
858
  }
848
859
  _ => Err(magnus::Error::new(
849
- magnus::exception::type_error(),
860
+ ruby.exception_type_error(),
850
861
  "node is not a heading node",
851
862
  )),
852
863
  }
@@ -854,20 +865,22 @@ impl CommonmarkerNode {
854
865
 
855
866
  fn get_list_type(&self) -> Result<Symbol, magnus::Error> {
856
867
  let node = self.inner.borrow();
868
+ let ruby = magnus::Ruby::get().unwrap();
857
869
 
858
870
  match &node.data.value {
859
871
  ComrakNodeValue::List(list) => match list.list_type {
860
- comrak::nodes::ListType::Bullet => Ok(Symbol::new("bullet")),
861
- comrak::nodes::ListType::Ordered => Ok(Symbol::new("ordered")),
872
+ comrak::nodes::ListType::Bullet => Ok(ruby.to_symbol("bullet")),
873
+ comrak::nodes::ListType::Ordered => Ok(ruby.to_symbol("ordered")),
862
874
  },
863
875
  _ => Err(magnus::Error::new(
864
- magnus::exception::type_error(),
876
+ ruby.exception_type_error(),
865
877
  "node is not a list node",
866
878
  )),
867
879
  }
868
880
  }
869
881
 
870
882
  fn set_list_type(&self, new_type: Symbol) -> Result<bool, magnus::Error> {
883
+ let ruby = magnus::Ruby::get().unwrap();
871
884
  let mut node = self.inner.borrow_mut();
872
885
 
873
886
  match node.data.value {
@@ -880,25 +893,27 @@ impl CommonmarkerNode {
880
893
  Ok(true)
881
894
  }
882
895
  _ => Err(magnus::Error::new(
883
- magnus::exception::type_error(),
896
+ ruby.exception_type_error(),
884
897
  "node is not a list node",
885
898
  )),
886
899
  }
887
900
  }
888
901
 
889
902
  fn get_list_start(&self) -> Result<usize, magnus::Error> {
903
+ let ruby = magnus::Ruby::get().unwrap();
890
904
  let node = self.inner.borrow();
891
905
 
892
906
  match &node.data.value {
893
907
  ComrakNodeValue::List(list) => Ok(list.start),
894
908
  _ => Err(magnus::Error::new(
895
- magnus::exception::type_error(),
909
+ ruby.exception_type_error(),
896
910
  "node is not a list node",
897
911
  )),
898
912
  }
899
913
  }
900
914
 
901
915
  fn set_list_start(&self, new_start: usize) -> Result<bool, magnus::Error> {
916
+ let ruby = magnus::Ruby::get().unwrap();
902
917
  let mut node = self.inner.borrow_mut();
903
918
 
904
919
  match node.data.value {
@@ -907,25 +922,27 @@ impl CommonmarkerNode {
907
922
  Ok(true)
908
923
  }
909
924
  _ => Err(magnus::Error::new(
910
- magnus::exception::type_error(),
925
+ ruby.exception_type_error(),
911
926
  "node is not a list node",
912
927
  )),
913
928
  }
914
929
  }
915
930
 
916
931
  fn get_list_tight(&self) -> Result<bool, magnus::Error> {
932
+ let ruby = magnus::Ruby::get().unwrap();
917
933
  let node = self.inner.borrow();
918
934
 
919
935
  match &node.data.value {
920
936
  ComrakNodeValue::List(list) => Ok(list.tight),
921
937
  _ => Err(magnus::Error::new(
922
- magnus::exception::type_error(),
938
+ ruby.exception_type_error(),
923
939
  "node is not a list node",
924
940
  )),
925
941
  }
926
942
  }
927
943
 
928
944
  fn set_list_tight(&self, new_tight: bool) -> Result<bool, magnus::Error> {
945
+ let ruby = magnus::Ruby::get().unwrap();
929
946
  let mut node = self.inner.borrow_mut();
930
947
 
931
948
  match node.data.value {
@@ -934,25 +951,27 @@ impl CommonmarkerNode {
934
951
  Ok(true)
935
952
  }
936
953
  _ => Err(magnus::Error::new(
937
- magnus::exception::type_error(),
954
+ ruby.exception_type_error(),
938
955
  "node is not a list node",
939
956
  )),
940
957
  }
941
958
  }
942
959
 
943
960
  fn get_fence_info(&self) -> Result<String, magnus::Error> {
961
+ let ruby = magnus::Ruby::get().unwrap();
944
962
  let node = self.inner.borrow();
945
963
 
946
964
  match &node.data.value {
947
965
  ComrakNodeValue::CodeBlock(code_block) => Ok(code_block.info.to_string()),
948
966
  _ => Err(magnus::Error::new(
949
- magnus::exception::type_error(),
967
+ ruby.exception_type_error(),
950
968
  "node is not a code block node",
951
969
  )),
952
970
  }
953
971
  }
954
972
 
955
973
  fn set_fence_info(&self, new_info: String) -> Result<bool, magnus::Error> {
974
+ let ruby = magnus::Ruby::get().unwrap();
956
975
  let mut node = self.inner.borrow_mut();
957
976
 
958
977
  match node.data.value {
@@ -961,13 +980,14 @@ impl CommonmarkerNode {
961
980
  Ok(true)
962
981
  }
963
982
  _ => Err(magnus::Error::new(
964
- magnus::exception::type_error(),
983
+ ruby.exception_type_error(),
965
984
  "node is not a code block node",
966
985
  )),
967
986
  }
968
987
  }
969
988
 
970
989
  fn to_html(&self, args: &[Value]) -> Result<String, magnus::Error> {
990
+ let ruby = magnus::Ruby::get().unwrap();
971
991
  let args = scan_args::scan_args::<(), (), (), (), _, ()>(args)?;
972
992
 
973
993
  let kwargs = scan_args::get_kwargs::<_, (), (Option<RHash>, Option<RHash>), ()>(
@@ -1024,7 +1044,7 @@ impl CommonmarkerNode {
1024
1044
  comrak_root_node.append(new_child);
1025
1045
  }
1026
1046
 
1027
- let mut output = vec![];
1047
+ let mut output = String::new();
1028
1048
  match comrak::format_html_with_plugins(
1029
1049
  &comrak_root_node,
1030
1050
  &comrak_options,
@@ -1034,22 +1054,17 @@ impl CommonmarkerNode {
1034
1054
  Ok(_) => {}
1035
1055
  Err(e) => {
1036
1056
  return Err(magnus::Error::new(
1037
- magnus::exception::runtime_error(),
1057
+ ruby.exception_runtime_error(),
1038
1058
  format!("cannot convert into html: {}", e),
1039
1059
  ));
1040
1060
  }
1041
1061
  }
1042
1062
 
1043
- match std::str::from_utf8(&output) {
1044
- Ok(s) => Ok(s.to_string()),
1045
- Err(_e) => Err(magnus::Error::new(
1046
- magnus::exception::runtime_error(),
1047
- "cannot convert into utf-8",
1048
- )),
1049
- }
1063
+ Ok(output)
1050
1064
  }
1051
1065
 
1052
1066
  fn to_commonmark(&self, args: &[Value]) -> Result<String, magnus::Error> {
1067
+ let ruby = magnus::Ruby::get().unwrap();
1053
1068
  let args = scan_args::scan_args::<(), (), (), (), _, ()>(args)?;
1054
1069
 
1055
1070
  let kwargs = scan_args::get_kwargs::<_, (), (Option<RHash>, Option<RHash>), ()>(
@@ -1060,10 +1075,7 @@ impl CommonmarkerNode {
1060
1075
  let (rb_options, rb_plugins) = kwargs.optional;
1061
1076
 
1062
1077
  let _comrak_options = format_options(rb_options);
1063
- let comrak_options = match format_options(rb_options) {
1064
- Ok(options) => options,
1065
- Err(err) => return Err(err),
1066
- };
1078
+ let comrak_options = format_options(rb_options)?;
1067
1079
 
1068
1080
  let mut comrak_plugins = comrak::Plugins::default();
1069
1081
 
@@ -1107,7 +1119,7 @@ impl CommonmarkerNode {
1107
1119
  comrak_root_node.append(new_child);
1108
1120
  }
1109
1121
 
1110
- let mut output = vec![];
1122
+ let mut output = String::new();
1111
1123
  match comrak::format_commonmark_with_plugins(
1112
1124
  &comrak_root_node,
1113
1125
  &comrak_options,
@@ -1117,25 +1129,20 @@ impl CommonmarkerNode {
1117
1129
  Ok(_) => {}
1118
1130
  Err(e) => {
1119
1131
  return Err(magnus::Error::new(
1120
- magnus::exception::runtime_error(),
1132
+ ruby.exception_runtime_error(),
1121
1133
  format!("cannot convert into html: {}", e),
1122
1134
  ));
1123
1135
  }
1124
1136
  }
1125
1137
 
1126
- match std::str::from_utf8(&output) {
1127
- Ok(s) => Ok(s.to_string()),
1128
- Err(_e) => Err(magnus::Error::new(
1129
- magnus::exception::runtime_error(),
1130
- "cannot convert into utf-8",
1131
- )),
1132
- }
1138
+ Ok(output)
1133
1139
  }
1134
1140
  }
1135
1141
 
1136
1142
  pub fn init(m_commonmarker: RModule) -> Result<(), magnus::Error> {
1143
+ let ruby = magnus::Ruby::get().unwrap();
1137
1144
  let c_node = m_commonmarker
1138
- .define_class("Node", magnus::class::object())
1145
+ .define_class("Node", ruby.class_object())
1139
1146
  .expect("cannot define class Commonmarker::Node");
1140
1147
 
1141
1148
  c_node.define_singleton_method("new", function!(CommonmarkerNode::new, -1))?;
@@ -4,7 +4,7 @@ use comrak::ComrakOptions;
4
4
 
5
5
  use magnus::value::ReprValue;
6
6
  use magnus::TryConvert;
7
- use magnus::{class, r_hash::ForEach, Error, RHash, Symbol, Value};
7
+ use magnus::{r_hash::ForEach, Error, RHash, Symbol, Value};
8
8
 
9
9
  use crate::utils::try_convert_string;
10
10
 
@@ -214,7 +214,8 @@ pub fn iterate_options_hash(
214
214
  key: Symbol,
215
215
  value: RHash,
216
216
  ) -> Result<ForEach, Error> {
217
- assert!(value.is_kind_of(class::hash()));
217
+ let ruby = magnus::Ruby::get().unwrap();
218
+ assert!(value.is_kind_of(ruby.class_hash()));
218
219
 
219
220
  if key.name().unwrap() == "parse" {
220
221
  iterate_parse_options(comrak_options, value);
@@ -3,7 +3,7 @@ use std::path::PathBuf;
3
3
  use comrak::plugins::syntect::{SyntectAdapter, SyntectAdapterBuilder};
4
4
 
5
5
  use magnus::value::ReprValue;
6
- use magnus::{exception, RHash, Symbol, TryConvert, Value};
6
+ use magnus::{RHash, TryConvert, Value};
7
7
  use syntect::highlighting::ThemeSet;
8
8
 
9
9
  use crate::EMPTY_STR;
@@ -14,7 +14,8 @@ pub fn construct_syntax_highlighter_from_plugin(
14
14
  match rb_plugins {
15
15
  None => Ok(None),
16
16
  Some(rb_plugins) => {
17
- let theme = match rb_plugins.get(Symbol::new(super::SYNTAX_HIGHLIGHTER_PLUGIN)) {
17
+ let ruby = magnus::Ruby::get_with(rb_plugins);
18
+ let theme = match rb_plugins.get(ruby.to_symbol(super::SYNTAX_HIGHLIGHTER_PLUGIN)) {
18
19
  Some(syntax_highlighter_options) => {
19
20
  match fetch_syntax_highlighter_theme(syntax_highlighter_options) {
20
21
  Ok(theme) => theme,
@@ -36,18 +37,19 @@ pub fn construct_syntax_highlighter_from_plugin(
36
37
  adapter = SyntectAdapter::new(None);
37
38
  Ok(Some(adapter))
38
39
  } else {
39
- let path =
40
- match rb_plugins.get(Symbol::new(super::SYNTAX_HIGHLIGHTER_PLUGIN)) {
41
- Some(syntax_highlighter_options) => {
42
- fetch_syntax_highlighter_path(syntax_highlighter_options)?
43
- }
44
- None => PathBuf::from("".to_string()), // no `syntax_highlighter:` defined
45
- };
40
+ let path = match rb_plugins
41
+ .get(ruby.to_symbol(super::SYNTAX_HIGHLIGHTER_PLUGIN))
42
+ {
43
+ Some(syntax_highlighter_options) => {
44
+ fetch_syntax_highlighter_path(syntax_highlighter_options)?
45
+ }
46
+ None => PathBuf::from("".to_string()), // no `syntax_highlighter:` defined
47
+ };
46
48
 
47
49
  if path.exists() {
48
50
  if !path.is_dir() {
49
51
  return Err(magnus::Error::new(
50
- exception::arg_error(),
52
+ ruby.exception_arg_error(),
51
53
  "`path` needs to be a directory",
52
54
  ));
53
55
  }
@@ -59,7 +61,7 @@ pub fn construct_syntax_highlighter_from_plugin(
59
61
  Ok(_) => {}
60
62
  Err(e) => {
61
63
  return Err(magnus::Error::new(
62
- exception::arg_error(),
64
+ ruby.exception_arg_error(),
63
65
  format!("failed to load theme set from path: {e}"),
64
66
  ));
65
67
  }
@@ -70,7 +72,7 @@ pub fn construct_syntax_highlighter_from_plugin(
70
72
  Some(theme) => theme,
71
73
  None => {
72
74
  return Err(magnus::Error::new(
73
- exception::arg_error(),
75
+ ruby.exception_arg_error(),
74
76
  format!("theme `{}` does not exist", theme),
75
77
  ));
76
78
  }
@@ -86,7 +88,7 @@ pub fn construct_syntax_highlighter_from_plugin(
86
88
  .get(&theme)
87
89
  .ok_or_else(|| {
88
90
  magnus::Error::new(
89
- exception::arg_error(),
91
+ ruby.exception_arg_error(),
90
92
  format!("theme `{}` does not exist", theme),
91
93
  )
92
94
  })?;
@@ -101,6 +103,7 @@ pub fn construct_syntax_highlighter_from_plugin(
101
103
  }
102
104
 
103
105
  fn fetch_syntax_highlighter_theme(value: Value) -> Result<Option<String>, magnus::Error> {
106
+ let ruby = magnus::Ruby::get_with(value);
104
107
  if value.is_nil() {
105
108
  // `syntax_highlighter: nil`
106
109
  return Ok(None);
@@ -116,18 +119,18 @@ fn fetch_syntax_highlighter_theme(value: Value) -> Result<Option<String>, magnus
116
119
 
117
120
  if syntax_highlighter_plugin.is_nil() || syntax_highlighter_plugin.is_empty() {
118
121
  return Err(magnus::Error::new(
119
- magnus::exception::type_error(),
122
+ ruby.exception_type_error(),
120
123
  "theme cannot be blank hash",
121
124
  ));
122
125
  }
123
126
 
124
- let theme_key = Symbol::new(super::SYNTAX_HIGHLIGHTER_PLUGIN_THEME_KEY);
127
+ let theme_key = ruby.to_symbol(super::SYNTAX_HIGHLIGHTER_PLUGIN_THEME_KEY);
125
128
 
126
129
  match syntax_highlighter_plugin.get(theme_key) {
127
130
  Some(theme) => {
128
131
  if theme.is_nil() {
129
132
  return Err(magnus::Error::new(
130
- magnus::exception::type_error(),
133
+ ruby.exception_type_error(),
131
134
  "theme cannot be nil",
132
135
  ));
133
136
  }
@@ -147,7 +150,8 @@ fn fetch_syntax_highlighter_path(value: Value) -> Result<PathBuf, magnus::Error>
147
150
  }
148
151
 
149
152
  let syntax_highlighter_plugin: RHash = TryConvert::try_convert(value)?;
150
- let path_key = Symbol::new(super::SYNTAX_HIGHLIGHTER_PLUGIN_PATH_KEY);
153
+ let ruby = magnus::Ruby::get_with(value);
154
+ let path_key = ruby.to_symbol(super::SYNTAX_HIGHLIGHTER_PLUGIN_PATH_KEY);
151
155
 
152
156
  match syntax_highlighter_plugin.get(path_key) {
153
157
  Some(path) => {