)(.+)()', self._highlight_lua, html, flags=re.DOTALL)
# change img title attribute to figcaption
html = re.sub(r'(Note: ', '
Note ') return html def _highlight_replace(self, code, css_class): return '' + re.sub(r']*>(.+?)', r'\1', code) + '' def _highlight_lua(self, m): code = m.group(2) code = re.sub(r'\b(math|table|string|class|enum|set|log|world)\b', r'\1', code) # globals code = re.sub(r'\b([A-Z_][A-Z0-9_]*)\b', r'\1', code) # CONSTANTS code = re.sub(r'\b(and|break|do|else|elseif|end|false|for|function|goto|if|in|local|nil|not|or|repeat|return|then|true|until|while)\b', r'\1', code) # keywords code = re.sub(r'(\a.*?[^\\]\a|\a\a)', lambda m: self._highlight_replace(m.group(1), 'text'), code) code = re.sub(r"('.*?[^\\]'|'')", lambda m: self._highlight_replace(m.group(1), 'text'), code) code = re.sub(r'(--.*)$', lambda m: self._highlight_replace(m.group(1), 'comment'), code, flags=re.MULTILINE) # single line comments return m.group(1) + code + m.group(3)