commonmarker 1.0.0.pre8-x64-mingw-ucrt → 1.0.0.pre9-x64-mingw-ucrt

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,13 +0,0 @@
1
- [package]
2
- name = "commonmarker"
3
- version = "1.0.0"
4
- edition = "2021"
5
-
6
- [dependencies]
7
- magnus = "0.5"
8
- comrak = { version = "0.16", features = ["shortcodes"] }
9
- syntect = { version = "5.0", features = ["plist-load"] }
10
-
11
- [lib]
12
- name = "commonmarker"
13
- crate-type = ["cdylib"]
@@ -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
-
@@ -1,6 +0,0 @@
1
- require "mkmf"
2
- require "rb_sys/mkmf"
3
-
4
- require_relative "_util"
5
-
6
- create_rust_makefile("commonmarker/commonmarker")
@@ -1,155 +0,0 @@
1
- extern crate core;
2
-
3
- use std::path::PathBuf;
4
-
5
- use ::syntect::highlighting::ThemeSet;
6
- use comrak::{
7
- adapters::SyntaxHighlighterAdapter,
8
- markdown_to_html, markdown_to_html_with_plugins,
9
- plugins::syntect::{SyntectAdapter, SyntectAdapterBuilder},
10
- ComrakOptions, ComrakPlugins,
11
- };
12
- use magnus::{
13
- define_module, exception, function, r_hash::ForEach, scan_args, Error, RHash, Symbol, Value,
14
- };
15
-
16
- mod options;
17
- use options::iterate_options_hash;
18
-
19
- mod plugins;
20
- use plugins::{
21
- syntax_highlighting::{
22
- fetch_syntax_highlighter_path, fetch_syntax_highlighter_theme,
23
- SYNTAX_HIGHLIGHTER_PLUGIN_DEFAULT_THEME,
24
- },
25
- SYNTAX_HIGHLIGHTER_PLUGIN,
26
- };
27
-
28
- mod utils;
29
-
30
- pub const EMPTY_STR: &str = "";
31
-
32
- fn commonmark_to_html<'a>(args: &[Value]) -> Result<String, magnus::Error> {
33
- let args = scan_args::scan_args(args)?;
34
- let (rb_commonmark,): (String,) = args.required;
35
- let _: () = args.optional;
36
- let _: () = args.splat;
37
- let _: () = args.trailing;
38
- let _: () = args.block;
39
-
40
- let kwargs = scan_args::get_kwargs::<_, (), (Option<RHash>, Option<RHash>), ()>(
41
- args.keywords,
42
- &[],
43
- &["options", "plugins"],
44
- )?;
45
- let (rb_options, rb_plugins) = kwargs.optional;
46
-
47
- let mut comrak_options = ComrakOptions::default();
48
-
49
- if let Some(rb_options) = rb_options {
50
- rb_options.foreach(|key: Symbol, value: RHash| {
51
- iterate_options_hash(&mut comrak_options, key, value)?;
52
- Ok(ForEach::Continue)
53
- })?;
54
- }
55
-
56
- if let Some(rb_plugins) = rb_plugins {
57
- let mut comrak_plugins = ComrakPlugins::default();
58
-
59
- let syntax_highlighter: Option<&dyn SyntaxHighlighterAdapter>;
60
- let adapter: SyntectAdapter;
61
-
62
- let theme = match rb_plugins.get(Symbol::new(SYNTAX_HIGHLIGHTER_PLUGIN)) {
63
- Some(syntax_highlighter_options) => {
64
- fetch_syntax_highlighter_theme(syntax_highlighter_options)?
65
- }
66
- None => SYNTAX_HIGHLIGHTER_PLUGIN_DEFAULT_THEME.to_string(), // no `syntax_highlighter:` defined
67
- };
68
-
69
- let path = match rb_plugins.get(Symbol::new(SYNTAX_HIGHLIGHTER_PLUGIN)) {
70
- Some(syntax_highlighter_options) => {
71
- fetch_syntax_highlighter_path(syntax_highlighter_options)?
72
- }
73
- None => PathBuf::from("".to_string()), // no `syntax_highlighter:` defined
74
- };
75
-
76
- if !path.eq(&PathBuf::from("".to_string())) && !path.exists() {
77
- return Err(Error::new(
78
- exception::arg_error(),
79
- format!("path does not exist"),
80
- ));
81
- }
82
-
83
- if theme.is_empty() && path.exists() {
84
- return Err(Error::new(
85
- exception::arg_error(),
86
- "`path` also needs `theme` passed into the `syntax_highlighter`",
87
- ));
88
- }
89
- if path.exists() && !path.is_dir() {
90
- return Err(Error::new(
91
- exception::arg_error(),
92
- "`path` needs to be a directory",
93
- ));
94
- }
95
-
96
- if path.exists() {
97
- let builder = SyntectAdapterBuilder::new();
98
- let mut ts = ThemeSet::load_defaults();
99
-
100
- match ts.add_from_folder(&path) {
101
- Ok(_) => {}
102
- Err(e) => {
103
- return Err(Error::new(
104
- exception::arg_error(),
105
- format!("failed to load theme set from path: {e}"),
106
- ));
107
- }
108
- }
109
-
110
- ts.themes.get(&theme).ok_or_else(|| {
111
- Error::new(
112
- exception::arg_error(),
113
- format!("theme `{}` does not exist", theme),
114
- )
115
- })?;
116
-
117
- adapter = builder.theme_set(ts).theme(&theme).build();
118
-
119
- syntax_highlighter = Some(&adapter);
120
- } else if theme.is_empty() || theme == "none" {
121
- syntax_highlighter = None;
122
- } else {
123
- ThemeSet::load_defaults()
124
- .themes
125
- .get(&theme)
126
- .ok_or_else(|| {
127
- Error::new(
128
- exception::arg_error(),
129
- format!("theme `{}` does not exist", theme),
130
- )
131
- })?;
132
- adapter = SyntectAdapter::new(&theme);
133
- syntax_highlighter = Some(&adapter);
134
- }
135
-
136
- comrak_plugins.render.codefence_syntax_highlighter = syntax_highlighter;
137
-
138
- Ok(markdown_to_html_with_plugins(
139
- &rb_commonmark,
140
- &comrak_options,
141
- &comrak_plugins,
142
- ))
143
- } else {
144
- Ok(markdown_to_html(&rb_commonmark, &comrak_options))
145
- }
146
- }
147
-
148
- #[magnus::init]
149
- fn init() -> Result<(), Error> {
150
- let module = define_module("Commonmarker")?;
151
-
152
- module.define_module_function("commonmark_to_html", function!(commonmark_to_html, -1))?;
153
-
154
- Ok(())
155
- }
@@ -1,134 +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
- const EXTENSION_SHORTCODES: &str = "shortcodes";
72
-
73
- fn iterate_extension_options(comrak_options: &mut ComrakOptions, options_hash: RHash) {
74
- options_hash
75
- .foreach(|key: Symbol, value: Value| {
76
- match key.name() {
77
- Ok(Cow::Borrowed(EXTENSION_STRIKETHROUGH)) => {
78
- comrak_options.extension.strikethrough = value.try_convert::<bool>()?;
79
- }
80
- Ok(Cow::Borrowed(EXTENSION_TAGFILTER)) => {
81
- comrak_options.extension.tagfilter = value.try_convert::<bool>()?;
82
- }
83
- Ok(Cow::Borrowed(EXTENSION_TABLE)) => {
84
- comrak_options.extension.table = value.try_convert::<bool>()?;
85
- }
86
- Ok(Cow::Borrowed(EXTENSION_AUTOLINK)) => {
87
- comrak_options.extension.autolink = value.try_convert::<bool>()?;
88
- }
89
- Ok(Cow::Borrowed(EXTENSION_TASKLIST)) => {
90
- comrak_options.extension.tasklist = value.try_convert::<bool>()?;
91
- }
92
- Ok(Cow::Borrowed(EXTENSION_SUPERSCRIPT)) => {
93
- comrak_options.extension.superscript = value.try_convert::<bool>()?;
94
- }
95
- Ok(Cow::Borrowed(EXTENSION_HEADER_IDS)) => {
96
- comrak_options.extension.header_ids = try_convert_string(value);
97
- }
98
- Ok(Cow::Borrowed(EXTENSION_FOOTNOTES)) => {
99
- comrak_options.extension.footnotes = value.try_convert::<bool>()?;
100
- }
101
- Ok(Cow::Borrowed(EXTENSION_DESCRIPTION_LISTS)) => {
102
- comrak_options.extension.description_lists = value.try_convert::<bool>()?;
103
- }
104
- Ok(Cow::Borrowed(EXTENSION_FRONT_MATTER_DELIMITER)) => {
105
- comrak_options.extension.front_matter_delimiter = try_convert_string(value);
106
- }
107
- Ok(Cow::Borrowed(EXTENSION_SHORTCODES)) => {
108
- comrak_options.extension.shortcodes = value.try_convert::<bool>()?;
109
- }
110
- _ => {}
111
- }
112
- Ok(ForEach::Continue)
113
- })
114
- .unwrap();
115
- }
116
-
117
- pub fn iterate_options_hash(
118
- comrak_options: &mut ComrakOptions,
119
- key: Symbol,
120
- value: RHash,
121
- ) -> Result<ForEach, Error> {
122
- assert!(value.is_kind_of(class::hash()));
123
-
124
- if key.name().unwrap() == "parse" {
125
- iterate_parse_options(comrak_options, value);
126
- }
127
- if key.name().unwrap() == "render" {
128
- iterate_render_options(comrak_options, value);
129
- }
130
- if key.name().unwrap() == "extension" {
131
- iterate_extension_options(comrak_options, value);
132
- }
133
- Ok(ForEach::Continue)
134
- }
@@ -1,58 +0,0 @@
1
- use std::path::PathBuf;
2
-
3
- use magnus::{RHash, Symbol, Value};
4
-
5
- use crate::EMPTY_STR;
6
-
7
- pub const SYNTAX_HIGHLIGHTER_PLUGIN_THEME_KEY: &str = "theme";
8
- pub const SYNTAX_HIGHLIGHTER_PLUGIN_PATH_KEY: &str = "path";
9
- pub const SYNTAX_HIGHLIGHTER_PLUGIN_DEFAULT_THEME: &str = "base16-ocean.dark";
10
-
11
- pub fn fetch_syntax_highlighter_theme(value: Value) -> Result<String, magnus::Error> {
12
- if value.is_nil() {
13
- // `syntax_highlighter: nil`
14
- return Ok(EMPTY_STR.to_string());
15
- }
16
-
17
- let syntax_highlighter_plugin = value.try_convert::<RHash>()?;
18
- let theme_key = Symbol::new(SYNTAX_HIGHLIGHTER_PLUGIN_THEME_KEY);
19
-
20
- match syntax_highlighter_plugin.get(theme_key) {
21
- Some(theme) => {
22
- if theme.is_nil() {
23
- // `syntax_highlighter: { theme: nil }`
24
- return Ok(EMPTY_STR.to_string());
25
- }
26
- Ok(theme.try_convert::<String>()?)
27
- }
28
- None => {
29
- // `syntax_highlighter: { }`
30
- Ok(EMPTY_STR.to_string())
31
- }
32
- }
33
- }
34
-
35
- pub fn fetch_syntax_highlighter_path(value: Value) -> Result<PathBuf, magnus::Error> {
36
- if value.is_nil() {
37
- // `syntax_highlighter: nil`
38
- return Ok(PathBuf::from(EMPTY_STR));
39
- }
40
-
41
- let syntax_highlighter_plugin = value.try_convert::<RHash>()?;
42
- let path_key = Symbol::new(SYNTAX_HIGHLIGHTER_PLUGIN_PATH_KEY);
43
-
44
- match syntax_highlighter_plugin.get(path_key) {
45
- Some(path) => {
46
- if path.is_nil() {
47
- // `syntax_highlighter: { path: nil }`
48
- return Ok(PathBuf::from(EMPTY_STR));
49
- }
50
-
51
- Ok(PathBuf::from(path.try_convert::<String>()?))
52
- }
53
- None => {
54
- // `syntax_highlighter: { }`
55
- Ok(PathBuf::from(EMPTY_STR))
56
- }
57
- }
58
- }
@@ -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
- // }
@@ -1,8 +0,0 @@
1
- use magnus::Value;
2
-
3
- pub fn try_convert_string(value: Value) -> Option<String> {
4
- match value.try_convert::<String>() {
5
- Ok(s) => Some(s),
6
- Err(_) => None,
7
- }
8
- }