Minnor changes to wikifs/tohtml.c so it generates more 'standard'(hah!) html that can be styled thru css. Also remove spaces from anchor names and other various fixes. Notes: Sat Oct 1 10:24:38 EDT 2005 rsc patch/note wikifs-tohtml-improvements I made the code a little clearer and made the new code look like the old code. I'm kind of annoyed I had to do the latter, since I wrote the wiki page about such things at your behest, and then you didn't follow the instructions. There were many strange spacings to go around. I also changed some things like to
. I can only assume you meant the latter, since to 8c, is just
. Russ Reference: /n/sources/patch/applied/wikifs-tohtml-improvements Date: Wed Sep 28 06:33:10 CES 2005 Reviewed-by: rsc --- /sys/src/cmd/wikifs/tohtml.c Wed Sep 28 06:26:13 2005 +++ /sys/src/cmd/wikifs/tohtml.c Wed Sep 28 06:26:04 2005 @@ -180,8 +180,8 @@ String* pagehtml(String *s, Wpage *wtxt, int ty) { - int inlist, inpre, inpara; - char *p, tmp[40]; + int inlist, inpre, inpara, t, tn; + char *p, *c, tmp[40]; Wpage *w; inlist = 0; @@ -189,49 +189,54 @@ inpara = 0; for(w=wtxt; w; w=w->next){ - switch(w->type){ + t = w->type; + tn = Whr; // This is the end + if(w->next) + tn = w->next->type; + + if(inlist && !(t == Wbullet || t == Wlink || t == Wman || t == Wplain)){ + inlist = 0; + s = s_append(s, "\n\n\n"); + } + if(inpre && (t == Wheading || t == Wpara || t == Wbullet || t == Whr || t == Wplain)){ + inpre = 0; + s = s_append(s, "\n"); + } + + switch(t){ case Wheading: - /* - if(!inpara){ - inpara = 1; - s = s_append(s, "\n

\n"); - } - */ - s = s_appendlist(s, "
\ntext,"\" />

", w->text, "

\n", nil); + // a name='' can't contain spaces + p = strdup(w->text); + for(c = p; *c != '\0'; c++) + if(*c == ' ') + *c = '_'; + s = s_appendlist(s, "\n

", w->text, "

\n", nil); + free(p); break; case Wpara: - if(inlist){ - inlist = 0; - s = s_append(s, "\n\n"); - } - if(inpre){ - inpre = 0; - s = s_append(s, "\n"); + if(inpara) { + s = s_append(s, "\n

\n"); + inpara = 0; } - if(!inpara){ + if( w->next && (tn != Wheading && tn != Wbullet && tn != Wpre && tn != Whr)) { + s = s_append(s, "\n

\n"); inpara = 1; - s = s_append(s, "\n

\n"); } + break; case Wbullet: - if(inpre){ - inpre = 0; - s = s_append(s, "\n"); - } - if(!inlist){ + if(!inlist) { inlist = 1; s = s_append(s, "\n

\n"); + s = s_append(s, "\n\n\n"); if(inpre) s = s_append(s, "\n"); - if(!inpara) - s = s_append(s, "\n

\n"); + if(inpara) + s = s_append(s, "\n

\n"); return s; } static String* -grey(String *s) -{ - return s_append(s, ""); -} - -static String* -ungrey(String *s) -{ - return s_append(s, ""); -} - -static String* copythru(String *s, char **newp, int *nlinep, int l) { char *oq, *q, *r; @@ -402,17 +380,30 @@ n2 = atoi(q+1); else n2 = n1; - s = grey(s); + s = s_append(s,""); s = copythru(s, &pnew, &nline, n1-1); - s = ungrey(s); + s = s_append(s,""); s = copythru(s, &pnew, &nline, n2); + s = s_append(s,""); break; +/* + //This is not what we want... + case 'd': + n1 = atoi(q+1); + + s = s_append(s,""); + s = copythru(s, &pnew, &nline, n1-1); + s = s_append(s,""); + s = copythru(s, &pnew, &nline, n1); + break; +*/ } } close(fdiff); - s = grey(s); + s = s_append(s,""); s = s_append(s, pnew); - s = ungrey(s); + s = s_append(s,""); + } s_free(new); s_free(old); @@ -429,7 +420,7 @@ char *atime; for(i=h->ndoc-1; i>=0; i--){ - s = s_append(s, "
\n"); + s = s_append(s, "
\n"); if(i==h->current) sprint(tmp, "index.html"); else @@ -445,8 +436,8 @@ s = s_append(s, ", conflicting write"); s = s_append(s, "\n"); if(h->doc[i].comment) - s = s_appendlist(s, "
", h->doc[i].comment, "\n", nil); - s = s_append(s, "

"); + s = s_appendlist(s, "
", h->doc[i].comment, "\n", nil); + s = s_append(s, "

"); s = s_diff(s, h, i, i-1); } s = s_append(s, "
"); --- /sys/src/cmd/wikifs/wiki2html.c Wed Sep 28 06:26:44 2005 +++ /sys/src/cmd/wikifs/wiki2html.c Wed Sep 28 06:26:38 2005 @@ -10,7 +10,7 @@ void usage(void) { - fprint(2, "usage: wiki2html [-d dir] wikifile\n"); + fprint(2, "usage: wiki2html [-hoDP ] [-d dir] wikifile\n"); exits("usage"); } @@ -18,6 +18,7 @@ main(int argc, char **argv) { int t; + int parse; String *h; Whist *doc; @@ -39,11 +40,23 @@ case 'D': t = Tdiff; break; + case 'P': + parse = 1; }ARGEND if(argc != 1) usage(); + if(parse) { + //doc = getcurrentbyname(argv[0]); + doc = getcurrent(atoi(argv[0])); + if(doc) { + printpage(doc->doc->wtxt); + exits(""); + } else { + exits("getbyname..."); + } + } if(t == Thistory || t==Tdiff) doc = gethistory(atoi(argv[0])); else