User:The Anome/rmcolors.py
Appearance
import string, re, sys
data = sys.stdin.readlines()
x_style_pattern = r"(?P<r>[a-z]*style\s*?=)[^|]*?(background:|color:)[^|]*"
color_pattern = "\{\{colors?\|(?:(?:[^\|}]*\|)*)(?P<r>[^\}\|]+)\}\}"
span_pattern = r"<span[^<>]+(?:background|color)[^<>]*>(?P<r>[^<>]*)</span>"
pipelink_pattern = r"\[\[\s*(?P<r>[^]|]+)\s*\|\s*\1\s*\]\]"
def convert_line(line):
# Strip trailing newline ONLY
while line[-1:] == "\n":
line = line[:-1]
oldline = line
# print "style:", re.findall(x_style__pattern, line)
# print "color:", re.findall(color_pattern, line)
# print "span:", re.findall(span_pattern, line)
line = re.sub(x_style_pattern, "\g<r>", line)
line = re.sub(color_pattern, "\g<r>", line)
line = re.sub(span_pattern, "\g<r>", line)
# print "pipelink:", re.findall(pipelink_pattern, line)
line = re.sub(pipelink_pattern, "[[\g<r>]]", line)
# ignore edits that changed only whitespace
if string.split(line) == string.split(oldline):
return oldline
else:
return line
for line in data:
print convert_line(line)