This commit is contained in:
cozis
2022-05-05 22:26:53 +02:00
parent 38e8ce9216
commit b7216c8694
3 changed files with 35 additions and 13 deletions
+1
View File
@@ -1,3 +1,4 @@
c2html
*.html
samples
vgcore.*
+1 -1
View File
@@ -1 +1 @@
gcc cli.c c2html.c -o c2html -Wall -Wextra
gcc cli.c c2html.c -o c2html -Wall -Wextra -g
+28 -7
View File
@@ -106,6 +106,7 @@ static Token *tokenize(const char *str, long len)
long curly_bracket_depth = 0;
bool only_spaces_since_line_start = 1;
bool prev_nonspace_was_directive = 0;
do {
if(i == len) {
T.kind = T_DONE;
@@ -459,7 +460,6 @@ static void print_escaped(buff_t *buff, const char *str, long len)
&& str[j] != '<'
&& str[j] != '>'
&& str[j] != ' '
&& str[j] != '\n'
&& str[j] != '\t')
j += 1;
@@ -472,14 +472,12 @@ static void print_escaped(buff_t *buff, const char *str, long len)
switch(str[j]) {
case '<': buff_printf(buff, "&lt;"); break;
case '>': buff_printf(buff, "&gt;"); break;
case '\n': buff_printf(buff, "<br />\n"); break;
case '\t': buff_printf(buff, "&emsp;&emsp;&emsp;&emsp;"); break;
case ' ':
if(j == 0 || str[j-1] != ' ')
buff_printf(buff, " ");
else
if(j == 0 || j == len-1 || (str[j-1] == ' ' || str[j-1] == '\t'))
buff_printf(buff, "&emsp;");
else
buff_printf(buff, " ");
break;
default: assert(0);
@@ -598,11 +596,34 @@ char *c2html(const char *str, long len, _Bool table_mode, const char *class_pref
break;
case T_COMMENT:
{
long j = tokens[i].off;
long end = j + tokens[i].len;
while(1) {
long line_off = j;
while(j < end && str[j] != '\n')
j += 1;
long line_len = j - line_off;
buff_printf(&buff, "<span class=\"%scomment\">", class_prefix);
print_escaped(&buff, str + tokens[i].off, tokens[i].len);
print_escaped(&buff, str + line_off, line_len);
buff_printf(&buff, "</span>");
if(j == end)
break;
j += 1; // Skip the '\n'.
lineno += 1;
if(table_mode)
buff_printf(&buff, "</td></tr>\n <tr><td>%d</td><td>", lineno);
else
buff_printf(&buff, "<br />\n");
}
break;
}
case T_OPERATOR:
buff_printf(&buff, "<span class=\"%soperator\">", class_prefix);
print_escaped(&buff, str + tokens[i].off, tokens[i].len);