diff options
author | cinap_lenrek <cinap_lenrek@gmx.de> | 2012-09-11 07:38:11 +0200 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@gmx.de> | 2012-09-11 07:38:11 +0200 |
commit | 7b3c5d9257286d653c2061501ebf8835e05d4658 (patch) | |
tree | 9c76ec27df8315de554192569b981fcf604eed8c /sys/src/cmd/mothra | |
parent | 6479692f56899a2c09a62efbb0d9415e5f07a9c1 (diff) |
mothra: special parse mode for <script> as parsetag gets confused by long javascript lines
Diffstat (limited to 'sys/src/cmd/mothra')
-rw-r--r-- | sys/src/cmd/mothra/html.h | 1 | ||||
-rw-r--r-- | sys/src/cmd/mothra/rdhtml.c | 45 |
2 files changed, 39 insertions, 7 deletions
diff --git a/sys/src/cmd/mothra/html.h b/sys/src/cmd/mothra/html.h index 35db0de35..0e3d1a8ea 100644 --- a/sys/src/cmd/mothra/html.h +++ b/sys/src/cmd/mothra/html.h @@ -33,6 +33,7 @@ struct Stack{ int indent; /* extra indent at paragraph start */ int number; /* paragraph number */ int ismap; /* flag of <img> */ + int isscript; /* inside <script> */ int width; /* size of image */ int height; char image[NNAME]; /* arg of <img> */ diff --git a/sys/src/cmd/mothra/rdhtml.c b/sys/src/cmd/mothra/rdhtml.c index 13a1dfe1d..a31454e77 100644 --- a/sys/src/cmd/mothra/rdhtml.c +++ b/sys/src/cmd/mothra/rdhtml.c @@ -462,6 +462,7 @@ int pl_getcomment(Hglob *g){ g->token[0]='\0'; return TAG; } + int lrunetochar(char *p, int v) { Rune r; @@ -470,17 +471,47 @@ int lrunetochar(char *p, int v) return runetochar(p, &r); } +int pl_getscript(Hglob *g){ + char *tokp, *t; + int c; + tokp = g->token; + *tokp++ = '<'; + while((c=pl_nextc(g)) != EOF){ + if(c==STAG || c==' ' || c=='\t' || c=='\n'){ + pl_putback(g, c); + break; + } + if(c==ETAG) c='>'; + tokp += lrunetochar(tokp, c); + if(c==0 || c=='>' || tokp >= &g->token[NTOKEN-UTFmax-1]) + break; + } + *tokp = '\0'; + t = tag[g->state->tag].name; + if(g->token[1] == '/' && cistrncmp(g->token+2, t, strlen(t)) == 0){ + g->tag=g->state->tag; + g->attr->name=0; + return ENDTAG; + } + pl_rmentities(g, g->token); + g->nsp=g->spacc; + g->spacc=0; + return TEXT; +} + /* * Read a start or end tag -- the caller has read the initial < */ int pl_gettag(Hglob *g){ char *tokp; int c, q; - tokp=g->token; + if(g->state->isscript) + return pl_getscript(g); if((c=pl_nextc(g))=='!' || c=='?') return pl_getcomment(g); pl_putback(g, c); q = 0; + tokp=g->token; while((c=pl_nextc(g))!=EOF){ if(c == '=' && q == 0) q = '='; @@ -649,6 +680,7 @@ void plrdhtml(char *name, int fd, Www *dst){ g.state->margin=0; g.state->indent=25; g.state->ismap=0; + g.state->isscript=0; g.state->width=0; g.state->height=0; g.dst=dst; @@ -1007,6 +1039,10 @@ void plrdhtml(char *name, int fd, Www *dst){ case Tag_isindex: rdform(&g); break; + case Tag_script: + case Tag_style: + g.state->isscript=1; + break; } break; @@ -1079,13 +1115,8 @@ void plrdhtml(char *name, int fd, Www *dst){ } break; case TEXT: - switch(g.state->tag){ - case Tag_script: - case Tag_object: - case Tag_applet: - case Tag_style: + if(g.state->isscript) continue; - } if(g.state->link[0]==0 && (str = linkify(g.token))){ nstrcpy(g.state->link, str, sizeof(g.state->link)); pl_htmloutput(&g, g.nsp, g.token, 0); |