diff options
author | John MacFarlane <jgm@berkeley.edu> | 2015-03-21 21:13:36 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2015-03-21 21:30:39 -0700 |
commit | 573dd81575b821661fb4aaa6f8c68b513f889f07 (patch) | |
tree | b638bf7d789dc19bfd101caf887faecc4c1fbd78 /src/main.c | |
parent | b31224fbe2072b8e2328c9607e8587e79a7f307d (diff) |
CommonMark renderer: Added 'width' parameter.
This controls column width for hard wrapping. By default it is
0, which means that no wrapping will be done.
Added a width parameter in `cmark_render_commonmark`.
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 25 |
1 files changed, 22 insertions, 3 deletions
@@ -25,6 +25,7 @@ void print_usage() printf("Usage: cmark [FILE*]\n"); printf("Options:\n"); printf(" --to, -t FORMAT Specify output format (html, xml, man, commonmark)\n"); + printf(" --width WIDTH Specify wrap width (default 0 = nowrap)\n"); printf(" --sourcepos Include source position attribute\n"); printf(" --hardbreaks Treat newlines as hard line breaks\n"); printf(" --smart Use smart punctuation\n"); @@ -34,9 +35,10 @@ void print_usage() } static void print_document(cmark_node *document, writer_format writer, - int options) + int options, int width) { char *result; + switch (writer) { case FORMAT_HTML: result = cmark_render_html(document, options); @@ -48,7 +50,7 @@ static void print_document(cmark_node *document, writer_format writer, result = cmark_render_man(document, options); break; case FORMAT_COMMONMARK: - result = cmark_render_commonmark(document, options); + result = cmark_render_commonmark(document, options, width); break; default: fprintf(stderr, "Unknown format %d\n", writer); @@ -66,6 +68,8 @@ int main(int argc, char *argv[]) cmark_parser *parser; size_t bytes; cmark_node *document; + int width; + char *unparsed; writer_format writer = FORMAT_HTML; int options = CMARK_OPT_DEFAULT; @@ -92,6 +96,21 @@ int main(int argc, char *argv[]) (strcmp(argv[i], "-h") == 0)) { print_usage(); exit(0); + } else if (strcmp(argv[i], "--width") == 0) { + i += 1; + if (i < argc) { + width = (int)strtol(argv[i], &unparsed, 10); + if (unparsed && strlen(unparsed) > 0) { + fprintf(stderr, + "failed parsing width '%s' at '%s'\n", + argv[i], unparsed); + exit(1); + } + } else { + fprintf(stderr, + "--width requires an argument\n"); + exit(1); + } } else if ((strcmp(argv[i], "-t") == 0) || (strcmp(argv[i], "--to") == 0)) { i += 1; @@ -159,7 +178,7 @@ int main(int argc, char *argv[]) cmark_parser_free(parser); start_timer(); - print_document(document, writer, options); + print_document(document, writer, options, width); end_timer("print_document"); start_timer(); |