ich habe ein kelines problem mit einer meiner extension (ich benutze mediawiki 1.10), welche in python geschrieben ist. das ganze problem findet sich hier (http://www.python-forum.de/topic-13876.html), da konnte mir aber leider niemand helfen . Meine "neue"Frage nun: kann mir jemand helfen zu entschlüsseln was genau diese funktion macht? (ich bin nciht so doll bewandert in python)...
Code: Alles auswählen
def doWiki(text):
#display-style math should be centered
text = re.sub(r'(?s)\n:+ *<math>(.*?)</math>\s*?([\.,;]?)\n', doMath, text)
text = re.sub(r'()\{([^|])', r'\\{\2', text)
text = re.sub(r'()([^|])\}', r'\2\\}', text)
text = doPreFormatted(text)
# take care of lists, tables and images
text = doIndent(text)
text = doTables(text)
text = doImages(text)
# first convert all HTML entities to Unicode
text = re.sub('&#([0-9]+?);', uni_dec2utf8, text)
text = re.sub('&#[xX]([0-9A-Fa-f]+?);', uni_hex2utf8, text)
text = re.sub('&([a-zA-Z0-9]+?);', entity2utf8, text)
text = re.sub(r'\$', r'\$', text)
# multi-pass regexp parser
for trans_tuple in translate:
print "replacing " + trans_tuple[0]
text = re.sub(trans_tuple[0], trans_tuple[1], text)
print "done"
# convert Unicode character to latex markup if possible
text = unicode2latex.convert2(text)
return text
also ich rufe dies methode mit einem text (den ganzen text) auf und dann gucke ich ob irgendwo math steht und rufe dann diese funktion auf:
Code: Alles auswählen
def doMath(mathtext):
mtext = mathtext.group(1).replace("&", "tableand")
mtext = re.sub(r'\n[ \t]*', r'\n', mtext) #remove whitespace at beginning of line
return "\n\\[" + mtext + mathtext.group(2) + "\\]\n"
text = re.sub(r'()\{([^|])', r'\\{\2', text) --> was bedeutet hier die \2!?
text = re.sub(r'\$', r'\$', text) -->
text = re.sub(trans_tuple[0], trans_tuple[1], text) --> und hier gucke ich in meinen translate array tupel [0] ist was ich suche im text und tupel[1] ist womit ich es ersetzte oder?!
danke für hilfe