diff --git a/hyde/ext/plugins/blockdown.py b/hyde/ext/plugins/blockdown.py deleted file mode 100644 index 17a8cb2..0000000 --- a/hyde/ext/plugins/blockdown.py +++ /dev/null @@ -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) \ No newline at end of file diff --git a/hyde/ext/plugins/markings.py b/hyde/ext/plugins/markings.py deleted file mode 100644 index 780b00a..0000000 --- a/hyde/ext/plugins/markings.py +++ /dev/null @@ -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) \ No newline at end of file diff --git a/hyde/ext/plugins/syntext.py b/hyde/ext/plugins/syntext.py deleted file mode 100644 index f69f6c1..0000000 --- a/hyde/ext/plugins/syntext.py +++ /dev/null @@ -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) diff --git a/hyde/ext/plugins/text.py b/hyde/ext/plugins/text.py new file mode 100644 index 0000000..f5970a9 --- /dev/null +++ b/hyde/ext/plugins/text.py @@ -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 + diff --git a/hyde/ext/plugins/textlinks.py b/hyde/ext/plugins/textlinks.py deleted file mode 100644 index 2555a74..0000000 --- a/hyde/ext/plugins/textlinks.py +++ /dev/null @@ -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 \ No newline at end of file diff --git a/hyde/tests/ext/test_auto_extend.py b/hyde/tests/ext/test_auto_extend.py index 431bf43..1d63400 100644 --- a/hyde/tests/ext/test_auto_extend.py +++ b/hyde/tests/ext/test_auto_extend.py @@ -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) \ No newline at end of file + self.assert_extended(s, txt, templ) diff --git a/hyde/tests/ext/test_blockdown.py b/hyde/tests/ext/test_blockdown.py index 7957bce..58ed17b 100644 --- a/hyde/tests/ext/test_blockdown.py +++ b/hyde/tests/ext/test_blockdown.py @@ -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() \ No newline at end of file + assert q('title').text().strip() == txt.strip() diff --git a/hyde/tests/ext/test_markings.py b/hyde/tests/ext/test_markings.py index b9be045..17d36e6 100644 --- a/hyde/tests/ext/test_markings.py +++ b/hyde/tests/ext/test_markings.py @@ -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) \ No newline at end of file + assert_valid_conversion(html) diff --git a/hyde/tests/ext/test_syntext.py b/hyde/tests/ext/test_syntext.py index 23a0d24..67e7064 100644 --- a/hyde/tests/ext/test_syntext.py +++ b/hyde/tests/ext/test_syntext.py @@ -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 \ No newline at end of file + assert q('figure.code').length == 1 diff --git a/hyde/tests/ext/test_textlinks.py b/hyde/tests/ext/test_textlinks.py index 4cf16d2..d50b7a1 100644 --- a/hyde/tests/ext/test_textlinks.py +++ b/hyde/tests/ext/test_textlinks.py @@ -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 \ No newline at end of file + assert '/media/img/hyde-logo.png' in html diff --git a/hyde/tests/sites/test_sorter/site.yaml b/hyde/tests/sites/test_sorter/site.yaml index b95445d..c037f33 100644 --- a/hyde/tests/sites/test_sorter/site.yaml +++ b/hyde/tests/sites/test_sorter/site.yaml @@ -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 diff --git a/hyde/tests/sites/test_tagger/site.yaml b/hyde/tests/sites/test_tagger/site.yaml index a2c21c7..9b7ee78 100644 --- a/hyde/tests/sites/test_tagger/site.yaml +++ b/hyde/tests/sites/test_tagger/site.yaml @@ -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 \ No newline at end of file + extension: html diff --git a/hyde/tests/ssp/site.yaml b/hyde/tests/ssp/site.yaml index 0d40562..1416503 100644 --- a/hyde/tests/ssp/site.yaml +++ b/hyde/tests/ssp/site.yaml @@ -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 \ No newline at end of file + archive_extension: html