commonmarker 1.0.0-arm64-darwin

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: eeeeadabfad4dced733c85bca4b18f2154fece4823633207cd9493b53b5c80c4
4
+ data.tar.gz: b3a4f8a1f7761f2da50e51d414f17745c130b5c2875de5b55c4f3deadf0e166a
5
+ SHA512:
6
+ metadata.gz: 7c71926131405a94822a6c7bf0b4558db634289d3be9a377cb34ebab741446c2b40c78687f250b2c7c9ec2b72d009ecc9ef2610dedb73598f749224d8d618bdc
7
+ data.tar.gz: 8d67fe7a3cb13d5a033e4c8ab9f7bb1ae7ba4ec382e9cc519c2f2185bdfddb20296b5235651e74c73aa451c9e9f511bc28e590598b5910a50a2312657c050393
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Garen J. Torikian
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,229 @@
1
+ # Commonmarker
2
+
3
+ > **Note**
4
+ > This README refers to the behavior in the new 1.0.0.pre gem.
5
+
6
+ Ruby wrapper for Rust's [comrak](https://github.com/kivikakk/comrak) crate.
7
+
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
+
10
+ For more information on available extensions, see [the documentation below](#extension-options).
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ gem 'commonmarker'
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install commonmarker
25
+
26
+ ## Usage
27
+
28
+ ### Converting to HTML
29
+
30
+ Call `to_html` on a string to convert it to HTML:
31
+
32
+ ```ruby
33
+ require 'commonmarker'
34
+ Commonmarker.to_html('"Hi *there*"', options: {
35
+ parse: { smart: true }
36
+ })
37
+ # <p>“Hi <em>there</em>”</p>\n
38
+ ```
39
+
40
+ The second argument is optional--[see below](#options) for more information.
41
+
42
+ ## Options and plugins
43
+
44
+ ### Options
45
+
46
+ Commonmarker accepts the same parse, render, and extensions options that comrak does, as a hash dictionary with symbol keys:
47
+
48
+ ```ruby
49
+ Commonmarker.to_html('"Hi *there*"', options:{
50
+ parse: { smart: true },
51
+ render: { hardbreaks: false}
52
+ })
53
+ ```
54
+
55
+ Note that there is a distinction in comrak for "parse" options and "render" options, which are represented in the tables below.
56
+
57
+ ### Parse options
58
+
59
+ | Name | Description | Default |
60
+ | --------------------- | ------------------------------------------------------------------------------------ | ------- |
61
+ | `smart` | Punctuation (quotes, full-stops and hyphens) are converted into 'smart' punctuation. | `false` |
62
+ | `default_info_string` | The default info string for fenced code blocks. | `""` |
63
+
64
+ ### Render options
65
+
66
+ | Name | Description | Default |
67
+ | ----------------- | ------------------------------------------------------------------------------------------------------ | ------- |
68
+ | `hardbreaks` | [Soft line breaks](http://spec.commonmark.org/0.27/#soft-line-breaks) translate into hard line breaks. | `true` |
69
+ | `github_pre_lang` | GitHub-style `<pre lang="xyz">` is used for fenced code blocks with info tags. | `true` |
70
+ | `width` | The wrap column when outputting CommonMark. | `80` |
71
+ | `unsafe` | Allow rendering of raw HTML and potentially dangerous links. | `false` |
72
+ | `escape` | Escape raw HTML instead of clobbering it. | `false` |
73
+
74
+ As well, there are several extensions which you can toggle in the same manner:
75
+
76
+ ```ruby
77
+ Commonmarker.to_html('"Hi *there*"', options: {
78
+ extension: { footnotes: true, description_lists: true },
79
+ render: { hardbreaks: false}
80
+ })
81
+ ```
82
+
83
+ ### Extension options
84
+
85
+ | Name | Description | Default |
86
+ | ------------------------ | ------------------------------------------------------------------------------------------------------------------- | ------- |
87
+ | `strikethrough` | Enables the [strikethrough extension](https://github.github.com/gfm/#strikethrough-extension-) from the GFM spec. | `true` |
88
+ | `tagfilter` | Enables the [tagfilter extension](https://github.github.com/gfm/#disallowed-raw-html-extension-) from the GFM spec. | `true` |
89
+ | `table` | Enables the [table extension](https://github.github.com/gfm/#tables-extension-) from the GFM spec. | `true` |
90
+ | `autolink` | Enables the [autolink extension](https://github.github.com/gfm/#autolinks-extension-) from the GFM spec. | `true` |
91
+ | `tasklist` | Enables the [task list extension](https://github.github.com/gfm/#task-list-items-extension-) from the GFM spec. | `true` |
92
+ | `superscript` | Enables the superscript Comrak extension. | `false` |
93
+ | `header_ids` | Enables the header IDs Comrak extension. from the GFM spec. | `""` |
94
+ | `footnotes` | Enables the footnotes extension per `cmark-gfm`. | `false` |
95
+ | `description_lists` | Enables the description lists extension. | `false` |
96
+ | `front_matter_delimiter` | Enables the front matter extension. | `""` |
97
+ | `shortcodes` | Enables the shortcodes extension. | `true` |
98
+
99
+ For more information on these options, see [the comrak documentation](https://github.com/kivikakk/comrak#usage).
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
+
182
+ ## Output formats
183
+
184
+ Commonmarker can currently only generate output in one format: HTML.
185
+
186
+ ### HTML
187
+
188
+ ```ruby
189
+ puts Commonmarker.to_html('*Hello* world!')
190
+
191
+ # <p><em>Hello</em> world!</p>
192
+ ```
193
+
194
+ ## Developing locally
195
+
196
+ After cloning the repo:
197
+
198
+ ```
199
+ script/bootstrap
200
+ bundle exec rake compile
201
+ ```
202
+
203
+ If there were no errors, you're done! Otherwise, make sure to follow the comrak dependency instructions.
204
+
205
+ ## Benchmarks
206
+
207
+ Some rough benchmarks:
208
+
209
+ ```
210
+ $ bundle exec rake benchmark
211
+
212
+ input size = 11064832 bytes
213
+
214
+ Warming up --------------------------------------
215
+ redcarpet 2.000 i/100ms
216
+ commonmarker with to_html
217
+ 1.000 i/100ms
218
+ kramdown 1.000 i/100ms
219
+ Calculating -------------------------------------
220
+ redcarpet 22.317 (± 4.5%) i/s - 112.000 in 5.036374s
221
+ commonmarker with to_html
222
+ 5.815 (± 0.0%) i/s - 30.000 in 5.168869s
223
+ kramdown 0.327 (± 0.0%) i/s - 2.000 in 6.121486s
224
+
225
+ Comparison:
226
+ redcarpet: 22.3 i/s
227
+ commonmarker with to_html: 5.8 i/s - 3.84x (± 0.00) slower
228
+ kramdown: 0.3 i/s - 68.30x (± 0.00) slower
229
+ ```
@@ -0,0 +1,98 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Commonmarker
4
+ module Config
5
+ # For details, see
6
+ # https://github.com/kivikakk/comrak/blob/162ef9354deb2c9b4a4e05be495aa372ba5bb696/src/main.rs#L201
7
+ OPTIONS = {
8
+ parse: {
9
+ smart: false,
10
+ default_info_string: "",
11
+ }.freeze,
12
+ render: {
13
+ hardbreaks: true,
14
+ github_pre_lang: true,
15
+ width: 80,
16
+ unsafe: false,
17
+ escape: false,
18
+ }.freeze,
19
+ extension: {
20
+ strikethrough: true,
21
+ tagfilter: true,
22
+ table: true,
23
+ autolink: true,
24
+ tasklist: true,
25
+ superscript: false,
26
+ header_ids: "",
27
+ footnotes: false,
28
+ description_lists: false,
29
+ front_matter_delimiter: "",
30
+ shortcodes: true,
31
+ },
32
+ format: [:html].freeze,
33
+ }.freeze
34
+
35
+ PLUGINS = {
36
+ syntax_highlighter: {
37
+ theme: "base16-ocean.dark",
38
+ path: "",
39
+ },
40
+ }
41
+
42
+ class << self
43
+ include Commonmarker::Utils
44
+
45
+ def merged_with_defaults(options)
46
+ Commonmarker::Config::OPTIONS.merge(process_options(options))
47
+ end
48
+
49
+ def process_options(options)
50
+ {
51
+ parse: process_parse_options(options[:parse]),
52
+ render: process_render_options(options[:render]),
53
+ extension: process_extension_options(options[:extension]),
54
+ }
55
+ end
56
+
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
68
+ hash[key] = value
69
+ next
70
+ end
71
+
72
+ # option explicitly not included, remove it
73
+ next if option[key].nil?
74
+
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
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)
94
+ end
95
+ end
96
+ end
97
+ end
98
+ 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
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ # native precompiled gems package shared libraries in <gem_dir>/lib/commonmarker/<ruby_version>
5
+ # load the precompiled extension file
6
+ ruby_version = /\d+\.\d+/.match(RUBY_VERSION)
7
+ require_relative "#{ruby_version}/commonmarker"
8
+ rescue LoadError
9
+ # fall back to the extension compiled upon installation.
10
+ # use "require" instead of "require_relative" because non-native gems will place C extension files
11
+ # in Gem::BasicSpecification#extension_dir after compilation (during normal installation), which
12
+ # is in $LOAD_PATH but not necessarily relative to this file (see nokogiri#2300)
13
+ require "commonmarker/commonmarker"
14
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "set"
4
+ require "stringio"
5
+
6
+ module Commonmarker
7
+ class Renderer
8
+ end
9
+ end
@@ -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
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Commonmarker
4
+ VERSION = "1.0.0"
5
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "commonmarker/extension"
4
+
5
+ require "commonmarker/utils"
6
+ require "commonmarker/config"
7
+ require "commonmarker/renderer"
8
+ require "commonmarker/version"
9
+
10
+ module Commonmarker
11
+ class << self
12
+ # Public: Parses a CommonMark string into an HTML string.
13
+ #
14
+ # text - A {String} of text
15
+ # options - A {Hash} of render, parse, and extension options to transform the text.
16
+ # plugins - A {Hash} of additional plugins.
17
+ #
18
+ # Returns a {String} of converted HTML.
19
+ def to_html(text, options: Commonmarker::Config::OPTIONS, plugins: Commonmarker::Config::PLUGINS)
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"
22
+ raise TypeError, "options must be a Hash; got a #{options.class}!" unless options.is_a?(Hash)
23
+
24
+ opts = Config.process_options(options)
25
+ plugins = Config.process_plugins(plugins)
26
+
27
+ commonmark_to_html(text, options: opts, plugins: plugins)
28
+ end
29
+ end
30
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: commonmarker
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: arm64-darwin
6
+ authors:
7
+ - Garen Torikian
8
+ - Ashe Connor
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2023-12-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '13.0'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '13.0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake-compiler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.2'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.2'
42
+ description: A fast, safe, extensible parser for CommonMark. This wraps the comrak
43
+ Rust crate.
44
+ email:
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - LICENSE.txt
50
+ - README.md
51
+ - lib/commonmarker.rb
52
+ - lib/commonmarker/3.1/commonmarker.bundle
53
+ - lib/commonmarker/3.2/commonmarker.bundle
54
+ - lib/commonmarker/config.rb
55
+ - lib/commonmarker/constants.rb
56
+ - lib/commonmarker/extension.rb
57
+ - lib/commonmarker/renderer.rb
58
+ - lib/commonmarker/utils.rb
59
+ - lib/commonmarker/version.rb
60
+ homepage: https://github.com/gjtorikian/commonmarker
61
+ licenses:
62
+ - MIT
63
+ metadata:
64
+ allowed_push_host: https://rubygems.org
65
+ funding_uri: https://github.com/sponsors/gjtorikian/
66
+ source_code_uri: https://github.com/gjtorikian/commonmarker
67
+ rubygems_mfa_required: 'true'
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '3.1'
77
+ - - "<"
78
+ - !ruby/object:Gem::Version
79
+ version: 3.3.dev
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 3.3.22
85
+ requirements: []
86
+ rubygems_version: 3.4.4
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: CommonMark parser and renderer. Written in Rust, wrapped in Ruby.
90
+ test_files: []