commonmarker 1.0.0.pre-x86_64-linux → 1.0.0-x86_64-linux

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dd90daad77bfe132364aaa6ce37094897c5f65a066222f04cb29c2f282af31f7
4
- data.tar.gz: 948e34ec324bbe792021841b96221dc2ff73d72b0d3fcf5d6db413d1a2cd9cb6
3
+ metadata.gz: a1a96e2f4aea56d0e93d9e08e7fbe4d635d997c0d55119aef855138c974dbb78
4
+ data.tar.gz: 0a651661fb8e12325816e56c974f9f3607904b3dcd8ee805c3182ce791338bbc
5
5
  SHA512:
6
- metadata.gz: 7c025eacb5c47467a315668341d62efce7bca7e6a24c14a8a61f71764004bfc6d9f1a1a27fe0e498c21c16ba13ccd3541bd7d707c2941c6e29623b154d104eae
7
- data.tar.gz: d1fbad8e96d7a858f1889af8f2f04b3a39ca9073f341f8977d95ffd028dd2514ef5cc9740dc92e26554e8de7782297e25824da38d89f356cec9e25a00b0d3e5c
6
+ metadata.gz: 783b0846f87faf840e4427ccf7fbb111c930ed67011e2b8ef1ff2753e6ab7554aec43232b1920b0ac5afa0762c88174533c54114c3023b61f36319cc2744b6e3
7
+ data.tar.gz: c8107e67cd2b486b9f46dfe3812d3f4fda3c5150c873a73e5daaa76e441360b75aa8e0631145cfb75b5c589d5fd25c3efeef05ed0b3e13a437756d7a7bd16ad9
data/README.md CHANGED
@@ -7,7 +7,7 @@ Ruby wrapper for Rust's [comrak](https://github.com/kivikakk/comrak) crate.
7
7
 
8
8
  It passes all of the CommonMark test suite, and is therefore spec-complete. It also includes extensions to the CommonMark spec as documented in the [GitHub Flavored Markdown spec](http://github.github.com/gfm/), such as support for tables, strikethroughs, and autolinking.
9
9
 
10
- For more information on available extensions, see [the documentation below](#extensions).
10
+ For more information on available extensions, see [the documentation below](#extension-options).
11
11
 
12
12
  ## Installation
13
13
 
@@ -27,7 +27,7 @@ Or install it yourself as:
27
27
 
28
28
  ### Converting to HTML
29
29
 
30
- Call `render_html` on a string to convert it to HTML:
30
+ Call `to_html` on a string to convert it to HTML:
31
31
 
32
32
  ```ruby
33
33
  require 'commonmarker'
@@ -39,9 +39,11 @@ Commonmarker.to_html('"Hi *there*"', options: {
39
39
 
40
40
  The second argument is optional--[see below](#options) for more information.
41
41
 
42
- ## Parse and Render Options
42
+ ## Options and plugins
43
43
 
44
- Commonmarker accepts the same options that comrak does, as a hash dictionary with symbol keys:
44
+ ### Options
45
+
46
+ Commonmarker accepts the same parse, render, and extensions options that comrak does, as a hash dictionary with symbol keys:
45
47
 
46
48
  ```ruby
47
49
  Commonmarker.to_html('"Hi *there*"', options:{
@@ -66,14 +68,14 @@ Note that there is a distinction in comrak for "parse" options and "render" opti
66
68
  | `hardbreaks` | [Soft line breaks](http://spec.commonmark.org/0.27/#soft-line-breaks) translate into hard line breaks. | `true` |
67
69
  | `github_pre_lang` | GitHub-style `<pre lang="xyz">` is used for fenced code blocks with info tags. | `true` |
68
70
  | `width` | The wrap column when outputting CommonMark. | `80` |
69
- | `unsafe_` | Allow rendering of raw HTML and potentially dangerous links. | `false` |
71
+ | `unsafe` | Allow rendering of raw HTML and potentially dangerous links. | `false` |
70
72
  | `escape` | Escape raw HTML instead of clobbering it. | `false` |
71
73
 
72
74
  As well, there are several extensions which you can toggle in the same manner:
73
75
 
74
76
  ```ruby
75
77
  Commonmarker.to_html('"Hi *there*"', options: {
76
- extensions: { footnotes: true, description_lists: true },
78
+ extension: { footnotes: true, description_lists: true },
77
79
  render: { hardbreaks: false}
78
80
  })
79
81
  ```
@@ -90,11 +92,93 @@ Commonmarker.to_html('"Hi *there*"', options: {
90
92
  | `superscript` | Enables the superscript Comrak extension. | `false` |
91
93
  | `header_ids` | Enables the header IDs Comrak extension. from the GFM spec. | `""` |
92
94
  | `footnotes` | Enables the footnotes extension per `cmark-gfm`. | `false` |
93
- | `description_lists` | Enables the description lists extension.. | `false` |
95
+ | `description_lists` | Enables the description lists extension. | `false` |
94
96
  | `front_matter_delimiter` | Enables the front matter extension. | `""` |
97
+ | `shortcodes` | Enables the shortcodes extension. | `true` |
95
98
 
96
99
  For more information on these options, see [the comrak documentation](https://github.com/kivikakk/comrak#usage).
97
100
 
101
+ ### Plugins
102
+
103
+ In addition to the possibilities provided by generic CommonMark rendering, Commonmarker also supports plugins as a means of
104
+ providing further niceties.
105
+
106
+ #### Syntax Highlighter Plugin
107
+
108
+ The library comes with [a set of pre-existing themes](https://docs.rs/syntect/5.0.0/syntect/highlighting/struct.ThemeSet.html#implementations) for highlighting code:
109
+
110
+ - `"base16-ocean.dark"`
111
+ - `"base16-eighties.dark"`
112
+ - `"base16-mocha.dark"`
113
+ - `"base16-ocean.light"`
114
+ - `"InspiredGitHub"`
115
+ - `"Solarized (dark)"`
116
+ - `"Solarized (light)"`
117
+
118
+ ````ruby
119
+ code = <<~CODE
120
+ ```ruby
121
+ def hello
122
+ puts "hello"
123
+ end
124
+ ```
125
+ CODE
126
+
127
+ # pass in a theme name from a pre-existing set
128
+ puts Commonmarker.to_html(code, plugins: { syntax_highlighter: { theme: "InspiredGitHub" } })
129
+
130
+ # <pre style="background-color:#ffffff;" lang="ruby"><code>
131
+ # <span style="font-weight:bold;color:#a71d5d;">def </span><span style="font-weight:bold;color:#795da3;">hello
132
+ # </span><span style="color:#62a35c;">puts </span><span style="color:#183691;">&quot;hello&quot;
133
+ # </span><span style="font-weight:bold;color:#a71d5d;">end
134
+ # </span>
135
+ # </code></pre>
136
+ ````
137
+
138
+ By default, the plugin uses the `"base16-ocean.dark"` theme to syntax highlight code.
139
+
140
+ To disable this plugin, set the value to `nil`:
141
+
142
+ ````ruby
143
+ code = <<~CODE
144
+ ```ruby
145
+ def hello
146
+ puts "hello"
147
+ end
148
+ ```
149
+ CODE
150
+
151
+ Commonmarker.to_html(code, plugins: { syntax_highlighter: nil })
152
+
153
+ # <pre lang="ruby"><code>def hello
154
+ # puts &quot;hello&quot;
155
+ # end
156
+ # </code></pre>
157
+ ````
158
+
159
+ To output CSS classes instead of `style` attributes, set the `theme` key to `""`:
160
+
161
+ ````ruby
162
+ code = <<~CODE
163
+ ```ruby
164
+ def hello
165
+ puts "hello"
166
+ end
167
+ CODE
168
+
169
+ Commonmarker.to_html(code, plugins: { syntax_highlighter: { theme: "" } })
170
+
171
+ # <pre class="syntax-highlighting"><code><span class="source ruby"><span class="meta function ruby"><span class="keyword control def ruby">def</span></span><span class="meta function ruby"> # <span class="entity name function ruby">hello</span></span>
172
+ # <span class="support function builtin ruby">puts</span> <span class="string quoted double ruby"><span class="punctuation definition string begin ruby">&quot;</span>hello<span class="punctuation definition string end ruby">&quot;</span></span>
173
+ # <span class="keyword control ruby">end</span>\n</span></code></pre>
174
+ ````
175
+
176
+ To use a custom theme, you can provide a `path` to a directory containing `.tmtheme` files to load:
177
+
178
+ ```ruby
179
+ Commonmarker.to_html(code, plugins: { syntax_highlighter: { theme: "Monokai", path: "./themes" } })
180
+ ```
181
+
98
182
  ## Output formats
99
183
 
100
184
  Commonmarker can currently only generate output in one format: HTML.
@@ -102,8 +186,7 @@ Commonmarker can currently only generate output in one format: HTML.
102
186
  ### HTML
103
187
 
104
188
  ```ruby
105
- html = CommonMarker.to_html('*Hello* world!', :DEFAULT)
106
- puts(html)
189
+ puts Commonmarker.to_html('*Hello* world!')
107
190
 
108
191
  # <p><em>Hello</em> world!</p>
109
192
  ```
Binary file
@@ -4,7 +4,7 @@ module Commonmarker
4
4
  module Config
5
5
  # For details, see
6
6
  # https://github.com/kivikakk/comrak/blob/162ef9354deb2c9b4a4e05be495aa372ba5bb696/src/main.rs#L201
7
- OPTS = {
7
+ OPTIONS = {
8
8
  parse: {
9
9
  smart: false,
10
10
  default_info_string: "",
@@ -13,7 +13,7 @@ module Commonmarker
13
13
  hardbreaks: true,
14
14
  github_pre_lang: true,
15
15
  width: 80,
16
- unsafe_: false,
16
+ unsafe: false,
17
17
  escape: false,
18
18
  }.freeze,
19
19
  extension: {
@@ -27,13 +27,23 @@ module Commonmarker
27
27
  footnotes: false,
28
28
  description_lists: false,
29
29
  front_matter_delimiter: "",
30
+ shortcodes: true,
30
31
  },
31
32
  format: [:html].freeze,
32
33
  }.freeze
33
34
 
35
+ PLUGINS = {
36
+ syntax_highlighter: {
37
+ theme: "base16-ocean.dark",
38
+ path: "",
39
+ },
40
+ }
41
+
34
42
  class << self
43
+ include Commonmarker::Utils
44
+
35
45
  def merged_with_defaults(options)
36
- Commonmarker::Config::OPTS.merge(process_options(options))
46
+ Commonmarker::Config::OPTIONS.merge(process_options(options))
37
47
  end
38
48
 
39
49
  def process_options(options)
@@ -43,29 +53,44 @@ module Commonmarker
43
53
  extension: process_extension_options(options[:extension]),
44
54
  }
45
55
  end
46
- end
47
56
 
48
- BOOLS = [true, false]
49
- ["parse", "render", "extension"].each do |type|
50
- define_singleton_method :"process_#{type}_options" do |options|
51
- Commonmarker::Config::OPTS[type.to_sym].each_with_object({}) do |(key, value), hash|
52
- if options.nil? # option not provided, go for the default
57
+ def process_plugins(plugins)
58
+ {
59
+ syntax_highlighter: process_syntax_highlighter_plugin(plugins&.fetch(:syntax_highlighter, nil)),
60
+ }
61
+ end
62
+ end
63
+
64
+ [:parse, :render, :extension].each do |type|
65
+ define_singleton_method :"process_#{type}_options" do |option|
66
+ Commonmarker::Config::OPTIONS[type].each_with_object({}) do |(key, value), hash|
67
+ if option.nil? # option not provided, go for the default
53
68
  hash[key] = value
54
69
  next
55
70
  end
56
71
 
57
72
  # option explicitly not included, remove it
58
- next if options[key].nil?
73
+ next if option[key].nil?
59
74
 
60
- value_klass = value.class
61
- if BOOLS.include?(value) && BOOLS.include?(options[key])
62
- hash[key] = options[key]
63
- elsif options[key].is_a?(value_klass)
64
- hash[key] = options[key]
65
- else
66
- expected_type = BOOLS.include?(value) ? "Boolean" : value_klass.to_s
67
- raise TypeError, "#{type}_options[:#{key}] must be a #{expected_type}; got #{options[key].class}"
75
+ hash[key] = fetch_kv(option, key, value, type)
76
+ end
77
+ end
78
+ end
79
+
80
+ [:syntax_highlighter].each do |type|
81
+ define_singleton_method :"process_#{type}_plugin" do |plugin|
82
+ return if plugin.nil? # plugin explicitly nil, remove it
83
+
84
+ Commonmarker::Config::PLUGINS[type].each_with_object({}) do |(key, value), hash|
85
+ if plugin.nil? # option not provided, go for the default
86
+ hash[key] = value
87
+ next
68
88
  end
89
+
90
+ # option explicitly not included, remove it
91
+ next if plugin[key].nil?
92
+
93
+ hash[key] = fetch_kv(plugin, key, value, type)
69
94
  end
70
95
  end
71
96
  end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Commonmarker
4
+ module Constants
5
+ BOOLS = [true, false].freeze
6
+ end
7
+ end
@@ -3,7 +3,7 @@
3
3
  begin
4
4
  # native precompiled gems package shared libraries in <gem_dir>/lib/commonmarker/<ruby_version>
5
5
  # load the precompiled extension file
6
- ruby_version = /\d+\.\d+/.match(::RUBY_VERSION)
6
+ ruby_version = /\d+\.\d+/.match(RUBY_VERSION)
7
7
  require_relative "#{ruby_version}/commonmarker"
8
8
  rescue LoadError
9
9
  # fall back to the extension compiled upon installation.
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "commonmarker/constants"
4
+
5
+ module Commonmarker
6
+ module Utils
7
+ include Commonmarker::Constants
8
+
9
+ def fetch_kv(option, key, value, type)
10
+ value_klass = value.class
11
+
12
+ if Constants::BOOLS.include?(value) && BOOLS.include?(option[key])
13
+ option[key]
14
+ elsif option[key].is_a?(value_klass)
15
+ option[key]
16
+ else
17
+ expected_type = Constants::BOOLS.include?(value) ? "Boolean" : value_klass.to_s
18
+ raise TypeError, "#{type} option `:#{key}` must be #{expected_type}; got #{option[key].class}"
19
+ end
20
+ end
21
+ end
22
+ end
@@ -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"
5
5
  end
data/lib/commonmarker.rb CHANGED
@@ -2,29 +2,29 @@
2
2
 
3
3
  require_relative "commonmarker/extension"
4
4
 
5
+ require "commonmarker/utils"
5
6
  require "commonmarker/config"
6
7
  require "commonmarker/renderer"
7
8
  require "commonmarker/version"
8
9
 
9
- if ENV.fetch("DEBUG", false)
10
- require "awesome_print"
11
- require "debug"
12
- end
13
-
14
10
  module Commonmarker
15
11
  class << self
16
12
  # Public: Parses a CommonMark string into an HTML string.
17
13
  #
18
14
  # text - A {String} of text
19
- # option - A {Hash} of render, parse, and extension options to transform the text.
15
+ # options - A {Hash} of render, parse, and extension options to transform the text.
16
+ # plugins - A {Hash} of additional plugins.
20
17
  #
21
18
  # Returns a {String} of converted HTML.
22
- def to_html(text, options: Commonmarker::Config::OPTS)
19
+ def to_html(text, options: Commonmarker::Config::OPTIONS, plugins: Commonmarker::Config::PLUGINS)
23
20
  raise TypeError, "text must be a String; got a #{text.class}!" unless text.is_a?(String)
21
+ raise TypeError, "text must be UTF-8 encoded; got #{text.encoding}!" unless text.encoding.name == "UTF-8"
24
22
  raise TypeError, "options must be a Hash; got a #{options.class}!" unless options.is_a?(Hash)
25
23
 
26
24
  opts = Config.process_options(options)
27
- commonmark_to_html(text.encode("UTF-8"), opts)
25
+ plugins = Config.process_plugins(plugins)
26
+
27
+ commonmark_to_html(text, options: opts, plugins: plugins)
28
28
  end
29
29
  end
30
30
  end
metadata CHANGED
@@ -1,30 +1,16 @@
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
5
5
  platform: x86_64-linux
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: 2022-11-03 00:00:00.000000000 Z
12
+ date: 2023-12-24 00:00:00.000000000 Z
13
13
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: rb_sys
16
- requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - "~>"
19
- - !ruby/object:Gem::Version
20
- version: '0.9'
21
- type: :runtime
22
- prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - "~>"
26
- - !ruby/object:Gem::Version
27
- version: '0.9'
28
14
  - !ruby/object:Gem::Dependency
29
15
  name: rake
30
16
  requirement: !ruby/object:Gem::Requirement
@@ -53,40 +39,23 @@ dependencies:
53
39
  - - "~>"
54
40
  - !ruby/object:Gem::Version
55
41
  version: '1.2'
56
- - !ruby/object:Gem::Dependency
57
- name: rake-compiler-dock
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - "~>"
61
- - !ruby/object:Gem::Version
62
- version: '1.2'
63
- type: :development
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - "~>"
68
- - !ruby/object:Gem::Version
69
- version: '1.2'
70
42
  description: A fast, safe, extensible parser for CommonMark. This wraps the comrak
71
43
  Rust crate.
72
- email:
44
+ email:
73
45
  executables: []
74
46
  extensions: []
75
47
  extra_rdoc_files: []
76
48
  files:
77
49
  - LICENSE.txt
78
50
  - README.md
79
- - commonmarker.gemspec
80
- - ext/commonmarker/Cargo.toml
81
- - ext/commonmarker/_util.rb
82
- - ext/commonmarker/extconf.rb
83
- - ext/commonmarker/src/comrak_options.rs
84
- - ext/commonmarker/src/lib.rs
85
51
  - lib/commonmarker.rb
86
52
  - lib/commonmarker/3.1/commonmarker.so
53
+ - lib/commonmarker/3.2/commonmarker.so
87
54
  - lib/commonmarker/config.rb
55
+ - lib/commonmarker/constants.rb
88
56
  - lib/commonmarker/extension.rb
89
57
  - lib/commonmarker/renderer.rb
58
+ - lib/commonmarker/utils.rb
90
59
  - lib/commonmarker/version.rb
91
60
  homepage: https://github.com/gjtorikian/commonmarker
92
61
  licenses:
@@ -96,7 +65,7 @@ metadata:
96
65
  funding_uri: https://github.com/sponsors/gjtorikian/
97
66
  source_code_uri: https://github.com/gjtorikian/commonmarker
98
67
  rubygems_mfa_required: 'true'
99
- post_install_message:
68
+ post_install_message:
100
69
  rdoc_options: []
101
70
  require_paths:
102
71
  - lib
@@ -107,15 +76,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
107
76
  version: '3.1'
108
77
  - - "<"
109
78
  - !ruby/object:Gem::Version
110
- version: 3.2.dev
79
+ version: 3.3.dev
111
80
  required_rubygems_version: !ruby/object:Gem::Requirement
112
81
  requirements:
113
82
  - - ">="
114
83
  - !ruby/object:Gem::Version
115
84
  version: 3.3.22
116
85
  requirements: []
117
- rubygems_version: 3.3.22
118
- signing_key:
86
+ rubygems_version: 3.4.4
87
+ signing_key:
119
88
  specification_version: 4
120
89
  summary: CommonMark parser and renderer. Written in Rust, wrapped in Ruby.
121
90
  test_files: []
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"]
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/Cargo.toml"]
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
@@ -1,12 +0,0 @@
1
- [package]
2
- name = "commonmarker"
3
- version = "1.0.0"
4
- edition = "2021"
5
-
6
- [dependencies]
7
- magnus = { git = "https://github.com/gjtorikian/magnus", branch = "main" } # waiting for release with full rb-sys backend
8
- comrak = "0.14.0"
9
-
10
- [lib]
11
- name = "commonmarker"
12
- 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")
@@ -1,107 +0,0 @@
1
- use comrak::ComrakOptions;
2
-
3
- use magnus::{class, r_hash::ForEach, Error, RHash, Symbol, Value};
4
-
5
- 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
- });
15
- }
16
-
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
- }
34
-
35
- if key.name().unwrap() == "escape" {
36
- comrak_options.render.escape = value.try_convert::<bool>()?;
37
- }
38
-
39
- Ok(ForEach::Continue)
40
- });
41
- }
42
-
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
- }
56
-
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
- });
88
- }
89
-
90
- pub fn iterate_options_hash(
91
- comrak_options: &mut ComrakOptions,
92
- key: Symbol,
93
- value: RHash,
94
- ) -> Result<ForEach, Error> {
95
- assert!(value.is_kind_of(class::hash()));
96
-
97
- if key.name().unwrap() == "parse" {
98
- iterate_parse_options(comrak_options, value);
99
- }
100
- if key.name().unwrap() == "render" {
101
- iterate_render_options(comrak_options, value);
102
- }
103
- if key.name().unwrap() == "extension" {
104
- iterate_extension_options(comrak_options, value);
105
- }
106
- Ok(ForEach::Continue)
107
- }
@@ -1,27 +0,0 @@
1
- extern crate core;
2
-
3
- use comrak::{markdown_to_html, ComrakOptions};
4
- use magnus::{define_module, function, r_hash::ForEach, Error, RHash, Symbol};
5
-
6
- mod comrak_options;
7
- use comrak_options::iterate_options_hash;
8
-
9
- fn commonmark_to_html(rb_commonmark: String, rb_options: magnus::RHash) -> String {
10
- let mut comrak_options = ComrakOptions::default();
11
-
12
- rb_options.foreach(|key: Symbol, value: RHash| {
13
- iterate_options_hash(&mut comrak_options, key, value);
14
- Ok(ForEach::Continue)
15
- });
16
-
17
- markdown_to_html(&rb_commonmark, &comrak_options)
18
- }
19
-
20
- #[magnus::init]
21
- fn init() -> Result<(), Error> {
22
- let module = define_module("Commonmarker")?;
23
-
24
- module.define_module_function("commonmark_to_html", function!(commonmark_to_html, 2))?;
25
-
26
- Ok(())
27
- }