From 7fe0c079fa833ed284a15a91b6d3a001af8e191c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20H=C3=BCbinette=20=28Hubbe=29?= <hubbe@hubbe.net> Date: Sat, 15 Jan 2000 22:00:26 -0800 Subject: [PATCH] support for XML output added Rev: tutorial/Makefile:1.56 Rev: tutorial/XML.pmod:1.1 Rev: tutorial/xml.pike:1.1 --- tutorial/Makefile | 3 ++ tutorial/XML.pmod | 73 +++++++++++++++++++++++++++++++++++++++++++++++ tutorial/xml.pike | 32 +++++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 tutorial/XML.pmod create mode 100644 tutorial/xml.pike diff --git a/tutorial/Makefile b/tutorial/Makefile index cc26f5a543..50f72e571d 100644 --- a/tutorial/Makefile +++ b/tutorial/Makefile @@ -65,6 +65,9 @@ tutorial_split.html: .DUMMY $(SRCFILES) tutorial.tex: .DUMMY $(SRCFILES) $(pike) ./wmmltohtml2 tutorial.wmml latex tutorial +tutorial.xml: .DUMMY $(SRCFILES) + $(pike) ./wmmltohtml2 tutorial.wmml xml tutorial + # latex has to be run twice to work with labels and stuff # but there are no labels yet... tutorial.dvi: tutorial.tex diff --git a/tutorial/XML.pmod b/tutorial/XML.pmod new file mode 100644 index 0000000000..66f88a58f2 --- /dev/null +++ b/tutorial/XML.pmod @@ -0,0 +1,73 @@ +import "."; + +string *from=({"&#a0;","&","<",">"}); +string *to=({" ","&","<",">"}); + +string unquote(string x) { return replace(x,from,to); } +string quote(string x) { return replace(x,to,from); } + +string *from_data=({"&#a0;","&","<",">","'","""}); +string *to_data=({" ","&","<",">","'","\""}); + +string unquote_data(string x) { return replace(x,from_data,to_data); } +string quote_data(string x) { return replace(x,to_data,from_data); } + +#define TAG object(Sgml.Tag)|string +#define SGML array(TAG) + +string mktag(string tag, mapping params, int end) +{ + string ret="<"+tag; + foreach(indices(params),string i) + if(params[i]) + ret+=" "+i+"='"+quote_data(stringp(params[i])?params[i]:i)+"'"; + + return ret + (end?"/>":">"); +} + +string generate(SGML data, void|function mkt) +{ + string ret=""; + if(!mkt) + { + mkt=mktag; + } + foreach(data, TAG foo) + { + if(stringp(foo)) + { + ret+=quote(foo); + } + else if (objectp(foo)) + { + ret+=mkt(foo->tag,foo->params,!foo->data); + if(foo->data) + { +#if 0 + if(foo->tag=="script") + { + // Magic for javascript! + ret+="\n<!--\n"+ + foo->data*""+ + "// -->\n"; + }else +#endif + ret+=generate(foo->data,mkt); + + ret+=mkt("/"+foo->tag,([]),0); + } + } + else error("got an illegal tag or string : %O\n" + "in: %O\n",foo,data); + } + + return ret; +} + + +#ifdef TEST +int main() +{ + write(sprintf("%O\n",group(lex(Stdio.read_file("tutorial.wmml"))))); +} +#endif diff --git a/tutorial/xml.pike b/tutorial/xml.pike new file mode 100644 index 0000000000..8ada3f32da --- /dev/null +++ b/tutorial/xml.pike @@ -0,0 +1,32 @@ +#include "types.h" +#if __VERSION__ >= 0.6 +import "."; +#endif /* __VERSION__ >= 0.6 */ +inherit Stdio.File : out; + + +void output(string base, WMML data) +{ + SGML newdata=({ + Sgml.Tag("wmml",([]),0, + ({ + /* FIXME: + * add toc, index_data and links + */ + "\n", + Sgml.Tag("metadata",([]),0,data->metadata),"\n", + Sgml.Tag("data",([]),0,data->data),"\n", + })) + }); + Stdio.File(base+".xml","wct")->write(XML.generate(newdata)); +} + +Sgml.Tag illustration(object o,void|mapping options) +{ + return Sgml.Tag("image",(["src":Gfx.mkgif(o,options)]),0); +} + +Sgml.Tag illustration_jpeg(object o,void|mapping options) +{ + return Sgml.Tag("image",(["src":Gfx.mkjpg(o,options)]),0); +} -- GitLab