0
+/**********************************************************************
0
+ Functions for printing Elements as groff (mm macros)
0
+ ***********************************************************************/
0
+static bool in_list_item = false; /* True if we're parsing contents of a list item. */
0
+/* print_groff_string - print string, escaping for groff */
0
+void print_groff_string(char *str) {
0
+ while (*str != '\0') {
0
+void print_groff_mm_element(element elt, int count);
0
+/* print_groff_mm_element_list - print a list of elements as groff ms */
0
+void print_groff_mm_element_list(item *list) {
0
+ while (list != NULL) {
0
+ print_groff_mm_element((*list).val, count);
0
+/* print_groff_mm_element - print an element as groff ms */
0
+void print_groff_mm_element(element elt, int count) {
0
+ printf("%s", elt.contents.str);
0
+ print_groff_string(elt.contents.str);
0
+ print_groff_string(elt.contents.str);
0
+ /* don't print HTML */
0
+ print_groff_mm_element_list(elt.contents.link.label);
0
+ printf(" (%s)", elt.contents.link.url);
0
+ print_groff_mm_element_list(elt.contents.link.label);
0
+ print_groff_mm_element_list(elt.contents.list);
0
+ print_groff_mm_element_list(elt.contents.list);
0
+ print_groff_mm_element_list(elt.contents.list);
0
+ case H1: case H2: case H3: case H4: case H5: case H6:
0
+ lev = elt.key - H1 + 1;
0
+ printf(".H %d \"", lev);
0
+ print_groff_mm_element_list(elt.contents.list);
0
+ print_groff_mm_element_list(elt.contents.list);
0
+ if (!in_list_item || count != 1)
0
+ print_groff_mm_element_list(elt.contents.list);
0
+ printf("\\l'\\n(.lu*8u/10u'");
0
+ /* don't print HTML block */
0
+ printf(".VERBON 2\n");
0
+ print_groff_string(elt.contents.str);
0
+ print_groff_mm_element_list(elt.contents.list);
0
+ print_groff_mm_element_list(elt.contents.list);
0
+ /* \001 is used to indicate boundaries between nested lists when there
0
+ * is no blank line. We split the string by \001 and parse
0
+ * each chunk separately. */
0
+ contents = strtok(elt.contents.str, "\001");
0
+ print_groff_mm_element(markdown(contents), 1);
0
+ while ((contents = strtok(NULL, "\001"))) {
0
+ print_groff_mm_element(markdown(contents), 1);
0
+ print_groff_mm_element(markdown(elt.contents.str), 1);
0
+ fprintf(stderr, "print_groff_mm_element encountered unknown element key = %d\n", elt.key);
0
/**********************************************************************
0
Main program and auxiliary functions.
0
printf("Usage: %s [options] [FILE]...\n"
0
"-t FORMAT or --to FORMAT convert to FORMAT (default is html)\n"
0
+ " FORMAT = html|latex|groff-mm\n"
0
"-o FILE or --output FILE send output to FILE (default is stdout)\n"
0
"-V or --version print program version and exit\n"
0
- "-h or --help show this message and exit\n"
0
- "This program reads the specified FILEs (or stdin if none are given)\n"
0
- "and converts them to FORMAT using markdown syntax conventions.\n"
0
- "Supported FORMATs: html latex\n",
0
+ "-h or --help show this message and exit\n",
0
/* the output filename is initially 0 (a.k.a. stdout) */
0
+ enum formats { HTML_FORMAT,
0
int output_format = HTML_FORMAT;
0
char *shortopts = "Vho:t:";
0
output_format = HTML_FORMAT;
0
else if (strcmp(format, "latex") == 0)
0
output_format = LATEX_FORMAT;
0
+ else if (strcmp(format, "groff-mm") == 0)
0
+ output_format = GROFF_MM_FORMAT;
0
fprintf(stderr, "%s: Unknown output format '%s'\n", progname, format);
0
print_latex_element(parsed_input);
0
+ print_groff_mm_element(parsed_input, 1);
0
fprintf(stderr, "print_element - unknown format = %d\n", output_format);
Comments
No one has commented yet.