pmacs3/mode_html.py

53 lines
2.1 KiB
Python
Raw Normal View History

2007-07-17 12:44:34 -04:00
import color, mode2
from lex3 import Grammar, PatternRule, RegionRule
2007-07-18 07:22:12 -04:00
from mode_xml import TagGrammar
from mode_javascript import JavascriptGrammar, Javascript
2007-07-17 12:44:34 -04:00
2007-07-18 07:22:12 -04:00
class HTMLGrammar(Grammar):
2007-07-17 12:44:34 -04:00
rules = [
2007-07-18 07:22:12 -04:00
# TODO: how does cdata work again?
2007-07-17 12:44:34 -04:00
RegionRule(r'comment', r'<!--', Grammar, r'-->'),
2007-07-18 07:22:12 -04:00
# BUG: not all scripts are javascript... but, dynamically choosing a
# grammar based on the 'type' attribute (which may be on a different
# line) could be pretty hairy.
RegionRule(r'script', r'<(?=script[^a-zA-Z0-9_])', TagGrammar, r'>', JavascriptGrammar, r'</(?=script>)', TagGrammar, r'>'),
RegionRule(r'tag', r'</?', TagGrammar, r'/?>'),
2007-07-17 12:44:34 -04:00
]
2007-07-18 07:22:12 -04:00
class HTML(mode2.Fundamental):
grammar = HTMLGrammar
colors = {
'comment.start': ('red', 'default'),
'comment.null': ('red', 'default'),
'comment.end': ('red', 'default'),
'script.start': ('default', 'default'),
'script.namespace': ('magenta', 'default'),
'script.name': ('blue', 'default'),
'script.attrname': ('cyan', 'default'),
'script.string.start': ('green', 'default'),
'script.string.null': ('green', 'default'),
'script.string.end': ('green', 'default'),
'script.end': ('default', 'default'),
'tag.start': ('default', 'default'),
'tag.namespace': ('magenta', 'default'),
'tag.name': ('blue', 'default'),
'tag.attrname': ('cyan', 'default'),
'tag.string.start': ('green', 'default'),
'tag.string.null': ('green', 'default'),
'tag.string.end': ('green', 'default'),
'tag.end': ('default', 'default'),
}
js = Javascript(None)
for name in js.colors:
colors['script.%s' % name] = js.colors[name]
del js
2007-07-17 12:44:34 -04:00
def __init__(self, w):
mode2.Fundamental.__init__(self, w)
self.add_bindings('close-paren', (')',))
self.add_bindings('close-brace', ('}',))
self.add_bindings('close-bracket', (']',))
def name(self):
2007-07-18 07:22:12 -04:00
return "HTML"