2012-08-05 09:25:31 -04:00
|
|
|
from lex import Grammar, PatternRule, RegionRule, OverrideRegionRule, PatternMatchRule
|
2012-08-04 12:51:17 -04:00
|
|
|
from mode import Fundamental
|
|
|
|
from method import Method, WrapParagraph
|
|
|
|
from mode.text import TextInsertSpace
|
2012-08-05 09:25:31 -04:00
|
|
|
|
|
|
|
from mode.c import CGrammar
|
|
|
|
from mode.html import HTMLGrammar
|
|
|
|
from mode.java import JavaGrammar
|
|
|
|
from mode.javascript import JavascriptGrammar
|
2012-08-04 12:51:17 -04:00
|
|
|
from mode.python import PythonGrammar
|
2012-08-05 09:25:31 -04:00
|
|
|
from mode.scala import ScalaGrammar
|
|
|
|
from mode.sql import SqlGrammar
|
|
|
|
from mode.xml import XMLGrammar
|
|
|
|
|
2012-08-09 00:29:35 -04:00
|
|
|
class LineGrammar(Grammar): pass
|
|
|
|
LineGrammar.rules = [
|
|
|
|
PatternRule('line', r'.+'),
|
|
|
|
PatternRule('eol', r'\n'),
|
|
|
|
]
|
2012-08-04 12:51:17 -04:00
|
|
|
|
2013-01-14 00:14:30 -05:00
|
|
|
class WordGrammar(Grammar): pass
|
|
|
|
WordGrammar.rules = [
|
|
|
|
PatternRule('word', r'[A-Za-z0-9_]+'),
|
|
|
|
]
|
|
|
|
|
2012-08-09 00:29:35 -04:00
|
|
|
class MarkdownGrammar(Grammar): pass
|
2012-08-05 09:25:31 -04:00
|
|
|
MarkdownGrammar.rules = [
|
2012-08-09 00:29:35 -04:00
|
|
|
PatternRule('md.head1', r'^#.+'),
|
|
|
|
PatternRule('md.head2', r'^##.+'),
|
|
|
|
PatternRule('md.head3', r'^###.+'),
|
|
|
|
PatternRule('md.head4', r'^####.+'),
|
|
|
|
PatternRule('md.head5', r'^#####.+'),
|
|
|
|
PatternRule('md.head6', r'^######.+'),
|
|
|
|
|
|
|
|
RegionRule('md.tag', r'^<(?P<tag>[a-zA-Z_][a-zA-Z0-9_]*)>$', HTMLGrammar, r'^</%(tag)s>$'),
|
2012-08-04 12:51:17 -04:00
|
|
|
|
2012-08-09 00:29:35 -04:00
|
|
|
PatternRule('md.bullet', r'^\s*[\*\-\*] '),
|
2012-08-04 12:51:17 -04:00
|
|
|
|
2012-08-05 09:25:31 -04:00
|
|
|
PatternMatchRule('', r'(\[.+?\])(\(.+?\))', 'md.linkname', 'md.linkurl'),
|
2012-08-04 12:51:17 -04:00
|
|
|
|
2012-08-09 00:29:35 -04:00
|
|
|
PatternRule('md.block3', r'^(?:>\s*>\s*>\s*)*>\s*>\s*>(?:[^>].*)?\n$'),
|
|
|
|
PatternRule('md.block2', r'^(?:>\s*>\s*>\s*)*>\s*>(?:[^>].*)?\n$'),
|
|
|
|
PatternRule('md.block1', r'^(?:>\s*>\s*>\s*)*>(?:[^>].*)?\n$'),
|
|
|
|
|
2012-08-05 09:25:31 -04:00
|
|
|
PatternRule('md.code', r'^(?: |\t).*$'),
|
2012-08-04 12:51:17 -04:00
|
|
|
|
2012-08-05 09:25:31 -04:00
|
|
|
PatternRule('md.inlinelink', r'http://[^`*\t(){}\[\] ]+'),
|
2012-08-04 12:51:17 -04:00
|
|
|
|
2012-08-05 09:25:31 -04:00
|
|
|
RegionRule('md.lang', r'^```c$', CGrammar, r'^```'),
|
|
|
|
RegionRule('md.lang', r'^```html$', HTMLGrammar, r'^```'),
|
|
|
|
RegionRule('md.lang', r'^```(?:javascript|js)$', JavascriptGrammar, r'^```'),
|
|
|
|
RegionRule('md.lang', r'^```java$', JavaGrammar, r'^```'),
|
|
|
|
RegionRule('md.lang', r'^```python$', PythonGrammar, r'^```'),
|
|
|
|
RegionRule('md.lang', r'^```scala$', ScalaGrammar, r'^```'),
|
|
|
|
RegionRule('md.lang', r'^```sql$', SqlGrammar, r'^```'),
|
|
|
|
RegionRule('md.lang', r'^```xml$', XMLGrammar, r'^```'),
|
2012-08-04 12:51:17 -04:00
|
|
|
|
2012-08-09 00:29:35 -04:00
|
|
|
RegionRule('md.code', r'^```.+$', LineGrammar, r'^```'),
|
2012-08-04 12:51:17 -04:00
|
|
|
|
2014-03-13 17:20:52 -04:00
|
|
|
PatternRule('md.escaped', r'\$[^$]+\$'),
|
|
|
|
|
2012-08-05 09:25:31 -04:00
|
|
|
RegionRule('md.bold', r'\*\*', MarkdownGrammar, r'\*\*'),
|
|
|
|
RegionRule('md.tt', r'``', MarkdownGrammar, r'``'),
|
2012-08-04 12:51:17 -04:00
|
|
|
|
2012-08-05 09:25:31 -04:00
|
|
|
RegionRule('md.bold', r'\*', MarkdownGrammar, r'\*'),
|
2013-01-14 00:14:30 -05:00
|
|
|
RegionRule('md.tt', r'`', WordGrammar, r'`'),
|
2012-08-04 12:51:17 -04:00
|
|
|
|
2012-12-05 14:33:51 -05:00
|
|
|
PatternRule('md.escaped', r'\\.'),
|
2012-08-05 09:25:31 -04:00
|
|
|
PatternRule('md.word', r'[a-zA-Z\'"\-]+'),
|
2012-08-04 12:51:17 -04:00
|
|
|
|
2012-08-09 00:29:35 -04:00
|
|
|
PatternRule('spaces', '\s+'),
|
|
|
|
PatternRule('eol', r'\n'),
|
|
|
|
#PatternRule('null', r'.'),
|
2012-08-05 09:25:31 -04:00
|
|
|
]
|
2012-08-04 12:51:17 -04:00
|
|
|
|
|
|
|
|
|
|
|
class MdWrapParagraph(WrapParagraph):
|
2014-03-13 17:20:52 -04:00
|
|
|
limit = 72
|
2012-08-04 12:51:17 -04:00
|
|
|
class MdInsertSpace(TextInsertSpace):
|
2014-03-13 17:20:52 -04:00
|
|
|
limit = 72
|
2012-08-04 12:51:17 -04:00
|
|
|
wrapper = MdWrapParagraph
|
|
|
|
|
2012-08-05 09:25:31 -04:00
|
|
|
# white is for delimiters, operators, numbers
|
|
|
|
default = ('default', 'default')
|
|
|
|
|
|
|
|
# magenta is for keywords/builtins
|
|
|
|
lo_magenta = ('magenta202', 'default')
|
|
|
|
hi_magenta = ('magenta414', 'default')
|
|
|
|
|
|
|
|
# red is for comments
|
|
|
|
lo_red = ('red300', 'default')
|
|
|
|
hi_red = ('red511', 'default')
|
|
|
|
|
|
|
|
# orange is for macro definitions, headers and constants
|
|
|
|
hi_orange = ('yellow531', 'default')
|
|
|
|
lo_orange = ('yellow520', 'default')
|
|
|
|
|
|
|
|
# yellow is for parts of macros
|
|
|
|
hi_yellow = ('yellow551', 'default')
|
|
|
|
lo_yellow = ('yellow330', 'default')
|
|
|
|
|
|
|
|
# green is for strings and characters
|
|
|
|
lo_green = ('green030', 'default')
|
|
|
|
hi_green = ('green050', 'default')
|
|
|
|
|
|
|
|
# cyan is for types
|
|
|
|
lo_cyan = ('cyan033', 'default')
|
|
|
|
hi_cyan = ('cyan155', 'default')
|
|
|
|
|
|
|
|
# blue is definitions, functions and some macros
|
|
|
|
lo_blue = ('blue113', 'default')
|
|
|
|
hi_blue = ('blue225', 'default')
|
|
|
|
|
2012-08-04 12:51:17 -04:00
|
|
|
class Markdown(Fundamental):
|
|
|
|
name = 'Markdown'
|
|
|
|
extensions = ['.md', ".markdown"]
|
|
|
|
grammar = MarkdownGrammar
|
|
|
|
colors = {
|
2012-08-05 09:25:31 -04:00
|
|
|
'md.head1': hi_blue,
|
|
|
|
'md.head2': hi_blue,
|
|
|
|
'md.head3': hi_blue,
|
|
|
|
'md.head4': hi_blue,
|
|
|
|
'md.head5': hi_blue,
|
|
|
|
'md.head6': hi_blue,
|
|
|
|
|
2012-08-09 00:29:35 -04:00
|
|
|
'md.tag.start': hi_magenta,
|
|
|
|
'md.tag.end': hi_magenta,
|
|
|
|
|
2012-08-05 09:25:31 -04:00
|
|
|
'md.linkname': hi_green,
|
|
|
|
'md.linkurl': hi_cyan,
|
|
|
|
|
2012-08-09 00:29:35 -04:00
|
|
|
'md.block1': hi_yellow,
|
|
|
|
'md.block2': hi_orange,
|
|
|
|
'md.block3': hi_red,
|
|
|
|
|
2012-08-05 09:25:31 -04:00
|
|
|
'md.code': lo_green,
|
|
|
|
'md.code.start': lo_green,
|
|
|
|
'md.code.null': lo_green,
|
|
|
|
'md.code.end': lo_green,
|
|
|
|
|
|
|
|
'md.lang': lo_green,
|
|
|
|
'md.lang.start': lo_green,
|
|
|
|
'md.lang.end': lo_green,
|
|
|
|
|
|
|
|
'md.bullet': lo_magenta,
|
|
|
|
|
|
|
|
'md.inlinelink': hi_red,
|
|
|
|
|
|
|
|
'md.bold.start': hi_orange,
|
|
|
|
'md.bold.null': hi_orange,
|
|
|
|
'md.bold.md.word': hi_orange,
|
|
|
|
'md.bold.end': hi_orange,
|
|
|
|
|
|
|
|
'md.tt.start': lo_orange,
|
2013-01-14 00:14:30 -05:00
|
|
|
'md.tt.word': lo_orange,
|
2012-08-05 09:25:31 -04:00
|
|
|
'md.tt.null': lo_orange,
|
|
|
|
'md.tt.md.word': lo_orange,
|
|
|
|
'md.tt.end': lo_orange,
|
2012-08-04 12:51:17 -04:00
|
|
|
}
|
|
|
|
actions = [MdInsertSpace, MdWrapParagraph]
|
|
|
|
config = {
|
2014-03-13 17:20:52 -04:00
|
|
|
'markdown.margin': 72,
|
2012-08-04 12:51:17 -04:00
|
|
|
}
|
|
|
|
_bindings = {
|
|
|
|
'md-insert-space': ('SPACE',),
|
|
|
|
'md-wrap-paragraph': ('M-q',),
|
|
|
|
}
|
|
|
|
|
|
|
|
install = Markdown.install
|