updated readme

This commit is contained in:
cozis
2022-05-05 19:01:06 +02:00
parent 0383d9494f
commit 9a2665d703
2 changed files with 31 additions and 14 deletions
+30 -10
View File
@@ -1,15 +1,44 @@
# c2html # c2html
A tool to add HTML syntax highlighting to C code. A tool to add HTML syntax highlighting to C code.
Basicaly you give `c2html` some C code as input and it classifies all the keywords, identifiers etc using `<span>` elements, associating them with the appropriate class names. By applying the `style.css` stylesheet to the generated output, you get the highliting. If you prefer, you can write your own style.
# Installation and usage # Installation and usage
c2html comes both as a C library and a command-line utility. c2html comes both as a C library and a command-line utility.
## Command-line interface
By running `build.sh`, the `c2h` executable is built, which is command-line interface of c2html.
You can highlight your C files by doing
```sh
./c2h --input file.c --output file.html
```
This command will generate the highlighted C code.
### --no-table
Normally, `c2h` will generate html using a `<table>` element, where each line is a `<tr>` element. This makes the output kind of big. By using the `--no-table` option, it's possible to generate a more lightweight output where lines are splitted using `<br/>` elements instead of using a `<table>`.
You'd use it like this;
```sh
./c2h --input file.c --output file.html --no-table
```
### --style
The HTML comes with no styling. If you want to apply a CSS to it, you can provide to `c2h` a style file using the `--style` option followed by the name of the file.
```sh
./c2h --input file.c --output file.html --style style.css
```
This will basically add a `<style>` element with the contents of the `style.css` file, before the normal HTML output.
## Library
The library only exports one function The library only exports one function
```c ```c
char *c2html(const char *str, long len, _Bool table_mode, char *c2html(const char *str, long len, _Bool table_mode,
const char *class_prefix, const char **error); const char *class_prefix, const char **error);
``` ```
which, given a string of C code, returns the version highlighted using HTML tags. which, given a string containing C code, returns the highlighted version using HTML tags.
For example, lets consider the For example, lets consider the
```c ```c
@@ -18,12 +47,6 @@ For example, lets consider the
int main() 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 <br /> 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; _Bool table_mode = 0;
const char *prefix = NULL; const char *prefix = NULL;
@@ -64,6 +87,3 @@ if `table_mode` were `1`, then the output would have been:
</div> </div>
</div> </div>
``` ```
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.
-3
View File
@@ -103,7 +103,6 @@ int main(int argc, char **argv)
*style_file = NULL, *style_file = NULL,
*prefix = NULL; *prefix = NULL;
bool notable = 0; bool notable = 0;
bool http = 0;
for(int i = 1; i < argc; i += 1) { for(int i = 1; i < argc; i += 1) {
if(!strcmp(argv[i], "-i") || !strcmp(argv[i], "--input")) { if(!strcmp(argv[i], "-i") || !strcmp(argv[i], "--input")) {
i += 1; i += 1;
@@ -135,8 +134,6 @@ int main(int argc, char **argv)
return -1; return -1;
} }
style_file = argv[i]; style_file = argv[i];
} else if(!strcmp(argv[i], "--http")) {
http = 1;
} else { } else {
fprintf(stderr, "Error: Unknown option %s\n", argv[i]); fprintf(stderr, "Error: Unknown option %s\n", argv[i]);
return -1; return -1;