ext/commonmarker/cmark/src/render.c in commonmarker-0.14.15 vs ext/commonmarker/cmark/src/render.c in commonmarker-0.15.0
- old
+ new
@@ -3,10 +3,11 @@
#include "chunk.h"
#include "cmark.h"
#include "utf8.h"
#include "render.h"
#include "node.h"
+#include "syntax_extension.h"
static CMARK_INLINE void S_cr(cmark_renderer *renderer) {
if (renderer->need_cr < 1) {
renderer->need_cr = 1;
}
@@ -28,10 +29,20 @@
int last_nonspace;
int len;
cmark_chunk remainder = cmark_chunk_literal("");
int k = renderer->buffer->size - 1;
+ cmark_syntax_extension *ext = NULL;
+ cmark_node *n = node;
+ while (n && !ext) {
+ ext = n->extension;
+ if (!ext)
+ n = n->parent;
+ }
+ if (ext && !ext->commonmark_escape_func)
+ ext = NULL;
+
wrap = wrap && !renderer->no_linebreaks;
if (renderer->in_tight_list_item && renderer->need_cr > 1) {
renderer->need_cr = 1;
}
@@ -61,9 +72,13 @@
len = cmark_utf8proc_iterate((const uint8_t *)source + i, length - i, &c);
if (len == -1) { // error condition
return; // return without rendering rest of string
}
+
+ if (ext && ext->commonmark_escape_func(ext, node, c))
+ cmark_strbuf_putc(renderer->buffer, '\\');
+
nextc = source[i + len];
if (c == 32 && wrap) {
if (!renderer->begin_line) {
last_nonspace = renderer->buffer->size;
cmark_strbuf_putc(renderer->buffer, ' ');