2007-10-23 16:27:50 -04:00
|
|
|
import color, method, mode
|
2008-10-15 22:49:28 -04:00
|
|
|
from lex import Grammar, PatternRule, RegionRule, PatternGroupRule, OverrideRegionRule
|
2009-03-14 19:53:44 -04:00
|
|
|
from method import Method
|
2007-10-23 16:27:50 -04:00
|
|
|
from mode.text import TextInsertSpace
|
2008-10-15 22:49:28 -04:00
|
|
|
from mode.python import PythonGrammar
|
2007-07-23 15:28:27 -04:00
|
|
|
|
2007-07-23 15:52:53 -04:00
|
|
|
class RSTString(Grammar):
|
|
|
|
rules = [
|
|
|
|
PatternRule('escaped', r'\\.'),
|
|
|
|
]
|
|
|
|
|
2007-07-23 15:28:27 -04:00
|
|
|
class RSTGrammar(Grammar):
|
|
|
|
rules = [
|
2008-10-15 22:49:28 -04:00
|
|
|
PatternRule(r'escape', r'\\.'),
|
2007-07-23 15:52:53 -04:00
|
|
|
|
2008-11-12 10:17:39 -05:00
|
|
|
PatternRule(r'bullet', r'^ *[-*+](?=$| )'),
|
|
|
|
PatternRule(r'enumeration', r'^ *(?:[0-9]+|#)\.(?=$| )'),
|
2008-11-12 10:16:26 -05:00
|
|
|
|
2007-07-23 15:52:53 -04:00
|
|
|
RegionRule(r'strong_emphasis', r'\*\*', RSTString, r'\*\*'),
|
2008-10-15 22:49:28 -04:00
|
|
|
RegionRule(r'emphasis', r'\*', RSTString, r'\*'),
|
2007-07-23 15:52:53 -04:00
|
|
|
RegionRule(r'inline_literal', r'``', RSTString, r'``'),
|
2008-10-15 22:49:28 -04:00
|
|
|
RegionRule(r'interpreted', r'`', RSTString, r'`_?'),
|
2007-07-23 15:52:53 -04:00
|
|
|
|
|
|
|
PatternRule(r'anonymous', r'[a-zA-Z]+__'),
|
|
|
|
PatternRule(r'reference', r'[a-zA-Z]+_'),
|
2008-10-15 22:49:28 -04:00
|
|
|
RegionRule(r'inline_internal', r'_`', RSTString, r'`'),
|
|
|
|
|
|
|
|
RegionRule(r'substitution', r'\|(?! )', RSTString, r'\|'),
|
2007-07-23 15:52:53 -04:00
|
|
|
PatternRule(r'footnote', r'\[[0-9]+\]_'),
|
|
|
|
PatternRule(r'citation', r'\[.+?\]_'),
|
2008-03-16 01:23:14 -04:00
|
|
|
PatternRule(r'rst_url', r'http://[^ ]+'),
|
2007-07-23 15:52:53 -04:00
|
|
|
|
2008-10-15 22:49:28 -04:00
|
|
|
PatternRule(r'title', r'^={3,}\n$'),
|
|
|
|
PatternRule(r'subtitle', r'^-{3,}\n$'),
|
|
|
|
|
|
|
|
PatternRule(r'option', r'^(?:--|-|/)[a-zA-Z]+(?:[ =][-a-zA-Z_]+)?'),
|
|
|
|
RegionRule(r'table', r'\+-+(\+-+)*\+\n$', Grammar, r'^\n$'),
|
|
|
|
|
|
|
|
PatternRule(r'field', r'^:.+?:'),
|
|
|
|
|
|
|
|
PatternRule(r'lineblock', r'^\|'),
|
|
|
|
RegionRule(r'blocktest', r'>>>', PythonGrammar, '^\n'),
|
|
|
|
OverrideRegionRule(r'code', r'^\.\. code-block:: +(?P<grammar>.+)\n$', None, r'^[^\n ]'),
|
2008-11-12 11:18:05 -05:00
|
|
|
RegionRule(r'literal_block', r'::\n$', Grammar, r'^(?=[^\n ])'),
|
2007-07-23 15:28:27 -04:00
|
|
|
]
|
|
|
|
|
2008-04-18 23:32:08 -04:00
|
|
|
class RstWrapParagraph(method.WrapParagraph):
|
|
|
|
limit = 75
|
2008-11-10 14:58:12 -05:00
|
|
|
class RstInsertSpace(TextInsertSpace):
|
|
|
|
limit = 75
|
|
|
|
wrapper = RstWrapParagraph
|
2008-04-18 23:32:08 -04:00
|
|
|
|
2009-03-14 19:53:44 -04:00
|
|
|
class RstBuild(Method):
|
|
|
|
pass
|
|
|
|
|
2007-10-21 20:55:29 -04:00
|
|
|
class RST(mode.Fundamental):
|
2007-10-18 17:07:35 -04:00
|
|
|
modename = 'RST'
|
|
|
|
extensions = ['.rst']
|
|
|
|
grammar = RSTGrammar
|
|
|
|
colors = {
|
2008-11-12 11:18:05 -05:00
|
|
|
'title': ('blue', 'default', 'bold'),
|
|
|
|
'subtitle': ('blue', 'default'),
|
|
|
|
'field': ('green', 'default', 'bold'),
|
|
|
|
'option': ('green', 'default', 'bold'),
|
2008-05-03 13:31:30 -04:00
|
|
|
'anonymous': ('blue', 'default', 'bold'),
|
|
|
|
'reference': ('blue', 'default', 'bold'),
|
|
|
|
'footnote': ('blue', 'default', 'bold'),
|
|
|
|
'citation': ('blue', 'default', 'bold'),
|
|
|
|
'rst_url': ('blue', 'default', 'bold'),
|
2007-07-23 15:52:53 -04:00
|
|
|
|
2008-10-15 22:49:28 -04:00
|
|
|
'table.start': ('cyan', 'default'),
|
|
|
|
'table.null': ('cyan', 'default'),
|
|
|
|
|
2008-05-03 13:31:30 -04:00
|
|
|
'bullet': ('magenta', 'default', 'bold'),
|
|
|
|
'enumeration': ('magenta', 'default', 'bold'),
|
2008-10-15 22:49:28 -04:00
|
|
|
|
|
|
|
'lineblock': ('cyan', 'default', 'bold'),
|
|
|
|
'blocktest.start': ('cyan', 'default', 'bold'),
|
|
|
|
|
|
|
|
'emphasis.start': ('red', 'default'),
|
|
|
|
'emphasis.null': ('red', 'default'),
|
|
|
|
'emphasis.end': ('red', 'default'),
|
|
|
|
'strong_emphasis.start': ('red', 'default', 'bold'),
|
|
|
|
'strong_emphasis.null': ('red', 'default', 'bold'),
|
|
|
|
'strong_emphasis.end': ('red', 'default', 'bold'),
|
|
|
|
'interpreted.start': ('magenta', 'default'),
|
|
|
|
'interpreted.null': ('magenta', 'default'),
|
|
|
|
'interpreted.end': ('magenta', 'default'),
|
|
|
|
'inline_literal.start': ('magenta', 'default', 'bold'),
|
|
|
|
'inline_literal.null': ('magenta', 'default', 'bold'),
|
|
|
|
'inline_literal.end': ('magenta', 'default', 'bold'),
|
|
|
|
'inline_internal.start': ('yellow', 'default'),
|
|
|
|
'inline_internal.null': ('yellow', 'default'),
|
|
|
|
'inline_internal.end': ('magenta', 'default'),
|
|
|
|
'substitution.start': ('cyan', 'default', 'bold'),
|
|
|
|
'substitution.null': ('cyan', 'default', 'bold'),
|
|
|
|
'substitution.end': ('cyan', 'default', 'bold'),
|
|
|
|
|
|
|
|
'code.start': ('yellow', 'default', 'bold'),
|
|
|
|
'literal_block.start': ('yellow', 'default', 'bold'),
|
|
|
|
'literal_block.null': ('green', 'default', 'bold'),
|
|
|
|
|
|
|
|
|
2007-07-23 15:28:27 -04:00
|
|
|
}
|
2008-04-18 23:32:08 -04:00
|
|
|
actions = [RstInsertSpace, RstWrapParagraph]
|
2008-11-10 14:58:12 -05:00
|
|
|
config = {
|
|
|
|
'rst.margin': 75,
|
|
|
|
}
|
2009-02-15 12:06:35 -05:00
|
|
|
_bindings = {
|
|
|
|
'rst-insert-space': ('SPACE',),
|
|
|
|
'rst-wrap-paragraph': ('M-q',),
|
|
|
|
}
|
2007-10-19 02:41:33 -04:00
|
|
|
|
|
|
|
install = RST.install
|