commonmarker 1.0.4 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a2600e08f80e8c7d68074711c54961feb13561eeaa0a7f5f46e01906d26405f
4
- data.tar.gz: 35475ea11ba513d261e7d132029bcdb1c515f1a91b8e69b417f0d389f66ce37a
3
+ metadata.gz: d30b2618d4b982b55e05eaa0cf53b7cbd87fbc38a643c1ee937e21184f15d0b7
4
+ data.tar.gz: 0bafeaf22b6a84423e437dcd8b4d0ba3b5beadd25868f67d61e31fd70152feea
5
5
  SHA512:
6
- metadata.gz: ff0cfd2e68b4900c187583a3fd878df0286ee21b1ef57467c1c8b6c68d106a8644b4827de9ae351b543b87ba373e0d03173a824817d58e700696448acab9d4ff
7
- data.tar.gz: 5ccdcd58ea9865d36adf6c4ceec4b6d35e15d1f2e03897d35005180e4488f69c942b888768b1ee25296b00b138c3d3a2424912abca05e5f520f6b9587b1926ff
6
+ metadata.gz: 2d183a2725c73d2c9c2464d780599694566eeaa15736a90db20035977393200c4e1e67e03c1194afb83e60b27e7ddd7fa4052abd2a09015663aa3736e0cd8509
7
+ data.tar.gz: 15dac96c9f6797553d743829058e0c3ec3bbed065987be0b534534700b71b7c057027bb2bcaacf912b99eccfc9f191663002653c8313a82d4e7a943b35e54cea
data/Cargo.lock CHANGED
@@ -221,19 +221,22 @@ version = "1.0.0"
221
221
  dependencies = [
222
222
  "comrak",
223
223
  "magnus",
224
+ "rctree",
224
225
  "syntect",
226
+ "typed-arena",
225
227
  ]
226
228
 
227
229
  [[package]]
228
230
  name = "comrak"
229
- version = "0.20.0"
231
+ version = "0.23.0"
230
232
  source = "registry+https://github.com/rust-lang/crates.io-index"
231
- checksum = "9f18e72341e6cdc7489cffb76f993812a14a906db54dedb020044ccc211dcaae"
233
+ checksum = "ab5681b26a36dc46800a908f7d932672a4e82f74759419dd4018bf40658457d5"
232
234
  dependencies = [
233
235
  "clap",
234
236
  "derive_builder",
235
237
  "emojis",
236
238
  "entities",
239
+ "in-place",
237
240
  "memchr",
238
241
  "once_cell",
239
242
  "regex",
@@ -376,6 +379,12 @@ dependencies = [
376
379
  "regex",
377
380
  ]
378
381
 
382
+ [[package]]
383
+ name = "fastrand"
384
+ version = "2.1.0"
385
+ source = "registry+https://github.com/rust-lang/crates.io-index"
386
+ checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a"
387
+
379
388
  [[package]]
380
389
  name = "flate2"
381
390
  version = "1.0.28"
@@ -416,6 +425,15 @@ version = "1.0.1"
416
425
  source = "registry+https://github.com/rust-lang/crates.io-index"
417
426
  checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
418
427
 
428
+ [[package]]
429
+ name = "in-place"
430
+ version = "0.2.0"
431
+ source = "registry+https://github.com/rust-lang/crates.io-index"
432
+ checksum = "1cdb69f3adfd5f493210cece799f4620417bf9965bc1536c22ae0e29ba27a8c0"
433
+ dependencies = [
434
+ "tempfile",
435
+ ]
436
+
419
437
  [[package]]
420
438
  name = "indexmap"
421
439
  version = "2.1.0"
@@ -446,9 +464,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
446
464
 
447
465
  [[package]]
448
466
  name = "libc"
449
- version = "0.2.151"
467
+ version = "0.2.154"
450
468
  source = "registry+https://github.com/rust-lang/crates.io-index"
451
- checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4"
469
+ checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346"
452
470
 
453
471
  [[package]]
454
472
  name = "libloading"
@@ -489,9 +507,9 @@ checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
489
507
 
490
508
  [[package]]
491
509
  name = "magnus"
492
- version = "0.6.2"
510
+ version = "0.6.3"
493
511
  source = "registry+https://github.com/rust-lang/crates.io-index"
494
- checksum = "4778544796676e8428e9c622460ebf284bea52d8b10db3aeb449d8b5e61b3a13"
512
+ checksum = "0fc7a31fb0b64761e3cd09a6975577601fccc5f08b8fc9245064fc4f71ed6a9d"
495
513
  dependencies = [
496
514
  "magnus-macros",
497
515
  "rb-sys",
@@ -676,6 +694,12 @@ version = "0.1.2"
676
694
  source = "registry+https://github.com/rust-lang/crates.io-index"
677
695
  checksum = "a35802679f07360454b418a5d1735c89716bde01d35b1560fc953c1415a0b3bb"
678
696
 
697
+ [[package]]
698
+ name = "rctree"
699
+ version = "0.6.0"
700
+ source = "registry+https://github.com/rust-lang/crates.io-index"
701
+ checksum = "e03e7866abec1101869ffa8e2c8355c4c2419d0214ece0cc3e428e5b94dea6e9"
702
+
679
703
  [[package]]
680
704
  name = "regex"
681
705
  version = "1.10.2"
@@ -685,7 +709,7 @@ dependencies = [
685
709
  "aho-corasick",
686
710
  "memchr",
687
711
  "regex-automata",
688
- "regex-syntax 0.8.2",
712
+ "regex-syntax",
689
713
  ]
690
714
 
691
715
  [[package]]
@@ -696,15 +720,9 @@ checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f"
696
720
  dependencies = [
697
721
  "aho-corasick",
698
722
  "memchr",
699
- "regex-syntax 0.8.2",
723
+ "regex-syntax",
700
724
  ]
701
725
 
702
- [[package]]
703
- name = "regex-syntax"
704
- version = "0.7.5"
705
- source = "registry+https://github.com/rust-lang/crates.io-index"
706
- checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da"
707
-
708
726
  [[package]]
709
727
  name = "regex-syntax"
710
728
  version = "0.8.2"
@@ -719,9 +737,9 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
719
737
 
720
738
  [[package]]
721
739
  name = "rustix"
722
- version = "0.38.28"
740
+ version = "0.38.34"
723
741
  source = "registry+https://github.com/rust-lang/crates.io-index"
724
- checksum = "72e572a5e8ca657d7366229cdde4bd14c4eb5499a9573d4d366fe1b599daa316"
742
+ checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f"
725
743
  dependencies = [
726
744
  "bitflags 2.4.1",
727
745
  "errno",
@@ -796,9 +814,9 @@ checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde"
796
814
 
797
815
  [[package]]
798
816
  name = "shlex"
799
- version = "1.2.0"
817
+ version = "1.3.0"
800
818
  source = "registry+https://github.com/rust-lang/crates.io-index"
801
- checksum = "a7cee0529a6d40f580e7a5e6c495c8fbfe21b7b52795ed4bb5e62cdf92bc6380"
819
+ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
802
820
 
803
821
  [[package]]
804
822
  name = "siphasher"
@@ -846,9 +864,9 @@ dependencies = [
846
864
 
847
865
  [[package]]
848
866
  name = "syntect"
849
- version = "5.1.0"
867
+ version = "5.2.0"
850
868
  source = "registry+https://github.com/rust-lang/crates.io-index"
851
- checksum = "e02b4b303bf8d08bfeb0445cba5068a3d306b6baece1d5582171a9bf49188f91"
869
+ checksum = "874dcfa363995604333cf947ae9f751ca3af4522c60886774c4963943b4746b1"
852
870
  dependencies = [
853
871
  "bincode",
854
872
  "bitflags 1.3.2",
@@ -858,14 +876,27 @@ dependencies = [
858
876
  "once_cell",
859
877
  "onig",
860
878
  "plist",
861
- "regex-syntax 0.7.5",
879
+ "regex-syntax",
862
880
  "serde",
881
+ "serde_derive",
863
882
  "serde_json",
864
883
  "thiserror",
865
884
  "walkdir",
866
885
  "yaml-rust",
867
886
  ]
868
887
 
888
+ [[package]]
889
+ name = "tempfile"
890
+ version = "3.10.1"
891
+ source = "registry+https://github.com/rust-lang/crates.io-index"
892
+ checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1"
893
+ dependencies = [
894
+ "cfg-if",
895
+ "fastrand",
896
+ "rustix",
897
+ "windows-sys 0.52.0",
898
+ ]
899
+
869
900
  [[package]]
870
901
  name = "terminal_size"
871
902
  version = "0.3.0"
data/README.md CHANGED
@@ -1,8 +1,5 @@
1
1
  # Commonmarker
2
2
 
3
- > **Note**
4
- > This README refers to the behavior in the new 1.0.0.pre gem.
5
-
6
3
  Ruby wrapper for Rust's [comrak](https://github.com/kivikakk/comrak) crate.
7
4
 
8
5
  It passes all of the CommonMark test suite, and is therefore spec-complete. It also includes extensions to the CommonMark spec as documented in the [GitHub Flavored Markdown spec](http://github.github.com/gfm/), such as support for tables, strikethroughs, and autolinking.
@@ -34,10 +31,108 @@ require 'commonmarker'
34
31
  Commonmarker.to_html('"Hi *there*"', options: {
35
32
  parse: { smart: true }
36
33
  })
37
- # <p>“Hi <em>there</em>”</p>\n
34
+ # => <p>“Hi <em>there</em>”</p>\n
35
+ ```
36
+
37
+ (The second argument is optional--[see below](#options-and-plugins) for more information.)
38
+
39
+ ### Generating a document
40
+
41
+ You can also parse a string to receive a `:document` node. You can then print that node to HTML, iterate over the children, and do other fun node stuff. For example:
42
+
43
+ ```ruby
44
+ require 'commonmarker'
45
+
46
+ doc = Commonmarker.parse("*Hello* world", options: {
47
+ parse: { smart: true }
48
+ })
49
+ puts(doc.to_html) # => <p><em>Hello</em> world</p>\n
50
+
51
+ doc.walk do |node|
52
+ puts node.type # => [:document, :paragraph, :emph, :text, :text]
53
+ end
38
54
  ```
39
55
 
40
- The second argument is optional--[see below](#options) for more information.
56
+ (The second argument is optional--[see below](#options-and-plugins) for more information.)
57
+
58
+ When it comes to modifying the document, you can perform the following operations:
59
+
60
+ - `insert_before`
61
+ - `insert_after`
62
+ - `prepend_child`
63
+ - `append_child`
64
+ - `delete`
65
+
66
+ You can also get the source position of a node by calling `source_position`:
67
+
68
+ ```ruby
69
+ doc = Commonmarker.parse("*Hello* world")
70
+ puts doc.first_child.first_child.source_position
71
+ # => {:start_line=>1, :start_column=>1, :end_line=>1, :end_column=>7}
72
+ ```
73
+
74
+ You can also modify the following attributes:
75
+
76
+ - `url`
77
+ - `title`
78
+ - `header_level`
79
+ - `list_type`
80
+ - `list_start`
81
+ - `list_tight`
82
+ - `fence_info`
83
+
84
+ #### Example: Walking the AST
85
+
86
+ You can use `walk` or `each` to iterate over nodes:
87
+
88
+ - `walk` will iterate on a node and recursively iterate on a node's children.
89
+ - `each` will iterate on a node and its children, but no further.
90
+
91
+ ```ruby
92
+ require 'commonmarker'
93
+
94
+ # parse some string
95
+ doc = Commonmarker.parse("# The site\n\n [GitHub](https://www.github.com)")
96
+
97
+ # Walk tree and print out URLs for links
98
+ doc.walk do |node|
99
+ if node.type == :link
100
+ printf("URL = %s\n", node.url)
101
+ end
102
+ end
103
+ # => URL = https://www.github.com
104
+
105
+ # Transform links to regular text
106
+ doc.walk do |node|
107
+ if node.type == :link
108
+ node.insert_before(node.first_child)
109
+ node.delete
110
+ end
111
+ end
112
+ # => <h1><a href=\"#the-site\"></a>The site</h1>\n<p>GitHub</p>\n
113
+ ```
114
+
115
+ #### Example: Converting a document back into raw CommonMark
116
+
117
+ You can use `to_commonmark` on a node to render it as raw text:
118
+
119
+ ```ruby
120
+ require 'commonmarker'
121
+
122
+ # parse some string
123
+ doc = Commonmarker.parse("# The site\n\n [GitHub](https://www.github.com)")
124
+
125
+ # Transform links to regular text
126
+ doc.walk do |node|
127
+ if node.type == :link
128
+ node.insert_before(node.first_child)
129
+ node.delete
130
+ end
131
+ end
132
+
133
+ doc.to_commonmark
134
+ # => # The site\n\nGitHub\n
135
+ ```
41
136
 
42
137
  ## Options and plugins
43
138
 
@@ -56,21 +151,23 @@ Note that there is a distinction in comrak for "parse" options and "render" opti
56
151
 
57
152
  ### Parse options
58
153
 
59
- | Name | Description | Default |
60
- | --------------------- | ------------------------------------------------------------------------------------ | ------- |
61
- | `smart` | Punctuation (quotes, full-stops and hyphens) are converted into 'smart' punctuation. | `false` |
62
- | `default_info_string` | The default info string for fenced code blocks. | `""` |
154
+ | Name | Description | Default |
155
+ | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | ------- |
156
+ | `smart` | Punctuation (quotes, full-stops and hyphens) are converted into 'smart' punctuation. | `false` |
157
+ | `default_info_string` | The default info string for fenced code blocks. | `""` |
158
+ | `relaxed_autolinks` | Enable relaxing of the autolink extension parsing, allowing links to be recognized when in brackets, as well as permitting any url scheme. | `false` |
63
159
 
64
160
  ### Render options
65
161
 
66
- | Name | Description | Default |
67
- | ----------------- | ------------------------------------------------------------------------------------------------------ | ------- |
68
- | `hardbreaks` | [Soft line breaks](http://spec.commonmark.org/0.27/#soft-line-breaks) translate into hard line breaks. | `true` |
69
- | `github_pre_lang` | GitHub-style `<pre lang="xyz">` is used for fenced code blocks with info tags. | `true` |
70
- | `width` | The wrap column when outputting CommonMark. | `80` |
71
- | `unsafe` | Allow rendering of raw HTML and potentially dangerous links. | `false` |
72
- | `escape` | Escape raw HTML instead of clobbering it. | `false` |
73
- | `sourcepos` | Include source position attribute in HTML and XML output. | `false` |
162
+ | Name | Description | Default |
163
+ | -------------------- | ------------------------------------------------------------------------------------------------------ | ------- |
164
+ | `hardbreaks` | [Soft line breaks](http://spec.commonmark.org/0.27/#soft-line-breaks) translate into hard line breaks. | `true` |
165
+ | `github_pre_lang` | GitHub-style `<pre lang="xyz">` is used for fenced code blocks with info tags. | `true` |
166
+ | `width` | The wrap column when outputting CommonMark. | `80` |
167
+ | `unsafe` | Allow rendering of raw HTML and potentially dangerous links. | `false` |
168
+ | `escape` | Escape raw HTML instead of clobbering it. | `false` |
169
+ | `sourcepos` | Include source position attribute in HTML and XML output. | `false` |
170
+ | `escaped_char_spans` | Wrap escaped characters in span tags | `true` |
74
171
 
75
172
  As well, there are several extensions which you can toggle in the same manner:
76
173
 
@@ -83,19 +180,21 @@ Commonmarker.to_html('"Hi *there*"', options: {
83
180
 
84
181
  ### Extension options
85
182
 
86
- | Name | Description | Default |
87
- | ------------------------ | ------------------------------------------------------------------------------------------------------------------- | ------- |
88
- | `strikethrough` | Enables the [strikethrough extension](https://github.github.com/gfm/#strikethrough-extension-) from the GFM spec. | `true` |
89
- | `tagfilter` | Enables the [tagfilter extension](https://github.github.com/gfm/#disallowed-raw-html-extension-) from the GFM spec. | `true` |
90
- | `table` | Enables the [table extension](https://github.github.com/gfm/#tables-extension-) from the GFM spec. | `true` |
91
- | `autolink` | Enables the [autolink extension](https://github.github.com/gfm/#autolinks-extension-) from the GFM spec. | `true` |
92
- | `tasklist` | Enables the [task list extension](https://github.github.com/gfm/#task-list-items-extension-) from the GFM spec. | `true` |
93
- | `superscript` | Enables the superscript Comrak extension. | `false` |
94
- | `header_ids` | Enables the header IDs Comrak extension. from the GFM spec. | `""` |
95
- | `footnotes` | Enables the footnotes extension per `cmark-gfm`. | `false` |
96
- | `description_lists` | Enables the description lists extension. | `false` |
97
- | `front_matter_delimiter` | Enables the front matter extension. | `""` |
98
- | `shortcodes` | Enables the shortcodes extension. | `true` |
183
+ | Name | Description | Default |
184
+ | --------------------------- | ------------------------------------------------------------------------------------------------------------------- | ------- |
185
+ | `strikethrough` | Enables the [strikethrough extension](https://github.github.com/gfm/#strikethrough-extension-) from the GFM spec. | `true` |
186
+ | `tagfilter` | Enables the [tagfilter extension](https://github.github.com/gfm/#disallowed-raw-html-extension-) from the GFM spec. | `true` |
187
+ | `table` | Enables the [table extension](https://github.github.com/gfm/#tables-extension-) from the GFM spec. | `true` |
188
+ | `autolink` | Enables the [autolink extension](https://github.github.com/gfm/#autolinks-extension-) from the GFM spec. | `true` |
189
+ | `tasklist` | Enables the [task list extension](https://github.github.com/gfm/#task-list-items-extension-) from the GFM spec. | `true` |
190
+ | `superscript` | Enables the superscript Comrak extension. | `false` |
191
+ | `header_ids` | Enables the header IDs Comrak extension. from the GFM spec. | `""` |
192
+ | `footnotes` | Enables the footnotes extension per `cmark-gfm`. | `false` |
193
+ | `description_lists` | Enables the description lists extension. | `false` |
194
+ | `front_matter_delimiter` | Enables the front matter extension. | `""` |
195
+ | `shortcodes` | Enables the shortcodes extension. | `true` |
196
+ | `multiline_block_quotes` | Enables the multiline block quotes extension. | `false` |
197
+ | `math_dollars`, `math_code` | Enables the math extension. | `false` |
99
198
 
100
199
  For more information on these options, see [the comrak documentation](https://github.com/kivikakk/comrak#usage).
101
200
 
@@ -205,26 +304,32 @@ If there were no errors, you're done! Otherwise, make sure to follow the comrak
205
304
 
206
305
  ## Benchmarks
207
306
 
208
- Some rough benchmarks:
209
-
210
307
  ```
211
- $ bundle exec rake benchmark
212
-
308
+ bundle exec rake benchmark
213
309
  input size = 11064832 bytes
214
310
 
311
+ ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
215
312
  Warming up --------------------------------------
216
- redcarpet 2.000 i/100ms
217
- commonmarker with to_html
218
- 1.000 i/100ms
219
- kramdown 1.000 i/100ms
313
+ Markly.render_html 1.000 i/100ms
314
+ Markly::Node#to_html 1.000 i/100ms
315
+ Commonmarker.to_html 1.000 i/100ms
316
+ Commonmarker::Node.to_html
317
+ 1.000 i/100ms
318
+ Kramdown::Document#to_html
319
+ 1.000 i/100ms
220
320
  Calculating -------------------------------------
221
- redcarpet 22.317 4.5%) i/s - 112.000 in 5.036374s
222
- commonmarker with to_html
223
- 5.815 (± 0.0%) i/s - 30.000 in 5.168869s
224
- kramdown 0.327 (± 0.0%) i/s - 2.000 in 6.121486s
321
+ Markly.render_html 15.606 25.6%) i/s - 71.000 in 5.047132s
322
+ Markly::Node#to_html 15.692 (±25.5%) i/s - 72.000 in 5.095810s
323
+ Commonmarker.to_html 4.482 (± 0.0%) i/s - 23.000 in 5.137680s
324
+ Commonmarker::Node.to_html
325
+ 5.092 (±19.6%) i/s - 25.000 in 5.072220s
326
+ Kramdown::Document#to_html
327
+ 0.379 (± 0.0%) i/s - 2.000 in 5.277770s
225
328
 
226
329
  Comparison:
227
- redcarpet: 22.3 i/s
228
- commonmarker with to_html: 5.8 i/s - 3.84x (± 0.00) slower
229
- kramdown: 0.3 i/s - 68.30x (± 0.00) slower
330
+ Markly::Node#to_html: 15.7 i/s
331
+ Markly.render_html: 15.6 i/s - same-ish: difference falls within error
332
+ Commonmarker::Node.to_html: 5.1 i/s - 3.08x slower
333
+ Commonmarker.to_html: 4.5 i/s - 3.50x slower
334
+ Kramdown::Document#to_html: 0.4 i/s - 41.40x slower
230
335
  ```
@@ -7,8 +7,10 @@ publish = false
7
7
 
8
8
  [dependencies]
9
9
  magnus = "0.6"
10
- comrak = { version = "0.20", features = ["shortcodes"] }
11
- syntect = { version = "5.1", features = ["plist-load"] }
10
+ comrak = { version = "0.23", features = ["shortcodes"] }
11
+ syntect = { version = "5.2", features = ["plist-load"] }
12
+ typed-arena = "2.0"
13
+ rctree = "0.6"
12
14
 
13
15
  [lib]
14
16
  name = "commonmarker"
@@ -5,13 +5,14 @@ use std::path::PathBuf;
5
5
  use ::syntect::highlighting::ThemeSet;
6
6
  use comrak::{
7
7
  adapters::SyntaxHighlighterAdapter,
8
- markdown_to_html, markdown_to_html_with_plugins,
8
+ markdown_to_html, markdown_to_html_with_plugins, parse_document,
9
9
  plugins::syntect::{SyntectAdapter, SyntectAdapterBuilder},
10
10
  ComrakOptions, ComrakPlugins,
11
11
  };
12
12
  use magnus::{
13
13
  define_module, exception, function, r_hash::ForEach, scan_args, Error, RHash, Symbol, Value,
14
14
  };
15
+ use node::CommonmarkerNode;
15
16
 
16
17
  mod options;
17
18
  use options::iterate_options_hash;
@@ -21,11 +22,36 @@ use plugins::{
21
22
  syntax_highlighting::{fetch_syntax_highlighter_path, fetch_syntax_highlighter_theme},
22
23
  SYNTAX_HIGHLIGHTER_PLUGIN,
23
24
  };
25
+ use typed_arena::Arena;
24
26
 
27
+ mod node;
25
28
  mod utils;
26
29
 
27
30
  pub const EMPTY_STR: &str = "";
28
31
 
32
+ fn commonmark_parse(args: &[Value]) -> Result<CommonmarkerNode, magnus::Error> {
33
+ let args = scan_args::scan_args::<_, (), (), (), _, ()>(args)?;
34
+ let (rb_commonmark,): (String,) = args.required;
35
+
36
+ let kwargs =
37
+ scan_args::get_kwargs::<_, (), (Option<RHash>,), ()>(args.keywords, &[], &["options"])?;
38
+ let (rb_options,) = kwargs.optional;
39
+
40
+ let mut comrak_options = ComrakOptions::default();
41
+
42
+ if let Some(rb_options) = rb_options {
43
+ rb_options.foreach(|key: Symbol, value: RHash| {
44
+ iterate_options_hash(&mut comrak_options, key, value)?;
45
+ Ok(ForEach::Continue)
46
+ })?;
47
+ }
48
+
49
+ let arena = Arena::new();
50
+ let root = parse_document(&arena, &rb_commonmark, &comrak_options);
51
+
52
+ CommonmarkerNode::new_from_comrak_node(root)
53
+ }
54
+
29
55
  fn commonmark_to_html(args: &[Value]) -> Result<String, magnus::Error> {
30
56
  let args = scan_args::scan_args::<_, (), (), (), _, ()>(args)?;
31
57
  let (rb_commonmark,): (String,) = args.required;
@@ -145,9 +171,13 @@ fn commonmark_to_html(args: &[Value]) -> Result<String, magnus::Error> {
145
171
 
146
172
  #[magnus::init]
147
173
  fn init() -> Result<(), Error> {
148
- let module = define_module("Commonmarker")?;
174
+ let m_commonmarker = define_module("Commonmarker")?;
175
+
176
+ m_commonmarker.define_module_function("commonmark_parse", function!(commonmark_parse, -1))?;
177
+ m_commonmarker
178
+ .define_module_function("commonmark_to_html", function!(commonmark_to_html, -1))?;
149
179
 
150
- module.define_module_function("commonmark_to_html", function!(commonmark_to_html, -1))?;
180
+ node::init(m_commonmarker).expect("cannot define Commonmarker::Node class");
151
181
 
152
182
  Ok(())
153
183
  }