PageRenderTime 22ms CodeModel.GetById 14ms app.highlight 4ms RepoModel.GetById 2ms app.codeStats 0ms

/hyde/ext/plugins/syntext.py

http://github.com/hyde/hyde
Python | 57 lines | 21 code | 8 blank | 28 comment | 2 complexity | 8bebdd7e8da9b5c68683efefcee92585 MD5 | raw file
 1# -*- coding: utf-8 -*-
 2"""
 3Syntext plugin
 4"""
 5
 6from hyde.plugin import TextyPlugin
 7
 8class SyntextPlugin(TextyPlugin):
 9    """
10    The plugin class for syntax text replacement.
11    """
12    def __init__(self, site):
13        super(SyntextPlugin, self).__init__(site)
14
15    @property
16    def tag_name(self):
17        """
18        The syntax tag.
19        """
20        return 'syntax'
21
22    @property
23    def default_open_pattern(self):
24        """
25        The default pattern for block open text.
26        """
27        return '^\s*~~~+\s*([A-Za-z0-9_\-\.:\']+)\s*~*\s*$'
28
29    @property
30    def default_close_pattern(self):
31        """
32        The default pattern for block close text.
33        """
34        return '^\s*~~~+\s*$'
35
36
37    def get_params(self, match, start=True):
38        """
39        ~~~css~~~ will return css
40        ~~~css/style.css will return css,style.css
41        """
42        params = super(SyntextPlugin, self).get_params(match, start)
43        if ':' in params:
44            (lex, _, filename) = params.rpartition(':')
45            params = 'lex=\'%(lex)s\',filename=\'%(filename)s\'' % locals()
46        return params
47
48    def text_to_tag(self, match, start=True):
49        """
50        Replace open pattern (default:~~~~~css~~~~~~)
51        with
52        {% syntax css %} or equivalent and
53        Replace close pattern (default: ~~~~~~)
54        with
55        {% endsyntax %} or equivalent
56        """
57        return super(SyntextPlugin, self).text_to_tag(match, start)