parent
cbba3b1917
commit
8c8eea6328
|
@ -177,7 +177,7 @@ class Application(object):
|
|||
'haskell', 'erlang', 'iperl', 'iperlmini', 'ipython', 'ipythonmini',
|
||||
'awk', 'shell', 'shellmini', 'fstab', 'yacc', 'pipe', 'mbox',
|
||||
'error', 'lua', 'lily', 'forth', 'ebnf', 'colortest', 'go',
|
||||
'inform6', 'scala',
|
||||
'inform6', 'scala', 'markdown',
|
||||
)
|
||||
for name in names:
|
||||
exec("import mode.%s; mode.%s.install(self)" % (name, name))
|
||||
|
|
|
@ -0,0 +1,130 @@
|
|||
from lex import Grammar, PatternRule, RegionRule, OverrideRegionRule
|
||||
from mode import Fundamental
|
||||
from method import Method, WrapParagraph
|
||||
from mode.text import TextInsertSpace
|
||||
from mode.python import PythonGrammar
|
||||
|
||||
def make_string_rules(forbid):
|
||||
return [
|
||||
PatternRule('escaped', r'\\.'),
|
||||
PatternRule('data', r'[^\\' + forbid + ']+'),
|
||||
]
|
||||
|
||||
class LineGrammar(Grammar): rules = [PatternRule('data', r'^.*\n$')]
|
||||
class MarkdownString1(Grammar): rules = make_string_rules('*')
|
||||
class MarkdownString2(Grammar): rules = make_string_rules('`')
|
||||
class MarkdownString3(Grammar): rules = make_string_rules('|')
|
||||
|
||||
class MarkdownGrammar(Grammar):
|
||||
rules = [
|
||||
#PatternRule(r'escape', r'\\.'),
|
||||
|
||||
#PatternRule(r'bullet', r'^ *[-*+](?=$| )'),
|
||||
#PatternRule(r'enumeration', r'^ *(?:[0-9]+|#)\.(?=$| )'),
|
||||
|
||||
#RegionRule(r'strong_emphasis', r'\*\*', MarkdownString1, r'\*\*'),
|
||||
#RegionRule(r'emphasis', r'\*', MarkdownString1, r'\*'),
|
||||
#RegionRule(r'inline_literal', r'``', MarkdownString2, r'``'),
|
||||
#RegionRule(r'interpreted', r'`', MarkdownString2, r'`_?'),
|
||||
|
||||
#PatternRule(r'anonymous', r'[a-zA-Z]+__'),
|
||||
#PatternRule(r'reference', r'[a-zA-Z]+_(?![a-zA-Z0-9_])'),
|
||||
#RegionRule(r'inline_internal', r'_`', MarkdownString2, r'`'),
|
||||
|
||||
#RegionRule(r'substitution', r'\|(?! )', MarkdownString3, r'\|'),
|
||||
#PatternRule('substitution', r'r\|[^ ]+\|'),
|
||||
#RegionRule(r'substitution', r'\|(?! )', MarkdownString3, r'\|'),
|
||||
#PatternRule(r'footnote', r'\[[0-9]+\]_'),
|
||||
#PatternRule(r'citation', r'\[.+?\]_'),
|
||||
#PatternRule(r'md_url', r'http://[^ ]+'),
|
||||
|
||||
#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$', LineGrammar, 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 ])'),
|
||||
#RegionRule(r'literal_block', r'::\n$', LineGrammar, r'^(?=[^\n ])'),
|
||||
|
||||
PatternRule('md.word', r'[a-zA-Z]+'),
|
||||
PatternRule('spaces', ' +'),
|
||||
PatternRule('eol', ' +'),
|
||||
PatternRule('null', r'.'),
|
||||
]
|
||||
|
||||
class MdWrapParagraph(WrapParagraph):
|
||||
limit = 75
|
||||
class MdInsertSpace(TextInsertSpace):
|
||||
limit = 75
|
||||
wrapper = MdWrapParagraph
|
||||
|
||||
class Markdown(Fundamental):
|
||||
name = 'Markdown'
|
||||
extensions = ['.md', ".markdown"]
|
||||
grammar = MarkdownGrammar
|
||||
colors = {
|
||||
#'title': ('blue', 'default', 'bold'),
|
||||
#'subtitle': ('blue', 'default'),
|
||||
#'field': ('green', 'default', 'bold'),
|
||||
#'option': ('green', 'default', 'bold'),
|
||||
#'anonymous': ('blue', 'default', 'bold'),
|
||||
#'reference': ('blue', 'default', 'bold'),
|
||||
#'footnote': ('blue', 'default', 'bold'),
|
||||
#'citation': ('blue', 'default', 'bold'),
|
||||
#'md_url': ('blue', 'default', 'bold'),
|
||||
#
|
||||
#'table.start': ('cyan', 'default'),
|
||||
#'table.data': ('cyan', 'default'),
|
||||
#'table.null': ('cyan', 'default'),
|
||||
#
|
||||
#'bullet': ('magenta', 'default', 'bold'),
|
||||
#'enumeration': ('magenta', 'default', 'bold'),
|
||||
#
|
||||
#'lineblock': ('cyan', 'default', 'bold'),
|
||||
#'blocktest.start': ('cyan', 'default', 'bold'),
|
||||
#
|
||||
#'emphasis.start': ('red', 'default'),
|
||||
#'emphasis.data': ('red', 'default'),
|
||||
#'emphasis.null': ('red', 'default'),
|
||||
#'emphasis.end': ('red', 'default'),
|
||||
#'strong_emphasis.start': ('red', 'default', 'bold'),
|
||||
#'strong_emphasis.data': ('red', 'default', 'bold'),
|
||||
#'strong_emphasis.null': ('red', 'default', 'bold'),
|
||||
#'strong_emphasis.end': ('red', 'default', 'bold'),
|
||||
#'interpreted.start': ('magenta', 'default'),
|
||||
#'interpreted.data': ('magenta', 'default'),
|
||||
#'interpreted.null': ('magenta', 'default'),
|
||||
#'interpreted.end': ('magenta', 'default'),
|
||||
#'inline_literal.start': ('magenta', 'default', 'bold'),
|
||||
#'inline_literal.data': ('magenta', 'default', 'bold'),
|
||||
#'inline_literal.null': ('magenta', 'default', 'bold'),
|
||||
#'inline_literal.end': ('magenta', 'default', 'bold'),
|
||||
#'inline_internal.start': ('yellow', 'default'),
|
||||
#'inline_internal.data': ('yellow', 'default'),
|
||||
#'inline_internal.null': ('yellow', 'default'),
|
||||
#'inline_internal.end': ('magenta', 'default'),
|
||||
#'substitution.start': ('cyan', 'default', 'bold'),
|
||||
#'substitution.data': ('cyan', 'default', 'bold'),
|
||||
#'substitution.null': ('cyan', 'default', 'bold'),
|
||||
#'substitution.end': ('cyan', 'default', 'bold'),
|
||||
#
|
||||
#'code.start': ('yellow', 'default', 'bold'),
|
||||
#'literal_block.start': ('yellow', 'default'),
|
||||
#'literal_block.data': ('yellow', 'default'),
|
||||
#'literal_block.null': ('yellow', 'default'),
|
||||
}
|
||||
actions = [MdInsertSpace, MdWrapParagraph]
|
||||
config = {
|
||||
'md.margin': 75,
|
||||
}
|
||||
_bindings = {
|
||||
'md-insert-space': ('SPACE',),
|
||||
'md-wrap-paragraph': ('M-q',),
|
||||
}
|
||||
|
||||
install = Markdown.install
|
Loading…
Reference in New Issue