Rafał Pitoń 11 лет назад
Родитель
Сommit
f3153b241a

+ 3 - 0
misago/markup/__init__.py

@@ -0,0 +1,3 @@
+from misago.markup.flavours import (common as common_flavour,
+                                    limited as limited_flavour)  # noqa
+from misago.markup.parser import parse  # noqa

+ 4 - 4
misago/markup/flavours.py

@@ -1,4 +1,4 @@
-from misago.markup.parser import parse_text
+from misago.markup.parser import parse
 
 
 def common(text, author=None, allow_mentions=True):
@@ -12,7 +12,7 @@ def common(text, author=None, allow_mentions=True):
 
     Returns dict object
     """
-    return parse_text(text, author=author, allow_mentions=allow_mentions)
+    return parse(text, author=author, allow_mentions=allow_mentions)
 
 
 def limited(text):
@@ -24,7 +24,7 @@ def limited(text):
 
     Returns parsed text
     """
-    result =  parse_text(text, allow_mentions=False, allow_links=True,
-                         allow_images=False, allow_blocks=False)
+    result =  parse(text, allow_mentions=False, allow_links=True,
+                    allow_images=False, allow_blocks=False)
 
     return result['parsed_text']

+ 3 - 34
misago/markup/parser.py

@@ -1,16 +1,12 @@
-from importlib import import_module
-
-from bs4 import BeautifulSoup
-from django.conf import settings
 import markdown
-
 from misago.markup.bbcode import inline, blocks
+from misago.markup.pipeline import pipeline
 
 
-__all__ = ['parse_text']
+__all__ = ['parse']
 
 
-def parse_text(text, author=None, allow_mentions=True, allow_links=True,
+def parse(text, author=None, allow_mentions=True, allow_links=True,
                allow_images=True, allow_blocks=True):
     """
     Message parser
@@ -96,30 +92,3 @@ def md_factory(author=None, allow_mentions=True, allow_links=True,
         del md.parser.blockprocessors['ulist']
 
     return pipeline.extend_markdown(md)
-
-
-class MarkupPipeline(object):
-    """
-    Small framework for extending parser
-    """
-    def extend_markdown(self, md):
-        for extension in settings.MISAGO_MARKUP_EXTENSIONS:
-            module = import_module(extension)
-            if hasattr(module, 'extend_markdown'):
-                hook = getattr(module, 'extend_markdown')
-                hook.extend_markdown(md)
-        return md
-
-    def process_result(self, result):
-        soup = BeautifulSoup(result['parsed_text'])
-        for extension in settings.MISAGO_MARKUP_EXTENSIONS:
-            module = import_module(extension)
-            if hasattr(module, 'clean_parsed'):
-                hook = getattr(module, 'clean_parsed')
-                hook.process_result(result, soup)
-
-        souped_text = unicode(soup.body).strip()[6:-7]
-        result['parsed_text'] = souped_text
-        return result
-
-pipeline = MarkupPipeline()

+ 31 - 0
misago/markup/pipeline.py

@@ -0,0 +1,31 @@
+from importlib import import_module
+
+from bs4 import BeautifulSoup
+from django.conf import settings
+
+
+class MarkupPipeline(object):
+    """
+    Small framework for extending parser
+    """
+    def extend_markdown(self, md):
+        for extension in settings.MISAGO_MARKUP_EXTENSIONS:
+            module = import_module(extension)
+            if hasattr(module, 'extend_markdown'):
+                hook = getattr(module, 'extend_markdown')
+                hook.extend_markdown(md)
+        return md
+
+    def process_result(self, result):
+        soup = BeautifulSoup(result['parsed_text'])
+        for extension in settings.MISAGO_MARKUP_EXTENSIONS:
+            module = import_module(extension)
+            if hasattr(module, 'clean_parsed'):
+                hook = getattr(module, 'clean_parsed')
+                hook.process_result(result, soup)
+
+        souped_text = unicode(soup.body).strip()[6:-7]
+        result['parsed_text'] = souped_text
+        return result
+
+pipeline = MarkupPipeline()

+ 3 - 3
misago/markup/tests.py

@@ -1,5 +1,5 @@
 from django.test import TestCase
-from misago.markup.parser import parse_text
+from misago.markup.parser import parse
 
 
 class ParserTests(TestCase):
@@ -34,7 +34,7 @@ Lorem [b]ipsum[/B].
 <p>Lorem <b>ipsum</b>.</p>
 """.strip()
 
-        result = parse_text(test_text)
+        result = parse(test_text)
         self.assertEqual(expected_result, result['parsed_text'])
 
     def test_blocks(self):
@@ -51,5 +51,5 @@ Dolor met.
 <p>Dolor met.</p>
 """.strip()
 
-        result = parse_text(test_text)
+        result = parse(test_text)
         self.assertEqual(expected_result, result['parsed_text'])