commonmarker 1.1.3 → 1.1.5
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 +186 -195
- data/README.md +33 -22
- data/ext/commonmarker/Cargo.toml +2 -2
- data/ext/commonmarker/src/lib.rs +31 -111
- data/ext/commonmarker/src/node.rs +72 -30
- data/ext/commonmarker/src/options.rs +51 -4
- data/ext/commonmarker/src/plugins/syntax_highlighting.rs +99 -7
- data/ext/commonmarker/src/plugins.rs +3 -0
- data/lib/commonmarker/config.rb +12 -1
- data/lib/commonmarker/version.rb +1 -1
- metadata +2 -2
@@ -1,14 +1,106 @@
|
|
1
1
|
use std::path::PathBuf;
|
2
2
|
|
3
|
+
use comrak::plugins::syntect::{SyntectAdapter, SyntectAdapterBuilder};
|
4
|
+
|
3
5
|
use magnus::value::ReprValue;
|
4
|
-
use magnus::{RHash, Symbol, TryConvert, Value};
|
6
|
+
use magnus::{exception, RHash, Symbol, TryConvert, Value};
|
7
|
+
use syntect::highlighting::ThemeSet;
|
5
8
|
|
6
9
|
use crate::EMPTY_STR;
|
7
10
|
|
8
|
-
pub
|
9
|
-
|
11
|
+
pub fn construct_syntax_highlighter_from_plugin(
|
12
|
+
rb_plugins: Option<RHash>,
|
13
|
+
) -> Result<Option<SyntectAdapter>, magnus::Error> {
|
14
|
+
match rb_plugins {
|
15
|
+
None => Ok(None),
|
16
|
+
Some(rb_plugins) => {
|
17
|
+
let theme = match rb_plugins.get(Symbol::new(super::SYNTAX_HIGHLIGHTER_PLUGIN)) {
|
18
|
+
Some(syntax_highlighter_options) => {
|
19
|
+
match fetch_syntax_highlighter_theme(syntax_highlighter_options) {
|
20
|
+
Ok(theme) => theme,
|
21
|
+
Err(e) => {
|
22
|
+
return Err(e);
|
23
|
+
}
|
24
|
+
}
|
25
|
+
}
|
26
|
+
None => None, // no `syntax_highlighter:` defined
|
27
|
+
};
|
28
|
+
|
29
|
+
let adapter: SyntectAdapter;
|
30
|
+
|
31
|
+
match theme {
|
32
|
+
None => Ok(None),
|
33
|
+
Some(theme) => {
|
34
|
+
if theme.is_empty() {
|
35
|
+
// no theme? uss css classes
|
36
|
+
adapter = SyntectAdapter::new(None);
|
37
|
+
Ok(Some(adapter))
|
38
|
+
} 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
|
+
};
|
46
|
+
|
47
|
+
if path.exists() {
|
48
|
+
if !path.is_dir() {
|
49
|
+
return Err(magnus::Error::new(
|
50
|
+
exception::arg_error(),
|
51
|
+
"`path` needs to be a directory",
|
52
|
+
));
|
53
|
+
}
|
54
|
+
|
55
|
+
let builder = SyntectAdapterBuilder::new();
|
56
|
+
let mut ts = ThemeSet::load_defaults();
|
57
|
+
|
58
|
+
match ts.add_from_folder(&path) {
|
59
|
+
Ok(_) => {}
|
60
|
+
Err(e) => {
|
61
|
+
return Err(magnus::Error::new(
|
62
|
+
exception::arg_error(),
|
63
|
+
format!("failed to load theme set from path: {e}"),
|
64
|
+
));
|
65
|
+
}
|
66
|
+
}
|
67
|
+
|
68
|
+
// check if the theme exists in the dir
|
69
|
+
match ts.themes.get(&theme) {
|
70
|
+
Some(theme) => theme,
|
71
|
+
None => {
|
72
|
+
return Err(magnus::Error::new(
|
73
|
+
exception::arg_error(),
|
74
|
+
format!("theme `{}` does not exist", theme),
|
75
|
+
));
|
76
|
+
}
|
77
|
+
};
|
78
|
+
|
79
|
+
adapter = builder.theme_set(ts).theme(&theme).build();
|
80
|
+
|
81
|
+
Ok(Some(adapter))
|
82
|
+
} else {
|
83
|
+
// no path? default theme lookup
|
84
|
+
ThemeSet::load_defaults()
|
85
|
+
.themes
|
86
|
+
.get(&theme)
|
87
|
+
.ok_or_else(|| {
|
88
|
+
magnus::Error::new(
|
89
|
+
exception::arg_error(),
|
90
|
+
format!("theme `{}` does not exist", theme),
|
91
|
+
)
|
92
|
+
})?;
|
93
|
+
adapter = SyntectAdapter::new(Some(&theme));
|
94
|
+
Ok(Some(adapter))
|
95
|
+
}
|
96
|
+
}
|
97
|
+
}
|
98
|
+
}
|
99
|
+
}
|
100
|
+
}
|
101
|
+
}
|
10
102
|
|
11
|
-
|
103
|
+
fn fetch_syntax_highlighter_theme(value: Value) -> Result<Option<String>, magnus::Error> {
|
12
104
|
if value.is_nil() {
|
13
105
|
// `syntax_highlighter: nil`
|
14
106
|
return Ok(None);
|
@@ -29,7 +121,7 @@ pub fn fetch_syntax_highlighter_theme(value: Value) -> Result<Option<String>, ma
|
|
29
121
|
));
|
30
122
|
}
|
31
123
|
|
32
|
-
let theme_key = Symbol::new(SYNTAX_HIGHLIGHTER_PLUGIN_THEME_KEY);
|
124
|
+
let theme_key = Symbol::new(super::SYNTAX_HIGHLIGHTER_PLUGIN_THEME_KEY);
|
33
125
|
|
34
126
|
match syntax_highlighter_plugin.get(theme_key) {
|
35
127
|
Some(theme) => {
|
@@ -48,14 +140,14 @@ pub fn fetch_syntax_highlighter_theme(value: Value) -> Result<Option<String>, ma
|
|
48
140
|
}
|
49
141
|
}
|
50
142
|
|
51
|
-
|
143
|
+
fn fetch_syntax_highlighter_path(value: Value) -> Result<PathBuf, magnus::Error> {
|
52
144
|
if value.is_nil() {
|
53
145
|
// `syntax_highlighter: nil`
|
54
146
|
return Ok(PathBuf::from(EMPTY_STR));
|
55
147
|
}
|
56
148
|
|
57
149
|
let syntax_highlighter_plugin: RHash = TryConvert::try_convert(value)?;
|
58
|
-
let path_key = Symbol::new(SYNTAX_HIGHLIGHTER_PLUGIN_PATH_KEY);
|
150
|
+
let path_key = Symbol::new(super::SYNTAX_HIGHLIGHTER_PLUGIN_PATH_KEY);
|
59
151
|
|
60
152
|
match syntax_highlighter_plugin.get(path_key) {
|
61
153
|
Some(path) => {
|
data/lib/commonmarker/config.rb
CHANGED
@@ -8,16 +8,22 @@ module Commonmarker
|
|
8
8
|
parse: {
|
9
9
|
smart: false,
|
10
10
|
default_info_string: "",
|
11
|
+
relaxed_tasklist_matching: false,
|
11
12
|
relaxed_autolinks: false,
|
12
13
|
}.freeze,
|
13
14
|
render: {
|
14
15
|
hardbreaks: true,
|
15
16
|
github_pre_lang: true,
|
17
|
+
full_info_string: false,
|
16
18
|
width: 80,
|
17
19
|
unsafe: false,
|
18
20
|
escape: false,
|
19
21
|
sourcepos: false,
|
20
22
|
escaped_char_spans: true,
|
23
|
+
ignore_setext: false,
|
24
|
+
ignore_empty_links: false,
|
25
|
+
gfm_quirks: false,
|
26
|
+
prefer_fenced: false,
|
21
27
|
}.freeze,
|
22
28
|
extension: {
|
23
29
|
strikethrough: true,
|
@@ -30,10 +36,15 @@ module Commonmarker
|
|
30
36
|
footnotes: false,
|
31
37
|
description_lists: false,
|
32
38
|
front_matter_delimiter: "",
|
33
|
-
shortcodes: true,
|
34
39
|
multiline_block_quotes: false,
|
35
40
|
math_dollars: false,
|
36
41
|
math_code: false,
|
42
|
+
shortcodes: true,
|
43
|
+
wikilinks_title_before_pipe: false,
|
44
|
+
wikilinks_title_after_pipe: false,
|
45
|
+
underline: false,
|
46
|
+
spoiler: false,
|
47
|
+
greentext: false,
|
37
48
|
},
|
38
49
|
format: [:html].freeze,
|
39
50
|
}.freeze
|
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: 1.1.
|
4
|
+
version: 1.1.5
|
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-07-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rb_sys
|