cmark

My personal build of CMark ✏️

Commit
455a6a937df0e6eb4612c0f818a36e6a0629ee4b
Parent
b27dcba03a6907cfc71aa0af5bfe737793c542ca
Author
John MacFarlane <jgm@berkeley.edu>
Date

Implemented --smart for man output.

Diffstat

2 files changed, 13 insertions, 6 deletions

Status File Name N° Changes Insertions Deletions
Modified man/man1/cmark.1 4 2 2
Modified src/man.c 15 11 4
diff --git a/man/man1/cmark.1 b/man/man1/cmark.1
@@ -36,8 +36,8 @@ Consolidate adjacent text nodes.
 Use smart punctuation.  Straight double and single quotes will
 be rendered as curly quotes, depending on their position.  `--`
 will be rendered as an en-dash. `---` will be rendered as
-an em-dash. `...` will be rendered as ellipses.  Currently
-only supported for HTML output.
+an em-dash. `...` will be rendered as ellipses.  (This option
+has no effect on XML output.)
 .TP 12n
 \-\-help
 Print usage information.
diff --git a/src/man.c b/src/man.c
@@ -7,6 +7,7 @@
 #include "cmark.h"
 #include "node.h"
 #include "buffer.h"
+#include "smart.h"
 
 // Functions to convert cmark_nodes to groff man strings.
 
@@ -46,7 +47,7 @@ struct render_state {
 
 static int
 S_render_node(cmark_node *node, cmark_event_type ev_type,
-              struct render_state *state)
+              struct render_state *state, long options)
 {
 	cmark_node *tmp;
 	cmark_strbuf *man = state->man;
@@ -165,8 +166,14 @@ S_render_node(cmark_node *node, cmark_event_type ev_type,
 		break;
 
 	case CMARK_NODE_TEXT:
-		escape_man(man, node->as.literal.data,
-		           node->as.literal.len);
+		if (options & CMARK_OPT_SMARTPUNCT) {
+			escape_with_smart(man, node, escape_man,
+					  "\\[lq]", "\\[rq]", "\\[oq]", "\\[cq]",
+					  "\\[em]", "\\[en]", "...");
+		} else {
+			escape_man(man, node->as.literal.data,
+				   node->as.literal.len);
+		}
 		break;
 
 	case CMARK_NODE_LINEBREAK:
@@ -241,7 +248,7 @@ char *cmark_render_man(cmark_node *root, long options)
 
 	while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) {
 		cur = cmark_iter_get_node(iter);
-		S_render_node(cur, ev_type, &state);
+		S_render_node(cur, ev_type, &state, options);
 	}
 	result = (char *)cmark_strbuf_detach(&man);