commonmarker 1.0.0.pre7-arm64-darwin → 1.0.0.pre8-arm64-darwin

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,12 +0,0 @@
1
- [package]
2
- name = "commonmarker"
3
- version = "1.0.0"
4
- edition = "2021"
5
-
6
- [dependencies]
7
- magnus = "0.4"
8
- comrak = { version = "0.16", features = ["shortcodes"] }
9
-
10
- [lib]
11
- name = "commonmarker"
12
- crate-type = ["cdylib"]
@@ -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,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,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,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
- // }
@@ -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
- }