commonmarker 0.23.10 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/Cargo.lock +1220 -0
  3. data/Cargo.toml +7 -0
  4. data/README.md +217 -170
  5. data/ext/commonmarker/Cargo.toml +20 -0
  6. data/ext/commonmarker/extconf.rb +3 -6
  7. data/ext/commonmarker/src/lib.rs +183 -0
  8. data/ext/commonmarker/src/node.rs +1095 -0
  9. data/ext/commonmarker/src/options.rs +165 -0
  10. data/ext/commonmarker/src/plugins/syntax_highlighting.rs +74 -0
  11. data/ext/commonmarker/src/plugins.rs +3 -0
  12. data/ext/commonmarker/src/utils.rs +8 -0
  13. data/lib/commonmarker/config.rb +90 -40
  14. data/lib/commonmarker/constants.rb +7 -0
  15. data/lib/commonmarker/extension.rb +14 -0
  16. data/lib/commonmarker/node/ast.rb +8 -0
  17. data/lib/commonmarker/node/inspect.rb +14 -4
  18. data/lib/commonmarker/node.rb +29 -47
  19. data/lib/commonmarker/renderer.rb +1 -127
  20. data/lib/commonmarker/utils.rb +22 -0
  21. data/lib/commonmarker/version.rb +2 -2
  22. data/lib/commonmarker.rb +27 -25
  23. metadata +38 -186
  24. data/Rakefile +0 -109
  25. data/bin/commonmarker +0 -118
  26. data/commonmarker.gemspec +0 -38
  27. data/ext/commonmarker/arena.c +0 -104
  28. data/ext/commonmarker/autolink.c +0 -508
  29. data/ext/commonmarker/autolink.h +0 -8
  30. data/ext/commonmarker/blocks.c +0 -1622
  31. data/ext/commonmarker/buffer.c +0 -278
  32. data/ext/commonmarker/buffer.h +0 -116
  33. data/ext/commonmarker/case_fold_switch.inc +0 -4327
  34. data/ext/commonmarker/chunk.h +0 -135
  35. data/ext/commonmarker/cmark-gfm-core-extensions.h +0 -54
  36. data/ext/commonmarker/cmark-gfm-extension_api.h +0 -737
  37. data/ext/commonmarker/cmark-gfm-extensions_export.h +0 -42
  38. data/ext/commonmarker/cmark-gfm.h +0 -833
  39. data/ext/commonmarker/cmark-gfm_export.h +0 -42
  40. data/ext/commonmarker/cmark-gfm_version.h +0 -7
  41. data/ext/commonmarker/cmark.c +0 -55
  42. data/ext/commonmarker/cmark_ctype.c +0 -44
  43. data/ext/commonmarker/cmark_ctype.h +0 -33
  44. data/ext/commonmarker/commonmark.c +0 -514
  45. data/ext/commonmarker/commonmarker.c +0 -1308
  46. data/ext/commonmarker/commonmarker.h +0 -16
  47. data/ext/commonmarker/config.h +0 -76
  48. data/ext/commonmarker/core-extensions.c +0 -27
  49. data/ext/commonmarker/entities.inc +0 -2138
  50. data/ext/commonmarker/ext_scanners.c +0 -879
  51. data/ext/commonmarker/ext_scanners.h +0 -24
  52. data/ext/commonmarker/footnotes.c +0 -63
  53. data/ext/commonmarker/footnotes.h +0 -27
  54. data/ext/commonmarker/houdini.h +0 -57
  55. data/ext/commonmarker/houdini_href_e.c +0 -100
  56. data/ext/commonmarker/houdini_html_e.c +0 -66
  57. data/ext/commonmarker/houdini_html_u.c +0 -149
  58. data/ext/commonmarker/html.c +0 -502
  59. data/ext/commonmarker/html.h +0 -27
  60. data/ext/commonmarker/inlines.c +0 -1788
  61. data/ext/commonmarker/inlines.h +0 -29
  62. data/ext/commonmarker/iterator.c +0 -159
  63. data/ext/commonmarker/iterator.h +0 -26
  64. data/ext/commonmarker/latex.c +0 -468
  65. data/ext/commonmarker/linked_list.c +0 -37
  66. data/ext/commonmarker/man.c +0 -274
  67. data/ext/commonmarker/map.c +0 -129
  68. data/ext/commonmarker/map.h +0 -44
  69. data/ext/commonmarker/node.c +0 -1045
  70. data/ext/commonmarker/node.h +0 -167
  71. data/ext/commonmarker/parser.h +0 -59
  72. data/ext/commonmarker/plaintext.c +0 -218
  73. data/ext/commonmarker/plugin.c +0 -36
  74. data/ext/commonmarker/plugin.h +0 -34
  75. data/ext/commonmarker/references.c +0 -43
  76. data/ext/commonmarker/references.h +0 -26
  77. data/ext/commonmarker/registry.c +0 -63
  78. data/ext/commonmarker/registry.h +0 -24
  79. data/ext/commonmarker/render.c +0 -213
  80. data/ext/commonmarker/render.h +0 -62
  81. data/ext/commonmarker/scanners.c +0 -14056
  82. data/ext/commonmarker/scanners.h +0 -70
  83. data/ext/commonmarker/scanners.re +0 -341
  84. data/ext/commonmarker/strikethrough.c +0 -167
  85. data/ext/commonmarker/strikethrough.h +0 -9
  86. data/ext/commonmarker/syntax_extension.c +0 -149
  87. data/ext/commonmarker/syntax_extension.h +0 -34
  88. data/ext/commonmarker/table.c +0 -917
  89. data/ext/commonmarker/table.h +0 -12
  90. data/ext/commonmarker/tagfilter.c +0 -60
  91. data/ext/commonmarker/tagfilter.h +0 -8
  92. data/ext/commonmarker/tasklist.c +0 -156
  93. data/ext/commonmarker/tasklist.h +0 -8
  94. data/ext/commonmarker/utf8.c +0 -317
  95. data/ext/commonmarker/utf8.h +0 -35
  96. data/ext/commonmarker/xml.c +0 -182
  97. data/lib/commonmarker/renderer/html_renderer.rb +0 -256
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
data/commonmarker.gemspec DELETED
@@ -1,38 +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 |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")
38
- end
@@ -1,104 +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
- struct arena_chunk *chunk;
72
- if (sz > A->sz) {
73
- A->prev = chunk = alloc_arena_chunk(sz, A->prev);
74
- } else if (sz > A->sz - A->used) {
75
- A = chunk = alloc_arena_chunk(A->sz + A->sz / 2, A);
76
- } else {
77
- chunk = A;
78
- }
79
- void *ptr = (uint8_t *) chunk->ptr + chunk->used;
80
- chunk->used += sz;
81
- *((size_t *) ptr) = sz - sizeof(size_t);
82
- return (uint8_t *) ptr + sizeof(size_t);
83
- }
84
-
85
- static void *arena_realloc(void *ptr, size_t size) {
86
- if (!A)
87
- init_arena();
88
-
89
- void *new_ptr = arena_calloc(1, size);
90
- if (ptr)
91
- memcpy(new_ptr, ptr, ((size_t *) ptr)[-1]);
92
- return new_ptr;
93
- }
94
-
95
- static void arena_free(void *ptr) {
96
- (void) ptr;
97
- /* no-op */
98
- }
99
-
100
- cmark_mem CMARK_ARENA_MEM_ALLOCATOR = {arena_calloc, arena_realloc, arena_free};
101
-
102
- cmark_mem *cmark_get_arena_mem_allocator(void) {
103
- return &CMARK_ARENA_MEM_ALLOCATOR;
104
- }