+ char *html = cmark_markdown_to_html(s, len, CMARK_OPT_DEFAULT);
+ if (strcmp(get_ext(filename), "md") == 0) htmlized = true;
+
+ if (!htmlized) {
+ // Copy STDOUT
+ int stdout_copy = dup(1);
+
+ // Redirect STDOUT
+ dup2(fileno(fp), 1);
+
+ char cmd[255] = "chroma --html --html-only --html-lines --html-lines-table --filename ";
+ strncat(cmd, filename, strlen(filename) + 1);
+ FILE *child = popen(cmd, "w");
+ if (child == NULL) {
+ printf("child is null: %s", strerror(errno));
+ exit(1);
+ }
+
+ // Give code to highlight through STDIN:
+ size_t i;
+ for (i = 0; *s && i < len; s++, i++) {
+ fprintf(child, "%c", *s);
+ }
+
+ pclose(child);
+ fflush(stdout);
+
+ // Give back STDOUT.
+ dup2(stdout_copy, 1);
+
+ } else {
+ fprintf(fp, "%s", html);
+ }