diff --git a/tutorial/Sgml.pmod b/tutorial/Sgml.pmod index 2ee426f6ba0f37432874a8b907c197396e67faca..e866695d08c01206e020695dcc6108547e4c69ec 100644 --- a/tutorial/Sgml.pmod +++ b/tutorial/Sgml.pmod @@ -128,6 +128,8 @@ SGML group(SGML data) if(strlen(foo->tag) && foo->tag[0]=='/') { string tag=foo->tag[1..]; + string t; + if (sscanf(tag,"%[^ \t\r\n>]%*s",t)==2) foo->tag=tag=t; for(int d=sizeof(ret)-1;d>=0;d--) { if(objectp(ret[d]) && !ret[d]->data && ret[d]->tag==tag) diff --git a/tutorial/Wmml.pmod b/tutorial/Wmml.pmod index 8767aef21db58d87fd2a673fc4f88c5acd73e032..ab1206b752c8ba556a685ee0770e071257504c5c 100644 --- a/tutorial/Wmml.pmod +++ b/tutorial/Wmml.pmod @@ -101,10 +101,11 @@ static private int verify_any(SGML data, string in) i=0; } case "p": + case "wbr": } if(x->data) - if(!verify_any(x->data," In tag "+x->tag+" near pos "+x->pos+"\n"+in)) + if(!verify_any(x->data," In tag "+(x->tag=="anchor"?x->tag+" (name="+x->params->name+")":x->tag)+" near pos "+x->pos+"\n"+in)) i=0; } } @@ -731,6 +732,7 @@ void save_image_cache(); int gifnum; mapping gifcache=([]); +mapping srccache=([]); string mkgif(object o) { @@ -771,9 +773,13 @@ object render_illustration(string pike_code, mapping params, float dpi) if(params->scale) dpi/=(float)params->scale; float scale=75.0/dpi; - if(params->src) img=img->fromppm(Process.popen("anytopnm 2>/dev/null "+src)); + if(params->src) + img=srccache[params->src]|| + (srccache[params->src]= + img->fromppm(Process.popen("anytopnm 2>/dev/null "+src))); if(scale!=1.0) img=img->scale(scale); - return compile_string("object `()(object src){ "+pike_code+" ; }")()(img); + return compile_string("import Image;\n" + "object `()(object src){ "+pike_code+" ; }")()(img); } private static string mkkey(mapping params, mixed ... other) @@ -801,9 +807,20 @@ string illustration_to_gif(TAG data, float dpi) string ret=illustration_cache[key]; if(!ret) { - ret=mkgif(render_illustration(pike_code,params, dpi)); - illustration_cache[key]=ret; - save_image_cache(); + mixed err=catch + { + ret=mkgif(render_illustration(pike_code,params, dpi)); + illustration_cache[key]=ret; + save_image_cache(); + }; + if (err) + { + werror("error while compiling and running\n"+pike_code+"\n"); + if (params->__from__) + werror("from "+params->__from__+":\n"); + werror(master()->describe_backtrace(err)+"\n"); + return "failed to illustrate..."; + } } return ret; } diff --git a/tutorial/wmml_to_html b/tutorial/wmml_to_html index eb5717c171de3ce60b2402ea669888a46022b790..c526e988ffbef2e8534f521849ba85d19e4c1dd5 100755 --- a/tutorial/wmml_to_html +++ b/tutorial/wmml_to_html @@ -84,6 +84,9 @@ string anchor(mixed a, mixed b, mixed c) add_to(foo[e], foo[..e]*"."); } + if (a=="anchor") + return "<a name="+b->name+">"+c+"</a name="+b->name+">"; + return 0; } @@ -276,7 +279,7 @@ string link(string tag, mapping params, string data) mixed tmp=aliases[params->to]; if(!tmp) { - werror("Unlinked <link> :"+params->to+"\n"); + werror("Unresolved <link> :"+params->to+"\n"); return 0; } @@ -321,6 +324,7 @@ string mkgif(object o) } mapping gifcache2=([]); +mapping srccache=([]); string illustration(string tag, mapping params, string data) { @@ -337,11 +341,26 @@ string illustration(string tag, mapping params, string data) string file; if(!(file=gifcache2[key])) { - if(params->src) img=img->fromppm(Process.popen("anytopnm "+src)); + mixed e; + if(params->src) + img=srccache[src] || + (srccache[src]=img->fromppm(Process.popen("anytopnm "+src))); if(scale!=1.0) img=img->scale(scale); - img=compile_string("object `()(object src){ "+data+" ; }")()(img); - file=mkgif(img); - gifcache2[key]=file; + if (e=catch + { + img=compile_string("import Image;\n" + "object `()(object src){ "+data+" ; }")()(img); + file=mkgif(img); + gifcache2[key]=file; + }) + { + werror("error while compiling and running\n"+data+"\n"); + if (params->__from__) + werror("from "+params->__from__+":\n"); + werror(master()->describe_backtrace(e)+"\n"); + return "<!-- failed to illustrate -->"; + } + params-=(["__from__":0]); } return end_img_tag("<img src="+file,params); @@ -385,7 +404,7 @@ int main() data=parse_html(data,(["include":do_include]),([])); /* Pass 1, find links for the index */ - data=parse_html(data, ([]) , (["a":anchor])); + data=parse_html(data, ([]) , (["a":anchor,"anchor":anchor])); /* Pass 2, parse chapters and sections */ data=parse_html(data, ([]) , TAGS);