commonmarker 0.23.11 → 1.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +70 -212
  3. data/commonmarker.gemspec +34 -31
  4. data/ext/commonmarker/Cargo.toml +12 -0
  5. data/ext/commonmarker/_util.rb +102 -0
  6. data/ext/commonmarker/extconf.rb +4 -5
  7. data/ext/commonmarker/src/comrak_options.rs +107 -0
  8. data/ext/commonmarker/src/lib.rs +27 -0
  9. data/lib/commonmarker/config.rb +57 -38
  10. data/lib/commonmarker/extension.rb +14 -0
  11. data/lib/commonmarker/renderer.rb +1 -127
  12. data/lib/commonmarker/version.rb +2 -2
  13. data/lib/commonmarker.rb +14 -29
  14. metadata +37 -181
  15. data/Rakefile +0 -109
  16. data/bin/commonmarker +0 -118
  17. data/ext/commonmarker/arena.c +0 -104
  18. data/ext/commonmarker/autolink.c +0 -508
  19. data/ext/commonmarker/autolink.h +0 -8
  20. data/ext/commonmarker/blocks.c +0 -1622
  21. data/ext/commonmarker/buffer.c +0 -278
  22. data/ext/commonmarker/buffer.h +0 -116
  23. data/ext/commonmarker/case_fold_switch.inc +0 -4327
  24. data/ext/commonmarker/chunk.h +0 -135
  25. data/ext/commonmarker/cmark-gfm-core-extensions.h +0 -54
  26. data/ext/commonmarker/cmark-gfm-extension_api.h +0 -737
  27. data/ext/commonmarker/cmark-gfm-extensions_export.h +0 -42
  28. data/ext/commonmarker/cmark-gfm.h +0 -833
  29. data/ext/commonmarker/cmark-gfm_export.h +0 -42
  30. data/ext/commonmarker/cmark-gfm_version.h +0 -7
  31. data/ext/commonmarker/cmark.c +0 -55
  32. data/ext/commonmarker/cmark_ctype.c +0 -44
  33. data/ext/commonmarker/cmark_ctype.h +0 -33
  34. data/ext/commonmarker/commonmark.c +0 -514
  35. data/ext/commonmarker/commonmarker.c +0 -1307
  36. data/ext/commonmarker/commonmarker.h +0 -16
  37. data/ext/commonmarker/config.h +0 -76
  38. data/ext/commonmarker/core-extensions.c +0 -27
  39. data/ext/commonmarker/entities.inc +0 -2138
  40. data/ext/commonmarker/ext_scanners.c +0 -879
  41. data/ext/commonmarker/ext_scanners.h +0 -24
  42. data/ext/commonmarker/footnotes.c +0 -63
  43. data/ext/commonmarker/footnotes.h +0 -27
  44. data/ext/commonmarker/houdini.h +0 -57
  45. data/ext/commonmarker/houdini_href_e.c +0 -100
  46. data/ext/commonmarker/houdini_html_e.c +0 -66
  47. data/ext/commonmarker/houdini_html_u.c +0 -149
  48. data/ext/commonmarker/html.c +0 -502
  49. data/ext/commonmarker/html.h +0 -27
  50. data/ext/commonmarker/inlines.c +0 -1788
  51. data/ext/commonmarker/inlines.h +0 -29
  52. data/ext/commonmarker/iterator.c +0 -159
  53. data/ext/commonmarker/iterator.h +0 -26
  54. data/ext/commonmarker/latex.c +0 -468
  55. data/ext/commonmarker/linked_list.c +0 -37
  56. data/ext/commonmarker/man.c +0 -274
  57. data/ext/commonmarker/map.c +0 -129
  58. data/ext/commonmarker/map.h +0 -44
  59. data/ext/commonmarker/node.c +0 -1045
  60. data/ext/commonmarker/node.h +0 -167
  61. data/ext/commonmarker/parser.h +0 -59
  62. data/ext/commonmarker/plaintext.c +0 -218
  63. data/ext/commonmarker/plugin.c +0 -36
  64. data/ext/commonmarker/plugin.h +0 -34
  65. data/ext/commonmarker/references.c +0 -43
  66. data/ext/commonmarker/references.h +0 -26
  67. data/ext/commonmarker/registry.c +0 -63
  68. data/ext/commonmarker/registry.h +0 -24
  69. data/ext/commonmarker/render.c +0 -213
  70. data/ext/commonmarker/render.h +0 -62
  71. data/ext/commonmarker/scanners.c +0 -14056
  72. data/ext/commonmarker/scanners.h +0 -70
  73. data/ext/commonmarker/scanners.re +0 -341
  74. data/ext/commonmarker/strikethrough.c +0 -167
  75. data/ext/commonmarker/strikethrough.h +0 -9
  76. data/ext/commonmarker/syntax_extension.c +0 -149
  77. data/ext/commonmarker/syntax_extension.h +0 -34
  78. data/ext/commonmarker/table.c +0 -917
  79. data/ext/commonmarker/table.h +0 -12
  80. data/ext/commonmarker/tagfilter.c +0 -60
  81. data/ext/commonmarker/tagfilter.h +0 -8
  82. data/ext/commonmarker/tasklist.c +0 -156
  83. data/ext/commonmarker/tasklist.h +0 -8
  84. data/ext/commonmarker/utf8.c +0 -317
  85. data/ext/commonmarker/utf8.h +0 -35
  86. data/ext/commonmarker/xml.c +0 -182
  87. data/lib/commonmarker/node/inspect.rb +0 -47
  88. data/lib/commonmarker/node.rb +0 -83
  89. data/lib/commonmarker/renderer/html_renderer.rb +0 -256
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e070ea3105d17c7c6aea2bed32918bf8f31eaf7fb70106e7c025bbce1c600bf9
4
- data.tar.gz: f15ac1f428763032f711a799823ad865bdae33e7c1c671876201d690090170bb
3
+ metadata.gz: 85a99af1031da784a9618bc20f6cca8fae6a0e30418bab8b28321d284e2f0186
4
+ data.tar.gz: 0cc0fd0f0efe60f8c09ab8dd4fd8b242797e290842690f83291306765e08929a
5
5
  SHA512:
6
- metadata.gz: 96a4195b535ebcff926773f0ea0b2b9b06b49cbf2b250e84ded16df5001805278482e22a89f30a2ede940453ca4a31b32eb9dbc7c315153bcdb40ae8c8294a3e
7
- data.tar.gz: d9d781435db9096282da3a75dc8dca6eccc69ac3f23e37f23e0fc8f1f9eb1403f381d78db0bb5f24810222730a7968f041f3df0ed5027fe7251278f44747e840
6
+ metadata.gz: f8156096352b9519ce2e8dd1e2154152e2c3963ba6c3b4268cdbfea5314da6500eaf974613a1e1d5b9463ab256ca44fe17d165ce3a987288791ac0dffebc6287
7
+ data.tar.gz: 8ded44525de5d687f2488a60d6e7ba7fd2226ba973de9c6de5d9032b3b51bf49f249b0e0adf9685b2cea621326d2d41cf119426dd6fbded03dda3811ea7c5c03
data/README.md CHANGED
@@ -1,9 +1,11 @@
1
- # CommonMarker
1
+ # Commonmarker
2
2
 
3
- ![Build Status](https://github.com/gjtorikian/commonmarker/workflows/CI/badge.svg) [![Gem Version](https://badge.fury.io/rb/commonmarker.svg)](http://badge.fury.io/rb/commonmarker)
3
+ > **Note**
4
+ > This README refers to the behavior in the new 1.0.0.pre gem.
4
5
 
5
- Ruby wrapper for [libcmark-gfm](https://github.com/github/cmark),
6
- GitHub's fork of the reference parser for CommonMark. It passes all of the C tests, 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.
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.
7
9
 
8
10
  For more information on available extensions, see [the documentation below](#extensions).
9
11
 
@@ -27,232 +29,83 @@ Or install it yourself as:
27
29
 
28
30
  Call `render_html` on a string to convert it to HTML:
29
31
 
30
- ``` ruby
31
- require 'commonmarker'
32
- CommonMarker.render_html('Hi *there*', :DEFAULT)
33
- # <p>Hi <em>there</em></p>\n
34
- ```
35
-
36
- The second argument is optional--[see below](#options) for more information.
37
-
38
- ### Generating a document
39
-
40
- You can also parse a string to receive a `Document` node. You can then print that node to HTML, iterate over the children, and other fun node stuff. For example:
41
-
42
- ``` ruby
32
+ ```ruby
43
33
  require 'commonmarker'
44
-
45
- doc = CommonMarker.render_doc('*Hello* world', :DEFAULT)
46
- puts(doc.to_html) # <p>Hi <em>there</em></p>\n
47
-
48
- doc.walk do |node|
49
- puts node.type # [:document, :paragraph, :text, :emph, :text]
50
- end
34
+ Commonmarker.to_html('"Hi *there*"', options: {
35
+ parse: { smart: true }
36
+ })
37
+ # <p>“Hi <em>there</em>”</p>\n
51
38
  ```
52
39
 
53
40
  The second argument is optional--[see below](#options) for more information.
54
41
 
55
- #### Example: walking the AST
42
+ ## Parse and Render Options
56
43
 
57
- You can use `walk` or `each` to iterate over nodes:
44
+ Commonmarker accepts the same options that comrak does, as a hash dictionary with symbol keys:
58
45
 
59
- - `walk` will iterate on a node and recursively iterate on a node's children.
60
- - `each` will iterate on a node and its children, but no further.
61
-
62
- ``` ruby
63
- require 'commonmarker'
64
-
65
- # parse the files specified on the command line
66
- doc = CommonMarker.render_doc("# The site\n\n [GitHub](https://www.github.com)")
67
-
68
- # Walk tree and print out URLs for links
69
- doc.walk do |node|
70
- if node.type == :link
71
- printf("URL = %s\n", node.url)
72
- end
73
- end
74
-
75
- # Capitalize all regular text in headers
76
- doc.walk do |node|
77
- if node.type == :header
78
- node.each do |subnode|
79
- if subnode.type == :text
80
- subnode.string_content = subnode.string_content.upcase
81
- end
82
- end
83
- end
84
- end
85
-
86
- # Transform links to regular text
87
- doc.walk do |node|
88
- if node.type == :link
89
- node.insert_before(node.first_child)
90
- node.delete
91
- end
92
- end
93
- ```
94
-
95
- ### Creating a custom renderer
96
-
97
- You can also derive a class from CommonMarker's `HtmlRenderer` class. This produces slower output, but is far more customizable. For example:
98
-
99
- ``` ruby
100
- class MyHtmlRenderer < CommonMarker::HtmlRenderer
101
- def initialize
102
- super
103
- @headerid = 1
104
- end
105
-
106
- def header(node)
107
- block do
108
- out("<h", node.header_level, " id=\"", @headerid, "\">",
109
- :children, "</h", node.header_level, ">")
110
- @headerid += 1
111
- end
112
- end
113
- end
114
-
115
- myrenderer = MyHtmlRenderer.new
116
- puts myrenderer.render(doc)
117
-
118
- # Print any warnings to STDERR
119
- renderer.warnings.each do |w|
120
- STDERR.write("#{w}\n")
121
- end
46
+ ```ruby
47
+ Commonmarker.to_html('"Hi *there*"', options:{
48
+ parse: { smart: true },
49
+ render: { hardbreaks: false}
50
+ })
122
51
  ```
123
52
 
124
- ## Options
125
-
126
- CommonMarker accepts the same options that CMark does, as symbols. Note that there is a distinction in CMark for "parse" options and "render" options, which are represented in the tables below.
53
+ Note that there is a distinction in comrak for "parse" options and "render" options, which are represented in the tables below.
127
54
 
128
55
  ### Parse options
129
56
 
130
- | Name | Description
131
- | ----------------------------- | -----------
132
- | `:DEFAULT` | The default parsing system.
133
- | `:SOURCEPOS` | Include source position in nodes
134
- | `:UNSAFE` | Allow raw/custom HTML and unsafe links.
135
- | `:VALIDATE_UTF8` | Replace illegal sequences with the replacement character `U+FFFD`.
136
- | `:SMART` | Use smart punctuation (curly quotes, etc.).
137
- | `:LIBERAL_HTML_TAG` | Support liberal parsing of inline HTML tags.
138
- | `:FOOTNOTES` | Parse footnotes.
139
- | `:STRIKETHROUGH_DOUBLE_TILDE` | Parse strikethroughs by double tildes (compatibility with [redcarpet](https://github.com/vmg/redcarpet))
57
+ | Name | Description | Default |
58
+ | --------------------- | ------------------------------------------------------------------------------------ | ------- |
59
+ | `smart` | Punctuation (quotes, full-stops and hyphens) are converted into 'smart' punctuation. | `false` |
60
+ | `default_info_string` | The default info string for fenced code blocks. | `""` |
140
61
 
141
62
  ### Render options
142
63
 
143
- | Name | Description |
144
- | ------------------ | ----------- |
145
- | `:DEFAULT` | The default rendering system. |
146
- | `:SOURCEPOS` | Include source position in rendered HTML. |
147
- | `:HARDBREAKS` | Treat `\n` as hardbreaks (by adding `<br/>`). |
148
- | `:UNSAFE` | Allow raw/custom HTML and unsafe links. |
149
- | `:NOBREAKS` | Translate `\n` in the source to a single whitespace. |
150
- | `:VALIDATE_UTF8` | Replace illegal sequences with the replacement character `U+FFFD`. |
151
- | `:SMART` | Use smart punctuation (curly quotes, etc.). |
152
- | `:GITHUB_PRE_LANG` | Use GitHub-style `<pre lang>` for fenced code blocks. |
153
- | `:LIBERAL_HTML_TAG` | Support liberal parsing of inline HTML tags. |
154
- | `:FOOTNOTES` | Render footnotes. |
155
- | `:STRIKETHROUGH_DOUBLE_TILDE` | Parse strikethroughs by double tildes (compatibility with [redcarpet](https://github.com/vmg/redcarpet)) |
156
- | `:TABLE_PREFER_STYLE_ATTRIBUTES` | Use `style` insted of `align` for table cells. |
157
- | `:FULL_INFO_STRING` | Include full info strings of code blocks in separate attribute. |
158
-
159
- ### Passing options
160
-
161
- To apply a single option, pass it in as a symbol argument:
162
-
163
- ``` ruby
164
- CommonMarker.render_doc("\"Hello,\" said the spider.", :SMART)
165
- # <p>“Hello,” said the spider.</p>\n
166
- ```
64
+ | Name | Description | Default |
65
+ | ----------------- | ------------------------------------------------------------------------------------------------------ | ------- |
66
+ | `hardbreaks` | [Soft line breaks](http://spec.commonmark.org/0.27/#soft-line-breaks) translate into hard line breaks. | `true` |
67
+ | `github_pre_lang` | GitHub-style `<pre lang="xyz">` is used for fenced code blocks with info tags. | `true` |
68
+ | `width` | The wrap column when outputting CommonMark. | `80` |
69
+ | `unsafe_` | Allow rendering of raw HTML and potentially dangerous links. | `false` |
70
+ | `escape` | Escape raw HTML instead of clobbering it. | `false` |
167
71
 
168
- To have multiple options applied, pass in an array of symbols:
72
+ As well, there are several extensions which you can toggle in the same manner:
169
73
 
170
- ``` ruby
171
- CommonMarker.render_html("\"'Shelob' is my name.\"", [:HARDBREAKS, :SOURCEPOS])
74
+ ```ruby
75
+ Commonmarker.to_html('"Hi *there*"', options: {
76
+ extensions: { footnotes: true, description_lists: true },
77
+ render: { hardbreaks: false}
78
+ })
172
79
  ```
173
80
 
174
- For more information on these options, see [the CMark documentation](https://git.io/v7nh1).
175
-
176
- ## Extensions
177
-
178
- Both `render_html` and `render_doc` take an optional third argument defining the extensions you want enabled as your CommonMark document is being processed. The documentation for these extensions are [defined in this spec](https://github.github.com/gfm/), and the rationale is provided [in this blog post](https://githubengineering.com/a-formal-spec-for-github-markdown/).
81
+ ### Extension options
179
82
 
180
- The available extensions are:
83
+ | Name | Description | Default |
84
+ | ------------------------ | ------------------------------------------------------------------------------------------------------------------- | ------- |
85
+ | `strikethrough` | Enables the [strikethrough extension](https://github.github.com/gfm/#strikethrough-extension-) from the GFM spec. | `true` |
86
+ | `tagfilter` | Enables the [tagfilter extension](https://github.github.com/gfm/#disallowed-raw-html-extension-) from the GFM spec. | `true` |
87
+ | `table` | Enables the [table extension](https://github.github.com/gfm/#tables-extension-) from the GFM spec. | `true` |
88
+ | `autolink` | Enables the [autolink extension](https://github.github.com/gfm/#autolinks-extension-) from the GFM spec. | `true` |
89
+ | `tasklist` | Enables the [task list extension](https://github.github.com/gfm/#task-list-items-extension-) from the GFM spec. | `true` |
90
+ | `superscript` | Enables the superscript Comrak extension. | `false` |
91
+ | `header_ids` | Enables the header IDs Comrak extension. from the GFM spec. | `""` |
92
+ | `footnotes` | Enables the footnotes extension per `cmark-gfm`. | `false` |
93
+ | `description_lists` | Enables the description lists extension.. | `false` |
94
+ | `front_matter_delimiter` | Enables the front matter extension. | `""` |
181
95
 
182
- * `:table` - This provides support for tables.
183
- * `:tasklist` - This provides support for task list items.
184
- * `:strikethrough` - This provides support for strikethroughs.
185
- * `:autolink` - This provides support for automatically converting URLs to anchor tags.
186
- * `:tagfilter` - This escapes [several "unsafe" HTML tags](https://github.github.com/gfm/#disallowed-raw-html-extension-), causing them to not have any effect.
96
+ For more information on these options, see [the comrak documentation](https://github.com/kivikakk/comrak#usage).
187
97
 
188
98
  ## Output formats
189
99
 
190
- Like CMark, CommonMarker can generate output in several formats: HTML, XML, plaintext, and commonmark are currently supported.
100
+ Commonmarker can currently only generate output in one format: HTML.
191
101
 
192
102
  ### HTML
193
103
 
194
- The default output format, HTML, will be generated when calling `to_html` or using `--to=html` on the command line.
195
-
196
- ```ruby
197
- doc = CommonMarker.render_doc('*Hello* world!', :DEFAULT)
198
- puts(doc.to_html)
199
-
200
- <p><em>Hello</em> world!</p>
201
- ```
202
-
203
- ### XML
204
-
205
- XML will be generated when calling `to_xml` or using `--to=xml` on the command line.
206
-
207
- ```ruby
208
- doc = CommonMarker.render_doc('*Hello* world!', :DEFAULT)
209
- puts(doc.to_xml)
210
-
211
- <?xml version="1.0" encoding="UTF-8"?>
212
- <!DOCTYPE document SYSTEM "CommonMark.dtd">
213
- <document xmlns="http://commonmark.org/xml/1.0">
214
- <paragraph>
215
- <emph>
216
- <text xml:space="preserve">Hello</text>
217
- </emph>
218
- <text xml:space="preserve"> world!</text>
219
- </paragraph>
220
- </document>
221
- ```
222
-
223
- ### Plaintext
224
-
225
- Plaintext will be generated when calling `to_plaintext` or using `--to=plaintext` on the command line.
226
-
227
104
  ```ruby
228
- doc = CommonMarker.render_doc('*Hello* world!', :DEFAULT)
229
- puts(doc.to_plaintext)
105
+ html = CommonMarker.to_html('*Hello* world!', :DEFAULT)
106
+ puts(html)
230
107
 
231
- Hello world!
232
- ```
233
-
234
- ### Commonmark
235
-
236
- Commonmark will be generated when calling `to_commonmark` or using `--to=commonmark` on the command line.
237
-
238
- ``` ruby
239
- text = <<-TEXT
240
- 1. I am a numeric list.
241
- 2. I continue the list.
242
- * Suddenly, an unordered list!
243
- * What fun!
244
- TEXT
245
-
246
- doc = CommonMarker.render_doc(text, :DEFAULT)
247
- puts(doc.to_commonmark)
248
-
249
- 1. I am a numeric list.
250
- 2. I continue the list.
251
-
252
- <!-- end list -->
253
-
254
- - Suddenly, an unordered list\!
255
- - What fun\!
108
+ # <p><em>Hello</em> world!</p>
256
109
  ```
257
110
 
258
111
  ## Developing locally
@@ -264,7 +117,7 @@ script/bootstrap
264
117
  bundle exec rake compile
265
118
  ```
266
119
 
267
- If there were no errors, you're done! Otherwise, make sure to follow the CMark dependency instructions.
120
+ If there were no errors, you're done! Otherwise, make sure to follow the comrak dependency instructions.
268
121
 
269
122
  ## Benchmarks
270
123
 
@@ -273,16 +126,21 @@ Some rough benchmarks:
273
126
  ```
274
127
  $ bundle exec rake benchmark
275
128
 
276
- input size = 11063727 bytes
129
+ input size = 11064832 bytes
277
130
 
278
- redcarpet
279
- 0.070000 0.020000 0.090000 ( 0.079641)
280
- github-markdown
281
- 0.070000 0.010000 0.080000 ( 0.083535)
131
+ Warming up --------------------------------------
132
+ redcarpet 2.000 i/100ms
282
133
  commonmarker with to_html
283
- 0.100000 0.010000 0.110000 ( 0.111947)
284
- commonmarker with ruby HtmlRenderer
285
- 1.830000 0.030000 1.860000 ( 1.866203)
286
- kramdown
287
- 4.610000 0.070000 4.680000 ( 4.678398)
134
+ 1.000 i/100ms
135
+ kramdown 1.000 i/100ms
136
+ Calculating -------------------------------------
137
+ redcarpet 22.317 (± 4.5%) i/s - 112.000 in 5.036374s
138
+ commonmarker with to_html
139
+ 5.815 (± 0.0%) i/s - 30.000 in 5.168869s
140
+ kramdown 0.327 (± 0.0%) i/s - 2.000 in 6.121486s
141
+
142
+ Comparison:
143
+ redcarpet: 22.3 i/s
144
+ commonmarker with to_html: 5.8 i/s - 3.84x (± 0.00) slower
145
+ kramdown: 0.3 i/s - 68.30x (± 0.00) slower
288
146
  ```
data/commonmarker.gemspec CHANGED
@@ -4,35 +4,38 @@ lib = File.expand_path("lib", __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  require "commonmarker/version"
6
6
 
7
- Gem::Specification.new do |s|
8
- s.name = "commonmarker"
9
- s.version = CommonMarker::VERSION
10
- s.summary = "CommonMark parser and renderer. Written in C, wrapped in Ruby."
11
- s.description = "A fast, safe, extensible parser for CommonMark. This wraps the official libcmark library."
12
- s.authors = ["Garen Torikian", "Ashe Connor"]
13
- s.homepage = "https://github.com/gjtorikian/commonmarker"
14
- s.license = "MIT"
15
-
16
- s.files = ["LICENSE.txt", "README.md", "Rakefile", "commonmarker.gemspec", "bin/commonmarker"]
17
- s.files += Dir.glob("lib/**/*.rb")
18
- s.files += Dir.glob("ext/commonmarker/*.*")
19
- s.extensions = ["ext/commonmarker/extconf.rb"]
20
-
21
- s.executables = ["commonmarker"]
22
- s.require_paths = ["lib", "ext"]
23
- s.required_ruby_version = [">= 2.6", "< 4.0"]
24
-
25
- s.metadata["rubygems_mfa_required"] = "true"
26
-
27
- s.rdoc_options += ["-x", "ext/commonmarker/cmark/.*"]
28
-
29
- s.add_development_dependency("awesome_print")
30
- s.add_development_dependency("json", "~> 2.3")
31
- s.add_development_dependency("minitest", "~> 5.6")
32
- s.add_development_dependency("minitest-focus", "~> 1.1")
33
- s.add_development_dependency("rake")
34
- s.add_development_dependency("rake-compiler", "~> 0.9")
35
- s.add_development_dependency("rdoc", "~> 6.2")
36
- s.add_development_dependency("rubocop")
37
- s.add_development_dependency("rubocop-standard")
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")
38
41
  end
@@ -0,0 +1,12 @@
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"]
@@ -0,0 +1,102 @@
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,7 +1,6 @@
1
- # frozen_string_literal: true
1
+ require "mkmf"
2
+ require "rb_sys/mkmf"
2
3
 
3
- require 'mkmf'
4
+ require_relative "_util"
4
5
 
5
- $CFLAGS << ' -std=c99'
6
-
7
- create_makefile('commonmarker/commonmarker')
6
+ create_rust_makefile("commonmarker")
@@ -0,0 +1,107 @@
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
+ }