# c2html A tool to add HTML syntax highlighting to C code. # Installation and usage c2html comes both as a C library and a command-line utility. The library only exports one function ```c char *c2html(const char *str, long len, _Bool table_mode, const char *class_prefix, const char **error); ``` which, given a string of C code, returns the version highlighted using HTML tags. For example, lets consider the ```c /* .. include stdlib.h, string.h and stdio.h .. */ #include "c2html.h" int main() { // Table mode refers to the structure of the output HTML. // If table_mode is turned off, then the output lines are // separated by
tags and there are no line numbers. // Using table mode, then the lines are represented as rows // of an HTML. The table has a first column with the line // numbers and the second with their content. _Bool table_mode = 0; const char *prefix = NULL; char *c = "int main() {\n" " int a = 5;\n" " return 0;\n" "}\n"; char *html = c2html(c, strlen(c), table_mode, prefix, NULL); printf("%s\n", html); free(html); return 0; } ``` will output: ```
int main() {
    int a = 5;
    return 0;
}
``` if `table_mode` were `1`, then the output would have been: ```
1int main() {
2  int a = 5;
3  return 0;
4}
5
``` the color doesn't come with the generated HTML, you need to add it yourself using CSS. There's an example CSS style provided in `style.css`, inspired by the Sublime Text color theme I use. Since the generated class names of the HTML tags are pretty generic (`identifier`, `operator`, `comment`, ..) they may conflict with your own CSS code. To avoid this problem you can specify a prefix to be prepented to these names. The command-line interface `c2h` uses the `c2h-` previx.