commonmarker 1.0.0.pre6-x86_64-linux → 1.0.0.pre8-x86_64-linux
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +43 -20
- data/lib/commonmarker/3.1/commonmarker.so +0 -0
- data/lib/commonmarker/3.2/commonmarker.so +0 -0
- data/lib/commonmarker/config.rb +3 -1
- data/lib/commonmarker/version.rb +1 -1
- metadata +3 -41
- data/Cargo.lock +0 -1058
- data/commonmarker.gemspec +0 -41
- data/ext/commonmarker/Cargo.toml +0 -12
- data/ext/commonmarker/extconf.rb +0 -6
- data/ext/commonmarker/src/lib.rs +0 -85
- data/ext/commonmarker/src/options.rs +0 -130
- data/ext/commonmarker/src/plugins/syntax_highlighting.rs +0 -30
- data/ext/commonmarker/src/plugins.rs +0 -21
- data/ext/commonmarker/src/utils.rs +0 -8
data/commonmarker.gemspec
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
lib = File.expand_path("lib", __dir__)
|
4
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
require "commonmarker/version"
|
6
|
-
|
7
|
-
Gem::Specification.new do |spec|
|
8
|
-
spec.name = "commonmarker"
|
9
|
-
spec.version = Commonmarker::VERSION
|
10
|
-
spec.summary = "CommonMark parser and renderer. Written in Rust, wrapped in Ruby."
|
11
|
-
spec.description = "A fast, safe, extensible parser for CommonMark. This wraps the comrak Rust crate."
|
12
|
-
spec.authors = ["Garen Torikian", "Ashe Connor"]
|
13
|
-
spec.license = "MIT"
|
14
|
-
spec.homepage = "https://github.com/gjtorikian/commonmarker"
|
15
|
-
|
16
|
-
spec.required_ruby_version = "~> 3.1"
|
17
|
-
# https://github.com/rubygems/rubygems/pull/5852#issuecomment-1231118509
|
18
|
-
spec.required_rubygems_version = ">= 3.3.22"
|
19
|
-
|
20
|
-
spec.files = ["LICENSE.txt", "README.md", "commonmarker.gemspec", "Cargo.lock"]
|
21
|
-
spec.files += Dir.glob("lib/**/*.rb")
|
22
|
-
spec.files += Dir.glob("ext/**/*.{rs,toml,lock,rb}")
|
23
|
-
spec.bindir = "exe"
|
24
|
-
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
25
|
-
|
26
|
-
spec.require_paths = ["lib"]
|
27
|
-
spec.extensions = ["ext/commonmarker/extconf.rb"]
|
28
|
-
|
29
|
-
spec.metadata = {
|
30
|
-
"allowed_push_host" => "https://rubygems.org",
|
31
|
-
"funding_uri" => "https://github.com/sponsors/gjtorikian/",
|
32
|
-
"source_code_uri" => "https://github.com/gjtorikian/commonmarker",
|
33
|
-
"rubygems_mfa_required" => "true",
|
34
|
-
}
|
35
|
-
|
36
|
-
spec.add_dependency("rb_sys", "~> 0.9")
|
37
|
-
|
38
|
-
spec.add_development_dependency("rake", "~> 13.0")
|
39
|
-
spec.add_development_dependency("rake-compiler", "~> 1.2")
|
40
|
-
spec.add_development_dependency("rake-compiler-dock", "~> 1.2")
|
41
|
-
end
|
data/ext/commonmarker/Cargo.toml
DELETED
data/ext/commonmarker/extconf.rb
DELETED
data/ext/commonmarker/src/lib.rs
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
extern crate core;
|
2
|
-
|
3
|
-
use comrak::{
|
4
|
-
adapters::SyntaxHighlighterAdapter, markdown_to_html, markdown_to_html_with_plugins,
|
5
|
-
plugins::syntect::SyntectAdapter, ComrakOptions, ComrakPlugins,
|
6
|
-
};
|
7
|
-
use magnus::{define_module, function, r_hash::ForEach, scan_args, Error, RHash, Symbol, Value};
|
8
|
-
|
9
|
-
mod options;
|
10
|
-
use options::iterate_options_hash;
|
11
|
-
|
12
|
-
mod plugins;
|
13
|
-
use plugins::{
|
14
|
-
syntax_highlighting::{
|
15
|
-
fetch_syntax_highlighter_theme, SYNTAX_HIGHLIGHTER_PLUGIN_DEFAULT_THEME,
|
16
|
-
},
|
17
|
-
SYNTAX_HIGHLIGHTER_PLUGIN,
|
18
|
-
};
|
19
|
-
|
20
|
-
mod utils;
|
21
|
-
|
22
|
-
pub const EMPTY_STR: &str = "";
|
23
|
-
|
24
|
-
fn commonmark_to_html<'a>(args: &[Value]) -> Result<String, magnus::Error> {
|
25
|
-
let args = scan_args::scan_args(args)?;
|
26
|
-
let (rb_commonmark,): (String,) = args.required;
|
27
|
-
let _: () = args.optional;
|
28
|
-
let _: () = args.splat;
|
29
|
-
let _: () = args.trailing;
|
30
|
-
let _: () = args.block;
|
31
|
-
|
32
|
-
let kwargs = scan_args::get_kwargs::<_, (), (Option<RHash>, Option<RHash>), ()>(
|
33
|
-
args.keywords,
|
34
|
-
&[],
|
35
|
-
&["options", "plugins"],
|
36
|
-
)?;
|
37
|
-
let (rb_options, rb_plugins) = kwargs.optional;
|
38
|
-
|
39
|
-
let mut comrak_options = ComrakOptions::default();
|
40
|
-
|
41
|
-
if let Some(rb_options) = rb_options {
|
42
|
-
rb_options.foreach(|key: Symbol, value: RHash| {
|
43
|
-
iterate_options_hash(&mut comrak_options, key, value)?;
|
44
|
-
Ok(ForEach::Continue)
|
45
|
-
})?;
|
46
|
-
}
|
47
|
-
|
48
|
-
if let Some(rb_plugins) = rb_plugins {
|
49
|
-
let mut comrak_plugins = ComrakPlugins::default();
|
50
|
-
|
51
|
-
let syntax_highlighter: Option<&dyn SyntaxHighlighterAdapter>;
|
52
|
-
let adapter: SyntectAdapter;
|
53
|
-
|
54
|
-
let theme = match rb_plugins.get(Symbol::new(SYNTAX_HIGHLIGHTER_PLUGIN)) {
|
55
|
-
Some(theme_val) => fetch_syntax_highlighter_theme(theme_val)?,
|
56
|
-
None => SYNTAX_HIGHLIGHTER_PLUGIN_DEFAULT_THEME.to_string(), // no `syntax_highlighter:` defined
|
57
|
-
};
|
58
|
-
|
59
|
-
if theme.is_empty() || theme == "none" {
|
60
|
-
syntax_highlighter = None;
|
61
|
-
} else {
|
62
|
-
adapter = SyntectAdapter::new(&theme);
|
63
|
-
syntax_highlighter = Some(&adapter);
|
64
|
-
}
|
65
|
-
|
66
|
-
comrak_plugins.render.codefence_syntax_highlighter = syntax_highlighter;
|
67
|
-
|
68
|
-
Ok(markdown_to_html_with_plugins(
|
69
|
-
&rb_commonmark,
|
70
|
-
&comrak_options,
|
71
|
-
&comrak_plugins,
|
72
|
-
))
|
73
|
-
} else {
|
74
|
-
Ok(markdown_to_html(&rb_commonmark, &comrak_options))
|
75
|
-
}
|
76
|
-
}
|
77
|
-
|
78
|
-
#[magnus::init]
|
79
|
-
fn init() -> Result<(), Error> {
|
80
|
-
let module = define_module("Commonmarker")?;
|
81
|
-
|
82
|
-
module.define_module_function("commonmark_to_html", function!(commonmark_to_html, -1))?;
|
83
|
-
|
84
|
-
Ok(())
|
85
|
-
}
|
@@ -1,130 +0,0 @@
|
|
1
|
-
use std::borrow::Cow;
|
2
|
-
|
3
|
-
use comrak::ComrakOptions;
|
4
|
-
|
5
|
-
use magnus::{class, r_hash::ForEach, Error, RHash, Symbol, Value};
|
6
|
-
|
7
|
-
use crate::utils::try_convert_string;
|
8
|
-
|
9
|
-
const PARSE_SMART: &str = "smart";
|
10
|
-
const PARSE_DEFAULT_INFO_STRING: &str = "default_info_string";
|
11
|
-
|
12
|
-
fn iterate_parse_options(comrak_options: &mut ComrakOptions, options_hash: RHash) {
|
13
|
-
options_hash
|
14
|
-
.foreach(|key: Symbol, value: Value| {
|
15
|
-
match key.name() {
|
16
|
-
Ok(Cow::Borrowed(PARSE_SMART)) => {
|
17
|
-
comrak_options.parse.smart = value.try_convert::<bool>()?;
|
18
|
-
}
|
19
|
-
Ok(Cow::Borrowed(PARSE_DEFAULT_INFO_STRING)) => {
|
20
|
-
comrak_options.parse.default_info_string = try_convert_string(value);
|
21
|
-
}
|
22
|
-
_ => {}
|
23
|
-
}
|
24
|
-
Ok(ForEach::Continue)
|
25
|
-
})
|
26
|
-
.unwrap();
|
27
|
-
}
|
28
|
-
|
29
|
-
const RENDER_HARDBREAKS: &str = "hardbreaks";
|
30
|
-
const RENDER_GITHUB_PRE_LANG: &str = "github_pre_lang";
|
31
|
-
const RENDER_WIDTH: &str = "width";
|
32
|
-
const RENDER_UNSAFE: &str = "unsafe_";
|
33
|
-
const RENDER_ESCAPE: &str = "escape";
|
34
|
-
|
35
|
-
fn iterate_render_options(comrak_options: &mut ComrakOptions, options_hash: RHash) {
|
36
|
-
options_hash
|
37
|
-
.foreach(|key: Symbol, value: Value| {
|
38
|
-
match key.name() {
|
39
|
-
Ok(Cow::Borrowed(RENDER_HARDBREAKS)) => {
|
40
|
-
comrak_options.render.hardbreaks = value.try_convert::<bool>()?;
|
41
|
-
}
|
42
|
-
Ok(Cow::Borrowed(RENDER_GITHUB_PRE_LANG)) => {
|
43
|
-
comrak_options.render.github_pre_lang = value.try_convert::<bool>()?;
|
44
|
-
}
|
45
|
-
Ok(Cow::Borrowed(RENDER_WIDTH)) => {
|
46
|
-
comrak_options.render.width = value.try_convert::<usize>()?;
|
47
|
-
}
|
48
|
-
Ok(Cow::Borrowed(RENDER_UNSAFE)) => {
|
49
|
-
comrak_options.render.unsafe_ = value.try_convert::<bool>()?;
|
50
|
-
}
|
51
|
-
Ok(Cow::Borrowed(RENDER_ESCAPE)) => {
|
52
|
-
comrak_options.render.escape = value.try_convert::<bool>()?;
|
53
|
-
}
|
54
|
-
_ => {}
|
55
|
-
}
|
56
|
-
Ok(ForEach::Continue)
|
57
|
-
})
|
58
|
-
.unwrap();
|
59
|
-
}
|
60
|
-
|
61
|
-
const EXTENSION_STRIKETHROUGH: &str = "strikethrough";
|
62
|
-
const EXTENSION_TAGFILTER: &str = "tagfilter";
|
63
|
-
const EXTENSION_TABLE: &str = "table";
|
64
|
-
const EXTENSION_AUTOLINK: &str = "autolink";
|
65
|
-
const EXTENSION_TASKLIST: &str = "tasklist";
|
66
|
-
const EXTENSION_SUPERSCRIPT: &str = "superscript";
|
67
|
-
const EXTENSION_HEADER_IDS: &str = "header_ids";
|
68
|
-
const EXTENSION_FOOTNOTES: &str = "footnotes";
|
69
|
-
const EXTENSION_DESCRIPTION_LISTS: &str = "description_lists";
|
70
|
-
const EXTENSION_FRONT_MATTER_DELIMITER: &str = "front_matter_delimiter";
|
71
|
-
|
72
|
-
fn iterate_extension_options(comrak_options: &mut ComrakOptions, options_hash: RHash) {
|
73
|
-
options_hash
|
74
|
-
.foreach(|key: Symbol, value: Value| {
|
75
|
-
match key.name() {
|
76
|
-
Ok(Cow::Borrowed(EXTENSION_STRIKETHROUGH)) => {
|
77
|
-
comrak_options.extension.strikethrough = value.try_convert::<bool>()?;
|
78
|
-
}
|
79
|
-
Ok(Cow::Borrowed(EXTENSION_TAGFILTER)) => {
|
80
|
-
comrak_options.extension.tagfilter = value.try_convert::<bool>()?;
|
81
|
-
}
|
82
|
-
Ok(Cow::Borrowed(EXTENSION_TABLE)) => {
|
83
|
-
comrak_options.extension.table = value.try_convert::<bool>()?;
|
84
|
-
}
|
85
|
-
Ok(Cow::Borrowed(EXTENSION_AUTOLINK)) => {
|
86
|
-
comrak_options.extension.autolink = value.try_convert::<bool>()?;
|
87
|
-
}
|
88
|
-
Ok(Cow::Borrowed(EXTENSION_TASKLIST)) => {
|
89
|
-
comrak_options.extension.tasklist = value.try_convert::<bool>()?;
|
90
|
-
}
|
91
|
-
Ok(Cow::Borrowed(EXTENSION_SUPERSCRIPT)) => {
|
92
|
-
comrak_options.extension.superscript = value.try_convert::<bool>()?;
|
93
|
-
}
|
94
|
-
Ok(Cow::Borrowed(EXTENSION_HEADER_IDS)) => {
|
95
|
-
comrak_options.extension.header_ids = try_convert_string(value);
|
96
|
-
}
|
97
|
-
Ok(Cow::Borrowed(EXTENSION_FOOTNOTES)) => {
|
98
|
-
comrak_options.extension.footnotes = value.try_convert::<bool>()?;
|
99
|
-
}
|
100
|
-
Ok(Cow::Borrowed(EXTENSION_DESCRIPTION_LISTS)) => {
|
101
|
-
comrak_options.extension.description_lists = value.try_convert::<bool>()?;
|
102
|
-
}
|
103
|
-
Ok(Cow::Borrowed(EXTENSION_FRONT_MATTER_DELIMITER)) => {
|
104
|
-
comrak_options.extension.front_matter_delimiter = try_convert_string(value);
|
105
|
-
}
|
106
|
-
_ => {}
|
107
|
-
}
|
108
|
-
Ok(ForEach::Continue)
|
109
|
-
})
|
110
|
-
.unwrap();
|
111
|
-
}
|
112
|
-
|
113
|
-
pub fn iterate_options_hash(
|
114
|
-
comrak_options: &mut ComrakOptions,
|
115
|
-
key: Symbol,
|
116
|
-
value: RHash,
|
117
|
-
) -> Result<ForEach, Error> {
|
118
|
-
assert!(value.is_kind_of(class::hash()));
|
119
|
-
|
120
|
-
if key.name().unwrap() == "parse" {
|
121
|
-
iterate_parse_options(comrak_options, value);
|
122
|
-
}
|
123
|
-
if key.name().unwrap() == "render" {
|
124
|
-
iterate_render_options(comrak_options, value);
|
125
|
-
}
|
126
|
-
if key.name().unwrap() == "extension" {
|
127
|
-
iterate_extension_options(comrak_options, value);
|
128
|
-
}
|
129
|
-
Ok(ForEach::Continue)
|
130
|
-
}
|
@@ -1,30 +0,0 @@
|
|
1
|
-
use magnus::{RHash, Symbol, Value};
|
2
|
-
|
3
|
-
use crate::EMPTY_STR;
|
4
|
-
|
5
|
-
pub const SYNTAX_HIGHLIGHTER_PLUGIN_THEME_KEY: &str = "theme";
|
6
|
-
pub const SYNTAX_HIGHLIGHTER_PLUGIN_DEFAULT_THEME: &str = "base16-ocean.dark";
|
7
|
-
|
8
|
-
pub fn fetch_syntax_highlighter_theme(value: Value) -> Result<String, magnus::Error> {
|
9
|
-
if value.is_nil() {
|
10
|
-
// `syntax_highlighter: nil`
|
11
|
-
return Ok(EMPTY_STR.to_string());
|
12
|
-
}
|
13
|
-
|
14
|
-
let syntax_highlighter_plugin = value.try_convert::<RHash>()?;
|
15
|
-
let theme_key = Symbol::new(SYNTAX_HIGHLIGHTER_PLUGIN_THEME_KEY);
|
16
|
-
|
17
|
-
match syntax_highlighter_plugin.get(theme_key) {
|
18
|
-
Some(theme) => {
|
19
|
-
if theme.is_nil() {
|
20
|
-
// `syntax_highlighter: { theme: nil }`
|
21
|
-
return Ok(EMPTY_STR.to_string());
|
22
|
-
}
|
23
|
-
Ok(theme.try_convert::<String>()?)
|
24
|
-
}
|
25
|
-
None => {
|
26
|
-
// `syntax_highlighter: { }`
|
27
|
-
Ok(EMPTY_STR.to_string())
|
28
|
-
}
|
29
|
-
}
|
30
|
-
}
|
@@ -1,21 +0,0 @@
|
|
1
|
-
// use comrak::ComrakPlugins;
|
2
|
-
// use magnus::{class, r_hash::ForEach, RHash, Symbol, Value};
|
3
|
-
|
4
|
-
// use crate::plugins::syntax_highlighting::fetch_syntax_highlighter_theme;
|
5
|
-
|
6
|
-
pub mod syntax_highlighting;
|
7
|
-
|
8
|
-
pub const SYNTAX_HIGHLIGHTER_PLUGIN: &str = "syntax_highlighter";
|
9
|
-
|
10
|
-
// pub fn iterate_plugins_hash(
|
11
|
-
// comrak_plugins: &mut ComrakPlugins,
|
12
|
-
// mut theme: String,
|
13
|
-
// key: Symbol,
|
14
|
-
// value: Value,
|
15
|
-
// ) -> Result<ForEach, magnus::Error> {
|
16
|
-
// if key.name().unwrap() == SYNTAX_HIGHLIGHTER_PLUGIN {
|
17
|
-
// theme = fetch_syntax_highlighter_theme(value)?;
|
18
|
-
// }
|
19
|
-
|
20
|
-
// Ok(ForEach::Continue)
|
21
|
-
// }
|