# Path: flask_blogging/processor.py
# class PostProcessor(object):
# 
#     _markdown_extensions = [MathJaxExtension(), MetaExtension()]
# 
#     @staticmethod
#     def create_slug(title):
#         return slugify(title)
# 
#     @staticmethod
#     def extract_images(post):
#         regex = re.compile(r'<\s*img [^>]*src="([^"]+)')
#         return regex.findall(post["rendered_text"])
# 
#     @classmethod
#     def construct_url(cls, post):
#         url = url_for("blogging.page_by_id", post_id=post["post_id"],
#                       slug=cls.create_slug(post["title"]))
#         return url
# 
#     @classmethod
#     def render_text(cls, post):
#         md = markdown.Markdown(extensions=cls.all_extensions())
#         post["rendered_text"] = md.convert(post["text"])
#         post["meta"] = md.Meta
# 
#     @classmethod
#     def is_author(cls, post, user):
#         return user.get_id() == u''+str(post['user_id'])
# 
#     @classmethod
#     def process(cls, post, render=True):
#         """
#         This method takes the post data and renders it
#         :param post:
#         :param render:
#         :return:
#         """
#         post["slug"] = cls.create_slug(post["title"])
#         post["editable"] = cls.is_author(post, current_user)
#         post["url"] = cls.construct_url(post)
#         post["priority"] = 0.8
#         if render:
#             cls.render_text(post)
#             post["meta"]["images"] = cls.extract_images(post)
# 
#     @classmethod
#     def all_extensions(cls):
#         return cls._markdown_extensions
# 
#     @classmethod
#     def set_custom_extensions(cls, extensions):
#         if type(extensions) == list:
#             cls._markdown_extensions.extend(extensions)
# 
# Path: flask_blogging/signals.py



    from builtins import object
from .processor import PostProcessor
from flask_principal import Principal, Permission, RoleNeed
from .signals import engine_initialised, post_processed, blueprint_created
from flask_fileupload import FlaskFileUpload
        from .views import create_blueprint

    def is_user_blogger(self):
        return self.blogger_permission.require().can()

    def get_posts(self, count=10, offset=0, recent=True, tag=None,
                  user_id=None, include_draft=False, render=False):
        posts = self.storage(count, offset, recent, tag, user_id,
                             include_draft)
        for post in posts:
            self.process_post(post, render=False)

    def process_post(self, post, render=True):
        """
        A high level view to create post processing.
        :param post: Dictionary representing the post
        :type post: dict
        :param render: Choice if the markdown text has to be converted or not
        :type render: bool
        :return:
        """
        post_processor = self.post_processor
        post_processor.process(post, render)
        try:
            author = self.user_callback(post["user_id"])
        except Exception:
            raise Exception("No user_loader has been installed for this "
                            "BloggingEngine. Add one with the "
                            "'BloggingEngine.user_loader' decorator.")
        if author is not None:
            post["user_name"] = self.get_user_name(author)

# Path: flask_blogging/processor.py
# class PostProcessor(object):
# 
#     _markdown_extensions = [MathJaxExtension(), MetaExtension()]
# 
#     @staticmethod
#     def create_slug(title):
#         return slugify(title)
# 
#     @staticmethod
#     def extract_images(post):
#         regex = re.compile(r'<\s*img [^>]*src="([^"]+)')
#         return regex.findall(post["rendered_text"])
# 
#     @classmethod
#     def construct_url(cls, post):
#         url = url_for("blogging.page_by_id", post_id=post["post_id"],
#                       slug=cls.create_slug(post["title"]))
#         return url
# 
#     @classmethod
#     def render_text(cls, post):
#         md = markdown.Markdown(extensions=cls.all_extensions())
#         post["rendered_text"] = md.convert(post["text"])
#         post["meta"] = md.Meta
# 
#     @classmethod
#     def is_author(cls, post, user):
#         return user.get_id() == u''+str(post['user_id'])
# 
#     @classmethod
#     def process(cls, post, render=True):
#         """
#         This method takes the post data and renders it
#         :param post:
#         :param render:
#         :return:
#         """
#         post["slug"] = cls.create_slug(post["title"])
#         post["editable"] = cls.is_author(post, current_user)
#         post["url"] = cls.construct_url(post)
#         post["priority"] = 0.8
#         if render:
#             cls.render_text(post)
#             post["meta"]["images"] = cls.extract_images(post)
# 
#     @classmethod
#     def all_extensions(cls):
#         return cls._markdown_extensions
# 
#     @classmethod
#     def set_custom_extensions(cls, extensions):
#         if type(extensions) == list:
#             cls._markdown_extensions.extend(extensions)
# 
# Path: flask_blogging/signals.py



# Path: flask_blogging/engine.py
    from builtins import object
from .processor import PostProcessor
from flask_principal import Principal, Permission, RoleNeed
from .signals import engine_initialised, post_processed, blueprint_created
from flask_fileupload import FlaskFileUpload
        from .views import create_blueprint


    def is_user_blogger(self):
        return self.blogger_permission.require().can()

    def get_posts(self, count=10, offset=0, recent=True, tag=None,
                  user_id=None, include_draft=False, render=False):
        posts = self.storage(count, offset, recent, tag, user_id,
                             include_draft)
        for post in posts:
            self.process_post(post, render=False)

    def process_post(self, post, render=True):
        """
        A high level view to create post processing.
        :param post: Dictionary representing the post
        :type post: dict
        :param render: Choice if the markdown text has to be converted or not
        :type render: bool
        :return:
        """
        post_processor = self.post_processor
        post_processor.process(post, render)
        try:
            author = self.user_callback(post["user_id"])
        except Exception:
            raise Exception("No user_loader has been installed for this "
                            "BloggingEngine. Add one with the "
                            "'BloggingEngine.user_loader' decorator.")
        if author is not None:
            post["user_name"] = self.get_user_name(author)

        post_processed.send(self.app, engine=self, post=post, render=render)