ich versteh's irgendwie net
ziel der methode ist es das textstück zu finden wo ein bild deklariert wird(bei dem Programm handelt es sich um ein Skript das wikitexte --> wikipedia in latex texte umwandelt um aus dem tex dokument ein pdf zu generieren)
Code: Alles auswählen
def doImages(text):
print text
itext=text;
for im,caption in re.findall(r'\[\[Image:([^\[\|]*)\|([^\[]*)\]\]', itext):
print "Test"
# latex hates "_" and " "-chars (and probably many others as well), strip .jpg
# pat: remove also \
imName = re.sub(r'[ _\\]+','',im)
#imName = re.sub(r'(.*)\.[^\.]*',r'\1',imName)
imName = re.sub(r'\.(jpg|JPG|gif|GIF|jpeg|JPEG)$','.png',imName)
# pat: convert the path (windows specific)
path = sys.argv[3].replace("\\","/")
print "path:" + path
# convert all wikitags to image commands
# pat, debug
print "image Name: " + imName
print "within path: " + sys.argv[3].replace("\\","/")
itext=re.sub(r'\[\[Image:.*\]\]' , r'\\begin{figure}[!h] \n \\begin{center} \n \\includegraphics[scale=0.5]{' + path + "/" + imName + '}\n \end{center} \n \\caption{'+caption+'} \n \\end{figure}', itext, count = 1)
return itext
so das ist die ganze methode udn ich hab fest gestellt, dass das skript halt ncoh nciht mal in die for schleife rein geht...aus welchem grund auch immer
print "match:", match
print
wieso ist das 2. print leer?
ich hab's grad mal ausprobiert...also die ausgabe ist: match: [] das war's
was heisst das? das er nix findet!? aber [[Image:Example.jpg]] steht in text
ich versteh das nicht...hab mir vor dem match, den text ausgeben lassen:
dies ist ein test bla blubb
<special>XHNxcnR7XHN1bV8wXm5cLCBhX25eMn0=
</special>
immer noch
<special>XGluZiB6IFxzdXAgYSBcZXhwIGIgXGxuIGMgXGxnIGQgXGxvZyBlIFxsb2dfezEwfSBmIFxrZXIg
Z1wsXCE=
</special>
QZCBLQUfdzbwszwbreh
funued6ube
== Headline text ==
tjzurjrtu6
[[Image:Example.jpg]]
<special>XGRlZyBoIFxnY2QgaSBcUHIgaiBcZGV0IGsgXGhvbSBsIFxhcmcgbSBcZGltIG5cLFwh
</special>
<special>XGJvbGRzeW1ib2x7XHVwc2lsb259IFxib2xkc3ltYm9se1xwaGl9IFxib2xkc3ltYm9se1xjaGl9
IFxib2xkc3ltYm9se1xwc2l9IFxib2xkc3ltYm9se1xvbWVnYX1cLFwh
</special>
bei den komischen <special> Tags nicht's bei denken, das stimmt schon so...aber die hauptsache ist ja, dass Image eindeutig drin steht...