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.
data/README.md CHANGED
@@ -156,12 +156,13 @@ Note that there is a distinction in comrak for "parse" options and "render" opti
156
156
 
157
157
  ### Parse options
158
158
 
159
- | Name | Description | Default |
160
- | --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
161
- | `smart` | Punctuation (quotes, full-stops and hyphens) are converted into 'smart' punctuation. | `false` |
162
- | `default_info_string` | The default info string for fenced code blocks. | `""` |
163
- | `relaxed_tasklist_matching` | Enables relaxing of the tasklist extension matching, allowing any non-space to be used for the "checked" state instead of only `x` and `X`. | `false` |
164
- | `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` |
159
+ | Name | Description | Default |
160
+ | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
161
+ | `smart` | Punctuation (quotes, full-stops and hyphens) are converted into 'smart' punctuation. | `false` |
162
+ | `default_info_string` | The default info string for fenced code blocks. | `""` |
163
+ | `relaxed_tasklist_matching` | Enables relaxing of the tasklist extension matching, allowing any non-space to be used for the "checked" state instead of only `x` and `X`. | `false` |
164
+ | `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` |
165
+ | `leave_footnote_definitions` | Allow footnote definitions to remain in their original positions instead of being moved to the document's end (only affects AST) | `false` |
165
166
 
166
167
  ### Render options
167
168
 
@@ -213,9 +214,11 @@ Commonmarker.to_html('"Hi *there*"', options: {
213
214
  | `underline` | Enables the underline extension. | `false` |
214
215
  | `spoiler` | Enables the spoiler extension. | `false` |
215
216
  | `greentext` | Enables the greentext extension. | `false` |
217
+ | `subtext` | Enables the subtext extension. | `false` |
216
218
  | `subscript` | Enables the subscript extension. | `false` |
217
219
  | `alerts` | Enables the alerts extension. | `false` |
218
220
  | `cjk_friendly_emphasis` | Enables the [CJK friendly emphasis](https://github.com/tats-u/markdown-cjk-friendly) extension. | `false` |
221
+ | `highlight` | Enables highlighting via `==` | `false` |
219
222
 
220
223
  For more information on these options, see [the comrak documentation](https://github.com/kivikakk/comrak#usage).
221
224
 
@@ -10,7 +10,7 @@ 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.44", features = ["shortcodes"] }
13
+ comrak = { version = "0.48", features = ["shortcodes"] }
14
14
  syntect = { version = "5.3", features = ["plist-load"] }
15
15
  typed-arena = "2.0"
16
16
  rctree = "0.6"
@@ -1,17 +1,18 @@
1
1
  extern crate core;
2
2
 
3
- use comrak::{markdown_to_html_with_plugins, parse_document, ComrakOptions};
4
- use magnus::{function, r_hash::ForEach, scan_args, Error, RHash, Symbol, Value};
3
+ use comrak::{markdown_to_html_with_plugins, parse_document};
4
+ use magnus::{function, scan_args, RHash, Ruby, Value};
5
5
  use node::CommonmarkerNode;
6
6
  use plugins::syntax_highlighting::construct_syntax_highlighter_from_plugin;
7
7
 
8
8
  mod options;
9
- use options::iterate_options_hash;
10
9
 
11
10
  mod plugins;
12
11
 
13
12
  use typed_arena::Arena;
14
13
 
14
+ use crate::options::{iterate_extension_options, iterate_parse_options, iterate_render_options};
15
+
15
16
  mod node;
16
17
  mod utils;
17
18
 
@@ -21,18 +22,32 @@ fn commonmark_parse(args: &[Value]) -> Result<CommonmarkerNode, magnus::Error> {
21
22
  let args = scan_args::scan_args::<_, (), (), (), _, ()>(args)?;
22
23
  let (rb_commonmark,): (String,) = args.required;
23
24
 
24
- let kwargs =
25
- scan_args::get_kwargs::<_, (), (Option<RHash>,), ()>(args.keywords, &[], &["options"])?;
26
- let (rb_options,) = kwargs.optional;
25
+ let kwargs = scan_args::get_kwargs::<_, (), (Option<RHash>, Option<RHash>, Option<RHash>), ()>(
26
+ args.keywords,
27
+ &[],
28
+ &["parse", "render", "extension"],
29
+ )?;
30
+ let (rb_parse, rb_render, rb_extension) = kwargs.optional;
27
31
 
28
- let mut comrak_options = ComrakOptions::default();
32
+ let mut comrak_parse_options = comrak::options::Parse::default();
33
+ let mut comrak_render_options = comrak::options::Render::default();
34
+ let mut comrak_extension_options = comrak::options::Extension::default();
29
35
 
30
- if let Some(rb_options) = rb_options {
31
- rb_options.foreach(|key: Symbol, value: RHash| {
32
- iterate_options_hash(&mut comrak_options, key, value)?;
33
- Ok(ForEach::Continue)
34
- })?;
36
+ if let Some(rb_parse) = rb_parse {
37
+ iterate_parse_options(&mut comrak_parse_options, rb_parse);
38
+ }
39
+ if let Some(rb_render) = rb_render {
40
+ iterate_render_options(&mut comrak_render_options, rb_render);
35
41
  }
42
+ if let Some(rb_extension) = rb_extension {
43
+ iterate_extension_options(&mut comrak_extension_options, rb_extension);
44
+ }
45
+
46
+ let comrak_options = comrak::Options {
47
+ parse: comrak_parse_options,
48
+ render: comrak_render_options,
49
+ extension: comrak_extension_options,
50
+ };
36
51
 
37
52
  let arena = Arena::new();
38
53
  let root = parse_document(&arena, &rb_commonmark, &comrak_options);
@@ -40,22 +55,39 @@ fn commonmark_parse(args: &[Value]) -> Result<CommonmarkerNode, magnus::Error> {
40
55
  CommonmarkerNode::new_from_comrak_node(root)
41
56
  }
42
57
 
43
- fn commonmark_to_html(args: &[Value]) -> Result<String, magnus::Error> {
58
+ fn commonmark_to_html(ruby: &Ruby, args: &[Value]) -> Result<String, magnus::Error> {
44
59
  let args = scan_args::scan_args::<_, (), (), (), _, ()>(args)?;
45
60
  let (rb_commonmark,): (String,) = args.required;
46
61
 
47
- let kwargs = scan_args::get_kwargs::<_, (), (Option<RHash>, Option<RHash>), ()>(
62
+ let kwargs = scan_args::get_kwargs::<
63
+ _,
64
+ (),
65
+ (Option<RHash>, Option<RHash>, Option<RHash>, Option<RHash>),
66
+ (),
67
+ >(
48
68
  args.keywords,
49
69
  &[],
50
- &["options", "plugins"],
70
+ &["render", "parse", "extension", "plugins"],
51
71
  )?;
52
- let (rb_options, rb_plugins) = kwargs.optional;
72
+ let (rb_render, rb_parse, rb_extension, rb_plugins) = kwargs.optional;
53
73
 
54
- let comrak_options = format_options(rb_options)?;
74
+ let mut comrak_parse_options = comrak::options::Parse::default();
75
+ let mut comrak_render_options = comrak::options::Render::default();
76
+ let mut comrak_extension_options = comrak::options::Extension::default();
55
77
 
56
- let mut comrak_plugins = comrak::Plugins::default();
78
+ if let Some(rb_parse) = rb_parse {
79
+ iterate_parse_options(&mut comrak_parse_options, rb_parse);
80
+ }
81
+ if let Some(rb_render) = rb_render {
82
+ iterate_render_options(&mut comrak_render_options, rb_render);
83
+ }
84
+ if let Some(rb_extension) = rb_extension {
85
+ iterate_extension_options(&mut comrak_extension_options, rb_extension);
86
+ }
87
+
88
+ let mut comrak_plugins = comrak::options::Plugins::default();
57
89
 
58
- let syntect_adapter = match construct_syntax_highlighter_from_plugin(rb_plugins) {
90
+ let syntect_adapter = match construct_syntax_highlighter_from_plugin(ruby, rb_plugins) {
59
91
  Ok(Some(adapter)) => Some(adapter),
60
92
  Ok(None) => None,
61
93
  Err(err) => return Err(err),
@@ -66,6 +98,12 @@ fn commonmark_to_html(args: &[Value]) -> Result<String, magnus::Error> {
66
98
  None => comrak_plugins.render.codefence_syntax_highlighter = None,
67
99
  }
68
100
 
101
+ let comrak_options = comrak::Options {
102
+ parse: comrak_parse_options,
103
+ render: comrak_render_options,
104
+ extension: comrak_extension_options,
105
+ };
106
+
69
107
  Ok(markdown_to_html_with_plugins(
70
108
  &rb_commonmark,
71
109
  &comrak_options,
@@ -73,29 +111,15 @@ fn commonmark_to_html(args: &[Value]) -> Result<String, magnus::Error> {
73
111
  ))
74
112
  }
75
113
 
76
- fn format_options<'c>(rb_options: Option<RHash>) -> Result<comrak::Options<'c>, magnus::Error> {
77
- let mut comrak_options = ComrakOptions::default();
78
-
79
- if let Some(rb_options) = rb_options {
80
- rb_options.foreach(|key: Symbol, value: RHash| {
81
- iterate_options_hash(&mut comrak_options, key, value)?;
82
- Ok(ForEach::Continue)
83
- })?;
84
- }
85
-
86
- Ok(comrak_options)
87
- }
88
-
89
114
  #[magnus::init]
90
- fn init() -> Result<(), Error> {
91
- let ruby = magnus::Ruby::get().unwrap();
115
+ fn init(ruby: &Ruby) -> Result<(), magnus::Error> {
92
116
  let m_commonmarker = ruby.define_module("Commonmarker")?;
93
117
 
94
118
  m_commonmarker.define_module_function("commonmark_parse", function!(commonmark_parse, -1))?;
95
119
  m_commonmarker
96
120
  .define_module_function("commonmark_to_html", function!(commonmark_to_html, -1))?;
97
121
 
98
- node::init(m_commonmarker).expect("cannot define Commonmarker::Node class");
122
+ node::init(ruby, m_commonmarker).expect("cannot define Commonmarker::Node class");
99
123
 
100
124
  Ok(())
101
125
  }