monk/codeHL/codeHLXML.py

37 lines
946 B
Python

#!/usr/bin/python
import monkDebug as debug
import sys
import monkTools
import re
listRegExp = [
[ r'<!\-\-!(.*?)\-\->', 'code-doxygen'],
[ r'<!\-\-(.*?)\-\->', 'code-comment'],
[ r'"((\\"|.)*?)"', 'code-text-quote'],
[ r"'(('|.)*?)'", 'code-text-quote'],
[ r'</[0-9a-zA-Z_]+|<[0-9a-zA-Z_]+|/>|>',
'code-function-name']
]
def transcode(value):
inValue = value
outValue = ""
haveFindSomething = False;
for reg1, color in listRegExp:
result = re.search(reg1, inValue, re.DOTALL)
while result != None:
haveFindSomething = True
# sub parse the start :
outValue += transcode(inValue[:result.start()])
# transform local
outValue += '<span class="' + color + '">'
outValue += result.group()
outValue += '</span>'
# change the input value
inValue = inValue[result.end():]
# Search again ...
result = re.search(reg1, inValue, re.DOTALL)
outValue += inValue
return outValue