diff --git a/tutorial/Sgml.pmod b/tutorial/Sgml.pmod index 270cecfa1474118a4e5fc67eff2fdce2969c9cf3..d3c7db91cbfba0d2b549ed75d28b08bbcda6466f 100644 --- a/tutorial/Sgml.pmod +++ b/tutorial/Sgml.pmod @@ -207,7 +207,9 @@ string generate(SGML data, void|function mkt) if(stringp(foo)) { ret+=quote(foo); - }else{ + } + else if (objectp(foo)) + { ret+=mkt(foo->tag,foo->params); if(foo->data) { @@ -215,6 +217,8 @@ string generate(SGML data, void|function mkt) ret+=mkt("/"+foo->tag,([])); } } + else error("got an illegal tag or string : %O\n" + "in: %O\n",foo,data); } return ret; diff --git a/tutorial/Wmml.pmod b/tutorial/Wmml.pmod index 020a1ad4f7516c59f85ee3e8da162598ae2261d8..bf6fcbec6406cada82b732aec872e52c5cb1bef3 100644 --- a/tutorial/Wmml.pmod +++ b/tutorial/Wmml.pmod @@ -89,6 +89,8 @@ static private int verify_any(SGML data, case "illustration": case "link": + case "add_appendix": + case "exercises": case "exercise": @@ -118,6 +120,8 @@ static private int verify_any(SGML data, case "data_description": case "elem": // in data_description + + case "execute": case "aargdesc": // in man_arguments case "aarg": // in man_arguments @@ -131,6 +135,7 @@ static private int verify_any(SGML data, break; + case "insert_added_appendices": case "ex_indent": case "ex_br": case "include": @@ -490,6 +495,8 @@ object(Enumerator) chapterE; object(Stacker) classbase; object(TocBuilder) toker; +array add_appendices=({}); + string name_to_link(string x) { return replace(x,({"->","->", "#"}),({".",".",""})); @@ -644,6 +651,15 @@ SGML low_make_concrete_wmml(SGML data) ret+=fix_section(tag,appendixE); appendixE->inc(); continue; + + case "add_appendix": + tag->tag="appendix"; + add_appendices+=fix_section(tag,appendixE); + continue; + + case "insert_added_appendices": + ret+=low_make_concrete_wmml(add_appendices); + continue; case "table": case "image": @@ -664,6 +680,10 @@ SGML low_make_concrete_wmml(SGML data) continue; } break; + + case "execute": + ret+=execute_contents(tag); + continue; case "class": case "module": @@ -868,9 +888,12 @@ int gifnum; mapping gifcache=([]); mapping srccache=([]); -string mkgif(mixed o) +string mkgif(mixed o,void|object alpha) { - string g=stringp(o)?o:Image.GIF.encode(o); + string g= + stringp(o)?o: + alpha?Image.GIF.encode(o,alpha): + Image.GIF.encode(o); int key=hash(g); @@ -962,9 +985,66 @@ string illustration_to_gif(TAG data, float dpi) return ret; } +array execute_contents(Tag tag) +{ + string data=get_text(tag->data); + + add_constant("illustration", + lambda(object o,void|object alpha) + { + return Sgml.Tag("image",(["gif":mkgif(o,alpha)]),0); + }); + add_constant("mktag", + lambda(string name,void|mapping arg,void|mixed cont) + { + if (arg) arg=(mapping(string:string))arg; + return Sgml.Tag(name, + arg||([]), + tag->pos, + arrayp(cont)?cont: + intp(cont)?({}):({cont}), + tag->file); + }); + + array ret; + + mixed err=catch + { + object po; + po=compile_string("#1 \"static stuff\"\n" + "array _res=({({})});\n" + "void write(mixed ...args) { _res[0]+=args; }\n" + "\n" + "void begin_tag(string name,void|mapping p) " + "{ _res=({({}),({name,p})})+_res; }\n" + "object end_tag() " + "{ object t=mktag(@_res[1],_res[0]); " + "_res=_res[2..]; return t;}\n" + "\n" + "#1 \"inline wmml generating code\"\n" + +data)(); + po->main(); + ret=po->_res[0]; + }; + if (err) + { + werror("error while compiling and running\n"+data+"\n"); + if (tag->params->__from__) + werror("from "+tag->params->__from__+":\n"); + werror(master()->describe_backtrace(err)+"\n"); + return ({"<!-- failed to execute wmml generator... -->"}); + } + return ret; +} + + string image_to_gif(TAG data, float dpi) { mapping params=data->params; + + if(params->gif) + return params->gif; + if(params->xfig) params->src=params->xfig+".fig"; diff --git a/tutorial/html.pike b/tutorial/html.pike index 1b3cfd61c284a05012e22063a95cb9d50cfd9f37..4df443c66bb0ce9310f784d0c981da9afdea0c94 100644 --- a/tutorial/html.pike +++ b/tutorial/html.pike @@ -44,6 +44,9 @@ TAG mkimgtag(string file, mapping params) if(params->align) p->align=params->align; if(params->alt) p->align=params->alt; add_file_to_export_list(file); + object o=Image.load(file); + p->xsize=o->xsize(); + p->ysize=o->ysize(); return Sgml.Tag("img",p,0); } @@ -639,7 +642,7 @@ SGML convert(SGML data) "Appendix ", data->params->number, ", ", - data->params->title, + data->params->title||error("Appendix without title"), })), "\n" })+ @@ -748,7 +751,8 @@ SGML convert(SGML data) SGML wmml_to_html(SGML data) { SGML ret=convert(data); - if(!(objectp(data[0]) && (data[0]->tag=="body" || data[0]->tag=="frameset"))) + if(!(objectp(data[0]) && + (data[0]->tag=="body" || data[0]->tag=="frameset"))) { ret=({ Sgml.Tag("body", diff --git a/tutorial/the_image_module.wmml b/tutorial/the_image_module.wmml index 2ff6ac8908f22c07a3a96eb5874c5dc9766d5d9e..9a592a375f5d4cbf4ed9a193041c544cb530d88e 100644 --- a/tutorial/the_image_module.wmml +++ b/tutorial/the_image_module.wmml @@ -13,5 +13,6 @@ bla blabla bla blah blah <include file=Image.wmml> </chapter> +<insert_added_appendices>