commonmarker 1.1.5 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Cargo.lock +52 -42
- data/README.md +13 -10
- data/ext/commonmarker/Cargo.toml +1 -1
- data/ext/commonmarker/src/lib.rs +1 -1
- data/ext/commonmarker/src/node.rs +7 -1
- data/ext/commonmarker/src/options.rs +4 -0
- data/lib/commonmarker/config.rb +17 -27
- data/lib/commonmarker/utils.rb +6 -6
- data/lib/commonmarker/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f34122978a31574f369375ef0bcd288516170b280e5add662b6c7df86f0b95c
|
4
|
+
data.tar.gz: '05322807148242e0e6af2fd1e177f494771c153041053a75ab9f8913bfaa857f'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29139b3c80a3e0a94f3f58d64eca0237a9f85ef25b2c89f94422f61d6732db67ef008adcf173884b8e3b9abb917ade60727f58e3f067d0d9ad7d5fc532e37e9b
|
7
|
+
data.tar.gz: 213071ff9f1f00c45277ecfcb7399f751411afff459c59ff3c2eccc9434d3289e1a942f7c54beb237dcb338e81ca6f5f501e56d37ff169aeeaf1bb352f0ca863
|
data/Cargo.lock
CHANGED
@@ -128,6 +128,31 @@ version = "2.6.0"
|
|
128
128
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
129
129
|
checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
|
130
130
|
|
131
|
+
[[package]]
|
132
|
+
name = "bon"
|
133
|
+
version = "3.0.2"
|
134
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
135
|
+
checksum = "a636f83af97c6946f3f5cf5c268ec02375bf5efd371110292dfd57961f57a509"
|
136
|
+
dependencies = [
|
137
|
+
"bon-macros",
|
138
|
+
"rustversion",
|
139
|
+
]
|
140
|
+
|
141
|
+
[[package]]
|
142
|
+
name = "bon-macros"
|
143
|
+
version = "3.0.2"
|
144
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
145
|
+
checksum = "a7eaf1bfaa5b8d512abfd36d0c432591fef139d3de9ee54f1f839ea109d70d33"
|
146
|
+
dependencies = [
|
147
|
+
"darling",
|
148
|
+
"ident_case",
|
149
|
+
"prettyplease",
|
150
|
+
"proc-macro2",
|
151
|
+
"quote",
|
152
|
+
"rustversion",
|
153
|
+
"syn",
|
154
|
+
]
|
155
|
+
|
131
156
|
[[package]]
|
132
157
|
name = "bumpalo"
|
133
158
|
version = "3.16.0"
|
@@ -237,13 +262,13 @@ dependencies = [
|
|
237
262
|
|
238
263
|
[[package]]
|
239
264
|
name = "comrak"
|
240
|
-
version = "0.
|
265
|
+
version = "0.30.0"
|
241
266
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
242
|
-
checksum = "
|
267
|
+
checksum = "949f8e6b02ebac005a8be2df9ec0876cafc83fdb9c510796c37f0fadf92dcd0e"
|
243
268
|
dependencies = [
|
269
|
+
"bon",
|
244
270
|
"caseless",
|
245
271
|
"clap",
|
246
|
-
"derive_builder",
|
247
272
|
"emojis",
|
248
273
|
"entities",
|
249
274
|
"memchr",
|
@@ -310,37 +335,6 @@ dependencies = [
|
|
310
335
|
"powerfmt",
|
311
336
|
]
|
312
337
|
|
313
|
-
[[package]]
|
314
|
-
name = "derive_builder"
|
315
|
-
version = "0.20.0"
|
316
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
317
|
-
checksum = "0350b5cb0331628a5916d6c5c0b72e97393b8b6b03b47a9284f4e7f5a405ffd7"
|
318
|
-
dependencies = [
|
319
|
-
"derive_builder_macro",
|
320
|
-
]
|
321
|
-
|
322
|
-
[[package]]
|
323
|
-
name = "derive_builder_core"
|
324
|
-
version = "0.20.0"
|
325
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
326
|
-
checksum = "d48cda787f839151732d396ac69e3473923d54312c070ee21e9effcaa8ca0b1d"
|
327
|
-
dependencies = [
|
328
|
-
"darling",
|
329
|
-
"proc-macro2",
|
330
|
-
"quote",
|
331
|
-
"syn",
|
332
|
-
]
|
333
|
-
|
334
|
-
[[package]]
|
335
|
-
name = "derive_builder_macro"
|
336
|
-
version = "0.20.0"
|
337
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
338
|
-
checksum = "206868b8242f27cecce124c19fd88157fbd0dd334df2587f36417bafbc85097b"
|
339
|
-
dependencies = [
|
340
|
-
"derive_builder_core",
|
341
|
-
"syn",
|
342
|
-
]
|
343
|
-
|
344
338
|
[[package]]
|
345
339
|
name = "deunicode"
|
346
340
|
version = "1.6.0"
|
@@ -642,11 +636,21 @@ version = "0.2.0"
|
|
642
636
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
643
637
|
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
|
644
638
|
|
639
|
+
[[package]]
|
640
|
+
name = "prettyplease"
|
641
|
+
version = "0.2.25"
|
642
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
643
|
+
checksum = "64d1ec885c64d0457d564db4ec299b2dae3f9c02808b8ad9c3a089c591b18033"
|
644
|
+
dependencies = [
|
645
|
+
"proc-macro2",
|
646
|
+
"syn",
|
647
|
+
]
|
648
|
+
|
645
649
|
[[package]]
|
646
650
|
name = "proc-macro2"
|
647
|
-
version = "1.0.
|
651
|
+
version = "1.0.92"
|
648
652
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
649
|
-
checksum = "
|
653
|
+
checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0"
|
650
654
|
dependencies = [
|
651
655
|
"unicode-ident",
|
652
656
|
]
|
@@ -671,18 +675,18 @@ dependencies = [
|
|
671
675
|
|
672
676
|
[[package]]
|
673
677
|
name = "rb-sys"
|
674
|
-
version = "0.9.
|
678
|
+
version = "0.9.103"
|
675
679
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
676
|
-
checksum = "
|
680
|
+
checksum = "91dbe37ab6ac2fba187480fb6544b92445e41e5c6f553bf0c33743f3c450a1df"
|
677
681
|
dependencies = [
|
678
682
|
"rb-sys-build",
|
679
683
|
]
|
680
684
|
|
681
685
|
[[package]]
|
682
686
|
name = "rb-sys-build"
|
683
|
-
version = "0.9.
|
687
|
+
version = "0.9.103"
|
684
688
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
685
|
-
checksum = "
|
689
|
+
checksum = "c4d56a49dcb646b70b758789c0d16c055a386a4f2a3346333abb69850fa860ce"
|
686
690
|
dependencies = [
|
687
691
|
"bindgen",
|
688
692
|
"lazy_static",
|
@@ -753,6 +757,12 @@ dependencies = [
|
|
753
757
|
"windows-sys 0.52.0",
|
754
758
|
]
|
755
759
|
|
760
|
+
[[package]]
|
761
|
+
name = "rustversion"
|
762
|
+
version = "1.0.18"
|
763
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
764
|
+
checksum = "0e819f2bc632f285be6d7cd36e25940d45b2391dd6d9b939e79de557f7014248"
|
765
|
+
|
756
766
|
[[package]]
|
757
767
|
name = "ryu"
|
758
768
|
version = "1.0.18"
|
@@ -842,9 +852,9 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
|
842
852
|
|
843
853
|
[[package]]
|
844
854
|
name = "syn"
|
845
|
-
version = "2.0.
|
855
|
+
version = "2.0.89"
|
846
856
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
847
|
-
checksum = "
|
857
|
+
checksum = "44d46482f1c1c87acd84dea20c1bf5ebff4c757009ed6bf19cfd36fb10e92c4e"
|
848
858
|
dependencies = [
|
849
859
|
"proc-macro2",
|
850
860
|
"quote",
|
data/README.md
CHANGED
@@ -4,7 +4,10 @@ Ruby wrapper for Rust's [comrak](https://github.com/kivikakk/comrak) crate.
|
|
4
4
|
|
5
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.
|
6
6
|
|
7
|
-
|
7
|
+
> [!NOTE]
|
8
|
+
> By default, several extensions not in any spec have been enabled, for the sake of end user convenience when generating HTML.
|
9
|
+
>
|
10
|
+
> For more information on the available options and extensions, see [the documentation below](#options-and-plugins).
|
8
11
|
|
9
12
|
## Installation
|
10
13
|
|
@@ -86,7 +89,7 @@ You can also modify the following attributes:
|
|
86
89
|
You can use `walk` or `each` to iterate over nodes:
|
87
90
|
|
88
91
|
- `walk` will iterate on a node and recursively iterate on a node's children.
|
89
|
-
- `each` will iterate on a node
|
92
|
+
- `each` will iterate on a node's direct children, but no further.
|
90
93
|
|
91
94
|
```ruby
|
92
95
|
require 'commonmarker'
|
@@ -147,16 +150,16 @@ Commonmarker.to_html('"Hi *there*"', options:{
|
|
147
150
|
})
|
148
151
|
```
|
149
152
|
|
150
|
-
Note that there is a distinction in comrak for "parse" options and "render" options, which are represented in the tables below.
|
153
|
+
Note that there is a distinction in comrak for "parse" options and "render" options, which are represented in the tables below. As well, if you wish to disable any-non boolean option, pass in `nil`.
|
151
154
|
|
152
155
|
### Parse options
|
153
156
|
|
154
|
-
| Name
|
155
|
-
|
|
156
|
-
| `smart`
|
157
|
-
| `default_info_string`
|
158
|
-
| `relaxed_tasklist_matching`
|
159
|
-
| `relaxed_autolinks`
|
157
|
+
| Name | Description | Default |
|
158
|
+
| --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
|
159
|
+
| `smart` | Punctuation (quotes, full-stops and hyphens) are converted into 'smart' punctuation. | `false` |
|
160
|
+
| `default_info_string` | The default info string for fenced code blocks. | `""` |
|
161
|
+
| `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` |
|
162
|
+
| `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` |
|
160
163
|
|
161
164
|
### Render options
|
162
165
|
|
@@ -187,7 +190,7 @@ Commonmarker.to_html('"Hi *there*"', options: {
|
|
187
190
|
### Extension options
|
188
191
|
|
189
192
|
| Name | Description | Default |
|
190
|
-
|
|
193
|
+
| ----------------------------- | ------------------------------------------------------------------------------------------------------------------- | ------- |
|
191
194
|
| `strikethrough` | Enables the [strikethrough extension](https://github.github.com/gfm/#strikethrough-extension-) from the GFM spec. | `true` |
|
192
195
|
| `tagfilter` | Enables the [tagfilter extension](https://github.github.com/gfm/#disallowed-raw-html-extension-) from the GFM spec. | `true` |
|
193
196
|
| `table` | Enables the [table extension](https://github.github.com/gfm/#tables-extension-) from the GFM spec. | `true` |
|
data/ext/commonmarker/Cargo.toml
CHANGED
@@ -10,7 +10,7 @@ magnus = { version = "0.7", features = ["rb-sys"] }
|
|
10
10
|
rb-sys = { version = "*", default-features = false, features = [
|
11
11
|
"stable-api-compiled-fallback",
|
12
12
|
] }
|
13
|
-
comrak = { version = "0.
|
13
|
+
comrak = { version = "0.30", features = ["shortcodes"] }
|
14
14
|
syntect = { version = "5.2", features = ["plist-load"] }
|
15
15
|
typed-arena = "2.0"
|
16
16
|
rctree = "0.6"
|
data/ext/commonmarker/src/lib.rs
CHANGED
@@ -76,7 +76,7 @@ fn commonmark_to_html(args: &[Value]) -> Result<String, magnus::Error> {
|
|
76
76
|
))
|
77
77
|
}
|
78
78
|
|
79
|
-
fn format_options
|
79
|
+
fn format_options(rb_options: Option<RHash>) -> Result<comrak::Options, magnus::Error> {
|
80
80
|
let mut comrak_options = ComrakOptions::default();
|
81
81
|
|
82
82
|
if let Some(rb_options) = rb_options {
|
@@ -66,6 +66,7 @@ impl CommonmarkerNode {
|
|
66
66
|
Option<String>,
|
67
67
|
Option<u8>,
|
68
68
|
Option<bool>,
|
69
|
+
Option<bool>,
|
69
70
|
),
|
70
71
|
(),
|
71
72
|
>(
|
@@ -78,11 +79,12 @@ impl CommonmarkerNode {
|
|
78
79
|
"delimiter",
|
79
80
|
"bullet_char",
|
80
81
|
"tight",
|
82
|
+
"task_list",
|
81
83
|
],
|
82
84
|
)?;
|
83
85
|
|
84
86
|
let (list_type,) = kwargs.required;
|
85
|
-
let (marker_offset, padding, start, delimiter, bullet_char, tight) =
|
87
|
+
let (marker_offset, padding, start, delimiter, bullet_char, tight, task_list) =
|
86
88
|
kwargs.optional;
|
87
89
|
|
88
90
|
let commonmark_list_type = list_type.to_string();
|
@@ -121,6 +123,7 @@ impl CommonmarkerNode {
|
|
121
123
|
// Whether the list is [tight](https://github.github.com/gfm/#tight), i.e. whether the
|
122
124
|
// paragraphs are wrapped in `<p>` tags when formatted as HTML.
|
123
125
|
tight: tight.unwrap_or(false),
|
126
|
+
is_task_list: task_list.unwrap_or(false),
|
124
127
|
})
|
125
128
|
}
|
126
129
|
"description_list" => ComrakNodeValue::DescriptionList,
|
@@ -335,6 +338,7 @@ impl CommonmarkerNode {
|
|
335
338
|
"strong" => ComrakNodeValue::Strong,
|
336
339
|
"strikethrough" => ComrakNodeValue::Strikethrough,
|
337
340
|
"superscript" => ComrakNodeValue::Superscript,
|
341
|
+
"subscript" => ComrakNodeValue::Subscript,
|
338
342
|
"link" => {
|
339
343
|
let kwargs = scan_args::get_kwargs::<_, (String,), (Option<String>,), ()>(
|
340
344
|
args.keywords,
|
@@ -462,6 +466,7 @@ impl CommonmarkerNode {
|
|
462
466
|
|
463
467
|
ComrakNodeValue::WikiLink(NodeWikiLink { url })
|
464
468
|
}
|
469
|
+
|
465
470
|
_ => panic!("unknown node type {}", node_type),
|
466
471
|
};
|
467
472
|
|
@@ -550,6 +555,7 @@ impl CommonmarkerNode {
|
|
550
555
|
ComrakNodeValue::Math(..) => Symbol::new("math"),
|
551
556
|
ComrakNodeValue::WikiLink(..) => Symbol::new("wikilink"),
|
552
557
|
ComrakNodeValue::Underline => Symbol::new("underline"),
|
558
|
+
ComrakNodeValue::Subscript => Symbol::new("subscript"),
|
553
559
|
ComrakNodeValue::SpoileredText => Symbol::new("spoilered_text"),
|
554
560
|
ComrakNodeValue::EscapedTag(_) => Symbol::new("escaped_tag"),
|
555
561
|
}
|
@@ -116,6 +116,7 @@ const EXTENSION_WIKILINKS_TITLE_BEFORE_PIPE: &str = "wikilinks_title_before_pipe
|
|
116
116
|
const EXTENSION_UNDERLINE: &str = "underline";
|
117
117
|
const EXTENSION_SPOILER: &str = "spoiler";
|
118
118
|
const EXTENSION_GREENTEXT: &str = "greentext";
|
119
|
+
const EXTENSION_SUBSCRIPT: &str = "subscript";
|
119
120
|
|
120
121
|
fn iterate_extension_options(comrak_options: &mut ComrakOptions, options_hash: RHash) {
|
121
122
|
options_hash
|
@@ -185,6 +186,9 @@ fn iterate_extension_options(comrak_options: &mut ComrakOptions, options_hash: R
|
|
185
186
|
Ok(Cow::Borrowed(EXTENSION_GREENTEXT)) => {
|
186
187
|
comrak_options.extension.greentext = TryConvert::try_convert(value)?;
|
187
188
|
}
|
189
|
+
Ok(Cow::Borrowed(EXTENSION_SUBSCRIPT)) => {
|
190
|
+
comrak_options.extension.subscript = TryConvert::try_convert(value)?;
|
191
|
+
}
|
188
192
|
_ => {}
|
189
193
|
}
|
190
194
|
Ok(ForEach::Continue)
|
data/lib/commonmarker/config.rb
CHANGED
@@ -45,7 +45,8 @@ module Commonmarker
|
|
45
45
|
underline: false,
|
46
46
|
spoiler: false,
|
47
47
|
greentext: false,
|
48
|
-
|
48
|
+
subscript: false,
|
49
|
+
}.freeze,
|
49
50
|
format: [:html].freeze,
|
50
51
|
}.freeze
|
51
52
|
|
@@ -59,15 +60,11 @@ module Commonmarker
|
|
59
60
|
class << self
|
60
61
|
include Commonmarker::Utils
|
61
62
|
|
62
|
-
def merged_with_defaults(options)
|
63
|
-
Commonmarker::Config::OPTIONS.merge(process_options(options))
|
64
|
-
end
|
65
|
-
|
66
63
|
def process_options(options)
|
67
64
|
{
|
68
|
-
parse: process_parse_options(options[:parse]),
|
69
|
-
render: process_render_options(options[:render]),
|
70
|
-
extension: process_extension_options(options[:extension]),
|
65
|
+
parse: process_parse_options(options[:parse].dup),
|
66
|
+
render: process_render_options(options[:render].dup),
|
67
|
+
extension: process_extension_options(options[:extension].dup),
|
71
68
|
}
|
72
69
|
end
|
73
70
|
|
@@ -79,37 +76,30 @@ module Commonmarker
|
|
79
76
|
end
|
80
77
|
|
81
78
|
[:parse, :render, :extension].each do |type|
|
82
|
-
define_singleton_method :"process_#{type}_options" do |
|
79
|
+
define_singleton_method :"process_#{type}_options" do |options|
|
83
80
|
Commonmarker::Config::OPTIONS[type].each_with_object({}) do |(key, value), hash|
|
84
|
-
if
|
81
|
+
if options.nil? || !options.key?(key) # option not provided, use the default
|
85
82
|
hash[key] = value
|
86
83
|
next
|
87
84
|
end
|
88
85
|
|
89
|
-
# option explicitly not included, remove it
|
90
|
-
|
86
|
+
if options[key].nil? # # option explicitly not included, remove it
|
87
|
+
options.delete(key)
|
88
|
+
next
|
89
|
+
end
|
91
90
|
|
92
|
-
hash[key] = fetch_kv(
|
91
|
+
hash[key] = fetch_kv(options, key, value, type)
|
93
92
|
end
|
94
93
|
end
|
95
94
|
end
|
96
95
|
|
97
|
-
|
98
|
-
|
99
|
-
return if plugin.nil? # plugin explicitly nil, remove it
|
96
|
+
define_singleton_method :process_syntax_highlighter_plugin do |options|
|
97
|
+
return if options.nil? # plugin explicitly nil, remove it
|
100
98
|
|
101
|
-
|
102
|
-
|
103
|
-
hash[key] = value
|
104
|
-
next
|
105
|
-
end
|
99
|
+
raise TypeError, "Expected a Hash for syntax_highlighter plugin, got #{options.class}" unless options.is_a?(Hash)
|
100
|
+
raise TypeError, "Expected a Hash for syntax_highlighter plugin, got nothing" if options.empty?
|
106
101
|
|
107
|
-
|
108
|
-
next if plugin[key].nil?
|
109
|
-
|
110
|
-
hash[key] = fetch_kv(plugin, key, value, type)
|
111
|
-
end
|
112
|
-
end
|
102
|
+
Commonmarker::Config::PLUGINS[:syntax_highlighter].merge(options)
|
113
103
|
end
|
114
104
|
end
|
115
105
|
end
|
data/lib/commonmarker/utils.rb
CHANGED
@@ -6,16 +6,16 @@ module Commonmarker
|
|
6
6
|
module Utils
|
7
7
|
include Commonmarker::Constants
|
8
8
|
|
9
|
-
def fetch_kv(
|
9
|
+
def fetch_kv(options, key, value, type)
|
10
10
|
value_klass = value.class
|
11
11
|
|
12
|
-
if Constants::BOOLS.include?(value) && BOOLS.include?(
|
13
|
-
|
14
|
-
elsif
|
15
|
-
|
12
|
+
if Constants::BOOLS.include?(value) && BOOLS.include?(options[key])
|
13
|
+
options[key]
|
14
|
+
elsif options[key].is_a?(value_klass)
|
15
|
+
options[key]
|
16
16
|
else
|
17
17
|
expected_type = Constants::BOOLS.include?(value) ? "Boolean" : value_klass.to_s
|
18
|
-
raise TypeError, "#{type} option `:#{key}` must be #{expected_type}; got #{
|
18
|
+
raise TypeError, "#{type} option `:#{key}` must be #{expected_type}; got #{options[key].class}"
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
data/lib/commonmarker/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: commonmarker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Garen Torikian
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2024-
|
12
|
+
date: 2024-11-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rb_sys
|