2007-07-21 11:40:53 -04:00
|
|
|
import color, mode2
|
|
|
|
from lex3 import Grammar, PatternRule, RegionRule
|
|
|
|
from mode.xml import TagGrammar
|
|
|
|
from mode.javascript import JavascriptGrammar, Javascript
|
|
|
|
|
|
|
|
class HTMLGrammar(Grammar):
|
|
|
|
rules = [
|
|
|
|
# TODO: how does cdata work again?
|
|
|
|
RegionRule(r'comment', r'<!--', Grammar, r'-->'),
|
|
|
|
# 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'/?>'),
|
|
|
|
]
|
|
|
|
|
|
|
|
class HTML(mode2.Fundamental):
|
2007-10-18 17:07:35 -04:00
|
|
|
modename = 'HTML'
|
|
|
|
extensions = ['.html', '.htm', '.shtml', '.shtm', '.xhtml']
|
|
|
|
grammar = HTMLGrammar
|
|
|
|
colors = {
|
2007-07-21 11:40:53 -04:00
|
|
|
'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'),
|
|
|
|
}
|
2007-10-18 17:07:35 -04:00
|
|
|
colors.update(Javascript.colors)
|
2007-07-21 11:40:53 -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', (']',))
|