# Path: yapper/utilities/extensions.py
# class LazyYoutubeExtension(Extension):
# 
#     """
#     Parses a youtube URL in markdown and renders that as an empty div
#     with data-* attributes to be used by lazyyt.js.
#     """
# 
#     def __init__(self):
#         super(LazyYoutubeExtension, self).__init__()
# 
#     def extendMarkdown(self, md, md_globals):
#         md.inlinePatterns.add(
#             'lazyyoutubeembed', LazyYoutubePattern(md), '_begin')


from urlparse import urlparse
from markdown import markdown
from pyembed.markdown import PyEmbedMarkdown
from .extensions import LazyYoutubeExtension
from config import Config
import bleach
    return attrs


def dont_linkify_urls(attrs, new=False):
    """Prevent file extensions to convert to links.

    This is a callback function used by bleach.linkify().
    Prevent strings ending with substrings in `file_exts` to be
    converted to links unless it starts with http or https.
    """
    file_exts = ('.py', '.md', '.sh')
    txt = attrs['_text']
    if txt.startswith(('http://', 'https://')):
        return attrs
    if txt.endswith(file_exts):
        return None
    return attrs


def create_post_from_md(body):
    """Parse markdown and linkify urls."""
    # allowed_tags = ['a', 'abbr', 'acronym', 'b', 'blockquote', 'code',
    #                 'em', 'li', 'i', 'ol', 'pre', 'strong', 'ul', 'h1',
    #                 'h2', 'h3', 'p', 'span']
    no_link_text = markdown(
        body,
        output_format='html5',
        extensions=[
            'codehilite(linenums=True)',
            PyEmbedMarkdown(),

# Path: yapper/utilities/extensions.py
# class LazyYoutubeExtension(Extension):
# 
#     """
#     Parses a youtube URL in markdown and renders that as an empty div
#     with data-* attributes to be used by lazyyt.js.
#     """
# 
#     def __init__(self):
#         super(LazyYoutubeExtension, self).__init__()
# 
#     def extendMarkdown(self, md, md_globals):
#         md.inlinePatterns.add(
#             'lazyyoutubeembed', LazyYoutubePattern(md), '_begin')


# Path: yapper/utilities/md.py
from urlparse import urlparse
from markdown import markdown
from pyembed.markdown import PyEmbedMarkdown
from .extensions import LazyYoutubeExtension
from config import Config
import bleach

    return attrs


def dont_linkify_urls(attrs, new=False):
    """Prevent file extensions to convert to links.

    This is a callback function used by bleach.linkify().
    Prevent strings ending with substrings in `file_exts` to be
    converted to links unless it starts with http or https.
    """
    file_exts = ('.py', '.md', '.sh')
    txt = attrs['_text']
    if txt.startswith(('http://', 'https://')):
        return attrs
    if txt.endswith(file_exts):
        return None
    return attrs


def create_post_from_md(body):
    """Parse markdown and linkify urls."""
    # allowed_tags = ['a', 'abbr', 'acronym', 'b', 'blockquote', 'code',
    #                 'em', 'li', 'i', 'ol', 'pre', 'strong', 'ul', 'h1',
    #                 'h2', 'h3', 'p', 'span']
    no_link_text = markdown(
        body,
        output_format='html5',
        extensions=[
            'codehilite(linenums=True)',
            PyEmbedMarkdown(),

            LazyYoutubeExtension()