Cleaner HTML output.
[rsc] --rw-rw-r-- M 667885 glenda sys 14527 Oct 1 11:13 sys/src/cmd/wikifs/tohtml.c
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/wikifs/tohtml.c:177,187 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/wikifs/tohtml.c:177,223
return p;
}
+ int okayinlist[Nwtxt] =
+ {
+ [Wbullet] 1,
+ [Wlink] 1,
+ [Wman] 1,
+ [Wplain] 1,
+ };
+
+ int okayinpre[Nwtxt] =
+ {
+ [Wlink] 1,
+ [Wman] 1,
+ [Wpre] 1,
+ };
+
+ int okayinpara[Nwtxt] =
+ {
+ [Wpara] 1,
+ [Wlink] 1,
+ [Wman] 1,
+ [Wplain] 1,
+ };
+
+ char*
+ nospaces(char *s)
+ {
+ char *q;
+ s = strdup(s);
+ if(s == nil)
+ return nil;
+ for(q=s; *q; q++)
+ if(*q == ' ')
+ *q = '_';
+ return s;
+ }
+
String*
pagehtml(String *s, Wpage *wtxt, int ty)
{
- int inlist, inpre, inpara;
char *p, tmp[40];
+ int inlist, inpara, inpre, t, tnext;
Wpage *w;
inlist = 0;
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/wikifs/tohtml.c:189,242 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/wikifs/tohtml.c:225,278
inpara = 0;
for(w=wtxt; w; w=w->next){
- switch(w->type){
+ t = w->type;
+ tnext = Whr;
+ if(w->next)
+ tnext = w->next->type;
+
+ if(inlist && !okayinlist[t]){
+ inlist = 0;
+ s = s_append(s, "\n\n\n");
+ }
+ if(inpre && !okayinpre[t]){
+ 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);
+ p = nospaces(w->text);
+ 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(inpara){
+ s = s_append(s, "\n\n");
+ inpara = 0;
}
- if(inpre){
- inpre = 0;
- s = s_append(s, "\n");
- }
- if(!inpara){
+ if(okayinpara[tnext]){
+ 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){
inlist = 1;
s = s_append(s, "\n
\n");
- }
- if(inpara)
- inpara = 0;
+ }else
+ s = s_append(s, "\n\n");
s = s_append(s, "\n- \n");
break;
case Wlink:
- if(inpara)
- inpara = 0;
if(w->url == nil)
p = mkurl(w->text, ty);
else
p = w->url;
-
s = s_appendlist(s, "", nil);
s = s_escappend(s, w->text, 0);
s = s_append(s, "");
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/wikifs/tohtml.c:245,253 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/wikifs/tohtml.c:281,286
break;
case Wman:
- if(inpara)
- inpara = 0;
-
sprint(tmp, "%d", w->section);
s = s_appendlist(s,
"\n");
- }
if(!inpre){
inpre = 1;
s = s_append(s, "\n
\n");
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/wikifs/tohtml.c:275,312 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/wikifs/tohtml.c:302,321
break;
case Wplain:
- if(inpre){
- inpre = 0;
- s = s_append(s, "
\n");
- }
- if(inpara)
- inpara = 0;
s = s_escappend(s, w->text, 0);
break;
}
}
if(inlist)
- 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;
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/wikifs/tohtml.c:394,418 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/wikifs/tohtml.c:403,429
p[Blinelen(&b)-1] = '\0';
if((q = strpbrk(p, "acd")) == nil)
continue;
+ n1 = atoi(q+1);
+ if(q = strchr(q, ','))
+ n2 = atoi(q+1);
+ else
+ n2 = n1;
switch(*q){
case 'a':
case 'c':
- n1 = atoi(q+1);
- if(q = strchr(q, ','))
- 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;
}
}
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);
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/wikifs/tohtml.c:429,435 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/wikifs/tohtml.c:440,446
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
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/wikifs/tohtml.c:445,452 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/wikifs/tohtml.c:456,463
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, "
");
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/wikifs/tohtml.c:564,570 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/wikifs/tohtml.c:575,581
break;
x = e; l=LINELEN;
while(l--)
- x+=chartorune(&r,x);
+ x+=chartorune(&r, x);
x = strchr(x, ' ');
if(x){
*x = '\0';
[rsc] --rw-rw-r-- M 667885 glenda sys 916 Oct 1 10:22 sys/src/cmd/wikifs/wiki2html.c
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/wikifs/wiki2html.c:10,16 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/wikifs/wiki2html.c:10,16
void
usage(void)
{
- fprint(2, "usage: wiki2html [-d dir] wikifile\n");
+ fprint(2, "usage: wiki2html [-hoDP ] [-d dir] wikifile\n");
exits("usage");
}
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/wikifs/wiki2html.c:18,23 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/wikifs/wiki2html.c:18,24
main(int argc, char **argv)
{
int t;
+ int parse;
String *h;
Whist *doc;
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/wikifs/wiki2html.c:39,44 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/wikifs/wiki2html.c:40,47
case 'D':
t = Tdiff;
break;
+ case 'P':
+ parse = 1;
}ARGEND
if(argc != 1)
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/wikifs/wiki2html.c:52,57 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/wikifs/wiki2html.c:55,64
if(doc == nil)
sysfatal("doc: %r");
+ if(parse){
+ printpage(doc->doc->wtxt);
+ exits(0);
+ }
if((h = tohtml(doc, doc->doc+doc->ndoc-1, t)) == nil)
sysfatal("wiki2html: %r");
[rsc] --rw-rw-r-- M 667885 glenda sys 14527 Oct 1 11:13 sys/src/cmd/wikifs/tohtml.c
[sys] --rwxrwxr-x M 667885 glenda sys 202486 Oct 1 23:08 386/bin/wikifs
/sys/src/cmd/wikifs/tohtml.c:diffhtml
/sys/src/cmd/wikifs/tohtml.c:doctext
/sys/src/cmd/wikifs/tohtml.c:dodiff
/sys/src/cmd/wikifs/tohtml.c:grey
/sys/src/cmd/wikifs/tohtml.c:historyhtml
/sys/src/cmd/wikifs/tohtml.c:historytext
/sys/src/cmd/wikifs/tohtml.c:nospaces
/sys/src/cmd/wikifs/tohtml.c:pagehtml
/sys/src/cmd/wikifs/tohtml.c:pagetext
/sys/src/cmd/wikifs/tohtml.c:s_appendbrk
/sys/src/cmd/wikifs/tohtml.c:s_diff
/sys/src/cmd/wikifs/tohtml.c:s_endline
/sys/src/cmd/wikifs/tohtml.c:tohtml
/sys/src/cmd/wikifs/tohtml.c:totext
/sys/src/cmd/wikifs/tohtml.c:ungrey