commonmarker 2.3.1 → 2.4.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.
- checksums.yaml +4 -4
- data/Cargo.lock +238 -189
- data/README.md +2 -1
- data/ext/commonmarker/Cargo.toml +2 -2
- data/ext/commonmarker/src/lib.rs +4 -6
- data/ext/commonmarker/src/node.rs +96 -77
- data/ext/commonmarker/src/options.rs +8 -2
- data/ext/commonmarker/src/plugins/syntax_highlighting.rs +21 -17
- data/lib/commonmarker/config.rb +1 -0
- data/lib/commonmarker/version.rb +1 -1
- metadata +2 -2
|
@@ -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::{
|
|
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
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
122
|
+
ruby.exception_type_error(),
|
|
120
123
|
"theme cannot be blank hash",
|
|
121
124
|
));
|
|
122
125
|
}
|
|
123
126
|
|
|
124
|
-
let 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
|
-
|
|
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
|
|
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) => {
|
data/lib/commonmarker/config.rb
CHANGED
data/lib/commonmarker/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: commonmarker
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Garen Torikian
|
|
8
8
|
- Ashe Connor
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2025-
|
|
11
|
+
date: 2025-09-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rb_sys
|