PageRenderTime 10ms CodeModel.GetById 2ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

/hyde/ext/plugins/blockdown.py

http://github.com/hyde/hyde
Python | 45 lines | 15 code | 6 blank | 24 comment | 0 complexity | 0d4d2375db91b1f06f27d6ffb3f37435 MD5 | raw file
 1# -*- coding: utf-8 -*-
 2"""
 3Blockdown plugin
 4"""
 5
 6from hyde.plugin import TextyPlugin
 7
 8class BlockdownPlugin(TextyPlugin):
 9    """
10    The plugin class for block text replacement.
11    """
12    def __init__(self, site):
13        super(BlockdownPlugin, self).__init__(site)
14
15    @property
16    def tag_name(self):
17        """
18        The block tag.
19        """
20        return 'block'
21
22    @property
23    def default_open_pattern(self):
24        """
25        The default pattern for block open text.
26        """
27        return '^\s*===+([A-Za-z0-9_\-\.]+)=*\s*$'
28
29    @property
30    def default_close_pattern(self):
31        """
32        The default pattern for block close text.
33        """
34        return '^\s*===+/+\s*=*/*([A-Za-z0-9_\-\.]*)[\s=/]*$'
35
36    def text_to_tag(self, match, start=True):
37        """
38        Replace open pattern (default:===[====]blockname[===========])
39        with
40        {% block blockname %} or equivalent and
41        Replace close pattern (default===[====]/[blockname][===========])
42        with
43        {% endblock blockname %} or equivalent
44        """
45        return super(BlockdownPlugin, self).text_to_tag(match, start)