commonmarker 1.0.0.pre → 1.0.0.pre.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 85a99af1031da784a9618bc20f6cca8fae6a0e30418bab8b28321d284e2f0186
4
- data.tar.gz: 0cc0fd0f0efe60f8c09ab8dd4fd8b242797e290842690f83291306765e08929a
3
+ metadata.gz: 50518c47228bb2c8fa7316a72874bd80441a7461e6763e7c267138a958b8f5bd
4
+ data.tar.gz: 20df9a9139bef07fbd0748c5b0ceeee9217c61ba521dca4aca9e7e71a5ba9ed7
5
5
  SHA512:
6
- metadata.gz: f8156096352b9519ce2e8dd1e2154152e2c3963ba6c3b4268cdbfea5314da6500eaf974613a1e1d5b9463ab256ca44fe17d165ce3a987288791ac0dffebc6287
7
- data.tar.gz: 8ded44525de5d687f2488a60d6e7ba7fd2226ba973de9c6de5d9032b3b51bf49f249b0e0adf9685b2cea621326d2d41cf119426dd6fbded03dda3811ea7c5c03
6
+ metadata.gz: 1c64b798bbfb45a53c70e2a07f7a5bd279ff49ebb7518d62d404af71c3d46a1a6f929f33f03b0bf4819bb28a5d7df83962626ca5cef431e07ba4a8d8dea08ef0
7
+ data.tar.gz: 5d5dbae1cb19fcafbdf9f83ae263ea60bcb0ad59adc2802b52c80af676b755900f875a6cf217f81e9124e519ae45d7b07f4e07e7dcba2cfdd5d64c3957fac846
@@ -5,7 +5,7 @@ edition = "2021"
5
5
 
6
6
  [dependencies]
7
7
  magnus = { git = "https://github.com/gjtorikian/magnus", branch = "main" } # waiting for release with full rb-sys backend
8
- comrak = "0.14.0"
8
+ comrak = "0.15.0"
9
9
 
10
10
  [lib]
11
11
  name = "commonmarker"
@@ -1,90 +1,111 @@
1
+ use std::borrow::Cow;
2
+
1
3
  use comrak::ComrakOptions;
2
4
 
3
5
  use magnus::{class, r_hash::ForEach, Error, RHash, Symbol, Value};
4
6
 
7
+ const PARSE_SMART: &str = "smart";
8
+ const PARSE_DEFAULT_INFO_STRING: &str = "default_info_string";
9
+
5
10
  fn iterate_parse_options(comrak_options: &mut ComrakOptions, options_hash: RHash) {
6
- options_hash.foreach(|key: Symbol, value: Value| {
7
- if key.name().unwrap() == "smart" {
8
- comrak_options.parse.smart = value.try_convert::<bool>()?;
9
- }
10
- if key.name().unwrap() == "default_info_string" {
11
- comrak_options.parse.default_info_string = Some(value.try_convert::<String>().unwrap());
12
- }
13
- Ok(ForEach::Continue)
14
- });
11
+ options_hash
12
+ .foreach(|key: Symbol, value: Value| {
13
+ match key.name() {
14
+ Ok(Cow::Borrowed(PARSE_SMART)) => {
15
+ comrak_options.parse.smart = value.try_convert::<bool>()?;
16
+ }
17
+ Ok(Cow::Borrowed(PARSE_DEFAULT_INFO_STRING)) => {
18
+ comrak_options.parse.default_info_string = try_convert_string(value);
19
+ }
20
+ _ => {}
21
+ }
22
+ Ok(ForEach::Continue)
23
+ })
24
+ .unwrap();
15
25
  }
16
26
 
17
- fn iterate_render_options(comrak_options: &mut ComrakOptions, options_hash: RHash) {
18
- options_hash.foreach(|key: Symbol, value: Value| {
19
- if key.name().unwrap() == "hardbreaks" {
20
- comrak_options.render.hardbreaks = value.try_convert::<bool>()?;
21
- }
22
-
23
- if key.name().unwrap() == "github_pre_lang" {
24
- comrak_options.render.github_pre_lang = value.try_convert::<bool>()?;
25
- }
26
-
27
- if key.name().unwrap() == "width" {
28
- comrak_options.render.width = value.try_convert::<usize>()?;
29
- }
30
-
31
- if key.name().unwrap() == "unsafe_" {
32
- comrak_options.render.unsafe_ = value.try_convert::<bool>()?;
33
- }
27
+ const RENDER_HARDBREAKS: &str = "hardbreaks";
28
+ const RENDER_GITHUB_PRE_LANG: &str = "github_pre_lang";
29
+ const RENDER_WIDTH: &str = "width";
30
+ const RENDER_UNSAFE: &str = "unsafe_";
31
+ const RENDER_ESCAPE: &str = "escape";
34
32
 
35
- if key.name().unwrap() == "escape" {
36
- comrak_options.render.escape = value.try_convert::<bool>()?;
37
- }
38
-
39
- Ok(ForEach::Continue)
40
- });
33
+ fn iterate_render_options(comrak_options: &mut ComrakOptions, options_hash: RHash) {
34
+ options_hash
35
+ .foreach(|key: Symbol, value: Value| {
36
+ match key.name() {
37
+ Ok(Cow::Borrowed(RENDER_HARDBREAKS)) => {
38
+ comrak_options.render.hardbreaks = value.try_convert::<bool>()?;
39
+ }
40
+ Ok(Cow::Borrowed(RENDER_GITHUB_PRE_LANG)) => {
41
+ comrak_options.render.github_pre_lang = value.try_convert::<bool>()?;
42
+ }
43
+ Ok(Cow::Borrowed(RENDER_WIDTH)) => {
44
+ comrak_options.render.width = value.try_convert::<usize>()?;
45
+ }
46
+ Ok(Cow::Borrowed(RENDER_UNSAFE)) => {
47
+ comrak_options.render.unsafe_ = value.try_convert::<bool>()?;
48
+ }
49
+ Ok(Cow::Borrowed(RENDER_ESCAPE)) => {
50
+ comrak_options.render.escape = value.try_convert::<bool>()?;
51
+ }
52
+ _ => {}
53
+ }
54
+ Ok(ForEach::Continue)
55
+ })
56
+ .unwrap();
41
57
  }
42
58
 
43
- fn iterate_extension_options(comrak_options: &mut ComrakOptions, options_hash: RHash) {
44
- options_hash.foreach(|key: Symbol, value: Value| {
45
- if key.name().unwrap() == "strikethrough" {
46
- comrak_options.extension.strikethrough = value.try_convert::<bool>()?;
47
- }
48
-
49
- if key.name().unwrap() == "tagfilter" {
50
- comrak_options.extension.tagfilter = value.try_convert::<bool>()?;
51
- }
52
-
53
- if key.name().unwrap() == "table" {
54
- comrak_options.extension.table = value.try_convert::<bool>()?;
55
- }
59
+ const EXTENSION_STRIKETHROUGH: &str = "strikethrough";
60
+ const EXTENSION_TAGFILTER: &str = "tagfilter";
61
+ const EXTENSION_TABLE: &str = "table";
62
+ const EXTENSION_AUTOLINK: &str = "autolink";
63
+ const EXTENSION_TASKLIST: &str = "tasklist";
64
+ const EXTENSION_SUPERSCRIPT: &str = "superscript";
65
+ const EXTENSION_HEADER_IDS: &str = "header_ids";
66
+ const EXTENSION_FOOTNOTES: &str = "footnotes";
67
+ const EXTENSION_DESCRIPTION_LISTS: &str = "description_lists";
68
+ const EXTENSION_FRONT_MATTER_DELIMITER: &str = "front_matter_delimiter";
56
69
 
57
- if key.name().unwrap() == "autolink" {
58
- comrak_options.extension.autolink = value.try_convert::<bool>()?;
59
- }
60
-
61
- if key.name().unwrap() == "tasklist" {
62
- comrak_options.extension.tasklist = value.try_convert::<bool>()?;
63
- }
64
-
65
- if key.name().unwrap() == "superscript" {
66
- comrak_options.extension.superscript = value.try_convert::<bool>()?;
67
- }
68
-
69
- if key.name().unwrap() == "header_ids" {
70
- comrak_options.extension.header_ids = Some(value.try_convert::<String>().unwrap());
71
- }
72
-
73
- if key.name().unwrap() == "footnotes" {
74
- comrak_options.extension.footnotes = value.try_convert::<bool>()?;
75
- }
76
-
77
- if key.name().unwrap() == "description_lists" {
78
- comrak_options.extension.description_lists = value.try_convert::<bool>()?;
79
- }
80
-
81
- if key.name().unwrap() == "front_matter_delimiter" {
82
- comrak_options.extension.front_matter_delimiter =
83
- Some(value.try_convert::<String>().unwrap());
84
- }
85
-
86
- Ok(ForEach::Continue)
87
- });
70
+ fn iterate_extension_options(comrak_options: &mut ComrakOptions, options_hash: RHash) {
71
+ options_hash
72
+ .foreach(|key: Symbol, value: Value| {
73
+ match key.name() {
74
+ Ok(Cow::Borrowed(EXTENSION_STRIKETHROUGH)) => {
75
+ comrak_options.extension.strikethrough = value.try_convert::<bool>()?;
76
+ }
77
+ Ok(Cow::Borrowed(EXTENSION_TAGFILTER)) => {
78
+ comrak_options.extension.tagfilter = value.try_convert::<bool>()?;
79
+ }
80
+ Ok(Cow::Borrowed(EXTENSION_TABLE)) => {
81
+ comrak_options.extension.table = value.try_convert::<bool>()?;
82
+ }
83
+ Ok(Cow::Borrowed(EXTENSION_AUTOLINK)) => {
84
+ comrak_options.extension.autolink = value.try_convert::<bool>()?;
85
+ }
86
+ Ok(Cow::Borrowed(EXTENSION_TASKLIST)) => {
87
+ comrak_options.extension.tasklist = value.try_convert::<bool>()?;
88
+ }
89
+ Ok(Cow::Borrowed(EXTENSION_SUPERSCRIPT)) => {
90
+ comrak_options.extension.superscript = value.try_convert::<bool>()?;
91
+ }
92
+ Ok(Cow::Borrowed(EXTENSION_HEADER_IDS)) => {
93
+ comrak_options.extension.header_ids = try_convert_string(value);
94
+ }
95
+ Ok(Cow::Borrowed(EXTENSION_FOOTNOTES)) => {
96
+ comrak_options.extension.footnotes = value.try_convert::<bool>()?;
97
+ }
98
+ Ok(Cow::Borrowed(EXTENSION_DESCRIPTION_LISTS)) => {
99
+ comrak_options.extension.description_lists = value.try_convert::<bool>()?;
100
+ }
101
+ Ok(Cow::Borrowed(EXTENSION_FRONT_MATTER_DELIMITER)) => {
102
+ comrak_options.extension.front_matter_delimiter = try_convert_string(value);
103
+ }
104
+ _ => {}
105
+ }
106
+ Ok(ForEach::Continue)
107
+ })
108
+ .unwrap();
88
109
  }
89
110
 
90
111
  pub fn iterate_options_hash(
@@ -105,3 +126,11 @@ pub fn iterate_options_hash(
105
126
  }
106
127
  Ok(ForEach::Continue)
107
128
  }
129
+
130
+ fn try_convert_string(value: Value) -> Option<String> {
131
+ if value.is_kind_of(class::string()) {
132
+ Some(value.try_convert::<String>().unwrap())
133
+ } else {
134
+ None
135
+ }
136
+ }
@@ -9,10 +9,12 @@ use comrak_options::iterate_options_hash;
9
9
  fn commonmark_to_html(rb_commonmark: String, rb_options: magnus::RHash) -> String {
10
10
  let mut comrak_options = ComrakOptions::default();
11
11
 
12
- rb_options.foreach(|key: Symbol, value: RHash| {
13
- iterate_options_hash(&mut comrak_options, key, value);
14
- Ok(ForEach::Continue)
15
- });
12
+ rb_options
13
+ .foreach(|key: Symbol, value: RHash| {
14
+ iterate_options_hash(&mut comrak_options, key, value).unwrap();
15
+ Ok(ForEach::Continue)
16
+ })
17
+ .unwrap();
16
18
 
17
19
  markdown_to_html(&rb_commonmark, &comrak_options)
18
20
  }
@@ -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: nil,
30
30
  },
31
31
  format: [:html].freeze,
32
32
  }.freeze
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Commonmarker
4
- VERSION = "1.0.0.pre"
4
+ VERSION = "1.0.0.pre.2"
5
5
  end
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.0.0.pre
4
+ version: 1.0.0.pre.2
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: 2022-11-03 00:00:00.000000000 Z
12
+ date: 2022-11-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rb_sys