Skip to content

Commit 7e3d85a

Browse files
authored
Merge pull request #33 from increments/merge-upstream-v0.23.6
Merge upstream v0.23.6
2 parents e361d62 + 2b0f67a commit 7e3d85a

File tree

6 files changed

+94
-9
lines changed

6 files changed

+94
-9
lines changed

.rubocop.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
inherit_from: .rubocop_todo.yml
2+
13
inherit_gem:
24
rubocop-standard:
35
- config/default.yml

.rubocop_todo.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# This configuration was generated by
2+
# `rubocop --auto-gen-config --exclude-limit 999999`
3+
# on 2022-10-03 03:50:46 UTC using RuboCop version 1.36.0.
4+
# The point is for the user to remove these configuration records
5+
# one by one as the offenses are removed from the code base.
6+
# Note that changes in the inspected code, or installation of new
7+
# versions of RuboCop, may require this file to be generated again.
8+
9+
# Offense count: 3
10+
# This cop supports safe autocorrection (--autocorrect).
11+
# Configuration parameters: EnforcedStyle.
12+
# SupportedStyles: def_self, self_class
13+
Style/ClassMethodsDefinitions:
14+
Exclude:
15+
- 'lib/qiita_marker.rb'
16+
- 'lib/qiita_marker/config.rb'
17+
18+
# Offense count: 2
19+
# This cop supports safe autocorrection (--autocorrect).
20+
# Configuration parameters: EnforcedStyleForMultiline.
21+
# SupportedStylesForMultiline: comma, consistent_comma, no_comma
22+
Style/TrailingCommaInArguments:
23+
Exclude:
24+
- 'lib/qiita_marker/renderer.rb'
25+
- 'test/test_commonmark.rb'

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
### Changed
88

9+
- [#33](https://github.com/increments/qiita_marker/pull/33): Update base CommonMarker version to `v0.23.6`.
10+
911
## 0.23.5.1 - 2022-06-21
1012

1113
### Changed

ext/qiita_marker/autolink.c

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,22 @@ static cmark_node *match(cmark_syntax_extension *ext, cmark_parser *parser,
286286
// inline was finished in inlines.c.
287287
}
288288

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+
289305
static void postprocess_text(cmark_parser *parser, cmark_node *text, int offset,
290306
int depth, cmark_syntax_extension *ext) {
291307
// 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,
296312
uint8_t *data = text->as.literal.data,
297313
*at;
298314
size_t size = text->as.literal.len;
315+
bool auto_mailto = true;
316+
bool is_xmpp = false;
299317
int rewind, max_rewind,
300318
nb = 0, np = 0, ns = 0;
301319

@@ -322,8 +340,18 @@ static void postprocess_text(cmark_parser *parser, cmark_node *text, int offset,
322340
if (strchr(".+-_", c) != NULL)
323341
continue;
324342

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+
}
327355

328356
break;
329357
}
@@ -343,6 +371,8 @@ static void postprocess_text(cmark_parser *parser, cmark_node *text, int offset,
343371
nb++;
344372
else if (c == '.' && link_end < size - 1 && cmark_isalnum(data[link_end + 1]))
345373
np++;
374+
else if (c == '/' && is_xmpp)
375+
continue;
346376
else if (c != '-' && c != '_')
347377
break;
348378
}
@@ -368,7 +398,8 @@ static void postprocess_text(cmark_parser *parser, cmark_node *text, int offset,
368398
}
369399
cmark_strbuf buf;
370400
cmark_strbuf_init(parser->mem, &buf, 10);
371-
cmark_strbuf_puts(&buf, "mailto:");
401+
if (auto_mailto)
402+
cmark_strbuf_puts(&buf, "mailto:");
372403
cmark_strbuf_put(&buf, data - rewind, (bufsize_t)(link_end + rewind));
373404
link_node->as.link.url = cmark_chunk_buf_detach(&buf);
374405

ext/qiita_marker/cmark-gfm_version.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef CMARK_GFM_VERSION_H
22
#define CMARK_GFM_VERSION_H
33

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"
66

77
#endif

ext/qiita_marker/inlines.c

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ typedef struct bracket {
4343
bool image;
4444
bool active;
4545
bool bracket_after;
46+
bool in_bracket_image0;
47+
bool in_bracket_image1;
4648
} bracket;
4749

4850
typedef struct subject{
@@ -526,6 +528,8 @@ static void push_bracket(subject *subj, bool image, cmark_node *inl_text) {
526528
bracket *b = (bracket *)subj->mem->calloc(1, sizeof(bracket));
527529
if (subj->last_bracket != NULL) {
528530
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;
529533
}
530534
b->image = image;
531535
b->active = true;
@@ -534,6 +538,11 @@ static void push_bracket(subject *subj, bool image, cmark_node *inl_text) {
534538
b->previous_delimiter = subj->last_delim;
535539
b->position = subj->pos;
536540
b->bracket_after = false;
541+
if (image) {
542+
b->in_bracket_image1 = true;
543+
} else {
544+
b->in_bracket_image0 = true;
545+
}
537546
subj->last_bracket = b;
538547
}
539548

@@ -1265,6 +1274,17 @@ static cmark_node *handle_close_bracket(cmark_parser *parser, subject *subj) {
12651274
}
12661275
opener = opener->previous;
12671276
}
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+
}
12681288
}
12691289

12701290
return NULL;
@@ -1674,10 +1694,15 @@ cmark_chunk *cmark_inline_parser_get_chunk(cmark_inline_parser *parser) {
16741694
}
16751695

16761696
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+
}
16811706
}
16821707

16831708
void cmark_node_unput(cmark_node *node, int n) {

0 commit comments

Comments
 (0)