summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/commonmark.c11
-rw-r--r--src/latex.c86
2 files changed, 40 insertions, 57 deletions
diff --git a/src/commonmark.c b/src/commonmark.c
index 7dc2767..5d098e7 100644
--- a/src/commonmark.c
+++ b/src/commonmark.c
@@ -50,16 +50,13 @@ static inline void outc(cmark_renderer *renderer,
cmark_strbuf_printf(renderer->buffer, "%%%2x", c);
renderer->column += 3;
} else {
- cmark_strbuf_putc(renderer->buffer, '\\');
- utf8proc_encode_char(c, renderer->buffer);
- renderer->column += 2;
+ cmark_render_ascii(renderer, "\\");
+ cmark_render_code_point(renderer, c);
}
- renderer->begin_line = false;
} else {
- utf8proc_encode_char(c, renderer->buffer);
- renderer->column += 1;
- renderer->begin_line = false;
+ cmark_render_code_point(renderer, c);
}
+ renderer->begin_line = (c == 10);
}
diff --git a/src/latex.c b/src/latex.c
index bf0c65e..592c40c 100644
--- a/src/latex.c
+++ b/src/latex.c
@@ -17,7 +17,6 @@
#define LIT(s) renderer->out(renderer, s, false, LITERAL)
#define CR() renderer->cr(renderer)
#define BLANKLINE() renderer->blankline(renderer)
-#define ASCII(s) cmark_render_ascii(renderer, s)
static inline void outc(cmark_renderer *renderer,
cmark_escaping escape,
@@ -25,8 +24,7 @@ static inline void outc(cmark_renderer *renderer,
unsigned char nextc)
{
if (escape == LITERAL) {
- utf8proc_encode_char(c, renderer->buffer);
- renderer->column += 1;
+ cmark_render_code_point(renderer, c);
} else {
switch(c) {
case 123: // '{'
@@ -34,129 +32,117 @@ static inline void outc(cmark_renderer *renderer,
case 35: // '#'
case 37: // '%'
case 38: // '&'
- ASCII("\\");
- utf8proc_encode_char(c, renderer->buffer);
- renderer->column += 1;
+ cmark_render_ascii(renderer, "\\");
+ cmark_render_code_point(renderer, c);
break;
case 36: // '$'
case 95: // '_'
if (escape == NORMAL) {
- ASCII("\\");
+ cmark_render_ascii(renderer, "\\");
}
- utf8proc_encode_char(c, renderer->buffer);
- renderer->column += 1;
+ cmark_render_code_point(renderer, c);
break;
case 45 : // '-'
if (nextc == 45) { // prevent ligature
- ASCII("\\-");
+ cmark_render_ascii(renderer, "\\-");
} else {
- ASCII("-");
+ cmark_render_ascii(renderer, "-");
}
break;
case 126: // '~'
if (escape == NORMAL) {
- ASCII("\\textasciitilde{}");
+ cmark_render_ascii(renderer, "\\textasciitilde{}");
} else {
- utf8proc_encode_char(c, renderer->buffer);
- renderer->column += 1;
+ cmark_render_code_point(renderer, c);
}
break;
case 94: // '^'
- ASCII("\\^{}");
+ cmark_render_ascii(renderer, "\\^{}");
break;
case 92: // '\\'
if (escape == URL) {
// / acts as path sep even on windows:
- ASCII("/");
+ cmark_render_ascii(renderer, "/");
} else {
- ASCII("\\textbackslash{}");
+ cmark_render_ascii(renderer, "\\textbackslash{}");
}
break;
case 124: // '|'
- ASCII("\\textbar{}");
+ cmark_render_ascii(renderer, "\\textbar{}");
break;
case 60: // '<'
- ASCII("\\textless{}");
+ cmark_render_ascii(renderer, "\\textless{}");
break;
case 62: // '>'
- ASCII("\\textgreater{}");
+ cmark_render_ascii(renderer, "\\textgreater{}");
break;
case 91: // '['
case 93: // ']'
- ASCII("{");
- utf8proc_encode_char(c, renderer->buffer);
- renderer->column += 1;
- ASCII("}");
+ cmark_render_ascii(renderer, "{");
+ cmark_render_code_point(renderer, c);
+ cmark_render_ascii(renderer, "}");
break;
case 34: // '"'
- ASCII("\\textquotedbl{}");
+ cmark_render_ascii(renderer, "\\textquotedbl{}");
// requires \usepackage[T1]{fontenc}
break;
case 39: // '\''
- ASCII("\\textquotesingle{}");
+ cmark_render_ascii(renderer, "\\textquotesingle{}");
// requires \usepackage{textcomp}
break;
case 160: // nbsp
- ASCII("~");
- renderer->column += 1;
+ cmark_render_ascii(renderer, "~");
break;
case 8230: // hellip
- ASCII("\\ldots{}");
+ cmark_render_ascii(renderer, "\\ldots{}");
break;
case 8216: // lsquo
if (escape == NORMAL) {
- ASCII("`");
+ cmark_render_ascii(renderer, "`");
} else {
- utf8proc_encode_char(c, renderer->buffer);
- renderer->column += 1;
+ cmark_render_code_point(renderer, c);
}
break;
case 8217: // rsquo
if (escape == NORMAL) {
- ASCII("\'");
+ cmark_render_ascii(renderer, "\'");
} else {
- utf8proc_encode_char(c, renderer->buffer);
- renderer->column += 1;
+ cmark_render_code_point(renderer, c);
}
break;
case 8220: // ldquo
if (escape == NORMAL) {
- ASCII("``");
+ cmark_render_ascii(renderer, "``");
} else {
- utf8proc_encode_char(c, renderer->buffer);
- renderer->column += 1;
+ cmark_render_code_point(renderer, c);
}
break;
case 8221: // rdquo
if (escape == NORMAL) {
- ASCII("''");
+ cmark_render_ascii(renderer, "''");
} else {
- utf8proc_encode_char(c, renderer->buffer);
- renderer->column += 1;
+ cmark_render_code_point(renderer, c);
}
break;
case 8212: // emdash
if (escape == NORMAL) {
- ASCII("---");
+ cmark_render_ascii(renderer, "---");
} else {
- utf8proc_encode_char(c, renderer->buffer);
- renderer->column += 1;
+ cmark_render_code_point(renderer, c);
}
break;
case 8211: // endash
if (escape == NORMAL) {
- ASCII("--");
+ cmark_render_ascii(renderer, "--");
} else {
- utf8proc_encode_char(c, renderer->buffer);
- renderer->column += 1;
+ cmark_render_code_point(renderer, c);
}
break;
default:
- utf8proc_encode_char(c, renderer->buffer);
- renderer->column += 1;
- renderer->begin_line = false;
+ cmark_render_code_point(renderer, c);
}
}
+ renderer->begin_line = (c == 10);
}
typedef enum {