diff options
author | John MacFarlane <jgm@berkeley.edu> | 2015-07-12 17:36:31 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2015-07-12 17:36:31 -0700 |
commit | c5e64712336b9707858bd71c7287c6fd6281545c (patch) | |
tree | 8956f0adf5643680ea255575d8fe96687597ef9e | |
parent | 26305f4eff1e2205c1259e82076295a575d7ca41 (diff) |
Small cleanups.
Moved begin_line setting into render.c, so you don't need to
worry about it in outc.
-rw-r--r-- | src/commonmark.c | 2 | ||||
-rw-r--r-- | src/latex.c | 222 | ||||
-rw-r--r-- | src/man.c | 1 | ||||
-rw-r--r-- | src/render.c | 4 |
4 files changed, 115 insertions, 114 deletions
diff --git a/src/commonmark.c b/src/commonmark.c index 5d098e7..dbb1910 100644 --- a/src/commonmark.c +++ b/src/commonmark.c @@ -56,8 +56,6 @@ static inline void outc(cmark_renderer *renderer, } else { cmark_render_code_point(renderer, c); } - renderer->begin_line = (c == 10); - } static int diff --git a/src/latex.c b/src/latex.c index 592c40c..34dffc7 100644 --- a/src/latex.c +++ b/src/latex.c @@ -25,124 +25,124 @@ static inline void outc(cmark_renderer *renderer, { if (escape == LITERAL) { cmark_render_code_point(renderer, c); - } else { - switch(c) { - case 123: // '{' - case 125: // '}' - case 35: // '#' - case 37: // '%' - case 38: // '&' + return; + } + + switch(c) { + case 123: // '{' + case 125: // '}' + case 35: // '#' + case 37: // '%' + case 38: // '&' + cmark_render_ascii(renderer, "\\"); + cmark_render_code_point(renderer, c); + break; + case 36: // '$' + case 95: // '_' + if (escape == NORMAL) { cmark_render_ascii(renderer, "\\"); + } + cmark_render_code_point(renderer, c); + break; + case 45 : // '-' + if (nextc == 45) { // prevent ligature + cmark_render_ascii(renderer, "\\-"); + } else { + cmark_render_ascii(renderer, "-"); + } + break; + case 126: // '~' + if (escape == NORMAL) { + cmark_render_ascii(renderer, "\\textasciitilde{}"); + } else { cmark_render_code_point(renderer, c); - break; - case 36: // '$' - case 95: // '_' - if (escape == NORMAL) { - cmark_render_ascii(renderer, "\\"); - } + } + break; + case 94: // '^' + cmark_render_ascii(renderer, "\\^{}"); + break; + case 92: // '\\' + if (escape == URL) { + // / acts as path sep even on windows: + cmark_render_ascii(renderer, "/"); + } else { + cmark_render_ascii(renderer, "\\textbackslash{}"); + } + break; + case 124: // '|' + cmark_render_ascii(renderer, "\\textbar{}"); + break; + case 60: // '<' + cmark_render_ascii(renderer, "\\textless{}"); + break; + case 62: // '>' + cmark_render_ascii(renderer, "\\textgreater{}"); + break; + case 91: // '[' + case 93: // ']' + cmark_render_ascii(renderer, "{"); + cmark_render_code_point(renderer, c); + cmark_render_ascii(renderer, "}"); + break; + case 34: // '"' + cmark_render_ascii(renderer, "\\textquotedbl{}"); + // requires \usepackage[T1]{fontenc} + break; + case 39: // '\'' + cmark_render_ascii(renderer, "\\textquotesingle{}"); + // requires \usepackage{textcomp} + break; + case 160: // nbsp + cmark_render_ascii(renderer, "~"); + break; + case 8230: // hellip + cmark_render_ascii(renderer, "\\ldots{}"); + break; + case 8216: // lsquo + if (escape == NORMAL) { + cmark_render_ascii(renderer, "`"); + } else { cmark_render_code_point(renderer, c); - break; - case 45 : // '-' - if (nextc == 45) { // prevent ligature - cmark_render_ascii(renderer, "\\-"); - } else { - cmark_render_ascii(renderer, "-"); - } - break; - case 126: // '~' - if (escape == NORMAL) { - cmark_render_ascii(renderer, "\\textasciitilde{}"); - } else { - cmark_render_code_point(renderer, c); - } - break; - case 94: // '^' - cmark_render_ascii(renderer, "\\^{}"); - break; - case 92: // '\\' - if (escape == URL) { - // / acts as path sep even on windows: - cmark_render_ascii(renderer, "/"); - } else { - cmark_render_ascii(renderer, "\\textbackslash{}"); - } - break; - case 124: // '|' - cmark_render_ascii(renderer, "\\textbar{}"); - break; - case 60: // '<' - cmark_render_ascii(renderer, "\\textless{}"); - break; - case 62: // '>' - cmark_render_ascii(renderer, "\\textgreater{}"); - break; - case 91: // '[' - case 93: // ']' - cmark_render_ascii(renderer, "{"); + } + break; + case 8217: // rsquo + if (escape == NORMAL) { + cmark_render_ascii(renderer, "\'"); + } else { cmark_render_code_point(renderer, c); - cmark_render_ascii(renderer, "}"); - break; - case 34: // '"' - cmark_render_ascii(renderer, "\\textquotedbl{}"); - // requires \usepackage[T1]{fontenc} - break; - case 39: // '\'' - cmark_render_ascii(renderer, "\\textquotesingle{}"); - // requires \usepackage{textcomp} - break; - case 160: // nbsp - cmark_render_ascii(renderer, "~"); - break; - case 8230: // hellip - cmark_render_ascii(renderer, "\\ldots{}"); - break; - case 8216: // lsquo - if (escape == NORMAL) { - cmark_render_ascii(renderer, "`"); - } else { - cmark_render_code_point(renderer, c); - } - break; - case 8217: // rsquo - if (escape == NORMAL) { - cmark_render_ascii(renderer, "\'"); - } else { - cmark_render_code_point(renderer, c); - } - break; - case 8220: // ldquo - if (escape == NORMAL) { - cmark_render_ascii(renderer, "``"); - } else { - cmark_render_code_point(renderer, c); - } - break; - case 8221: // rdquo - if (escape == NORMAL) { - cmark_render_ascii(renderer, "''"); - } else { - cmark_render_code_point(renderer, c); - } - break; - case 8212: // emdash - if (escape == NORMAL) { - cmark_render_ascii(renderer, "---"); - } else { - cmark_render_code_point(renderer, c); - } - break; - case 8211: // endash - if (escape == NORMAL) { - cmark_render_ascii(renderer, "--"); - } else { - cmark_render_code_point(renderer, c); - } - break; - default: + } + break; + case 8220: // ldquo + if (escape == NORMAL) { + cmark_render_ascii(renderer, "``"); + } else { cmark_render_code_point(renderer, c); } + break; + case 8221: // rdquo + if (escape == NORMAL) { + cmark_render_ascii(renderer, "''"); + } else { + cmark_render_code_point(renderer, c); + } + break; + case 8212: // emdash + if (escape == NORMAL) { + cmark_render_ascii(renderer, "---"); + } else { + cmark_render_code_point(renderer, c); + } + break; + case 8211: // endash + if (escape == NORMAL) { + cmark_render_ascii(renderer, "--"); + } else { + cmark_render_code_point(renderer, c); + } + break; + default: + cmark_render_code_point(renderer, c); } - renderer->begin_line = (c == 10); } typedef enum { @@ -71,7 +71,6 @@ void S_outc(cmark_renderer *renderer, default: cmark_render_code_point(renderer, c); } - renderer->begin_line = (c == 10); } static int diff --git a/src/render.c b/src/render.c index 9fea832..ab53558 100644 --- a/src/render.c +++ b/src/render.c @@ -86,8 +86,12 @@ void S_out(cmark_renderer *renderer, renderer->column = 0; renderer->begin_line = true; renderer->last_breakable = 0; + } else if (escape == LITERAL) { + cmark_render_code_point(renderer, c); + renderer->begin_line = false; } else { (renderer->outc)(renderer, escape, c, nextc); + renderer->begin_line = false; } // If adding the character went beyond width, look for an |