qiita_marker 0.23.5.0 → 0.23.6.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 15bfc4813af77558d6c0b4ffbb931229e00d558d0c417048b636ce7c27ac31a7
4
- data.tar.gz: af9febe461508838d294f9d2d20dfe896c30c467b82b50b36924040c7287c070
3
+ metadata.gz: b0e45d2000570d0cdf3f3c74e8b3f49936438c4183b31ce632eedbedc8bd920d
4
+ data.tar.gz: 3c732d6f5f94c5c575816a6866d61d1ca44e1557d320dda0215440a626064603
5
5
  SHA512:
6
- metadata.gz: 2fc608ddea2a044b4c64b9f32e8dbc44cf838213f6c67e9457f36fa303b7223a20c932a261e3f21fac256ceab34d018b9c6d9757ce86eecf250a3aefa585407b
7
- data.tar.gz: 66b65a1652e9a0904423490cb8999de85d21928f169f72965ca2b90bc32cfadda46193662ebdae70dea6bcb5819a349256a24911f53c65d168bd9285db107968
6
+ metadata.gz: 150f04fca8e8a325b3d981b67ec12a95fd489aa3eb8b08c0b50e9ac2b21c8a9797ca5b6e6b8bd26f51fc215cc3f9121ce8167c2bc78d4d93ee7020cf72db3e00
7
+ data.tar.gz: 439012adb32af3319165a4eeec5b19d796410b4aaddd84a0256684da172a1fc2dddf00d5175239cbbf3f9ac7d6020e8ef800afd32bdd8445b296750b0a14ffd7
@@ -286,6 +286,22 @@ static cmark_node *match(cmark_syntax_extension *ext, cmark_parser *parser,
286
286
  // inline was finished in inlines.c.
287
287
  }
288
288
 
289
+ static bool validate_protocol(char protocol[], uint8_t *data, int rewind) {
290
+ size_t len = strlen(protocol);
291
+
292
+ // Check that the protocol matches
293
+ for (int i = 1; i <= len; i++) {
294
+ if (data[-rewind - i] != protocol[len - i]) {
295
+ return false;
296
+ }
297
+ }
298
+
299
+ char prev_char = data[-rewind - len - 1];
300
+
301
+ // Make sure the character before the protocol is non-alphanumeric
302
+ return !cmark_isalnum(prev_char);
303
+ }
304
+
289
305
  static void postprocess_text(cmark_parser *parser, cmark_node *text, int offset,
290
306
  int depth, cmark_syntax_extension *ext) {
291
307
  // postprocess_text can recurse very deeply if there is a very long line of
@@ -296,6 +312,8 @@ static void postprocess_text(cmark_parser *parser, cmark_node *text, int offset,
296
312
  uint8_t *data = text->as.literal.data,
297
313
  *at;
298
314
  size_t size = text->as.literal.len;
315
+ bool auto_mailto = true;
316
+ bool is_xmpp = false;
299
317
  int rewind, max_rewind,
300
318
  nb = 0, np = 0, ns = 0;
301
319
 
@@ -322,8 +340,18 @@ static void postprocess_text(cmark_parser *parser, cmark_node *text, int offset,
322
340
  if (strchr(".+-_", c) != NULL)
323
341
  continue;
324
342
 
325
- if (c == '/')
326
- ns++;
343
+ if (strchr(":", c) != NULL) {
344
+ if (validate_protocol("mailto:", data, rewind)) {
345
+ auto_mailto = false;
346
+ continue;
347
+ }
348
+
349
+ if (validate_protocol("xmpp:", data, rewind)) {
350
+ auto_mailto = false;
351
+ is_xmpp = true;
352
+ continue;
353
+ }
354
+ }
327
355
 
328
356
  break;
329
357
  }
@@ -343,6 +371,8 @@ static void postprocess_text(cmark_parser *parser, cmark_node *text, int offset,
343
371
  nb++;
344
372
  else if (c == '.' && link_end < size - 1 && cmark_isalnum(data[link_end + 1]))
345
373
  np++;
374
+ else if (c == '/' && is_xmpp)
375
+ continue;
346
376
  else if (c != '-' && c != '_')
347
377
  break;
348
378
  }
@@ -368,7 +398,8 @@ static void postprocess_text(cmark_parser *parser, cmark_node *text, int offset,
368
398
  }
369
399
  cmark_strbuf buf;
370
400
  cmark_strbuf_init(parser->mem, &buf, 10);
371
- cmark_strbuf_puts(&buf, "mailto:");
401
+ if (auto_mailto)
402
+ cmark_strbuf_puts(&buf, "mailto:");
372
403
  cmark_strbuf_put(&buf, data - rewind, (bufsize_t)(link_end + rewind));
373
404
  link_node->as.link.url = cmark_chunk_buf_detach(&buf);
374
405
 
@@ -22,6 +22,7 @@
22
22
  #include "houdini.h"
23
23
  #include "buffer.h"
24
24
  #include "footnotes.h"
25
+ #include "qfm_custom_block.h"
25
26
 
26
27
  #define CODE_INDENT 4
27
28
  #define TAB_STOP 4
@@ -289,7 +290,9 @@ static cmark_node *finalize(cmark_parser *parser, cmark_node *b) {
289
290
  b->end_column = parser->last_line_length;
290
291
  } else if (S_type(b) == CMARK_NODE_DOCUMENT ||
291
292
  (S_type(b) == CMARK_NODE_CODE_BLOCK && b->as.code.fenced) ||
292
- (S_type(b) == CMARK_NODE_HEADING && b->as.heading.setext)) {
293
+ (S_type(b) == CMARK_NODE_HEADING && b->as.heading.setext) ||
294
+ /* For make the sourcepos of the `qfm_custom_block` accurate */
295
+ (cmark_node_get_type(b) == CMARK_NODE_QFM_CUSTOM_BLOCK)) {
293
296
  b->end_line = parser->line_number;
294
297
  b->end_column = parser->curline.size;
295
298
  if (b->end_column && parser->curline.ptr[b->end_column - 1] == '\n')
@@ -1,7 +1,7 @@
1
1
  #ifndef CMARK_GFM_VERSION_H
2
2
  #define CMARK_GFM_VERSION_H
3
3
 
4
- #define CMARK_GFM_VERSION ((0 << 24) | (29 << 16) | (0 << 8) | 4)
5
- #define CMARK_GFM_VERSION_STRING "0.29.0.gfm.4"
4
+ #define CMARK_GFM_VERSION ((0 << 24) | (29 << 16) | (0 << 8) | 6)
5
+ #define CMARK_GFM_VERSION_STRING "0.29.0.gfm.6"
6
6
 
7
7
  #endif
@@ -43,6 +43,8 @@ typedef struct bracket {
43
43
  bool image;
44
44
  bool active;
45
45
  bool bracket_after;
46
+ bool in_bracket_image0;
47
+ bool in_bracket_image1;
46
48
  } bracket;
47
49
 
48
50
  typedef struct subject{
@@ -526,6 +528,8 @@ static void push_bracket(subject *subj, bool image, cmark_node *inl_text) {
526
528
  bracket *b = (bracket *)subj->mem->calloc(1, sizeof(bracket));
527
529
  if (subj->last_bracket != NULL) {
528
530
  subj->last_bracket->bracket_after = true;
531
+ b->in_bracket_image0 = subj->last_bracket->in_bracket_image0;
532
+ b->in_bracket_image1 = subj->last_bracket->in_bracket_image1;
529
533
  }
530
534
  b->image = image;
531
535
  b->active = true;
@@ -534,6 +538,11 @@ static void push_bracket(subject *subj, bool image, cmark_node *inl_text) {
534
538
  b->previous_delimiter = subj->last_delim;
535
539
  b->position = subj->pos;
536
540
  b->bracket_after = false;
541
+ if (image) {
542
+ b->in_bracket_image1 = true;
543
+ } else {
544
+ b->in_bracket_image0 = true;
545
+ }
537
546
  subj->last_bracket = b;
538
547
  }
539
548
 
@@ -1265,6 +1274,17 @@ match:
1265
1274
  }
1266
1275
  opener = opener->previous;
1267
1276
  }
1277
+ bool in_bracket_image1 = false;
1278
+ if (opener) {
1279
+ in_bracket_image1 = opener->in_bracket_image1;
1280
+ }
1281
+ bracket *opener2 = subj->last_bracket;
1282
+ while (opener2 != opener) {
1283
+ if (opener2->image) {
1284
+ opener2->in_bracket_image1 = in_bracket_image1;
1285
+ }
1286
+ opener2 = opener2->previous;
1287
+ }
1268
1288
  }
1269
1289
 
1270
1290
  return NULL;
@@ -1674,10 +1694,15 @@ cmark_chunk *cmark_inline_parser_get_chunk(cmark_inline_parser *parser) {
1674
1694
  }
1675
1695
 
1676
1696
  int cmark_inline_parser_in_bracket(cmark_inline_parser *parser, int image) {
1677
- for (bracket *b = parser->last_bracket; b; b = b->previous)
1678
- if (b->active && b->image == (image != 0))
1679
- return 1;
1680
- return 0;
1697
+ bracket *b = parser->last_bracket;
1698
+ if (!b) {
1699
+ return 0;
1700
+ }
1701
+ if (image != 0) {
1702
+ return b->in_bracket_image1;
1703
+ } else {
1704
+ return b->in_bracket_image0;
1705
+ }
1681
1706
  }
1682
1707
 
1683
1708
  void cmark_node_unput(cmark_node *node, int n) {
@@ -6,14 +6,13 @@
6
6
  #include "houdini.h"
7
7
  #include "qfm_custom_block.h"
8
8
  #include "qfm_scanners.h"
9
- #include "strikethrough.h"
10
9
 
11
10
  cmark_node_type CMARK_NODE_QFM_CUSTOM_BLOCK;
12
11
 
13
12
  typedef struct {
13
+ /* info: Text following the opening custom block fence (optional). This is
14
+ * trimmed of leading and trailing whitespace. */
14
15
  cmark_chunk info;
15
- bool opening;
16
- cmark_strbuf *xml_attr_buff;
17
16
  } node_qfm_custom_block;
18
17
 
19
18
  static void escape_html(cmark_strbuf *dest, const unsigned char *source,
@@ -21,33 +20,6 @@ static void escape_html(cmark_strbuf *dest, const unsigned char *source,
21
20
  houdini_escape_html0(dest, source, length, 0);
22
21
  }
23
22
 
24
- static bool get_qfm_custom_block_opening(cmark_node *node) {
25
- if (node == NULL) {
26
- return false;
27
- }
28
-
29
- cmark_node_type node_type = cmark_node_get_type(node);
30
- if (node_type == CMARK_NODE_QFM_CUSTOM_BLOCK) {
31
- return ((node_qfm_custom_block *)node->as.opaque)->opening;
32
- } else {
33
- return false;
34
- }
35
- }
36
-
37
- static bool set_qfm_custom_block_opening(cmark_node *node, bool opening) {
38
- if (node == NULL) {
39
- return false;
40
- }
41
-
42
- cmark_node_type node_type = cmark_node_get_type(node);
43
- if (node_type == CMARK_NODE_QFM_CUSTOM_BLOCK) {
44
- ((node_qfm_custom_block *)node->as.opaque)->opening = opening;
45
- return true;
46
- } else {
47
- return false;
48
- }
49
- }
50
-
51
23
  static cmark_chunk *get_qfm_custom_block_info(cmark_node *node) {
52
24
  if (node == NULL) {
53
25
  return NULL;
@@ -81,26 +53,21 @@ static void free_node_qfm_custom_block(cmark_mem *mem, void *ptr) {
81
53
  node_qfm_custom_block *cb = (node_qfm_custom_block *)ptr;
82
54
 
83
55
  cmark_chunk_free(mem, &cb->info);
84
- cmark_strbuf_free(cb->xml_attr_buff);
85
56
  mem->free(cb);
86
57
  }
87
58
 
59
+ /* Now, a custom block can contain another custom block, but this behavior is
60
+ * not a specification. */
88
61
  static int matches(cmark_syntax_extension *self, cmark_parser *parser,
89
62
  unsigned char *input, int len,
90
63
  cmark_node *parent_container) {
91
- int res = 0;
92
-
93
- if (get_qfm_custom_block_opening(parent_container)) {
94
- bufsize_t matched = scan_close_qfm_custom_block_fence(
95
- input, len, cmark_parser_get_first_nonspace(parser));
64
+ int res = 1;
65
+ bufsize_t matched = scan_close_qfm_custom_block_fence(
66
+ input, len, cmark_parser_get_first_nonspace(parser));
96
67
 
97
- if (matched > 0) {
98
- set_qfm_custom_block_opening(parent_container, false);
99
- cmark_parser_advance_offset(parser, (char *)input,
100
- len - cmark_parser_get_offset(parser), 0);
101
- } else {
102
- res = 1;
103
- }
68
+ if (matched > 0) {
69
+ cmark_parser_advance_offset(parser, (char *)input, matched, 0);
70
+ res = 0;
104
71
  }
105
72
 
106
73
  return res;
@@ -120,21 +87,34 @@ static cmark_node *try_opening_qfm_custom_block_block(
120
87
 
121
88
  cmark_node *custom_block_node = cmark_parser_add_child(
122
89
  parser, parent_container, CMARK_NODE_QFM_CUSTOM_BLOCK,
123
- parser->first_nonspace_column);
90
+ parser->first_nonspace + 1);
124
91
  custom_block_node->as.opaque = (node_qfm_custom_block *)parser->mem->calloc(
125
92
  1, sizeof(node_qfm_custom_block));
126
93
 
127
94
  cmark_strbuf *info = parser->mem->calloc(1, sizeof(cmark_strbuf));
128
- cmark_strbuf_init(parser->mem, info, len - matched);
129
- cmark_strbuf_put(info, input + matched, len - matched);
130
- cmark_strbuf_trim(info);
95
+ bufsize_t info_startpos = cmark_parser_get_first_nonspace(parser) + matched;
96
+
97
+ /* Length from after opening custom block fence to before newline character.
98
+ */
99
+ bufsize_t info_len = len - info_startpos;
100
+ if (info_len > 0 && input[len - 1] == '\n') {
101
+ info_len -= 1;
102
+ }
103
+ if (info_len > 0 && input[len - 1] == '\r') {
104
+ info_len -= 1;
105
+ }
131
106
 
132
- set_qfm_custom_block_opening(custom_block_node, true);
107
+ cmark_strbuf_init(parser->mem, info, info_len);
108
+ cmark_strbuf_put(info, input + info_startpos, info_len);
109
+ cmark_strbuf_trim(info);
133
110
  set_qfm_custom_block_info(custom_block_node, (char *)info->ptr);
134
111
 
135
112
  cmark_node_set_syntax_extension(custom_block_node, self);
136
113
  cmark_parser_advance_offset(parser, (char *)input,
137
- len - cmark_parser_get_offset(parser), 0);
114
+ cmark_parser_get_first_nonspace(parser) +
115
+ matched + info_len -
116
+ cmark_parser_get_offset(parser),
117
+ 0);
138
118
 
139
119
  return custom_block_node;
140
120
  }
@@ -155,12 +135,14 @@ static const char *get_type_string(cmark_syntax_extension *self,
155
135
 
156
136
  static int can_contain(cmark_syntax_extension *self, cmark_node *node,
157
137
  cmark_node_type child_type) {
138
+ /* Can contain all block nodes */
158
139
  cmark_node_type node_type = cmark_node_get_type(node);
159
140
 
160
141
  return node_type == CMARK_NODE_QFM_CUSTOM_BLOCK;
161
142
  }
162
143
 
163
144
  static int contains_inlines(cmark_syntax_extension *self, cmark_node *node) {
145
+ /* Can contain all inline nodes */
164
146
  cmark_node_type node_type = cmark_node_get_type(node);
165
147
 
166
148
  return node_type == CMARK_NODE_QFM_CUSTOM_BLOCK;
@@ -210,9 +192,8 @@ static const char *xml_attr(cmark_syntax_extension *self, cmark_node *node) {
210
192
  if (node_type == CMARK_NODE_QFM_CUSTOM_BLOCK) {
211
193
  cmark_chunk *info = get_qfm_custom_block_info(node);
212
194
  cmark_mem *mem = node->content.mem;
213
-
214
195
  cmark_strbuf *xml_attr_buff = mem->calloc(1, sizeof(cmark_strbuf));
215
- ((node_qfm_custom_block *)node->as.opaque)->xml_attr_buff = xml_attr_buff;
196
+
216
197
  cmark_strbuf_init(
217
198
  mem, xml_attr_buff,
218
199
  17 + info->len); // `17` is length of ` data-metadata="` and `"`.
@@ -220,7 +201,7 @@ static const char *xml_attr(cmark_syntax_extension *self, cmark_node *node) {
220
201
  cmark_strbuf_puts(xml_attr_buff, (char *)info->data);
221
202
  cmark_strbuf_putc(xml_attr_buff, '"');
222
203
 
223
- return (char *)xml_attr_buff->ptr;
204
+ return (char *)cmark_strbuf_detach(xml_attr_buff);
224
205
  }
225
206
 
226
207
  return NULL;
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module QiitaMarker
4
- VERSION = "0.23.5.0"
4
+ VERSION = "0.23.6.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qiita_marker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.23.5.0
4
+ version: 0.23.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Qiita Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-01 00:00:00.000000000 Z
11
+ date: 2022-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print