Skip to content

Commit

Permalink
Fix for multibyte emoji.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbarex committed Jan 4, 2021
1 parent 26468d7 commit cbbfacc
Show file tree
Hide file tree
Showing 4 changed files with 1,873 additions and 1,838 deletions.
4 changes: 2 additions & 2 deletions Resources/default.css
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pre.hl { background-color: var(--hl_Background);


pre {
max-width: 902px;;
max-width: 902px;
}
* {
box-sizing: border-box;
Expand Down Expand Up @@ -454,7 +454,7 @@ input[type="checkbox"] {
}

.markdown-body img.emoji {
max-width: 20px;
max-width: 18px;
}

.markdown-body span.frame {
Expand Down
44 changes: 25 additions & 19 deletions cmark-gfm/extensions/emoji.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ static cmark_node *match(cmark_syntax_extension *self, cmark_parser *parser,
int at = start + 1;
int end = at;

while (end < size && (!cmark_isspace(data[end]) && data[end] != ':')) {
while (end < size && data[end] != ':' && !cmark_isspace(data[end])) {
end++;
}

Expand All @@ -111,34 +111,35 @@ static cmark_node *match(cmark_syntax_extension *self, cmark_parser *parser,

cmark_node *node = NULL;

char *url = get_emoji_url(placeholder);
if (url) {
bool use_characters = cmark_syntax_extension_emoji_get_use_characters(self);
if (use_characters) {
char *emoji = get_emoji(placeholder);
if (emoji) {
node = cmark_node_new_with_mem(CMARK_NODE_TEXT, parser->mem);

cmark_node_set_literal(node, emoji);
// cmark_node_set_syntax_extension(node, self);
free(emoji);
} else {
// Use image as fallback.
goto image_mode;
}
const char *url;
bool use_characters = cmark_syntax_extension_emoji_get_use_characters(self);

if (use_characters) {
const char *emoji = get_emoji_glyphs(placeholder);
if (emoji) {
node = cmark_node_new_with_mem(CMARK_NODE_TEXT, parser->mem);

cmark_node_set_literal(node, emoji);
} else {
image_mode:
// Use image as fallback.
goto process_as_image;
}
} else {
process_as_image:
url = get_emoji_url(placeholder);
if (url) {
node = cmark_node_new_with_mem(CMARK_NODE_IMAGE, parser->mem);

cmark_node_set_url(node, url);
cmark_node_set_title(node, placeholder);
cmark_node_set_syntax_extension(node, self);
}

}

if (node != NULL) {
cmark_inline_parser_set_offset(inline_parser, start + (end - start) + 1);
}

free(url);
parser->mem->free(placeholder);

return node;
Expand Down Expand Up @@ -205,5 +206,10 @@ cmark_syntax_extension *create_emoji_extension(void) {
// cmark_syntax_extension_set_postprocess_func(ext, postprocess);
cmark_syntax_extension_set_match_inline_func(ext, match);

cmark_mem *mem = cmark_get_default_mem_allocator();
cmark_llist *special_chars = NULL;
special_chars = cmark_llist_append(mem, special_chars, (void *)':');
cmark_syntax_extension_set_special_inline_chars(ext, special_chars);

return ext;
}
Loading

0 comments on commit cbbfacc

Please sign in to comment.