commonmarker 0.23.7.pre1 → 1.0.0.pre.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 +136 -0
  8. data/ext/commonmarker/src/lib.rs +29 -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 +34 -178
  15. data/Rakefile +0 -109
  16. data/bin/commonmarker +0 -118
  17. data/ext/commonmarker/arena.c +0 -103
  18. data/ext/commonmarker/autolink.c +0 -456
  19. data/ext/commonmarker/autolink.h +0 -8
  20. data/ext/commonmarker/blocks.c +0 -1596
  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 -736
  27. data/ext/commonmarker/cmark-gfm-extensions_export.h +0 -42
  28. data/ext/commonmarker/cmark-gfm.h +0 -817
  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 -529
  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 -486
  49. data/ext/commonmarker/html.h +0 -27
  50. data/ext/commonmarker/inlines.c +0 -1716
  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 -466
  55. data/ext/commonmarker/linked_list.c +0 -37
  56. data/ext/commonmarker/man.c +0 -278
  57. data/ext/commonmarker/map.c +0 -122
  58. data/ext/commonmarker/map.h +0 -41
  59. data/ext/commonmarker/node.c +0 -979
  60. data/ext/commonmarker/node.h +0 -125
  61. data/ext/commonmarker/parser.h +0 -58
  62. data/ext/commonmarker/plaintext.c +0 -235
  63. data/ext/commonmarker/plugin.c +0 -36
  64. data/ext/commonmarker/plugin.h +0 -34
  65. data/ext/commonmarker/references.c +0 -42
  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 -205
  70. data/ext/commonmarker/render.h +0 -62
  71. data/ext/commonmarker/scanners.c +0 -10508
  72. data/ext/commonmarker/scanners.h +0 -62
  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 -848
  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 -181
  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 -252
metadata CHANGED
@@ -1,262 +1,118 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: commonmarker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.23.7.pre1
4
+ version: 1.0.0.pre.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garen Torikian
8
8
  - Ashe Connor
9
9
  autorequire:
10
- bindir: bin
10
+ bindir: exe
11
11
  cert_chain: []
12
- date: 2022-11-14 00:00:00.000000000 Z
12
+ date: 2022-11-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: awesome_print
15
+ name: rb_sys
16
16
  requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - ">="
19
- - !ruby/object:Gem::Version
20
- version: '0'
21
- type: :development
22
- prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- version: '0'
28
- - !ruby/object:Gem::Dependency
29
- name: json
30
- requirement: !ruby/object:Gem::Requirement
31
- requirements:
32
- - - "~>"
33
- - !ruby/object:Gem::Version
34
- version: '2.3'
35
- type: :development
36
- prerelease: false
37
- version_requirements: !ruby/object:Gem::Requirement
38
17
  requirements:
39
18
  - - "~>"
40
19
  - !ruby/object:Gem::Version
41
- version: '2.3'
42
- - !ruby/object:Gem::Dependency
43
- name: minitest
44
- requirement: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - "~>"
47
- - !ruby/object:Gem::Version
48
- version: '5.6'
49
- type: :development
20
+ version: '0.9'
21
+ type: :runtime
50
22
  prerelease: false
51
23
  version_requirements: !ruby/object:Gem::Requirement
52
24
  requirements:
53
25
  - - "~>"
54
26
  - !ruby/object:Gem::Version
55
- version: '5.6'
27
+ version: '0.9'
56
28
  - !ruby/object:Gem::Dependency
57
- name: minitest-focus
29
+ name: rake
58
30
  requirement: !ruby/object:Gem::Requirement
59
31
  requirements:
60
32
  - - "~>"
61
33
  - !ruby/object:Gem::Version
62
- version: '1.1'
34
+ version: '13.0'
63
35
  type: :development
64
36
  prerelease: false
65
37
  version_requirements: !ruby/object:Gem::Requirement
66
38
  requirements:
67
39
  - - "~>"
68
40
  - !ruby/object:Gem::Version
69
- version: '1.1'
70
- - !ruby/object:Gem::Dependency
71
- name: rake
72
- requirement: !ruby/object:Gem::Requirement
73
- requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- version: '0'
77
- type: :development
78
- prerelease: false
79
- version_requirements: !ruby/object:Gem::Requirement
80
- requirements:
81
- - - ">="
82
- - !ruby/object:Gem::Version
83
- version: '0'
41
+ version: '13.0'
84
42
  - !ruby/object:Gem::Dependency
85
43
  name: rake-compiler
86
44
  requirement: !ruby/object:Gem::Requirement
87
45
  requirements:
88
46
  - - "~>"
89
47
  - !ruby/object:Gem::Version
90
- version: '0.9'
48
+ version: '1.2'
91
49
  type: :development
92
50
  prerelease: false
93
51
  version_requirements: !ruby/object:Gem::Requirement
94
52
  requirements:
95
53
  - - "~>"
96
54
  - !ruby/object:Gem::Version
97
- version: '0.9'
55
+ version: '1.2'
98
56
  - !ruby/object:Gem::Dependency
99
- name: rdoc
57
+ name: rake-compiler-dock
100
58
  requirement: !ruby/object:Gem::Requirement
101
59
  requirements:
102
60
  - - "~>"
103
61
  - !ruby/object:Gem::Version
104
- version: '6.2'
62
+ version: '1.2'
105
63
  type: :development
106
64
  prerelease: false
107
65
  version_requirements: !ruby/object:Gem::Requirement
108
66
  requirements:
109
67
  - - "~>"
110
68
  - !ruby/object:Gem::Version
111
- version: '6.2'
112
- - !ruby/object:Gem::Dependency
113
- name: rubocop
114
- requirement: !ruby/object:Gem::Requirement
115
- requirements:
116
- - - ">="
117
- - !ruby/object:Gem::Version
118
- version: '0'
119
- type: :development
120
- prerelease: false
121
- version_requirements: !ruby/object:Gem::Requirement
122
- requirements:
123
- - - ">="
124
- - !ruby/object:Gem::Version
125
- version: '0'
126
- - !ruby/object:Gem::Dependency
127
- name: rubocop-standard
128
- requirement: !ruby/object:Gem::Requirement
129
- requirements:
130
- - - ">="
131
- - !ruby/object:Gem::Version
132
- version: '0'
133
- type: :development
134
- prerelease: false
135
- version_requirements: !ruby/object:Gem::Requirement
136
- requirements:
137
- - - ">="
138
- - !ruby/object:Gem::Version
139
- version: '0'
140
- description: A fast, safe, extensible parser for CommonMark. This wraps the official
141
- libcmark library.
69
+ version: '1.2'
70
+ description: A fast, safe, extensible parser for CommonMark. This wraps the comrak
71
+ Rust crate.
142
72
  email:
143
- executables:
144
- - commonmarker
73
+ executables: []
145
74
  extensions:
146
- - ext/commonmarker/extconf.rb
75
+ - ext/commonmarker/Cargo.toml
147
76
  extra_rdoc_files: []
148
77
  files:
149
78
  - LICENSE.txt
150
79
  - README.md
151
- - Rakefile
152
- - bin/commonmarker
153
80
  - commonmarker.gemspec
154
- - ext/commonmarker/arena.c
155
- - ext/commonmarker/autolink.c
156
- - ext/commonmarker/autolink.h
157
- - ext/commonmarker/blocks.c
158
- - ext/commonmarker/buffer.c
159
- - ext/commonmarker/buffer.h
160
- - ext/commonmarker/case_fold_switch.inc
161
- - ext/commonmarker/chunk.h
162
- - ext/commonmarker/cmark-gfm-core-extensions.h
163
- - ext/commonmarker/cmark-gfm-extension_api.h
164
- - ext/commonmarker/cmark-gfm-extensions_export.h
165
- - ext/commonmarker/cmark-gfm.h
166
- - ext/commonmarker/cmark-gfm_export.h
167
- - ext/commonmarker/cmark-gfm_version.h
168
- - ext/commonmarker/cmark.c
169
- - ext/commonmarker/cmark_ctype.c
170
- - ext/commonmarker/cmark_ctype.h
171
- - ext/commonmarker/commonmark.c
172
- - ext/commonmarker/commonmarker.c
173
- - ext/commonmarker/commonmarker.h
174
- - ext/commonmarker/config.h
175
- - ext/commonmarker/core-extensions.c
176
- - ext/commonmarker/entities.inc
177
- - ext/commonmarker/ext_scanners.c
178
- - ext/commonmarker/ext_scanners.h
81
+ - ext/commonmarker/Cargo.toml
82
+ - ext/commonmarker/_util.rb
179
83
  - ext/commonmarker/extconf.rb
180
- - ext/commonmarker/footnotes.c
181
- - ext/commonmarker/footnotes.h
182
- - ext/commonmarker/houdini.h
183
- - ext/commonmarker/houdini_href_e.c
184
- - ext/commonmarker/houdini_html_e.c
185
- - ext/commonmarker/houdini_html_u.c
186
- - ext/commonmarker/html.c
187
- - ext/commonmarker/html.h
188
- - ext/commonmarker/inlines.c
189
- - ext/commonmarker/inlines.h
190
- - ext/commonmarker/iterator.c
191
- - ext/commonmarker/iterator.h
192
- - ext/commonmarker/latex.c
193
- - ext/commonmarker/linked_list.c
194
- - ext/commonmarker/man.c
195
- - ext/commonmarker/map.c
196
- - ext/commonmarker/map.h
197
- - ext/commonmarker/node.c
198
- - ext/commonmarker/node.h
199
- - ext/commonmarker/parser.h
200
- - ext/commonmarker/plaintext.c
201
- - ext/commonmarker/plugin.c
202
- - ext/commonmarker/plugin.h
203
- - ext/commonmarker/references.c
204
- - ext/commonmarker/references.h
205
- - ext/commonmarker/registry.c
206
- - ext/commonmarker/registry.h
207
- - ext/commonmarker/render.c
208
- - ext/commonmarker/render.h
209
- - ext/commonmarker/scanners.c
210
- - ext/commonmarker/scanners.h
211
- - ext/commonmarker/scanners.re
212
- - ext/commonmarker/strikethrough.c
213
- - ext/commonmarker/strikethrough.h
214
- - ext/commonmarker/syntax_extension.c
215
- - ext/commonmarker/syntax_extension.h
216
- - ext/commonmarker/table.c
217
- - ext/commonmarker/table.h
218
- - ext/commonmarker/tagfilter.c
219
- - ext/commonmarker/tagfilter.h
220
- - ext/commonmarker/tasklist.c
221
- - ext/commonmarker/tasklist.h
222
- - ext/commonmarker/utf8.c
223
- - ext/commonmarker/utf8.h
224
- - ext/commonmarker/xml.c
84
+ - ext/commonmarker/src/comrak_options.rs
85
+ - ext/commonmarker/src/lib.rs
225
86
  - lib/commonmarker.rb
226
87
  - lib/commonmarker/config.rb
227
- - lib/commonmarker/node.rb
228
- - lib/commonmarker/node/inspect.rb
88
+ - lib/commonmarker/extension.rb
229
89
  - lib/commonmarker/renderer.rb
230
- - lib/commonmarker/renderer/html_renderer.rb
231
90
  - lib/commonmarker/version.rb
232
91
  homepage: https://github.com/gjtorikian/commonmarker
233
92
  licenses:
234
93
  - MIT
235
94
  metadata:
95
+ allowed_push_host: https://rubygems.org
96
+ funding_uri: https://github.com/sponsors/gjtorikian/
97
+ source_code_uri: https://github.com/gjtorikian/commonmarker
236
98
  rubygems_mfa_required: 'true'
237
99
  post_install_message:
238
- rdoc_options:
239
- - "-x"
240
- - ext/commonmarker/cmark/.*
100
+ rdoc_options: []
241
101
  require_paths:
242
102
  - lib
243
- - ext
244
103
  required_ruby_version: !ruby/object:Gem::Requirement
245
104
  requirements:
246
- - - ">="
247
- - !ruby/object:Gem::Version
248
- version: '2.6'
249
- - - "<"
105
+ - - "~>"
250
106
  - !ruby/object:Gem::Version
251
- version: '4.0'
107
+ version: '3.1'
252
108
  required_rubygems_version: !ruby/object:Gem::Requirement
253
109
  requirements:
254
- - - ">"
110
+ - - ">="
255
111
  - !ruby/object:Gem::Version
256
- version: 1.3.1
112
+ version: 3.3.22
257
113
  requirements: []
258
- rubygems_version: 3.3.7
114
+ rubygems_version: 3.3.22
259
115
  signing_key:
260
116
  specification_version: 4
261
- summary: CommonMark parser and renderer. Written in C, wrapped in Ruby.
117
+ summary: CommonMark parser and renderer. Written in Rust, wrapped in Ruby.
262
118
  test_files: []
data/Rakefile DELETED
@@ -1,109 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "date"
4
- require "rake/clean"
5
- require "rake/extensiontask"
6
- require "digest/md5"
7
-
8
- host_os = RbConfig::CONFIG["host_os"]
9
- require "devkit" if host_os == "mingw32"
10
-
11
- task default: [:test]
12
-
13
- # Gem Spec
14
- gem_spec = Gem::Specification.load("commonmarker.gemspec")
15
-
16
- # Ruby Extension
17
- Rake::ExtensionTask.new("commonmarker", gem_spec) do |ext|
18
- ext.lib_dir = File.join("lib", "commonmarker")
19
- end
20
-
21
- # Packaging
22
- require "bundler/gem_tasks"
23
-
24
- # Testing
25
- require "rake/testtask"
26
-
27
- Rake::TestTask.new("test:unit") do |t|
28
- t.libs << "lib"
29
- t.libs << "test"
30
- t.pattern = "test/test_*.rb"
31
- t.verbose = true
32
- t.warning = false
33
- end
34
-
35
- desc "Run unit tests"
36
- task "test:unit" => :compile
37
-
38
- desc "Run unit and conformance tests"
39
- task test: ["test:unit"]
40
-
41
- require "rubocop/rake_task"
42
-
43
- RuboCop::RakeTask.new(:rubocop)
44
-
45
- desc "Run benchmarks"
46
- task :benchmark do
47
- if ENV["FETCH_PROGIT"]
48
- %x(rm -rf test/progit)
49
- %x(git clone https://github.com/progit/progit.git test/progit)
50
- langs = ["ar", "az", "be", "ca", "cs", "de", "en", "eo", "es", "es-ni", "fa", "fi", "fr", "hi", "hu", "id", "it", "ja", "ko", "mk", "nl", "no-nb", "pl", "pt-br", "ro", "ru", "sr", "th", "tr", "uk", "vi", "zh", "zh-tw"]
51
- langs.each do |lang|
52
- %x(cat test/progit/#{lang}/*/*.markdown >> test/benchinput.md)
53
- end
54
- end
55
- $LOAD_PATH.unshift("lib")
56
- load "test/benchmark.rb"
57
- end
58
-
59
- desc "Match C style of cmark"
60
- task :format do
61
- sh "clang-format -style llvm -i ext/commonmarker/*.c ext/commonmarker/*.h"
62
- end
63
-
64
- # Documentation
65
- require "rdoc/task"
66
-
67
- desc "Generate API documentation"
68
- RDoc::Task.new do |rd|
69
- rd.rdoc_dir = "docs"
70
- rd.main = "README.md"
71
- rd.rdoc_files.include("README.md", "lib/**/*.rb", "ext/commonmarker/commonmarker.c")
72
-
73
- rd.options << "--markup tomdoc"
74
- rd.options << "--inline-source"
75
- rd.options << "--line-numbers"
76
- rd.options << "--all"
77
- rd.options << "--fileboxes"
78
- end
79
-
80
- desc "Generate the documentation and run a web server"
81
- task serve: [:rdoc] do
82
- require "webrick"
83
-
84
- puts "Navigate to http://localhost:3000 to see the docs"
85
-
86
- server = WEBrick::HTTPServer.new(Port: 3000)
87
- server.mount("/", WEBrick::HTTPServlet::FileHandler, "docs")
88
- trap("INT") { server.stop }
89
- server.start
90
- end
91
-
92
- desc "Generate and publish docs to gh-pages"
93
- task publish: [:rdoc] do
94
- require "tmpdir"
95
- require "shellwords"
96
-
97
- Dir.mktmpdir do |tmp|
98
- system "mv docs/* #{tmp}"
99
- system "git checkout origin/gh-pages"
100
- system "rm -rf *"
101
- system "mv #{tmp}/* ."
102
- message = Shellwords.escape("Site updated at #{Time.now.utc}")
103
- system "git add ."
104
- system "git commit -am #{message}"
105
- system "git push origin gh-pages --force"
106
- system "git checkout master"
107
- system "echo yolo"
108
- end
109
- end
data/bin/commonmarker DELETED
@@ -1,118 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require 'optparse'
5
-
6
- $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
7
- require 'commonmarker'
8
-
9
- root = File.expand_path('..', __dir__)
10
- $LOAD_PATH.unshift File.expand_path('lib', root)
11
-
12
- def parse_options
13
- options = Struct.new(:active_extensions, :active_parse_options, :active_render_options, :output_format, :renderer)
14
- .new([], [:DEFAULT], [:DEFAULT], :html)
15
- extensions = CommonMarker.extensions
16
- parse_options = CommonMarker::Config::OPTS.fetch(:parse)
17
- render_options = CommonMarker::Config::OPTS.fetch(:render)
18
- format_options = CommonMarker::Config::OPTS.fetch(:format)
19
-
20
- option_parser = OptionParser.new do |opts|
21
- opts.banner = 'Usage: commonmarker [--html-renderer] [--extension=EXTENSION]'
22
- opts.separator ' [--to=FORMAT]'
23
- opts.separator ' [--parse-option=OPTION]'
24
- opts.separator ' [--render-option=OPTION]'
25
- opts.separator ' [FILE..]'
26
- opts.separator ''
27
- opts.separator 'Convert one or more CommonMark files to HTML and write to standard output.'
28
- opts.separator 'If no FILE argument is provided, text will be read from STDIN.'
29
- opts.separator ''
30
-
31
- opts.on('--extension=EXTENSION', Array, 'Use EXTENSION for parsing and HTML output (unless --html-renderer is specified)') do |values|
32
- values.each do |value|
33
- if extensions.include?(value)
34
- options.active_extensions << value.to_sym
35
- else
36
- abort("extension '#{value}' not found")
37
- end
38
- end
39
- end
40
-
41
- opts.on('-h', '--help', 'Prints this help') do
42
- puts opts
43
- puts
44
- puts "Available formats: #{format_options.join(', ')}"
45
- puts "Available extentions: #{extensions.join(', ')}"
46
- puts "Available parse options: #{parse_options.keys.join(', ')}"
47
- puts "Available render options: #{render_options.keys.join(', ')}"
48
- puts
49
- puts 'See the README for more information on these.'
50
- exit
51
- end
52
-
53
- opts.on('-tFORMAT', '--to=FORMAT', String, 'Specify output FORMAT') do |value|
54
- value = value.to_sym
55
- if format_options.include?(value)
56
- options.output_format = value
57
- else
58
- abort("format '#{value}' not found")
59
- end
60
- end
61
-
62
- opts.on('--html-renderer', 'Use the HtmlRenderer renderer rather than the native C renderer (only valid when format is html)') do
63
- options.renderer = true
64
- end
65
-
66
- opts.on('--parse-option=OPTION', Array, 'OPTION passed during parsing') do |values|
67
- values.each do |value|
68
- if parse_options.key?(value.to_sym)
69
- options.active_parse_options << value.to_sym
70
- else
71
- abort("parse-option '#{value}' not found")
72
- end
73
- end
74
- end
75
-
76
- opts.on('--render-option=OPTION', Array, 'OPTION passed during rendering') do |values|
77
- values.each do |value|
78
- if render_options.key?(value.to_sym)
79
- options.active_render_options << value.to_sym
80
- else
81
- abort("render-option '#{value}' not found")
82
- end
83
- end
84
- end
85
-
86
- opts.on('-v', '--version', 'Version information') do
87
- puts "commonmarker #{CommonMarker::VERSION}"
88
- exit
89
- end
90
- end
91
-
92
- option_parser.parse!
93
-
94
- options
95
- end
96
-
97
- options = parse_options
98
-
99
- abort("format '#{options.output_format}' does not support using the HtmlRenderer renderer") if
100
- options.renderer && options.output_format != :html
101
-
102
- doc = CommonMarker.render_doc(ARGF.read, options.active_parse_options, options.active_extensions)
103
-
104
- case options.output_format
105
- when :html
106
- if options.renderer
107
- renderer = CommonMarker::HtmlRenderer.new(options: options.active_render_options, extensions: options.active_extensions)
108
- $stdout.write(renderer.render(doc))
109
- else
110
- $stdout.write(doc.to_html(options.active_render_options, options.active_extensions))
111
- end
112
- when :xml
113
- $stdout.write(doc.to_xml(options.active_render_options))
114
- when :commonmark
115
- $stdout.write(doc.to_commonmark(options.active_render_options))
116
- when :plaintext
117
- $stdout.write(doc.to_plaintext(options.active_render_options))
118
- end
@@ -1,103 +0,0 @@
1
- #include <stdlib.h>
2
- #include <string.h>
3
- #include <stdint.h>
4
- #include "cmark-gfm.h"
5
- #include "cmark-gfm-extension_api.h"
6
-
7
- static struct arena_chunk {
8
- size_t sz, used;
9
- uint8_t push_point;
10
- void *ptr;
11
- struct arena_chunk *prev;
12
- } *A = NULL;
13
-
14
- static struct arena_chunk *alloc_arena_chunk(size_t sz, struct arena_chunk *prev) {
15
- struct arena_chunk *c = (struct arena_chunk *)calloc(1, sizeof(*c));
16
- if (!c)
17
- abort();
18
- c->sz = sz;
19
- c->ptr = calloc(1, sz);
20
- if (!c->ptr)
21
- abort();
22
- c->prev = prev;
23
- return c;
24
- }
25
-
26
- void cmark_arena_push(void) {
27
- if (!A)
28
- return;
29
- A->push_point = 1;
30
- A = alloc_arena_chunk(10240, A);
31
- }
32
-
33
- int cmark_arena_pop(void) {
34
- if (!A)
35
- return 0;
36
- while (A && !A->push_point) {
37
- free(A->ptr);
38
- struct arena_chunk *n = A->prev;
39
- free(A);
40
- A = n;
41
- }
42
- if (A)
43
- A->push_point = 0;
44
- return 1;
45
- }
46
-
47
- static void init_arena(void) {
48
- A = alloc_arena_chunk(4 * 1048576, NULL);
49
- }
50
-
51
- void cmark_arena_reset(void) {
52
- while (A) {
53
- free(A->ptr);
54
- struct arena_chunk *n = A->prev;
55
- free(A);
56
- A = n;
57
- }
58
- }
59
-
60
- static void *arena_calloc(size_t nmem, size_t size) {
61
- if (!A)
62
- init_arena();
63
-
64
- size_t sz = nmem * size + sizeof(size_t);
65
-
66
- // Round allocation sizes to largest integer size to
67
- // ensure returned memory is correctly aligned
68
- const size_t align = sizeof(size_t) - 1;
69
- sz = (sz + align) & ~align;
70
-
71
- if (sz > A->sz) {
72
- A->prev = alloc_arena_chunk(sz, A->prev);
73
- return (uint8_t *) A->prev->ptr + sizeof(size_t);
74
- }
75
- if (sz > A->sz - A->used) {
76
- A = alloc_arena_chunk(A->sz + A->sz / 2, A);
77
- }
78
- void *ptr = (uint8_t *) A->ptr + A->used;
79
- A->used += sz;
80
- *((size_t *) ptr) = sz - sizeof(size_t);
81
- return (uint8_t *) ptr + sizeof(size_t);
82
- }
83
-
84
- static void *arena_realloc(void *ptr, size_t size) {
85
- if (!A)
86
- init_arena();
87
-
88
- void *new_ptr = arena_calloc(1, size);
89
- if (ptr)
90
- memcpy(new_ptr, ptr, ((size_t *) ptr)[-1]);
91
- return new_ptr;
92
- }
93
-
94
- static void arena_free(void *ptr) {
95
- (void) ptr;
96
- /* no-op */
97
- }
98
-
99
- cmark_mem CMARK_ARENA_MEM_ALLOCATOR = {arena_calloc, arena_realloc, arena_free};
100
-
101
- cmark_mem *cmark_get_arena_mem_allocator() {
102
- return &CMARK_ARENA_MEM_ALLOCATOR;
103
- }