Meta:Tools/Wiki conversions/DocBook to Wiki
Hoi!
http://download.blender.org/documentation/xml2wiki/
holds a rough translation of XMLs to WIKI syntax, please feel free to cut and paste them in the relevant Wiki page!
Beware, some checks and edits will be necessary!
We're working to have all the images online automatically, so don't loose your time uploading them!
Do it Yourself
This will need to be placed on a less prominent place, but I think it deserve maximum attention in this moment.
Here is a tentative DocBook 2 MediaWiki converter [v.0.0.2 06/10/05]. use it as
perl xml2wiki.pl IMGROOT <file.xml >file.txt
Being IMGROOT the prefix to append to image names and links.
Then you can copy and paste the .txt on the wiki... it will need some editing.
#!/usr/bin/perl
# DocBook XML to MediaWiki Converter V. 0.0.2
# Many bugs fixed thanks to Ewout feedback
# (C) 2005 Stefano Selleri [GNU GPL License, look for it]
# Designed for migrating Blender DOC from DocBook to Mediawiki
# Use at your Own RISK!
$IMGPATH = shift ;
$xml = "";
while (<STDIN>) {
s/^[ ,\t]*//;
$xml .= $_
}
$xml =~ s/\r//sg;
while($xml =~ /<xref(.*?)\/>/s) {
$lab = $1; $id = $lab; $id =~ s/(.*?)=(.*?)/$2/s;
$id =~ s/"//g; while($id =~ s/^ //s){} while($id =~ s/ $//s){}
$xml =~ /id *= *" *$id(.*?)<title>(.*?)<\/title>/s;
$cap = $2;
if (length($cap)<2){$cap=$id;}
$xml =~ s/<xref$lab\/>/''$cap''/sg;
}
$xml =~ s/<!--(.*?)-->//sg;
$xml =~ s/<chapter(.*?)>(.*?)<title>(.*?)<\/title>//sg;
$xml =~ s/<\/chapter>//sg;
$xml =~ s/<para>//sg;
$xml =~ s/<\/para>/\n/sg;
$xml =~ s/<section(.*?)<title>(.*?)<\/title>/==$2==\n/sg;
$xml =~ s/<section(.*?)>//sg;
$xml =~ s/<\/section>//sg;
$xml =~ s/<bridgehead(.*?)>(.*?)<\/bridgehead>/====$2====\n$3/sg;
$xml =~ s/<figure(.*?)<title>(.*?)<\/title>(.*?)<(.*?)fileref(.*?)\/([^\/]*?)"(.*?)<\/figure>/\[\[Image:$IMGPATH-$6|frame|none|$2\]\]/sg;
$xml =~ s/<guiicon(.*?)fileref(.*?)\/([^\/]*?)"(.*?)<\/guiicon>/\[\[Image:$IMGPATH-$3\]\]/sg;
$xml =~ s/<emphasis>(.*?)<\/emphasis>/''$1''/sg;
$xml =~ s/<literal>(.*?)<\/literal>/\{\{Literal|$1\}\}/sg;
$xml =~ s/\&(.?)KEY;/\{\{K|$1\}\}/sg;
$xml =~ s/<keycap>(.?)KEY<\/keycap>/\{\{K|$1\}\}/sg;
$xml =~ s/<keycap>(.*?)<\/keycap>/\{\{KEY|$1\}\}/sg;
$xml =~ s/<itemizedlist>//sg;
$xml =~ s/<\/itemizedlist>//sg;
$xml =~ s/<orderedlist>//sg;
$xml =~ s/<\/orderedlist>//sg;
$xml =~ s/<variablelist>//sg;
$xml =~ s/<\/variablelist>//sg;
$xml =~ s/<varlistentry>//sg;
$xml =~ s/<\/varlistentry>//sg;
$xml =~ s/<term>(.*?)<\/term>/====$1====/sg;
$xml =~ s/<listitem>/\*/sg;
while($xml =~ s/\n\* *\n/\n\*/sg){};
$xml =~ s/<\/listitem>//sg;
$xml =~ s/<superscript>/<sup>/sg;
$xml =~ s/<\/superscript>/<\/sup>/sg;
$xml =~ s/<subscript>/<sup>/sg;
$xml =~ s/<\/subscript>/<\/sup>/sg;
$xml =~ s/<note>(.*?)<title>(.*?)<\/title>(.*?)<\/note>/\{\{Note|$2|$3\}\}/sg;
$xml =~ s/<note>(.*?)<\/note>/\{\{Note|Note|$1\}\}/sg;
$xml =~ s/<tip>(.*?)<title>(.*?)<\/title>(.*?)<\/tip>/\{\{Note|$2|$3\}\}/sg;
$xml =~ s/<tip>(.*?)<\/tip>/\{\{Note|A Tip|$1\}\}/sg;
while($xml =~ s/\n //sg){};
while($xml =~ s/\|\n //sg){};
while($xml =~ s/ \n/\n/sg){};
while($xml =~ s/\n\n/\n/sg){};
print $xml;
__END__
while($xml =~ /<tip>(.*?)<\/tip>/s) {
$content = $1;
$formatted = $content;
if ($formatted =~ /<title>(.*?)<\/title>/) {
$title = $1;
$formatted =~ s/<title>$title<\/title>//s;
} else {
$title = "A Tip";
}
$formatted =~ s/\{\{K\|(.*?)\}\}/'''$1'''/sg;
$formatted =~ s/\{\{KEY\|(.*?)\}\}/'''$1'''/sg;
$formatted =~ s/\{\{Literal\|(.*?)\}\}/<tt>$1<\/tt>/sg;
$formatted =~ s/\{//sg;
$formatted =~ s/\}//sg;
$content =~s/\(/\\\(/g;
$content =~s/\)/\\\)/g;
$content =~s/\?/\\\?/g;
$content =~s/\//\\\//g;
$content =~s/\*/\\\*/g;
#print $content;
$xml =~ s/<tip>$content<\/tip>/\{\{Tip|$title|$formatted\}\}/sg;
}
while($xml =~ /<note>(.*?)<\/note>/sg) {
$content = $1;
$formatted = $content;
if ($formatted =~ /<title>(.*?)<\/title>/) {
$title = $1;
$formatted =~ s/<title>$title<\/title>//s;
} else {
$title = "Note";
}
$formatted =~ s/\{\{K\|(.*?)\}\}/'''$1'''/sg;
$formatted =~ s/\{\{KEY\|(.*?)\}\}/'''$1'''/sg;
$formatted =~ s/\{\{Literal\|(.*?)\}\}/<tt>$1<\/tt>/sg;
$formatted =~ s/\{//sg;
$formatted =~ s/\{//sg;
$content =~s/\(/\\\(/g;
$content =~s/\)/\\\)/g;
$content =~s/\?/\\\?/g;
$content =~s/\//\\\//g;
$content =~s/\*/\\\*/g;
$xml =~ s/<note>$content<\/note>/\{\{Note|$title|$formatted\}\}/sg;
}
Going recursively in your tree
Of course, if you have several XML to parse this recursive parser might prove useful:
#!/usr/bin/perl
# DocBook XML to MediaWiki Converter V. 0.0.2
# Many bugs fixed thanks to Ewout feedback
# (C) 2005 Stefano Selleri [GNU GPL License, look for it]
# Designed for migrating Blender DOC from DocBook to Mediawiki
# Use at your Own RISK!
$IMGPATH = shift ;
sub getXML {
my $a = shift;
my @b = `ls $a/*.xml 2>1`;
if (@b==0) {
#print "no files\n";
my @c = `ls $a/* -d 2>1`;
for my $c (@c) {
#print $c;
chomp($c);
my @d = getXML("$c");
@b = (@b,@d);
}
return @b;
} else {
return @b;
print @b,"++";
}
}
sub getPNG {
my $a = shift;
my @b = `ls $a/*.png 2>1`;
if (@b==0) {
#print "no files\n";
my @c = `ls $a/* -d 2>1`;
for my $c (@c) {
#print $c;
chomp($c);
my @d = getPNG("$c");
@b = (@b,@d);
}
return @b;
} else {
return @b;
print @b,"++";
}
}
#####################################
@a = `ls Part* -d`;
#@a = `ls PartM -d`;
for $a (@a) {
chomp($a);
print "+-> Parsing $a\n";
@b = getXML($a);
@f = getPNG($a);
#print @f;
for $b (@b) {
if ($b =~ /\/en\//) {
print "\n\n",$b;
chomp($b);
print "New Location?\n";
$loc = readline(*STDIN);
chomp($loc);
if (length($loc)>0) {
$img = $loc;
$img =~ s/\//-/g;
}
$b =~ /(.*)\/(.*)\.(.*)/;
$c = "WIKED/".$img."-$2.wiki";
print"| +-> Translating $b to $c\n";
#print "xml2wiki.pl $img <$b >$c";
$a = `xml2wiki.pl $img <$b >$c`;
$a = `gatherimg.pl $img <$c`;
open(FH,"<$c");
$xml = "";
while (<FH>) {
if(/\[\[Image:$img-(.*?)\]\]/){
$bi = $1;
$bi =~ s/(.*?)\|(.*)/$1/;
for $f (@f) {
chomp($f);
if($f =~ /$bi/) {
print $bi,"->", $f;
$aa = `cp $f WIKEDIMG/$img-$bi`;
}
}
}
}
close (FH);
#die
}
}
print @b;
print "-------------------------\n";
}
Python script
This is a Python Script that tries to do the conversion, and takes the most common tags into account. If you think more tags should be added, or want to report a bug, don't hesitate to contact the author.
To use the script, just load it into Blender Text Window and run it. The File Selector appears: select a XML file to convert. The script creates a TXT file in the same folder as the original one.
Correct the '%%%%%' indications in the output file (as well as other corrections needed).
####################################################################
# #
# Script: DOCBOOK TO WIKI #
# Author: Pep Ribal #
# Version: 1.0 #
# #
####################################################################
# #
# IMPORTANT #
# ========= #
# LOOK FOR '%%%%%' INDICATIONS IN THE OUTPUT FILE #
# Set titleNote as desired (translation of "Note") #
# Double quotes assumed in tags (atrib="val" style) #
# #
####################################################################
#
# Recognized tags so far:
#
# chapter, section, bridgehead, orderedlist, itemizedlist,
# emphasis, literal, xref, figure, informalequation, link,
# inlinegraphic, command, tip, note, para, keycap
#
import Blender.Window
# set titleNote to the desired value in doble quotes (in English, "Note")
titleNote="Note"
# Advances until next '<' char; 0 - No output, 1- Output; returns tag name
def nextag(out):
global buffer,lastChar,fout
while len(buffer)>0 and buffer[0]!="<":
if out==1:
# No TABS, NLs or CRs will be written:
if buffer[0]=="\t" or buffer[0]=="\n" or buffer[0]=="\r":
presentChar=" "
else:
presentChar=buffer[0]
if (lastChar==" " or lastChar=="\n" or lastChar=="(") and presentChar==" ":
presentChar="" # Avoid these combinations
fout.write(presentChar)
if presentChar!="":
lastChar=presentChar
buffer=buffer[1:]
if buffer=="":
return # EOF
tag=""
while buffer[0]!=" " and buffer[0]!="\t" and buffer[0]!="\n" and buffer[0]!="\r" and buffer[0]!=">":
tag=tag+buffer[0]
buffer=buffer[1:]
buffer=buffer[1:]
return tag[1:]
# Returns string until string found (removes all from buffer)
def contentUntil(until):
global buffer
straux=""
lastChar="*" # This is not the global variable; just an internal control var
while not buffer.startswith(until):
# No TABS, NLs or CRs will be written:
if buffer[0]=="\t" or buffer[0]=="\n" or buffer[0]=="\r":
presentChar=" "
else:
presentChar=buffer[0]
if (lastChar==" " or lastChar=="\n" or lastChar=="(") and presentChar==" ":
presentChar="" # Avoid these combinations
straux+=presentChar
buffer=buffer[1:]
if presentChar!="":
lastChar=presentChar
buffer=buffer[len(until):]
return straux
def fileSel(filename):
xml2wiki(filename)
def xml2wiki(fname):
global buffer,lastChar,fout
listType="?"
lastChar="*"
fin=open(fname,"r")
fout=open(fname[:-4]+".txt","w")
buffer=fin.read()
outp=0
while len(buffer)>0:
aux=nextag(outp)
if aux=="chapter":
contentUntil("<title>")
fout.write("\n='''"+contentUntil("</title>")+"'''=\n")
lastChar="\n"
elif aux=="section":
contentUntil("<title>")
fout.write("\n="+contentUntil("</title>")+"=\n")
lastChar="\n"
elif aux=="bridgehead":
contentUntil(">")
fout.write("\n==="+contentUntil("</bridgehead>")+"===\n")
lastChar="\n"
elif aux=="para":
fout.write("\n")
lastChar="\n"
outp=1
elif aux=="emphasis" or aux=="/emphasis":
fout.write("''")
lastChar="'"
elif aux=="/para":
fout.write("\n")
lastChar="\n"
outp=0
elif aux=="itemizedlist":
fout.write("\n")
lastChar="\n"
listType="* "
elif aux=="orderedlist":
fout.write("\n")
lastChar="\n"
listType="# "
elif aux=="listitem":
contentUntil("<para>")
outp=1
fout.write(listType)
lastChar=" "
elif aux=="keycap":
fout.write("{{KEY|"+contentUntil("</keycap>")+"}}")
lastChar="}"
elif aux=="literal":
fout.write("{{Literal|"+contentUntil("</literal>")+"}}")
lastChar="}"
elif aux=="xref":
contentUntil('="')
fout.write("''%%%%%XREF:"+contentUntil('"/>')+"''")
lastChar="'"
elif aux=="figure":
contentUntil("<title>")
aux=contentUntil("</title>")
contentUntil('fileref="')
fout.write("\n[[Image:"+contentUntil('"')+"|frame|none|"+aux+"]]\n")
lastChar="\n"
contentUntil("</figure>")
elif aux=="inlinegraphic":
contentUntil('="')
fout.write("[[Image:"+contentUntil('"')+"]]")
lastChar="]"
contentUntil(">")
elif aux=="command":
fout.write("%%%%%COMMAND:")
lastChar=":"
elif aux=="/command":
fout.write(":COMMAND%%%%%")
lastChar="%"
elif aux=="tip" or aux=="note":
while buffer[0]!="<": # We might want to keep the '<' char in buffer
buffer=buffer[1:]
if buffer[:7]=="<title>":
buffer=buffer[7:]
fout.write("\n{{Tip|"+contentUntil("</title>")+"|")
else:
fout.write("\n{{Tip|"+titleNote+"|")
lastChar="|"
elif aux=="/tip" or aux=="/note":
fout.write("}}\n")
lastChar="\n"
elif aux=="informalequation":
fout.write("\n%%%%%INFORMALEQUATION:")
fout.write(contentUntil("</informalequation>"))
fout.write(":INFORMALEQUATION%%%%%\n")
lastChar="\n"
elif aux=="link":
contentUntil('="')
fout.write("%%%%%LINK:"+contentUntil('">')+"==>"+contentUntil("</link>")+":LINK%%%%%")
lastChar="%"
fout.close()
fin.close()
Blender.Window.FileSelector(fileSel,"Select XML")