parent
e858fa7ba7
commit
f5bb6804e8
49
mode/html.py
49
mode/html.py
|
@ -1,16 +1,18 @@
|
||||||
import color, mode
|
import color, mode
|
||||||
from lex import Grammar, PatternRule, RegionRule
|
from lex import Grammar, PatternRule, RegionRule
|
||||||
from mode.xml import TagGrammar
|
from mode.xml import TagGrammar
|
||||||
from mode.javascript import JavascriptGrammar, Javascript
|
from mode.javascript import JavascriptGrammar
|
||||||
|
from mode.css import CSSGrammar
|
||||||
|
|
||||||
class HTMLGrammar(Grammar):
|
class HTMLGrammar(Grammar):
|
||||||
rules = [
|
rules = [
|
||||||
# TODO: how does cdata work again?
|
# TODO: how does cdata work again?
|
||||||
RegionRule(r'comment', r'<!--', Grammar, r'-->'),
|
RegionRule(r'comment', r'<!--', Grammar, r'-->'),
|
||||||
# BUG: not all scripts are javascript... but, dynamically choosing a
|
# BUG: not all scripts are javascript and not all styles are CSS
|
||||||
# grammar based on the 'type' attribute (which may be on a different
|
# but, dynamically choosing a grammar based on the 'type' attribute
|
||||||
# line) could be pretty hairy.
|
# (which may be on a different line) is impractical.
|
||||||
RegionRule(r'script', r'<(?=script[^a-zA-Z0-9_])', TagGrammar, r'>', JavascriptGrammar, r'</(?=script>)', TagGrammar, r'>'),
|
RegionRule(r'script', r'<(?=script[^a-zA-Z0-9_])', TagGrammar, r'>', JavascriptGrammar, r'</(?=script>)', TagGrammar, r'>'),
|
||||||
|
RegionRule(r'style', r'<(?=style[^a-zA-Z0-9_])', TagGrammar, r'>', CSSGrammar, r'</(?=style>)', TagGrammar, r'>'),
|
||||||
RegionRule(r'tag', r'</?', TagGrammar, r'/?>'),
|
RegionRule(r'tag', r'</?', TagGrammar, r'/?>'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -18,34 +20,27 @@ class HTML(mode.Fundamental):
|
||||||
modename = 'HTML'
|
modename = 'HTML'
|
||||||
extensions = ['.html', '.htm', '.shtml', '.shtm', '.xhtml']
|
extensions = ['.html', '.htm', '.shtml', '.shtm', '.xhtml']
|
||||||
grammar = HTMLGrammar
|
grammar = HTMLGrammar
|
||||||
colors = {
|
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'),
|
|
||||||
}
|
|
||||||
#colors.update(Javascript.colors)
|
|
||||||
def __init__(self, w):
|
def __init__(self, w):
|
||||||
mode.Fundamental.__init__(self, w)
|
mode.Fundamental.__init__(self, w)
|
||||||
self.add_bindings('close-paren', (')',))
|
self.add_bindings('close-paren', (')',))
|
||||||
self.add_bindings('close-brace', ('}',))
|
self.add_bindings('close-brace', ('}',))
|
||||||
self.add_bindings('close-bracket', (']',))
|
self.add_bindings('close-bracket', (']',))
|
||||||
|
|
||||||
|
_colorbase = {
|
||||||
|
'start': ('default', 'default'),
|
||||||
|
'namespace': ('magenta', 'default'),
|
||||||
|
'name': ('blue', 'default'),
|
||||||
|
'attrname': ('cyan', 'default'),
|
||||||
|
'string.start': ('green', 'default'),
|
||||||
|
'string.null': ('green', 'default'),
|
||||||
|
'string.end': ('green', 'default'),
|
||||||
|
'end': ('default', 'default'),
|
||||||
|
}
|
||||||
|
for _name in _colorbase:
|
||||||
|
HTML.colors['script.%s' % _name] = _colorbase[_name]
|
||||||
|
HTML.colors['style.%s' % _name] = _colorbase[_name]
|
||||||
|
HTML.colors['tag.%s' % _name] = _colorbase[_name]
|
||||||
|
|
||||||
install = HTML.install
|
install = HTML.install
|
||||||
|
|
Loading…
Reference in New Issue