Skip to content
Snippets Groups Projects
Commit 7fe0c079 authored by Fredrik Hübinette (Hubbe)'s avatar Fredrik Hübinette (Hubbe)
Browse files

support for XML output added

Rev: tutorial/Makefile:1.56
Rev: tutorial/XML.pmod:1.1
Rev: tutorial/xml.pike:1.1
parent 84cfceca
No related branches found
No related tags found
No related merge requests found
...@@ -65,6 +65,9 @@ tutorial_split.html: .DUMMY $(SRCFILES) ...@@ -65,6 +65,9 @@ tutorial_split.html: .DUMMY $(SRCFILES)
tutorial.tex: .DUMMY $(SRCFILES) tutorial.tex: .DUMMY $(SRCFILES)
$(pike) ./wmmltohtml2 tutorial.wmml latex tutorial $(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 # latex has to be run twice to work with labels and stuff
# but there are no labels yet... # but there are no labels yet...
tutorial.dvi: tutorial.tex tutorial.dvi: tutorial.tex
......
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;","&amp;","&lt;","&gt;","&apos;","&quot;"});
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
#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);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment