diff options
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(); |