qiita_marker 0.23.5.0 → 0.23.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/qiita_marker/blocks.c +4 -1
- data/ext/qiita_marker/qfm_custom_block.c +33 -52
- data/lib/qiita_marker/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 343d2a549df9aee75c4bb3890307425d9a82251a2dfe46826afd6f8a8bfcb245
|
4
|
+
data.tar.gz: bf76c480df59b28e13cace472228b3ca39a60d9ce3406a866125f347c18689c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c8c25dda4cadad88e855c84fa02d42de53c54c87665ca6b5530483a78b57e100b3df9869fe1f451faf16679a5de3ed7c6f630c9568258fdb559fd0d255cb2e2
|
7
|
+
data.tar.gz: d0927839957a98673181f2235f8a4e16a6ddfc2fa5bb88259d0cb7723bf925472e8214f98aa5ede40a24d3420af48b8b8e877472278efeb683eba80c171edd92
|
data/ext/qiita_marker/blocks.c
CHANGED
@@ -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')
|
@@ -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 =
|
92
|
-
|
93
|
-
|
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
|
-
|
98
|
-
|
99
|
-
|
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->
|
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
|
-
|
129
|
-
|
130
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
204
|
+
return (char *)cmark_strbuf_detach(xml_attr_buff);
|
224
205
|
}
|
225
206
|
|
226
207
|
return NULL;
|
data/lib/qiita_marker/version.rb
CHANGED
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.
|
4
|
+
version: 0.23.5.1
|
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-
|
11
|
+
date: 2022-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: awesome_print
|