commonmarker 1.0.0.pre-aarch64-linux → 1.0.1-aarch64-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: ae94393bd66ad4a95111860ec0dec2d209c6a3aef16d4362a416e8d1794c541e
4
- data.tar.gz: a868396154104751bc1f9f95c0580c57011093c75beafe452b740d828e136806
3
+ metadata.gz: 379a470f508500e2e560734084beb2ccf4b8db5543dec5d5c2d5ee87eaec24c8
4
+ data.tar.gz: e75575555b73d4831cfee1e67344d6b9dd40c93e791e7759757472a7032eec3a
5
5
  SHA512:
6
- metadata.gz: 8774c45f6ddea8d6ed13ea10ac233364c9279197116cc2121c45ae44981804d12cc8814c5fc6f42964fc01d25ad21b9feab00a92d4782011d47a45a5ebc6927a
7
- data.tar.gz: 453b852620d9be3dcefd3d6cb939935579fbc56a6ef2e3c24eaf0e897e6c4e1fe00f54e63764edff511a6e6026c8876a2f2b32eccda82bd5d114f6fc62236005
6
+ metadata.gz: 994764484fba08e5dc84d8d323bca634bca139eaa6c150bad8275324910ae9c7c71703d9e3c589ffe475b963413c702e048ea6b9ad91f37a20e8dbc91055234c
7
+ data.tar.gz: 4710cbb0866d9fa6abd4213344f5b2b56576b3ee1628c472d1bab3c14ca9db59e43a888436ec6b42f5251575bb4d96bdd18b51b5bb6dd1c25b01024f79ef04a6
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,15 @@ 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` |
73
+ | `sourcepos` | Include source position attribute in HTML and XML output. | `false` |
71
74
 
72
75
  As well, there are several extensions which you can toggle in the same manner:
73
76
 
74
77
  ```ruby
75
78
  Commonmarker.to_html('"Hi *there*"', options: {
76
- extensions: { footnotes: true, description_lists: true },
79
+ extension: { footnotes: true, description_lists: true },
77
80
  render: { hardbreaks: false}
78
81
  })
79
82
  ```
@@ -90,11 +93,93 @@ Commonmarker.to_html('"Hi *there*"', options: {
90
93
  | `superscript` | Enables the superscript Comrak extension. | `false` |
91
94
  | `header_ids` | Enables the header IDs Comrak extension. from the GFM spec. | `""` |
92
95
  | `footnotes` | Enables the footnotes extension per `cmark-gfm`. | `false` |
93
- | `description_lists` | Enables the description lists extension.. | `false` |
96
+ | `description_lists` | Enables the description lists extension. | `false` |
94
97
  | `front_matter_delimiter` | Enables the front matter extension. | `""` |
98
+ | `shortcodes` | Enables the shortcodes extension. | `true` |
95
99
 
96
100
  For more information on these options, see [the comrak documentation](https://github.com/kivikakk/comrak#usage).
97
101
 
102
+ ### Plugins
103
+
104
+ In addition to the possibilities provided by generic CommonMark rendering, Commonmarker also supports plugins as a means of
105
+ providing further niceties.
106
+
107
+ #### Syntax Highlighter Plugin
108
+
109
+ 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:
110
+
111
+ - `"base16-ocean.dark"`
112
+ - `"base16-eighties.dark"`
113
+ - `"base16-mocha.dark"`
114
+ - `"base16-ocean.light"`
115
+ - `"InspiredGitHub"`
116
+ - `"Solarized (dark)"`
117
+ - `"Solarized (light)"`
118
+
119
+ ````ruby
120
+ code = <<~CODE
121
+ ```ruby
122
+ def hello
123
+ puts "hello"
124
+ end
125
+ ```
126
+ CODE
127
+
128
+ # pass in a theme name from a pre-existing set
129
+ puts Commonmarker.to_html(code, plugins: { syntax_highlighter: { theme: "InspiredGitHub" } })
130
+
131
+ # <pre style="background-color:#ffffff;" lang="ruby"><code>
132
+ # <span style="font-weight:bold;color:#a71d5d;">def </span><span style="font-weight:bold;color:#795da3;">hello
133
+ # </span><span style="color:#62a35c;">puts </span><span style="color:#183691;">&quot;hello&quot;
134
+ # </span><span style="font-weight:bold;color:#a71d5d;">end
135
+ # </span>
136
+ # </code></pre>
137
+ ````
138
+
139
+ By default, the plugin uses the `"base16-ocean.dark"` theme to syntax highlight code.
140
+
141
+ To disable this plugin, set the value to `nil`:
142
+
143
+ ````ruby
144
+ code = <<~CODE
145
+ ```ruby
146
+ def hello
147
+ puts "hello"
148
+ end
149
+ ```
150
+ CODE
151
+
152
+ Commonmarker.to_html(code, plugins: { syntax_highlighter: nil })
153
+
154
+ # <pre lang="ruby"><code>def hello
155
+ # puts &quot;hello&quot;
156
+ # end
157
+ # </code></pre>
158
+ ````
159
+
160
+ To output CSS classes instead of `style` attributes, set the `theme` key to `""`:
161
+
162
+ ````ruby
163
+ code = <<~CODE
164
+ ```ruby
165
+ def hello
166
+ puts "hello"
167
+ end
168
+ CODE
169
+
170
+ Commonmarker.to_html(code, plugins: { syntax_highlighter: { theme: "" } })
171
+
172
+ # <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>
173
+ # <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>
174
+ # <span class="keyword control ruby">end</span>\n</span></code></pre>
175
+ ````
176
+
177
+ To use a custom theme, you can provide a `path` to a directory containing `.tmtheme` files to load:
178
+
179
+ ```ruby
180
+ Commonmarker.to_html(code, plugins: { syntax_highlighter: { theme: "Monokai", path: "./themes" } })
181
+ ```
182
+
98
183
  ## Output formats
99
184
 
100
185
  Commonmarker can currently only generate output in one format: HTML.
@@ -102,8 +187,7 @@ Commonmarker can currently only generate output in one format: HTML.
102
187
  ### HTML
103
188
 
104
189
  ```ruby
105
- html = CommonMarker.to_html('*Hello* world!', :DEFAULT)
106
- puts(html)
190
+ puts Commonmarker.to_html('*Hello* world!')
107
191
 
108
192
  # <p><em>Hello</em> world!</p>
109
193
  ```
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,8 +13,9 @@ 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
+ sourcepos: false,
18
19
  }.freeze,
19
20
  extension: {
20
21
  strikethrough: true,
@@ -27,13 +28,23 @@ module Commonmarker
27
28
  footnotes: false,
28
29
  description_lists: false,
29
30
  front_matter_delimiter: "",
31
+ shortcodes: true,
30
32
  },
31
33
  format: [:html].freeze,
32
34
  }.freeze
33
35
 
36
+ PLUGINS = {
37
+ syntax_highlighter: {
38
+ theme: "base16-ocean.dark",
39
+ path: "",
40
+ },
41
+ }
42
+
34
43
  class << self
44
+ include Commonmarker::Utils
45
+
35
46
  def merged_with_defaults(options)
36
- Commonmarker::Config::OPTS.merge(process_options(options))
47
+ Commonmarker::Config::OPTIONS.merge(process_options(options))
37
48
  end
38
49
 
39
50
  def process_options(options)
@@ -43,29 +54,44 @@ module Commonmarker
43
54
  extension: process_extension_options(options[:extension]),
44
55
  }
45
56
  end
46
- end
47
57
 
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
58
+ def process_plugins(plugins)
59
+ {
60
+ syntax_highlighter: process_syntax_highlighter_plugin(plugins&.fetch(:syntax_highlighter, nil)),
61
+ }
62
+ end
63
+ end
64
+
65
+ [:parse, :render, :extension].each do |type|
66
+ define_singleton_method :"process_#{type}_options" do |option|
67
+ Commonmarker::Config::OPTIONS[type].each_with_object({}) do |(key, value), hash|
68
+ if option.nil? # option not provided, go for the default
53
69
  hash[key] = value
54
70
  next
55
71
  end
56
72
 
57
73
  # option explicitly not included, remove it
58
- next if options[key].nil?
74
+ next if option[key].nil?
59
75
 
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}"
76
+ hash[key] = fetch_kv(option, key, value, type)
77
+ end
78
+ end
79
+ end
80
+
81
+ [:syntax_highlighter].each do |type|
82
+ define_singleton_method :"process_#{type}_plugin" do |plugin|
83
+ return if plugin.nil? # plugin explicitly nil, remove it
84
+
85
+ Commonmarker::Config::PLUGINS[type].each_with_object({}) do |(key, value), hash|
86
+ if plugin.nil? # option not provided, go for the default
87
+ hash[key] = value
88
+ next
68
89
  end
90
+
91
+ # option explicitly not included, remove it
92
+ next if plugin[key].nil?
93
+
94
+ hash[key] = fetch_kv(plugin, key, value, type)
69
95
  end
70
96
  end
71
97
  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.1"
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.1
5
5
  platform: aarch64-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-27 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
- }