pre2html

Unnamed repository; edit this file to name it for gitweb.
git clone https://logand.com/git/pre2html.git/
Log | Files | Refs

commit 03b3b1922d3be42e074d46b4bbad0f9d313b00c0
parent 550356cc72c891e31f7f12e1c57dce69131bdefb
Author: Tomas Hlavaty <tom@logand.com>
Date:   Tue,  6 Sep 2011 09:19:24 +0200

CODE...END div added

Diffstat:
Mtext2html.c | 42+++++++++++++++++++++++++++++-------------
1 file changed, 29 insertions(+), 13 deletions(-)

diff --git a/text2html.c b/text2html.c @@ -23,6 +23,12 @@ static int head(char *what, char *buf, char *end) { } return !*what; } + +static int tail(char *what, char *buf, char *end) { + while(*what && buf < --end) { + if(*what++ != *end) return 0; + } + return !*what; } static char *find(char what, char *buf, char *end) { @@ -54,6 +60,23 @@ static void text(char *buf, char *end) { escape(*buf); } +static void rest(char *b, char *e) { + while(b < e) { + if(head("<http:", b, e) || head("<https:", b, e)) { + escape(*b++); + char *n = find('>', b, e); + printf("<a href=\""); + attr(b, n); + printf("\">"); + text(b, n); + printf("</a>"); + b = n; + escape(*b++); + } + else escape(*b++); + } +} + int main() { char buf[BLEN]; char *end = buf + BLEN; @@ -62,20 +85,13 @@ int main() { while(0 < (n = line(buf, end))) { char *b = buf; char *e = buf + n; - while(b < e) { - if(head("<http:", b, e) || head("<https:", b, e)) { - escape(*b++); - char *n = find('>', b, e); - printf("<a href=\""); - attr(b, n); - printf("\">"); - text(b, n); - printf("</a>"); - b = n; - escape(*b++); - } - else escape(*b++); + if(head("CODE", b, e)) + printf("<div style=\"color:#080\">"); + } + else if(head("END", b, e)) { + printf("</div>"); } + else rest(b, e); } puts("</pre>"); return 0;