From 455a6a937df0e6eb4612c0f818a36e6a0629ee4b Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sun, 15 Feb 2015 11:15:04 -0800 Subject: Implemented --smart for man output. --- man/man1/cmark.1 | 4 ++-- src/man.c | 15 +++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/man/man1/cmark.1 b/man/man1/cmark.1 index 305761f..c2a023a 100644 --- 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 index f57eb75..970bb6d 100644 --- 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); -- cgit v1.2.3