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

/hyde/ext/plugins/markings.py

http://github.com/hyde/hyde
Python | 85 lines | 34 code | 12 blank | 39 comment | 0 complexity | 51442150e5f8e5a2da2a7e6f4d712f98 MD5 | raw file
 1# -*- coding: utf-8 -*-
 2"""
 3Markings plugin
 4"""
 5
 6from hyde.plugin import TextyPlugin
 7
 8class MarkingsPlugin(TextyPlugin):
 9    """
10    The plugin class for mark text replacement.
11    """
12    def __init__(self, site):
13        super(MarkingsPlugin, self).__init__(site)
14
15    @property
16    def tag_name(self):
17        """
18        The mark tag.
19        """
20        return 'mark'
21
22    @property
23    def default_open_pattern(self):
24        """
25        The default pattern for mark open text.
26        """
27        return u'^§§+\s*([A-Za-z0-9_\-]+)\s*$'
28
29    @property
30    def default_close_pattern(self):
31        """
32        The default pattern for mark close text.
33        """
34        return u'^§§+\s*/([A-Za-z0-9_\-]*)\s*$'
35
36    def text_to_tag(self, match, start=True):
37        """
38        Replace open pattern (default:§§ CSS)
39        with
40        {% mark CSS %} or equivalent and
41        Replace close pattern (default: §§ /CSS)
42        with
43        {% endmark %} or equivalent
44        """
45        return super(MarkingsPlugin, self).text_to_tag(match, start)
46
47
48class ReferencePlugin(TextyPlugin):
49    """
50    The plugin class for reference text replacement.
51    """
52    def __init__(self, site):
53        super(ReferencePlugin, self).__init__(site)
54
55    @property
56    def tag_name(self):
57        """
58        The refer tag.
59        """
60        return 'refer to'
61
62    @property
63    def default_open_pattern(self):
64        """
65        The default pattern for mark open text.
66        """
67        return u'^?\s*([^\s]+)\s*as\s*([A-Za-z0-9_\-]+)\s*$'
68
69    @property
70    def default_close_pattern(self):
71        """
72        No close pattern.
73        """
74        return None
75
76    def text_to_tag(self, match, start=True):
77        """
78        Replace open pattern (default: ? inc.md as inc)
79        with
80        {% refer to "inc.md" as inc %} or equivalent.
81        """
82        if not match.lastindex:
83            return ''
84        params = '"%s" as %s' % (match.groups(1)[0], match.groups(1)[1])
85        return self.template.get_open_tag(self.tag_name, params)