* blockdown * markings * syntext * textlinksmain
| @@ -1,45 +0,0 @@ | |||
| # -*- coding: utf-8 -*- | |||
| """ | |||
| Blockdown plugin | |||
| """ | |||
| from hyde.plugin import TextyPlugin | |||
| class BlockdownPlugin(TextyPlugin): | |||
| """ | |||
| The plugin class for block text replacement. | |||
| """ | |||
| def __init__(self, site): | |||
| super(BlockdownPlugin, self).__init__(site) | |||
| @property | |||
| def tag_name(self): | |||
| """ | |||
| The block tag. | |||
| """ | |||
| return 'block' | |||
| @property | |||
| def default_open_pattern(self): | |||
| """ | |||
| The default pattern for block open text. | |||
| """ | |||
| return '^\s*===+([A-Za-z0-9_\-\.]+)=*\s*$' | |||
| @property | |||
| def default_close_pattern(self): | |||
| """ | |||
| The default pattern for block close text. | |||
| """ | |||
| return '^\s*===+/+\s*=*/*([A-Za-z0-9_\-\.]*)[\s=/]*$' | |||
| def text_to_tag(self, match, start=True): | |||
| """ | |||
| Replace open pattern (default:===[====]blockname[===========]) | |||
| with | |||
| {% block blockname %} or equivalent and | |||
| Replace close pattern (default===[====]/[blockname][===========]) | |||
| with | |||
| {% endblock blockname %} or equivalent | |||
| """ | |||
| return super(BlockdownPlugin, self).text_to_tag(match, start) | |||
| @@ -1,85 +0,0 @@ | |||
| # -*- coding: utf-8 -*- | |||
| """ | |||
| Markings plugin | |||
| """ | |||
| from hyde.plugin import TextyPlugin | |||
| class MarkingsPlugin(TextyPlugin): | |||
| """ | |||
| The plugin class for mark text replacement. | |||
| """ | |||
| def __init__(self, site): | |||
| super(MarkingsPlugin, self).__init__(site) | |||
| @property | |||
| def tag_name(self): | |||
| """ | |||
| The mark tag. | |||
| """ | |||
| return 'mark' | |||
| @property | |||
| def default_open_pattern(self): | |||
| """ | |||
| The default pattern for mark open text. | |||
| """ | |||
| return u'^§§+\s*([A-Za-z0-9_\-]+)\s*$' | |||
| @property | |||
| def default_close_pattern(self): | |||
| """ | |||
| The default pattern for mark close text. | |||
| """ | |||
| return u'^§§+\s*/([A-Za-z0-9_\-]*)\s*$' | |||
| def text_to_tag(self, match, start=True): | |||
| """ | |||
| Replace open pattern (default:§§ CSS) | |||
| with | |||
| {% mark CSS %} or equivalent and | |||
| Replace close pattern (default: §§ /CSS) | |||
| with | |||
| {% endmark %} or equivalent | |||
| """ | |||
| return super(MarkingsPlugin, self).text_to_tag(match, start) | |||
| class ReferencePlugin(TextyPlugin): | |||
| """ | |||
| The plugin class for reference text replacement. | |||
| """ | |||
| def __init__(self, site): | |||
| super(ReferencePlugin, self).__init__(site) | |||
| @property | |||
| def tag_name(self): | |||
| """ | |||
| The refer tag. | |||
| """ | |||
| return 'refer to' | |||
| @property | |||
| def default_open_pattern(self): | |||
| """ | |||
| The default pattern for mark open text. | |||
| """ | |||
| return u'^※\s*([^\s]+)\s*as\s*([A-Za-z0-9_\-]+)\s*$' | |||
| @property | |||
| def default_close_pattern(self): | |||
| """ | |||
| No close pattern. | |||
| """ | |||
| return None | |||
| def text_to_tag(self, match, start=True): | |||
| """ | |||
| Replace open pattern (default: ※ inc.md as inc) | |||
| with | |||
| {% refer to "inc.md" as inc %} or equivalent. | |||
| """ | |||
| if not match.lastindex: | |||
| return '' | |||
| params = '"%s" as %s' % (match.groups(1)[0], match.groups(1)[1]) | |||
| return self.template.get_open_tag(self.tag_name, params) | |||
| @@ -1,57 +0,0 @@ | |||
| # -*- coding: utf-8 -*- | |||
| """ | |||
| Syntext plugin | |||
| """ | |||
| from hyde.plugin import TextyPlugin | |||
| class SyntextPlugin(TextyPlugin): | |||
| """ | |||
| The plugin class for syntax text replacement. | |||
| """ | |||
| def __init__(self, site): | |||
| super(SyntextPlugin, self).__init__(site) | |||
| @property | |||
| def tag_name(self): | |||
| """ | |||
| The syntax tag. | |||
| """ | |||
| return 'syntax' | |||
| @property | |||
| def default_open_pattern(self): | |||
| """ | |||
| The default pattern for block open text. | |||
| """ | |||
| return '^\s*~~~+\s*([A-Za-z0-9_\-\.:\']+)\s*~*\s*$' | |||
| @property | |||
| def default_close_pattern(self): | |||
| """ | |||
| The default pattern for block close text. | |||
| """ | |||
| return '^\s*~~~+\s*$' | |||
| def get_params(self, match, start=True): | |||
| """ | |||
| ~~~css~~~ will return css | |||
| ~~~css/style.css will return css,style.css | |||
| """ | |||
| params = super(SyntextPlugin, self).get_params(match, start) | |||
| if ':' in params: | |||
| (lex, _, filename) = params.rpartition(':') | |||
| params = 'lex=\'%(lex)s\',filename=\'%(filename)s\'' % locals() | |||
| return params | |||
| def text_to_tag(self, match, start=True): | |||
| """ | |||
| Replace open pattern (default:~~~~~css~~~~~~) | |||
| with | |||
| {% syntax css %} or equivalent and | |||
| Replace close pattern (default: ~~~~~~) | |||
| with | |||
| {% endsyntax %} or equivalent | |||
| """ | |||
| return super(SyntextPlugin, self).text_to_tag(match, start) | |||
| @@ -0,0 +1,210 @@ | |||
| # -*- coding: utf-8 -*- | |||
| """ | |||
| Text processing plugins | |||
| """ | |||
| from hyde.plugin import Plugin,TextyPlugin | |||
| class BlockdownPlugin(TextyPlugin): | |||
| """ | |||
| The plugin class for block text replacement. | |||
| """ | |||
| def __init__(self, site): | |||
| super(BlockdownPlugin, self).__init__(site) | |||
| @property | |||
| def tag_name(self): | |||
| """ | |||
| The block tag. | |||
| """ | |||
| return 'block' | |||
| @property | |||
| def default_open_pattern(self): | |||
| """ | |||
| The default pattern for block open text. | |||
| """ | |||
| return '^\s*===+([A-Za-z0-9_\-\.]+)=*\s*$' | |||
| @property | |||
| def default_close_pattern(self): | |||
| """ | |||
| The default pattern for block close text. | |||
| """ | |||
| return '^\s*===+/+\s*=*/*([A-Za-z0-9_\-\.]*)[\s=/]*$' | |||
| def text_to_tag(self, match, start=True): | |||
| """ | |||
| Replace open pattern (default:===[====]blockname[===========]) | |||
| with | |||
| {% block blockname %} or equivalent and | |||
| Replace close pattern (default===[====]/[blockname][===========]) | |||
| with | |||
| {% endblock blockname %} or equivalent | |||
| """ | |||
| return super(BlockdownPlugin, self).text_to_tag(match, start) | |||
| class MarkingsPlugin(TextyPlugin): | |||
| """ | |||
| The plugin class for mark text replacement. | |||
| """ | |||
| def __init__(self, site): | |||
| super(MarkingsPlugin, self).__init__(site) | |||
| @property | |||
| def tag_name(self): | |||
| """ | |||
| The mark tag. | |||
| """ | |||
| return 'mark' | |||
| @property | |||
| def default_open_pattern(self): | |||
| """ | |||
| The default pattern for mark open text. | |||
| """ | |||
| return u'^§§+\s*([A-Za-z0-9_\-]+)\s*$' | |||
| @property | |||
| def default_close_pattern(self): | |||
| """ | |||
| The default pattern for mark close text. | |||
| """ | |||
| return u'^§§+\s*/([A-Za-z0-9_\-]*)\s*$' | |||
| def text_to_tag(self, match, start=True): | |||
| """ | |||
| Replace open pattern (default:§§ CSS) | |||
| with | |||
| {% mark CSS %} or equivalent and | |||
| Replace close pattern (default: §§ /CSS) | |||
| with | |||
| {% endmark %} or equivalent | |||
| """ | |||
| return super(MarkingsPlugin, self).text_to_tag(match, start) | |||
| class ReferencePlugin(TextyPlugin): | |||
| """ | |||
| The plugin class for reference text replacement. | |||
| """ | |||
| def __init__(self, site): | |||
| super(ReferencePlugin, self).__init__(site) | |||
| @property | |||
| def tag_name(self): | |||
| """ | |||
| The refer tag. | |||
| """ | |||
| return 'refer to' | |||
| @property | |||
| def default_open_pattern(self): | |||
| """ | |||
| The default pattern for mark open text. | |||
| """ | |||
| return u'^※\s*([^\s]+)\s*as\s*([A-Za-z0-9_\-]+)\s*$' | |||
| @property | |||
| def default_close_pattern(self): | |||
| """ | |||
| No close pattern. | |||
| """ | |||
| return None | |||
| def text_to_tag(self, match, start=True): | |||
| """ | |||
| Replace open pattern (default: ※ inc.md as inc) | |||
| with | |||
| {% refer to "inc.md" as inc %} or equivalent. | |||
| """ | |||
| if not match.lastindex: | |||
| return '' | |||
| params = '"%s" as %s' % (match.groups(1)[0], match.groups(1)[1]) | |||
| return self.template.get_open_tag(self.tag_name, params) | |||
| class SyntextPlugin(TextyPlugin): | |||
| """ | |||
| The plugin class for syntax text replacement. | |||
| """ | |||
| def __init__(self, site): | |||
| super(SyntextPlugin, self).__init__(site) | |||
| @property | |||
| def tag_name(self): | |||
| """ | |||
| The syntax tag. | |||
| """ | |||
| return 'syntax' | |||
| @property | |||
| def default_open_pattern(self): | |||
| """ | |||
| The default pattern for block open text. | |||
| """ | |||
| return '^\s*~~~+\s*([A-Za-z0-9_\-\.:\']+)\s*~*\s*$' | |||
| @property | |||
| def default_close_pattern(self): | |||
| """ | |||
| The default pattern for block close text. | |||
| """ | |||
| return '^\s*~~~+\s*$' | |||
| def get_params(self, match, start=True): | |||
| """ | |||
| ~~~css~~~ will return css | |||
| ~~~css/style.css will return css,style.css | |||
| """ | |||
| params = super(SyntextPlugin, self).get_params(match, start) | |||
| if ':' in params: | |||
| (lex, _, filename) = params.rpartition(':') | |||
| params = 'lex=\'%(lex)s\',filename=\'%(filename)s\'' % locals() | |||
| return params | |||
| def text_to_tag(self, match, start=True): | |||
| """ | |||
| Replace open pattern (default:~~~~~css~~~~~~) | |||
| with | |||
| {% syntax css %} or equivalent and | |||
| Replace close pattern (default: ~~~~~~) | |||
| with | |||
| {% endsyntax %} or equivalent | |||
| """ | |||
| return super(SyntextPlugin, self).text_to_tag(match, start) | |||
| import re | |||
| class TextlinksPlugin(Plugin): | |||
| """ | |||
| The plugin class for syntax text replacement. | |||
| """ | |||
| def __init__(self, site): | |||
| super(TextlinksPlugin, self).__init__(site) | |||
| def begin_text_resource(self, resource, text): | |||
| """ | |||
| Replace content url pattern [[/abc/def]]) | |||
| with | |||
| {{ content_url('/abc/def') }} or equivalent and | |||
| Replace media url pattern [[!!/abc/def]] | |||
| with | |||
| {{ media_url('/abc/def') }} or equivalent. | |||
| """ | |||
| if not resource.uses_template: | |||
| return text | |||
| content_link = re.compile('\[\[([^\]^!][^\]]*)\]\]', re.UNICODE|re.MULTILINE) | |||
| media_link = re.compile('\[\[\!\!([^\]]*)\]\]', re.UNICODE|re.MULTILINE) | |||
| def replace_content(match): | |||
| return self.template.get_content_url_statement(match.groups(1)[0]) | |||
| def replace_media(match): | |||
| return self.template.get_media_url_statement(match.groups(1)[0]) | |||
| text = content_link.sub(replace_content, text) | |||
| text = media_link.sub(replace_media, text) | |||
| return text | |||
| @@ -1,35 +0,0 @@ | |||
| # -*- coding: utf-8 -*- | |||
| """ | |||
| Textlinks plugin | |||
| """ | |||
| import re | |||
| from hyde.plugin import Plugin | |||
| class TextlinksPlugin(Plugin): | |||
| """ | |||
| The plugin class for syntax text replacement. | |||
| """ | |||
| def __init__(self, site): | |||
| super(TextlinksPlugin, self).__init__(site) | |||
| def begin_text_resource(self, resource, text): | |||
| """ | |||
| Replace content url pattern [[/abc/def]]) | |||
| with | |||
| {{ content_url('/abc/def') }} or equivalent and | |||
| Replace media url pattern [[!!/abc/def]] | |||
| with | |||
| {{ media_url('/abc/def') }} or equivalent. | |||
| """ | |||
| if not resource.uses_template: | |||
| return text | |||
| content_link = re.compile('\[\[([^\]^!][^\]]*)\]\]', re.UNICODE|re.MULTILINE) | |||
| media_link = re.compile('\[\[\!\!([^\]]*)\]\]', re.UNICODE|re.MULTILINE) | |||
| def replace_content(match): | |||
| return self.template.get_content_url_statement(match.groups(1)[0]) | |||
| def replace_media(match): | |||
| return self.template.get_media_url_statement(match.groups(1)[0]) | |||
| text = content_link.sub(replace_content, text) | |||
| text = media_link.sub(replace_media, text) | |||
| return text | |||
| @@ -43,7 +43,7 @@ class TestAutoExtend(object): | |||
| s = Site(TEST_SITE) | |||
| s.config.plugins = ['hyde.ext.plugins.meta.MetaPlugin', | |||
| 'hyde.ext.plugins.auto_extend.AutoExtendPlugin', | |||
| 'hyde.ext.plugins.blockdown.BlockdownPlugin'] | |||
| 'hyde.ext.plugins.text.BlockdownPlugin'] | |||
| txt ="This template tests to make sure blocks can be replaced with markdownish syntax." | |||
| templ = """ | |||
| --- | |||
| @@ -60,7 +60,7 @@ extends: base.html | |||
| s = Site(TEST_SITE) | |||
| s.config.plugins = ['hyde.ext.plugins.meta.MetaPlugin', | |||
| 'hyde.ext.plugins.auto_extend.AutoExtendPlugin', | |||
| 'hyde.ext.plugins.blockdown.BlockdownPlugin'] | |||
| 'hyde.ext.plugins.text.BlockdownPlugin'] | |||
| txt ="This template tests to make sure blocks can be replaced with markdownish syntax." | |||
| templ = """ | |||
| --- | |||
| @@ -69,4 +69,4 @@ default_block: title | |||
| --- | |||
| %s | |||
| """ | |||
| self.assert_extended(s, txt, templ) | |||
| self.assert_extended(s, txt, templ) | |||
| @@ -25,7 +25,7 @@ class TestBlockdown(object): | |||
| def test_can_parse_blockdown(self): | |||
| s = Site(TEST_SITE) | |||
| s.config.plugins = ['hyde.ext.plugins.blockdown.BlockdownPlugin'] | |||
| s.config.plugins = ['hyde.ext.plugins.text.BlockdownPlugin'] | |||
| txt ="This template tests to make sure blocks can be replaced with markdownish syntax." | |||
| templ = """ | |||
| {%% extends "base.html" %%} | |||
| @@ -43,4 +43,4 @@ class TestBlockdown(object): | |||
| assert target.exists | |||
| text = target.read_all() | |||
| q = PyQuery(text) | |||
| assert q('title').text().strip() == txt.strip() | |||
| assert q('title').text().strip() == txt.strip() | |||
| @@ -65,7 +65,7 @@ Hyde & Jinja | |||
| site = Site(TEST_SITE) | |||
| site.config.plugins = [ | |||
| 'hyde.ext.plugins.meta.MetaPlugin', | |||
| 'hyde.ext.plugins.markings.MarkingsPlugin'] | |||
| 'hyde.ext.plugins.text.MarkingsPlugin'] | |||
| inc = File(TEST_SITE.child('content/inc.md')) | |||
| inc.write(text) | |||
| site.load() | |||
| @@ -104,8 +104,8 @@ Hyde & Jinja | |||
| site = Site(TEST_SITE) | |||
| site.config.plugins = [ | |||
| 'hyde.ext.plugins.meta.MetaPlugin', | |||
| 'hyde.ext.plugins.markings.MarkingsPlugin', | |||
| 'hyde.ext.plugins.markings.ReferencePlugin'] | |||
| 'hyde.ext.plugins.text.MarkingsPlugin', | |||
| 'hyde.ext.plugins.text.ReferencePlugin'] | |||
| inc = File(site.content.source_folder.child('inc.md')) | |||
| inc.write(text.strip()) | |||
| src = File(site.content.source_folder.child('src.html')) | |||
| @@ -115,4 +115,4 @@ Hyde & Jinja | |||
| f = File(site.config.deploy_root_path.child(src.name)) | |||
| assert f.exists | |||
| html = f.read_all() | |||
| assert_valid_conversion(html) | |||
| assert_valid_conversion(html) | |||
| @@ -36,7 +36,7 @@ class TestSyntext(object): | |||
| site = Site(TEST_SITE) | |||
| site.config.plugins = [ | |||
| 'hyde.ext.plugins.meta.MetaPlugin', | |||
| 'hyde.ext.plugins.syntext.SyntextPlugin'] | |||
| 'hyde.ext.plugins.text.SyntextPlugin'] | |||
| syn = File(site.content.source_folder.child('syn.html')) | |||
| syn.write(text) | |||
| gen = Generator(site) | |||
| @@ -46,4 +46,4 @@ class TestSyntext(object): | |||
| html = f.read_all() | |||
| assert html | |||
| q = PyQuery(html) | |||
| assert q('figure.code').length == 1 | |||
| assert q('figure.code').length == 1 | |||
| @@ -44,7 +44,7 @@ class TestTextlinks(object): | |||
| {%% endmarkdown %%} | |||
| """ | |||
| site = Site(TEST_SITE) | |||
| site.config.plugins = ['hyde.ext.plugins.textlinks.TextlinksPlugin'] | |||
| site.config.plugins = ['hyde.ext.plugins.text.TextlinksPlugin'] | |||
| site.config.base_url = 'http://example.com/' | |||
| site.config.media_url = '/media' | |||
| tlink = File(site.content.source_folder.child('tlink.html')) | |||
| @@ -57,4 +57,4 @@ class TestTextlinks(object): | |||
| assert html | |||
| for name, path in d.items(): | |||
| assert quote(site.config.base_url + path) in html | |||
| assert '/media/img/hyde-logo.png' in html | |||
| assert '/media/img/hyde-logo.png' in html | |||
| @@ -6,7 +6,7 @@ plugins: | |||
| - hyde.ext.plugins.meta.MetaPlugin | |||
| - hyde.ext.plugins.auto_extend.AutoExtendPlugin | |||
| - hyde.ext.plugins.sorter.SorterPlugin | |||
| - hyde.ext.plugins.textlinks.TextlinksPlugin | |||
| - hyde.ext.plugins.text.TextlinksPlugin | |||
| meta: | |||
| nodemeta: meta.yaml | |||
| created: !!timestamp 2010-01-01 00:00:00 | |||
| @@ -7,7 +7,7 @@ plugins: | |||
| - hyde.ext.plugins.auto_extend.AutoExtendPlugin | |||
| - hyde.ext.plugins.sorter.SorterPlugin | |||
| - hyde.ext.plugins.tagger.TaggerPlugin | |||
| - hyde.ext.plugins.textlinks.TextlinksPlugin | |||
| - hyde.ext.plugins.text.TextlinksPlugin | |||
| meta: | |||
| nodemeta: meta.yaml | |||
| created: !!timestamp 2010-01-01 00:00:00 | |||
| @@ -27,4 +27,4 @@ tagger: | |||
| template: tagged_posts.j2 | |||
| source: blog | |||
| target: blog/tags | |||
| extension: html | |||
| extension: html | |||
| @@ -7,8 +7,8 @@ plugins: | |||
| - hyde.ext.plugins.auto_extend.AutoExtendPlugin | |||
| - hyde.ext.plugins.sorter.SorterPlugin | |||
| - hyde.ext.plugins.tagger.TaggerPlugin | |||
| - hyde.ext.plugins.syntext.SyntextPlugin | |||
| - hyde.ext.plugins.textlinks.TextlinksPlugin | |||
| - hyde.ext.plugins.text.SyntextPlugin | |||
| - hyde.ext.plugins.text.TextlinksPlugin | |||
| - ext.banner.BannerPlugin | |||
| context: | |||
| data: | |||
| @@ -57,4 +57,4 @@ tagger: | |||
| source: blog | |||
| target: blog/tags | |||
| template: tagged_posts.j2 | |||
| archive_extension: html | |||
| archive_extension: html | |||