cmark

My personal build of CMark ✏️

Commit
c5e64712336b9707858bd71c7287c6fd6281545c
Parent
26305f4eff1e2205c1259e82076295a575d7ca41
Author
John MacFarlane <jgm@berkeley.edu>
Date

Small cleanups.

Moved begin_line setting into render.c, so you don't need to worry about it in outc.

Diffstat

4 files changed, 115 insertions, 114 deletions

Status File Name N° Changes Insertions Deletions
Modified src/commonmark.c 2 0 2
Modified src/latex.c 222 111 111
Modified src/man.c 1 0 1
Modified src/render.c 4 4 0
diff --git 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
@@ -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  {
diff --git a/src/man.c b/src/man.c
@@ -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
@@ -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