commonmarker 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of commonmarker might be problematic. Click here for more details.

Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/ext/commonmarker/cmark/CMakeLists.txt +10 -4
  3. data/ext/commonmarker/cmark/Makefile +5 -5
  4. data/ext/commonmarker/cmark/api_test/CMakeLists.txt +1 -1
  5. data/ext/commonmarker/cmark/api_test/main.c +16 -0
  6. data/ext/commonmarker/cmark/build/CMakeCache.txt +3 -4
  7. data/ext/commonmarker/cmark/build/CMakeFiles/2.8.10.1/CMakeSystem.cmake +4 -4
  8. data/ext/commonmarker/cmark/build/CMakeFiles/CMakeError.log +12 -12
  9. data/ext/commonmarker/cmark/build/CMakeFiles/CMakeOutput.log +97 -142
  10. data/ext/commonmarker/cmark/build/CMakeFiles/Makefile.cmake +0 -1
  11. data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/build.make +1 -1
  12. data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/link.txt +1 -1
  13. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/DependInfo.cmake +1 -1
  14. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/build.make +23 -23
  15. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/cmake_clean.cmake +2 -2
  16. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/link.txt +1 -1
  17. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/blocks.c.o +0 -0
  18. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/buffer.c.o +0 -0
  19. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/cmark.c.o +0 -0
  20. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/commonmark.c.o +0 -0
  21. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/houdini_html_u.c.o +0 -0
  22. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/html.c.o +0 -0
  23. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/inlines.c.o +0 -0
  24. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/node.c.o +0 -0
  25. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/references.c.o +0 -0
  26. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/render.c.o +0 -0
  27. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/scanners.c.o +0 -0
  28. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/utf8.c.o +0 -0
  29. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/xml.c.o +0 -0
  30. data/ext/commonmarker/cmark/build/src/cmake_install.cmake +3 -3
  31. data/ext/commonmarker/cmark/build/src/cmark_version.h +2 -2
  32. data/ext/commonmarker/cmark/build/src/config.h +6 -6
  33. data/ext/commonmarker/cmark/build/src/libcmark.a +0 -0
  34. data/ext/commonmarker/cmark/build/src/libcmark.pc +1 -1
  35. data/ext/commonmarker/cmark/build/testdir/CTestTestfile.cmake +4 -4
  36. data/ext/commonmarker/cmark/changelog.txt +46 -0
  37. data/ext/commonmarker/cmark/man/man3/cmark.3 +21 -20
  38. data/ext/commonmarker/cmark/src/CMakeLists.txt +4 -6
  39. data/ext/commonmarker/cmark/src/bench.h +8 -8
  40. data/ext/commonmarker/cmark/src/blocks.c +917 -947
  41. data/ext/commonmarker/cmark/src/buffer.c +213 -288
  42. data/ext/commonmarker/cmark/src/buffer.h +19 -21
  43. data/ext/commonmarker/cmark/src/chunk.h +78 -82
  44. data/ext/commonmarker/cmark/src/cmark.c +9 -17
  45. data/ext/commonmarker/cmark/src/cmark.h +113 -157
  46. data/ext/commonmarker/cmark/src/cmark_ctype.c +24 -35
  47. data/ext/commonmarker/cmark/src/commonmark.c +390 -425
  48. data/ext/commonmarker/cmark/src/config.h.in +6 -6
  49. data/ext/commonmarker/cmark/src/houdini.h +21 -15
  50. data/ext/commonmarker/cmark/src/houdini_href_e.c +50 -57
  51. data/ext/commonmarker/cmark/src/houdini_html_e.c +36 -51
  52. data/ext/commonmarker/cmark/src/houdini_html_u.c +119 -124
  53. data/ext/commonmarker/cmark/src/html.c +289 -307
  54. data/ext/commonmarker/cmark/src/inlines.c +976 -1030
  55. data/ext/commonmarker/cmark/src/inlines.h +4 -2
  56. data/ext/commonmarker/cmark/src/iterator.c +96 -126
  57. data/ext/commonmarker/cmark/src/iterator.h +5 -5
  58. data/ext/commonmarker/cmark/src/latex.c +379 -401
  59. data/ext/commonmarker/cmark/src/main.c +168 -175
  60. data/ext/commonmarker/cmark/src/man.c +212 -226
  61. data/ext/commonmarker/cmark/src/node.c +746 -839
  62. data/ext/commonmarker/cmark/src/node.h +47 -48
  63. data/ext/commonmarker/cmark/src/parser.h +14 -14
  64. data/ext/commonmarker/cmark/src/references.c +101 -111
  65. data/ext/commonmarker/cmark/src/references.h +10 -8
  66. data/ext/commonmarker/cmark/src/render.c +144 -167
  67. data/ext/commonmarker/cmark/src/render.h +22 -41
  68. data/ext/commonmarker/cmark/src/scanners.c +27695 -20903
  69. data/ext/commonmarker/cmark/src/scanners.h +2 -1
  70. data/ext/commonmarker/cmark/src/scanners.re +1 -1
  71. data/ext/commonmarker/cmark/src/utf8.c +276 -419
  72. data/ext/commonmarker/cmark/src/utf8.h +6 -6
  73. data/ext/commonmarker/cmark/src/xml.c +129 -144
  74. data/ext/commonmarker/cmark/test/CMakeLists.txt +4 -4
  75. data/ext/commonmarker/cmark/test/smart_punct.txt +8 -0
  76. data/ext/commonmarker/cmark/test/spec.txt +109 -47
  77. data/lib/commonmarker/version.rb +1 -1
  78. metadata +2 -2
@@ -5,182 +5,159 @@
5
5
  #include "utf8.h"
6
6
  #include "render.h"
7
7
 
8
- static inline
9
- void S_cr(cmark_renderer *renderer)
10
- {
11
- if (renderer->need_cr < 1) {
12
- renderer->need_cr = 1;
13
- }
8
+ static inline void S_cr(cmark_renderer *renderer) {
9
+ if (renderer->need_cr < 1) {
10
+ renderer->need_cr = 1;
11
+ }
14
12
  }
15
13
 
16
- static inline
17
- void S_blankline(cmark_renderer *renderer)
18
- {
19
- if (renderer->need_cr < 2) {
20
- renderer->need_cr = 2;
21
- }
14
+ static inline void S_blankline(cmark_renderer *renderer) {
15
+ if (renderer->need_cr < 2) {
16
+ renderer->need_cr = 2;
17
+ }
22
18
  }
23
19
 
24
- static
25
- void S_out(cmark_renderer *renderer,
26
- const char *source,
27
- bool wrap,
28
- cmark_escaping escape)
29
- {
30
- int length = cmark_strbuf_safe_strlen(source);
31
- unsigned char nextc;
32
- int32_t c;
33
- int i = 0;
34
- int len;
35
- cmark_chunk remainder = cmark_chunk_literal("");
36
- int k = renderer->buffer->size - 1;
37
-
38
- wrap = wrap && !renderer->no_wrap;
39
-
40
- if (renderer->in_tight_list_item && renderer->need_cr > 1) {
41
- renderer->need_cr = 1;
42
- }
43
- while (renderer->need_cr) {
44
- if (k < 0 || renderer->buffer->ptr[k] == '\n') {
45
- k -= 1;
46
- } else {
47
- cmark_strbuf_putc(renderer->buffer, '\n');
48
- if (renderer->need_cr > 1) {
49
- cmark_strbuf_put(renderer->buffer, renderer->prefix->ptr,
50
- renderer->prefix->size);
51
- }
52
- }
53
- renderer->column = 0;
54
- renderer->begin_line = true;
55
- renderer->need_cr -= 1;
56
- }
57
-
58
- while (i < length) {
59
- if (renderer->begin_line) {
60
- cmark_strbuf_put(renderer->buffer, renderer->prefix->ptr,
61
- renderer->prefix->size);
62
- // note: this assumes prefix is ascii:
63
- renderer->column = renderer->prefix->size;
64
- }
65
-
66
- len = utf8proc_iterate((const uint8_t *)source + i, length - i, &c);
67
- if (len == -1) { // error condition
68
- return; // return without rendering rest of string
69
- }
70
- nextc = source[i + len];
71
- if (c == 32 && wrap) {
72
- if (!renderer->begin_line) {
73
- cmark_strbuf_putc(renderer->buffer, ' ');
74
- renderer->column += 1;
75
- renderer->begin_line = false;
76
- renderer->last_breakable = renderer->buffer->size -
77
- 1;
78
- // skip following spaces
79
- while (source[i + 1] == ' ') {
80
- i++;
81
- }
82
- }
83
-
84
- } else if (c == 10) {
85
- cmark_strbuf_putc(renderer->buffer, '\n');
86
- renderer->column = 0;
87
- renderer->begin_line = true;
88
- renderer->last_breakable = 0;
89
- } else if (escape == LITERAL) {
90
- cmark_render_code_point(renderer, c);
91
- renderer->begin_line = false;
92
- } else {
93
- (renderer->outc)(renderer, escape, c, nextc);
94
- renderer->begin_line = false;
95
- }
96
-
97
- // If adding the character went beyond width, look for an
98
- // earlier place where the line could be broken:
99
- if (renderer->width > 0 &&
100
- renderer->column > renderer->width &&
101
- !renderer->begin_line &&
102
- renderer->last_breakable > 0) {
103
-
104
- // copy from last_breakable to remainder
105
- cmark_chunk_set_cstr(&remainder, (char *) renderer->buffer->ptr + renderer->last_breakable + 1);
106
- // truncate at last_breakable
107
- cmark_strbuf_truncate(renderer->buffer, renderer->last_breakable);
108
- // add newline, prefix, and remainder
109
- cmark_strbuf_putc(renderer->buffer, '\n');
110
- cmark_strbuf_put(renderer->buffer, renderer->prefix->ptr,
111
- renderer->prefix->size);
112
- cmark_strbuf_put(renderer->buffer, remainder.data, remainder.len);
113
- renderer->column = renderer->prefix->size + remainder.len;
114
- cmark_chunk_free(&remainder);
115
- renderer->last_breakable = 0;
116
- renderer->begin_line = false;
117
- }
118
-
119
- i += len;
120
- }
20
+ static void S_out(cmark_renderer *renderer, const char *source, bool wrap,
21
+ cmark_escaping escape) {
22
+ int length = cmark_strbuf_safe_strlen(source);
23
+ unsigned char nextc;
24
+ int32_t c;
25
+ int i = 0;
26
+ int len;
27
+ cmark_chunk remainder = cmark_chunk_literal("");
28
+ int k = renderer->buffer->size - 1;
29
+
30
+ wrap = wrap && !renderer->no_wrap;
31
+
32
+ if (renderer->in_tight_list_item && renderer->need_cr > 1) {
33
+ renderer->need_cr = 1;
34
+ }
35
+ while (renderer->need_cr) {
36
+ if (k < 0 || renderer->buffer->ptr[k] == '\n') {
37
+ k -= 1;
38
+ } else {
39
+ cmark_strbuf_putc(renderer->buffer, '\n');
40
+ if (renderer->need_cr > 1) {
41
+ cmark_strbuf_put(renderer->buffer, renderer->prefix->ptr,
42
+ renderer->prefix->size);
43
+ }
44
+ }
45
+ renderer->column = 0;
46
+ renderer->begin_line = true;
47
+ renderer->need_cr -= 1;
48
+ }
49
+
50
+ while (i < length) {
51
+ if (renderer->begin_line) {
52
+ cmark_strbuf_put(renderer->buffer, renderer->prefix->ptr,
53
+ renderer->prefix->size);
54
+ // note: this assumes prefix is ascii:
55
+ renderer->column = renderer->prefix->size;
56
+ }
57
+
58
+ len = cmark_utf8proc_iterate((const uint8_t *)source + i, length - i, &c);
59
+ if (len == -1) { // error condition
60
+ return; // return without rendering rest of string
61
+ }
62
+ nextc = source[i + len];
63
+ if (c == 32 && wrap) {
64
+ if (!renderer->begin_line) {
65
+ cmark_strbuf_putc(renderer->buffer, ' ');
66
+ renderer->column += 1;
67
+ renderer->begin_line = false;
68
+ renderer->last_breakable = renderer->buffer->size - 1;
69
+ // skip following spaces
70
+ while (source[i + 1] == ' ') {
71
+ i++;
72
+ }
73
+ }
74
+
75
+ } else if (c == 10) {
76
+ cmark_strbuf_putc(renderer->buffer, '\n');
77
+ renderer->column = 0;
78
+ renderer->begin_line = true;
79
+ renderer->last_breakable = 0;
80
+ } else if (escape == LITERAL) {
81
+ cmark_render_code_point(renderer, c);
82
+ renderer->begin_line = false;
83
+ } else {
84
+ (renderer->outc)(renderer, escape, c, nextc);
85
+ renderer->begin_line = false;
86
+ }
87
+
88
+ // If adding the character went beyond width, look for an
89
+ // earlier place where the line could be broken:
90
+ if (renderer->width > 0 && renderer->column > renderer->width &&
91
+ !renderer->begin_line && renderer->last_breakable > 0) {
92
+
93
+ // copy from last_breakable to remainder
94
+ cmark_chunk_set_cstr(&remainder, (char *)renderer->buffer->ptr +
95
+ renderer->last_breakable + 1);
96
+ // truncate at last_breakable
97
+ cmark_strbuf_truncate(renderer->buffer, renderer->last_breakable);
98
+ // add newline, prefix, and remainder
99
+ cmark_strbuf_putc(renderer->buffer, '\n');
100
+ cmark_strbuf_put(renderer->buffer, renderer->prefix->ptr,
101
+ renderer->prefix->size);
102
+ cmark_strbuf_put(renderer->buffer, remainder.data, remainder.len);
103
+ renderer->column = renderer->prefix->size + remainder.len;
104
+ cmark_chunk_free(&remainder);
105
+ renderer->last_breakable = 0;
106
+ renderer->begin_line = false;
107
+ }
108
+
109
+ i += len;
110
+ }
121
111
  }
122
112
 
123
113
  // Assumes no newlines, assumes ascii content:
124
- void
125
- cmark_render_ascii(cmark_renderer* renderer, const char* s)
126
- {
127
- int origsize = renderer->buffer->size;
128
- cmark_strbuf_puts(renderer->buffer, s);
129
- renderer->column += renderer->buffer->size - origsize;
114
+ void cmark_render_ascii(cmark_renderer *renderer, const char *s) {
115
+ int origsize = renderer->buffer->size;
116
+ cmark_strbuf_puts(renderer->buffer, s);
117
+ renderer->column += renderer->buffer->size - origsize;
130
118
  }
131
119
 
132
- void
133
- cmark_render_code_point(cmark_renderer *renderer, uint32_t c)
134
- {
135
- utf8proc_encode_char(c, renderer->buffer);
136
- renderer->column += 1;
120
+ void cmark_render_code_point(cmark_renderer *renderer, uint32_t c) {
121
+ cmark_utf8proc_encode_char(c, renderer->buffer);
122
+ renderer->column += 1;
137
123
  }
138
124
 
139
- char*
140
- cmark_render(cmark_node *root,
141
- int options,
142
- int width,
143
- void (*outc)(cmark_renderer*,
144
- cmark_escaping,
145
- int32_t,
146
- unsigned char),
147
- int (*render_node)(cmark_renderer *renderer,
148
- cmark_node *node,
149
- cmark_event_type ev_type,
150
- int options))
151
- {
152
- cmark_strbuf pref = GH_BUF_INIT;
153
- cmark_strbuf buf = GH_BUF_INIT;
154
- cmark_node *cur;
155
- cmark_event_type ev_type;
156
- char *result;
157
- cmark_iter *iter = cmark_iter_new(root);
158
-
159
- cmark_renderer renderer = { &buf, &pref, 0, width,
160
- 0, 0, true, false, false,
161
- outc, S_cr, S_blankline, S_out
162
- };
163
-
164
- while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) {
165
- cur = cmark_iter_get_node(iter);
166
- if (!render_node(&renderer, cur, ev_type, options)) {
167
- // a false value causes us to skip processing
168
- // the node's contents. this is used for
169
- // autolinks.
170
- cmark_iter_reset(iter, cur, CMARK_EVENT_EXIT);
171
- }
172
- }
173
-
174
- // ensure final newline
175
- if (renderer.buffer->ptr[renderer.buffer->size - 1] != '\n') {
176
- cmark_strbuf_putc(renderer.buffer, '\n');
177
- }
178
-
179
- result = (char *)cmark_strbuf_detach(renderer.buffer);
180
-
181
- cmark_iter_free(iter);
182
- cmark_strbuf_free(renderer.prefix);
183
- cmark_strbuf_free(renderer.buffer);
184
-
185
- return result;
125
+ char *cmark_render(cmark_node *root, int options, int width,
126
+ void (*outc)(cmark_renderer *, cmark_escaping, int32_t,
127
+ unsigned char),
128
+ int (*render_node)(cmark_renderer *renderer,
129
+ cmark_node *node,
130
+ cmark_event_type ev_type, int options)) {
131
+ cmark_strbuf pref = GH_BUF_INIT;
132
+ cmark_strbuf buf = GH_BUF_INIT;
133
+ cmark_node *cur;
134
+ cmark_event_type ev_type;
135
+ char *result;
136
+ cmark_iter *iter = cmark_iter_new(root);
137
+
138
+ cmark_renderer renderer = {&buf, &pref, 0, width, 0, 0, true,
139
+ false, false, outc, S_cr, S_blankline, S_out};
140
+
141
+ while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) {
142
+ cur = cmark_iter_get_node(iter);
143
+ if (!render_node(&renderer, cur, ev_type, options)) {
144
+ // a false value causes us to skip processing
145
+ // the node's contents. this is used for
146
+ // autolinks.
147
+ cmark_iter_reset(iter, cur, CMARK_EVENT_EXIT);
148
+ }
149
+ }
150
+
151
+ // ensure final newline
152
+ if (renderer.buffer->ptr[renderer.buffer->size - 1] != '\n') {
153
+ cmark_strbuf_putc(renderer.buffer, '\n');
154
+ }
155
+
156
+ result = (char *)cmark_strbuf_detach(renderer.buffer);
157
+
158
+ cmark_iter_free(iter);
159
+ cmark_strbuf_free(renderer.prefix);
160
+ cmark_strbuf_free(renderer.buffer);
161
+
162
+ return result;
186
163
  }
@@ -9,55 +9,36 @@ extern "C" {
9
9
  #include "buffer.h"
10
10
  #include "chunk.h"
11
11
 
12
- typedef enum {
13
- LITERAL,
14
- NORMAL,
15
- TITLE,
16
- URL
17
- } cmark_escaping;
12
+ typedef enum { LITERAL, NORMAL, TITLE, URL } cmark_escaping;
18
13
 
19
14
  struct cmark_renderer {
20
- cmark_strbuf* buffer;
21
- cmark_strbuf* prefix;
22
- int column;
23
- int width;
24
- int need_cr;
25
- bufsize_t last_breakable;
26
- bool begin_line;
27
- bool no_wrap;
28
- bool in_tight_list_item;
29
- void (*outc)(struct cmark_renderer*,
30
- cmark_escaping,
31
- int32_t,
32
- unsigned char);
33
- void (*cr)(struct cmark_renderer*);
34
- void (*blankline)(struct cmark_renderer*);
35
- void (*out)(struct cmark_renderer*,
36
- const char *,
37
- bool,
38
- cmark_escaping);
15
+ cmark_strbuf *buffer;
16
+ cmark_strbuf *prefix;
17
+ int column;
18
+ int width;
19
+ int need_cr;
20
+ bufsize_t last_breakable;
21
+ bool begin_line;
22
+ bool no_wrap;
23
+ bool in_tight_list_item;
24
+ void (*outc)(struct cmark_renderer *, cmark_escaping, int32_t, unsigned char);
25
+ void (*cr)(struct cmark_renderer *);
26
+ void (*blankline)(struct cmark_renderer *);
27
+ void (*out)(struct cmark_renderer *, const char *, bool, cmark_escaping);
39
28
  };
40
29
 
41
30
  typedef struct cmark_renderer cmark_renderer;
42
31
 
43
- void
44
- cmark_render_ascii(cmark_renderer *renderer, const char* s);
32
+ void cmark_render_ascii(cmark_renderer *renderer, const char *s);
45
33
 
46
- void
47
- cmark_render_code_point(cmark_renderer *renderer, uint32_t c);
34
+ void cmark_render_code_point(cmark_renderer *renderer, uint32_t c);
48
35
 
49
- char*
50
- cmark_render(cmark_node *root,
51
- int options,
52
- int width,
53
- void (*outc)(cmark_renderer*,
54
- cmark_escaping,
55
- int32_t,
56
- unsigned char),
57
- int (*render_node)(cmark_renderer *renderer,
58
- cmark_node *node,
59
- cmark_event_type ev_type,
60
- int options));
36
+ char *cmark_render(cmark_node *root, int options, int width,
37
+ void (*outc)(cmark_renderer *, cmark_escaping, int32_t,
38
+ unsigned char),
39
+ int (*render_node)(cmark_renderer *renderer,
40
+ cmark_node *node,
41
+ cmark_event_type ev_type, int options));
61
42
 
62
43
  #ifdef __cplusplus
63
44
  }