commonmarker 1.0.0.pre8 → 1.0.0.pre11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Cargo.lock +301 -373
- data/Cargo.toml +6 -0
- data/ext/commonmarker/Cargo.toml +3 -3
- data/ext/commonmarker/extconf.rb +0 -2
- data/ext/commonmarker/src/lib.rs +3 -7
- data/ext/commonmarker/src/options.rs +22 -16
- data/ext/commonmarker/src/plugins/syntax_highlighting.rs +6 -5
- data/ext/commonmarker/src/plugins.rs +0 -18
- data/ext/commonmarker/src/utils.rs +2 -2
- data/lib/commonmarker/config.rb +2 -2
- data/lib/commonmarker/version.rb +1 -1
- data/lib/commonmarker.rb +0 -5
- metadata +8 -22
- data/ext/commonmarker/_util.rb +0 -102
data/Cargo.toml
ADDED
data/ext/commonmarker/Cargo.toml
CHANGED
@@ -4,9 +4,9 @@ version = "1.0.0"
|
|
4
4
|
edition = "2021"
|
5
5
|
|
6
6
|
[dependencies]
|
7
|
-
magnus = "0.
|
8
|
-
comrak = { version = "0.
|
9
|
-
syntect = { version = "5.
|
7
|
+
magnus = "0.6"
|
8
|
+
comrak = { version = "0.19", features = ["shortcodes"] }
|
9
|
+
syntect = { version = "5.1", features = ["plist-load"] }
|
10
10
|
|
11
11
|
[lib]
|
12
12
|
name = "commonmarker"
|
data/ext/commonmarker/extconf.rb
CHANGED
data/ext/commonmarker/src/lib.rs
CHANGED
@@ -29,13 +29,9 @@ mod utils;
|
|
29
29
|
|
30
30
|
pub const EMPTY_STR: &str = "";
|
31
31
|
|
32
|
-
fn commonmark_to_html
|
33
|
-
let args = scan_args::scan_args(args)?;
|
32
|
+
fn commonmark_to_html(args: &[Value]) -> Result<String, magnus::Error> {
|
33
|
+
let args = scan_args::scan_args::<_, (), (), (), _, ()>(args)?;
|
34
34
|
let (rb_commonmark,): (String,) = args.required;
|
35
|
-
let _: () = args.optional;
|
36
|
-
let _: () = args.splat;
|
37
|
-
let _: () = args.trailing;
|
38
|
-
let _: () = args.block;
|
39
35
|
|
40
36
|
let kwargs = scan_args::get_kwargs::<_, (), (Option<RHash>, Option<RHash>), ()>(
|
41
37
|
args.keywords,
|
@@ -76,7 +72,7 @@ fn commonmark_to_html<'a>(args: &[Value]) -> Result<String, magnus::Error> {
|
|
76
72
|
if !path.eq(&PathBuf::from("".to_string())) && !path.exists() {
|
77
73
|
return Err(Error::new(
|
78
74
|
exception::arg_error(),
|
79
|
-
|
75
|
+
"path does not exist".to_string(),
|
80
76
|
));
|
81
77
|
}
|
82
78
|
|
@@ -2,6 +2,8 @@ use std::borrow::Cow;
|
|
2
2
|
|
3
3
|
use comrak::ComrakOptions;
|
4
4
|
|
5
|
+
use magnus::value::ReprValue;
|
6
|
+
use magnus::TryConvert;
|
5
7
|
use magnus::{class, r_hash::ForEach, Error, RHash, Symbol, Value};
|
6
8
|
|
7
9
|
use crate::utils::try_convert_string;
|
@@ -14,7 +16,7 @@ fn iterate_parse_options(comrak_options: &mut ComrakOptions, options_hash: RHash
|
|
14
16
|
.foreach(|key: Symbol, value: Value| {
|
15
17
|
match key.name() {
|
16
18
|
Ok(Cow::Borrowed(PARSE_SMART)) => {
|
17
|
-
comrak_options.parse.smart =
|
19
|
+
comrak_options.parse.smart = TryConvert::try_convert(value)?;
|
18
20
|
}
|
19
21
|
Ok(Cow::Borrowed(PARSE_DEFAULT_INFO_STRING)) => {
|
20
22
|
comrak_options.parse.default_info_string = try_convert_string(value);
|
@@ -37,19 +39,19 @@ fn iterate_render_options(comrak_options: &mut ComrakOptions, options_hash: RHas
|
|
37
39
|
.foreach(|key: Symbol, value: Value| {
|
38
40
|
match key.name() {
|
39
41
|
Ok(Cow::Borrowed(RENDER_HARDBREAKS)) => {
|
40
|
-
comrak_options.render.hardbreaks =
|
42
|
+
comrak_options.render.hardbreaks = TryConvert::try_convert(value)?;
|
41
43
|
}
|
42
44
|
Ok(Cow::Borrowed(RENDER_GITHUB_PRE_LANG)) => {
|
43
|
-
comrak_options.render.github_pre_lang =
|
45
|
+
comrak_options.render.github_pre_lang = TryConvert::try_convert(value)?;
|
44
46
|
}
|
45
47
|
Ok(Cow::Borrowed(RENDER_WIDTH)) => {
|
46
|
-
comrak_options.render.width =
|
48
|
+
comrak_options.render.width = TryConvert::try_convert(value)?;
|
47
49
|
}
|
48
50
|
Ok(Cow::Borrowed(RENDER_UNSAFE)) => {
|
49
|
-
comrak_options.render.unsafe_ =
|
51
|
+
comrak_options.render.unsafe_ = TryConvert::try_convert(value)?;
|
50
52
|
}
|
51
53
|
Ok(Cow::Borrowed(RENDER_ESCAPE)) => {
|
52
|
-
comrak_options.render.escape =
|
54
|
+
comrak_options.render.escape = TryConvert::try_convert(value)?;
|
53
55
|
}
|
54
56
|
_ => {}
|
55
57
|
}
|
@@ -75,37 +77,41 @@ fn iterate_extension_options(comrak_options: &mut ComrakOptions, options_hash: R
|
|
75
77
|
.foreach(|key: Symbol, value: Value| {
|
76
78
|
match key.name() {
|
77
79
|
Ok(Cow::Borrowed(EXTENSION_STRIKETHROUGH)) => {
|
78
|
-
comrak_options.extension.strikethrough =
|
80
|
+
comrak_options.extension.strikethrough = TryConvert::try_convert(value)?;
|
79
81
|
}
|
80
82
|
Ok(Cow::Borrowed(EXTENSION_TAGFILTER)) => {
|
81
|
-
comrak_options.extension.tagfilter =
|
83
|
+
comrak_options.extension.tagfilter = TryConvert::try_convert(value)?;
|
82
84
|
}
|
83
85
|
Ok(Cow::Borrowed(EXTENSION_TABLE)) => {
|
84
|
-
comrak_options.extension.table =
|
86
|
+
comrak_options.extension.table = TryConvert::try_convert(value)?;
|
85
87
|
}
|
86
88
|
Ok(Cow::Borrowed(EXTENSION_AUTOLINK)) => {
|
87
|
-
comrak_options.extension.autolink =
|
89
|
+
comrak_options.extension.autolink = TryConvert::try_convert(value)?;
|
88
90
|
}
|
89
91
|
Ok(Cow::Borrowed(EXTENSION_TASKLIST)) => {
|
90
|
-
comrak_options.extension.tasklist =
|
92
|
+
comrak_options.extension.tasklist = TryConvert::try_convert(value)?;
|
91
93
|
}
|
92
94
|
Ok(Cow::Borrowed(EXTENSION_SUPERSCRIPT)) => {
|
93
|
-
comrak_options.extension.superscript =
|
95
|
+
comrak_options.extension.superscript = TryConvert::try_convert(value)?;
|
94
96
|
}
|
95
97
|
Ok(Cow::Borrowed(EXTENSION_HEADER_IDS)) => {
|
96
98
|
comrak_options.extension.header_ids = try_convert_string(value);
|
97
99
|
}
|
98
100
|
Ok(Cow::Borrowed(EXTENSION_FOOTNOTES)) => {
|
99
|
-
comrak_options.extension.footnotes =
|
101
|
+
comrak_options.extension.footnotes = TryConvert::try_convert(value)?;
|
100
102
|
}
|
101
103
|
Ok(Cow::Borrowed(EXTENSION_DESCRIPTION_LISTS)) => {
|
102
|
-
comrak_options.extension.description_lists =
|
104
|
+
comrak_options.extension.description_lists = TryConvert::try_convert(value)?;
|
103
105
|
}
|
104
106
|
Ok(Cow::Borrowed(EXTENSION_FRONT_MATTER_DELIMITER)) => {
|
105
|
-
|
107
|
+
if let Some(option) = try_convert_string(value) {
|
108
|
+
if !option.is_empty() {
|
109
|
+
comrak_options.extension.front_matter_delimiter = Some(option);
|
110
|
+
}
|
111
|
+
}
|
106
112
|
}
|
107
113
|
Ok(Cow::Borrowed(EXTENSION_SHORTCODES)) => {
|
108
|
-
comrak_options.extension.shortcodes =
|
114
|
+
comrak_options.extension.shortcodes = TryConvert::try_convert(value)?;
|
109
115
|
}
|
110
116
|
_ => {}
|
111
117
|
}
|
@@ -1,6 +1,7 @@
|
|
1
1
|
use std::path::PathBuf;
|
2
2
|
|
3
|
-
use magnus::
|
3
|
+
use magnus::value::ReprValue;
|
4
|
+
use magnus::{RHash, Symbol, TryConvert, Value};
|
4
5
|
|
5
6
|
use crate::EMPTY_STR;
|
6
7
|
|
@@ -14,7 +15,7 @@ pub fn fetch_syntax_highlighter_theme(value: Value) -> Result<String, magnus::Er
|
|
14
15
|
return Ok(EMPTY_STR.to_string());
|
15
16
|
}
|
16
17
|
|
17
|
-
let syntax_highlighter_plugin =
|
18
|
+
let syntax_highlighter_plugin: RHash = TryConvert::try_convert(value)?;
|
18
19
|
let theme_key = Symbol::new(SYNTAX_HIGHLIGHTER_PLUGIN_THEME_KEY);
|
19
20
|
|
20
21
|
match syntax_highlighter_plugin.get(theme_key) {
|
@@ -38,7 +39,7 @@ pub fn fetch_syntax_highlighter_path(value: Value) -> Result<PathBuf, magnus::Er
|
|
38
39
|
return Ok(PathBuf::from(EMPTY_STR));
|
39
40
|
}
|
40
41
|
|
41
|
-
let syntax_highlighter_plugin =
|
42
|
+
let syntax_highlighter_plugin: RHash = TryConvert::try_convert(value)?;
|
42
43
|
let path_key = Symbol::new(SYNTAX_HIGHLIGHTER_PLUGIN_PATH_KEY);
|
43
44
|
|
44
45
|
match syntax_highlighter_plugin.get(path_key) {
|
@@ -47,8 +48,8 @@ pub fn fetch_syntax_highlighter_path(value: Value) -> Result<PathBuf, magnus::Er
|
|
47
48
|
// `syntax_highlighter: { path: nil }`
|
48
49
|
return Ok(PathBuf::from(EMPTY_STR));
|
49
50
|
}
|
50
|
-
|
51
|
-
Ok(PathBuf::from(
|
51
|
+
let val: String = TryConvert::try_convert(path)?;
|
52
|
+
Ok(PathBuf::from(val))
|
52
53
|
}
|
53
54
|
None => {
|
54
55
|
// `syntax_highlighter: { }`
|
@@ -1,21 +1,3 @@
|
|
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
1
|
pub mod syntax_highlighting;
|
7
2
|
|
8
3
|
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
|
-
// }
|
data/lib/commonmarker/config.rb
CHANGED
@@ -26,7 +26,7 @@ module Commonmarker
|
|
26
26
|
header_ids: "",
|
27
27
|
footnotes: false,
|
28
28
|
description_lists: false,
|
29
|
-
front_matter_delimiter:
|
29
|
+
front_matter_delimiter: "",
|
30
30
|
shortcodes: true,
|
31
31
|
},
|
32
32
|
format: [:html].freeze,
|
@@ -79,7 +79,7 @@ module Commonmarker
|
|
79
79
|
|
80
80
|
[:syntax_highlighter].each do |type|
|
81
81
|
define_singleton_method :"process_#{type}_plugin" do |plugin|
|
82
|
-
return
|
82
|
+
return if plugin.nil? # plugin explicitly nil, remove it
|
83
83
|
|
84
84
|
Commonmarker::Config::PLUGINS[type].each_with_object({}) do |(key, value), hash|
|
85
85
|
if plugin.nil? # option not provided, go for the default
|
data/lib/commonmarker/version.rb
CHANGED
data/lib/commonmarker.rb
CHANGED
@@ -7,11 +7,6 @@ require "commonmarker/config"
|
|
7
7
|
require "commonmarker/renderer"
|
8
8
|
require "commonmarker/version"
|
9
9
|
|
10
|
-
if ENV.fetch("DEBUG", false)
|
11
|
-
require "awesome_print"
|
12
|
-
require "debug"
|
13
|
-
end
|
14
|
-
|
15
10
|
module Commonmarker
|
16
11
|
class << self
|
17
12
|
# Public: Parses a CommonMark string into an HTML string.
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: commonmarker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.pre11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Garen Torikian
|
8
8
|
- Ashe Connor
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-
|
12
|
+
date: 2023-11-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rb_sys
|
@@ -54,33 +54,19 @@ dependencies:
|
|
54
54
|
- - "~>"
|
55
55
|
- !ruby/object:Gem::Version
|
56
56
|
version: '1.2'
|
57
|
-
- !ruby/object:Gem::Dependency
|
58
|
-
name: rake-compiler-dock
|
59
|
-
requirement: !ruby/object:Gem::Requirement
|
60
|
-
requirements:
|
61
|
-
- - "~>"
|
62
|
-
- !ruby/object:Gem::Version
|
63
|
-
version: '1.2'
|
64
|
-
type: :development
|
65
|
-
prerelease: false
|
66
|
-
version_requirements: !ruby/object:Gem::Requirement
|
67
|
-
requirements:
|
68
|
-
- - "~>"
|
69
|
-
- !ruby/object:Gem::Version
|
70
|
-
version: '1.2'
|
71
57
|
description: A fast, safe, extensible parser for CommonMark. This wraps the comrak
|
72
58
|
Rust crate.
|
73
|
-
email:
|
59
|
+
email:
|
74
60
|
executables: []
|
75
61
|
extensions:
|
76
62
|
- ext/commonmarker/extconf.rb
|
77
63
|
extra_rdoc_files: []
|
78
64
|
files:
|
79
65
|
- Cargo.lock
|
66
|
+
- Cargo.toml
|
80
67
|
- LICENSE.txt
|
81
68
|
- README.md
|
82
69
|
- ext/commonmarker/Cargo.toml
|
83
|
-
- ext/commonmarker/_util.rb
|
84
70
|
- ext/commonmarker/extconf.rb
|
85
71
|
- ext/commonmarker/src/lib.rs
|
86
72
|
- ext/commonmarker/src/options.rs
|
@@ -102,7 +88,7 @@ metadata:
|
|
102
88
|
funding_uri: https://github.com/sponsors/gjtorikian/
|
103
89
|
source_code_uri: https://github.com/gjtorikian/commonmarker
|
104
90
|
rubygems_mfa_required: 'true'
|
105
|
-
post_install_message:
|
91
|
+
post_install_message:
|
106
92
|
rdoc_options: []
|
107
93
|
require_paths:
|
108
94
|
- lib
|
@@ -117,8 +103,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
103
|
- !ruby/object:Gem::Version
|
118
104
|
version: 3.3.22
|
119
105
|
requirements: []
|
120
|
-
rubygems_version: 3.4.
|
121
|
-
signing_key:
|
106
|
+
rubygems_version: 3.4.21
|
107
|
+
signing_key:
|
122
108
|
specification_version: 4
|
123
109
|
summary: CommonMark parser and renderer. Written in Rust, wrapped in Ruby.
|
124
110
|
test_files: []
|
data/ext/commonmarker/_util.rb
DELETED
@@ -1,102 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RUBY_MAJOR, RUBY_MINOR = RUBY_VERSION.split(".").collect(&:to_i)
|
4
|
-
|
5
|
-
PACKAGE_ROOT_DIR = File.expand_path(File.join(File.dirname(__FILE__), "..", ".."))
|
6
|
-
PACKAGE_EXT_DIR = File.join(PACKAGE_ROOT_DIR, "ext", "commonmarker")
|
7
|
-
|
8
|
-
OS = case os = RbConfig::CONFIG["host_os"].downcase
|
9
|
-
when /linux/
|
10
|
-
# The official ruby-alpine Docker containers pre-build Ruby. As a result,
|
11
|
-
# Ruby doesn't know that it's on a musl-based platform. `ldd` is the
|
12
|
-
# a more reliable way to detect musl.
|
13
|
-
# See https://github.com/skylightio/skylight-ruby/issues/92
|
14
|
-
if ENV["SKYLIGHT_MUSL"] || %x(ldd --version 2>&1).include?("musl")
|
15
|
-
"linux-musl"
|
16
|
-
else
|
17
|
-
"linux"
|
18
|
-
end
|
19
|
-
when /darwin/
|
20
|
-
"darwin"
|
21
|
-
when /freebsd/
|
22
|
-
"freebsd"
|
23
|
-
when /netbsd/
|
24
|
-
"netbsd"
|
25
|
-
when /openbsd/
|
26
|
-
"openbsd"
|
27
|
-
when /sunos|solaris/
|
28
|
-
"solaris"
|
29
|
-
when /mingw|mswin/
|
30
|
-
"windows"
|
31
|
-
else
|
32
|
-
os
|
33
|
-
end
|
34
|
-
|
35
|
-
# Normalize the platform CPU
|
36
|
-
ARCH = case cpu = RbConfig::CONFIG["host_cpu"].downcase
|
37
|
-
when /amd64|x86_64|x64/
|
38
|
-
"x86_64"
|
39
|
-
when /i?86|x86|i86pc/
|
40
|
-
"x86"
|
41
|
-
when /ppc|powerpc/
|
42
|
-
"powerpc"
|
43
|
-
when /^aarch/
|
44
|
-
"aarch"
|
45
|
-
when /^arm/
|
46
|
-
"arm"
|
47
|
-
else
|
48
|
-
cpu
|
49
|
-
end
|
50
|
-
|
51
|
-
def windows?
|
52
|
-
OS == "windows"
|
53
|
-
end
|
54
|
-
|
55
|
-
def solaris?
|
56
|
-
OS == solaries
|
57
|
-
end
|
58
|
-
|
59
|
-
def darwin?
|
60
|
-
OS == "darwin"
|
61
|
-
end
|
62
|
-
|
63
|
-
def macos?
|
64
|
-
darwin? || OS == "macos"
|
65
|
-
end
|
66
|
-
|
67
|
-
def openbsd?
|
68
|
-
OS == "openbsd"
|
69
|
-
end
|
70
|
-
|
71
|
-
def aix?
|
72
|
-
OS == "aix"
|
73
|
-
end
|
74
|
-
|
75
|
-
def nix?
|
76
|
-
!(windows? || solaris? || darwin?)
|
77
|
-
end
|
78
|
-
|
79
|
-
def x86_64?
|
80
|
-
ARCH == "x86_64"
|
81
|
-
end
|
82
|
-
|
83
|
-
def x86?
|
84
|
-
ARCH == "x86"
|
85
|
-
end
|
86
|
-
|
87
|
-
def abs_path(path)
|
88
|
-
File.join(PACKAGE_EXT_DIR, path)
|
89
|
-
end
|
90
|
-
|
91
|
-
def find_header_or_abort(header, *paths)
|
92
|
-
find_header(header, *paths) || abort("#{header} was expected in `#{paths.join(", ")}`, but it is missing.")
|
93
|
-
end
|
94
|
-
|
95
|
-
def find_library_or_abort(lib, func, *paths)
|
96
|
-
find_library(lib, func, *paths) || abort("#{lib} was expected in `#{paths.join(", ")}`, but it is missing.")
|
97
|
-
end
|
98
|
-
|
99
|
-
def concat_flags(*args)
|
100
|
-
args.compact.join(" ")
|
101
|
-
end
|
102
|
-
|