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
+31 -11
View File
@@ -1,15 +1,44 @@
# c2html
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
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
```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.
which, given a string containing C code, returns the highlighted version using HTML tags.
For example, lets consider the
```c
@@ -18,12 +47,6 @@ For example, lets consider the
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;
const char *prefix = NULL;
@@ -63,7 +86,4 @@ if `table_mode` were `1`, then the output would have been:
</table>
</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.
```