pmacs3/mode/html.py

47 lines
1.8 KiB
Python
Raw Normal View History

2007-10-21 20:55:29 -04:00
import color, mode
2007-10-21 20:52:48 -04:00
from lex import Grammar, PatternRule, RegionRule
2007-07-21 11:40:53 -04:00
from mode.xml import TagGrammar
2008-04-02 19:50:18 -04:00
from mode.javascript import JavascriptGrammar
from mode.css import CSSGrammar
2007-07-21 11:40:53 -04:00
class HTMLGrammar(Grammar):
rules = [
# TODO: how does cdata work again?
RegionRule(r'comment', r'<!--', Grammar, r'-->'),
2008-04-02 19:50:18 -04:00
# BUG: not all scripts are javascript and not all styles are CSS
# but, dynamically choosing a grammar based on the 'type' attribute
# (which may be on a different line) is impractical.
2007-07-21 11:40:53 -04:00
RegionRule(r'script', r'<(?=script[^a-zA-Z0-9_])', TagGrammar, r'>', JavascriptGrammar, r'</(?=script>)', TagGrammar, r'>'),
2008-04-02 19:50:18 -04:00
RegionRule(r'style', r'<(?=style[^a-zA-Z0-9_])', TagGrammar, r'>', CSSGrammar, r'</(?=style>)', TagGrammar, r'>'),
2007-07-21 11:40:53 -04:00
RegionRule(r'tag', r'</?', TagGrammar, r'/?>'),
]
2007-10-21 20:55:29 -04:00
class HTML(mode.Fundamental):
2007-10-18 17:07:35 -04:00
modename = 'HTML'
extensions = ['.html', '.htm', '.shtml', '.shtm', '.xhtml']
grammar = HTMLGrammar
2008-04-02 19:50:18 -04:00
colors = {}
2007-07-21 11:40:53 -04:00
def __init__(self, w):
2007-10-21 20:55:29 -04:00
mode.Fundamental.__init__(self, w)
2007-07-21 11:40:53 -04:00
self.add_bindings('close-paren', (')',))
self.add_bindings('close-brace', ('}',))
self.add_bindings('close-bracket', (']',))
2007-10-19 02:41:33 -04:00
2008-04-02 19:50:18 -04:00
_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]
2007-10-19 02:41:33 -04:00
install = HTML.install