def html(self):
     html = parse_html(
         markdown(self.content),
         oembed,
         maxwidth=300,
         urlize_all=True)
     return Markup(html)
Exemple #2
0
def rich_content(content, maxwidth=300):
    html = parse_html(
        markdown(content),
        oembed,
        maxwidth=maxwidth,
        urlize_all=True)
    return Markup(html)
Exemple #3
0
def detail(slug):
    r = db_posts.scan(FilterExpression='published = :b AND slug = :s',
                      ExpressionAttributeValues={
                          ":b": True,
                          ":s": slug
                      })

    if len(r) > 0:
        post = r['Items'][0]

        # convert post content to HTML
        hilite = CodeHiliteExtension(linenums=False, css_class='highlight')
        extras = ExtraExtension()
        post['content'] = markdown(post['content'],
                                   extensions=[hilite, extras])
        post['content'] = parse_html(post['content'],
                                     oembed_providers,
                                     urlize_all=True,
                                     maxwidth=app.config['SITE_WIDTH'])
        post['content'] = Markup(post['content'])

        return render_template('detail.html', post=post)
    else:
        flash('Post not found.', 'danger')
        return redirect(url_for('home'))
Exemple #4
0
def rich_content(content, maxwidth=300):
    html = parse_html(
        markdown(content),
        oembed,
        maxwidth=maxwidth,
        urlize_all=True)
    return Markup(html)
Exemple #5
0
 def html_content(self):
     hilite = CodeHiliteExtension(linenums=False, css_class='highlight')
     extras = ExtraExtension()
     markdown_content = markdown(self.content, extensions=[hilite, extras])
     oembed_content = parse_html(markdown_content,
                                 urlize_all=True,
                                 maxwidth=app.config['SITE_WIDTH'])
     return Markup(oembed_content)
 def html_content(self):
     hilite = CodeHiliteExtension(linenums=False, css_class='highlight')
     extras = ExtraExtension()
     markdown_content = markdown(self.content, extensions=[hilite, extras])
     oembed_content = parse_html(markdown_content,
                                 oembed_providers,
                                 urlize_all=True)
     return Markup(oembed_content)
Exemple #7
0
	def html_content(self):
		hilite = CodeHiliteExtension(linenums=False, css_class='highlight')
		extras = ExtraExtension()
		markdown_content = markdown(self.content, extensions=[hilite, extras])
		oembed_content = parse_html(
			markdown_content,
			oembed_providers,
			urlize_all=True,
			maxwidth=app.config['SITE_WIDTH'])
Exemple #8
0
	def html_content(self):
		hilite = CodeHiliteExtension(linenums=False, css_class='highlight')
		extras = ExtraExtension()
		markdown_content = markdown(self.content, extensions=[hilite, extras])
		oembed_content = parse_html(
			markdown_content,
			oembed_providers,
			urlize_all=True)
		return Markup(oembed_content)
Exemple #9
0
 def html_content(self):
     # todo: research what all these things do
     hilite = CodeHiliteExtension(linenums=False, css_class="highlight")
     extras = ExtraExtension()
     markdown_content = markdown(self.content, extensions=[hilite, extras])
     oembed_content = parse_html(markdown_content,
                                 oembed_providers,
                                 urlize_all=True,
                                 maxwidth=app.config["SITE_WIDTH"])
     return Markup(oembed_content)
Exemple #10
0
 def html_content(self):
     """ parses markdown content """
     hil = CodeHiliteExtension(linenums=True, css_class='highlight')
     extra = ExtraExtension()
     mrkdwn_content = markdown(self.text, extensions=[hil, extra])
     oembed_content = parse_html(
         mrkdwn_content,
         OEMBED_PROVIDERS,
         urlize_all=True)
     return Markup(oembed_content)
Exemple #11
0
 def html(self):
     """
     Run the content throught markdown, converts links into objects
     and return the html code
     """
     html = parse_html(markdown(self.content),
                       oembed,
                       maxwidth=300,
                       urlize_all=True)
     return Markup(html)
Exemple #12
0
def html_content(text):

    hilite = CodeHiliteExtension(linenums=False, css_class='highlight')
    extras = ExtraExtension()
    markdown_content = markdown(text, extensions=[hilite, extras])
    oembed_providers = bootstrap_basic(OEmbedCache())
    oembed_content = parse_html(markdown_content,
                                oembed_providers,
                                urlize_all=True,
                                maxwidth=SITE_WIDTH)
    return Markup(oembed_content)
 def html_content(self):
     """Parse article bosy for markup and features."""
     hilite = CodeHiliteExtension(linenums=False, css_class='highlight')
     extras = ExtraExtension()
     markdown_content = markdown(self.body, extensions=[hilite, extras])
     oembed_providers = bootstrap_basic(OEmbedCache)
     oembed_content = parse_html(
         markdown_content,
         oembed_providers,
         urlize_all=True)
     return Markup(oembed_content)
Exemple #14
0
 def html_content(self):
     hilite = CodeHiliteExtension(linenums=False, css_class='highlight')
     extras = ExtraExtension()
     markdown_content = markdown(self.content, extensions=[hilite, extras])
     oembed_content = parse_html(markdown_content,
                                 oembed_providers,
                                 urlize_all=True,
                                 maxwidth=app.config["SITE_WIDTH"])
     return Markup(
         oembed_content
     )  # The Markup object tells Flask that we trust the HTML content, so it will not be escaped when rendered in the template.
Exemple #15
0
def books():
    log.info("Request /books")
    books = models.book.all()
    for book in books:
        content = parse_html(
            book["content"],
            oembed_providers,
            urlize_all=True,
        )

        book["content"] = Markup(content)

    return render_template("books.html", books=books, config=config)
Exemple #16
0
 def html_content(self):
     """
     Generate HTML representation of the markdown-formatted blog entry,
     and also convert any media URLs into rich media objects such as video
     players or images."""
     hilite = CodeHiliteExtension(linenums=False, css_class='highlight')
     extras = ExtraExtension()
     markdown_content = markdown(self.content, extensions=[hilite, extras])
     oembed_content = parse_html(markdown_content,
                                 oembed_providers,
                                 urlize_all=True,
                                 maxwidth=app.config['SITE_WIDTH'])
     return Markup(oembed_content)
Exemple #17
0
 def html_content(self):
     """
     Generate HTML representation of the markdown-formatted blog entry,
     and also convert any media URLs into rich media objects such as video
     players or images.
     """
     hilite = CodeHiliteExtension(linenums=False, css_class="highlight")
     extras = ExtraExtension()
     markdown_content = markdown(self.content, extensions=[hilite, extras])
     oembed_content = parse_html(
         markdown_content, oembed_providers, urlize_all=True, maxwidth=app.config["SITE_WIDTH"]
     )
     return Markup(oembed_content)
Exemple #18
0
    def html(self):
        """
        Convenience method. Runs the content through markdown,
        converts links into objects where possible,
        and returns the HTML code.
        """

        html = parse_html(
            markdown(self.content),
            oembed,
            maxwidth=300,
            urlize_all=True)
        return Markup(html)
Exemple #19
0
 def html_content(self):
     app = current_app._get_current_object()
     # hilite = CodeHiLiteExtension(linenums=False, css_class='highlight')
     extras = ExtraExtension()
     #TODO why can I not add CodeHiLiteExtension????
     # markdown_content = markdown(self.body, extensions=[hilite, extras])
     markdown_content = markdown(self.body, extensions=[extras])
     oembed_providers = bootstrap_basic(OEmbedCache())
     oembed_content = parse_html(
         markdown_content,
         oembed_providers,
         urlize_all=True,
         maxwidth=app.config['SITE_WIDTH'])
     return Markup(oembed_content)
Exemple #20
0
def post(slug):
    log.info(f"Request /{slug}")

    try:
        entry = models.post.get(slug)
    except Exception:
        return "oops.. I could not find this page!!"

    content = parse_html(
        entry["content"],
        oembed_providers,
        urlize_all=True,
    )
    entry["content"] = Markup(content)
    return render_template("article.html", post=entry, config=config)
Exemple #21
0
    def html_content_preview(self, limit):
        hilite = CodeHiliteExtension(linenums=False, css_class="highlight")
        extras = ExtraExtension()

        # adding ellipsis if necessary, otherwise entire content is the preview
        if (len(self.content) <= limit):
            markdown_content = markdown(self.content,
                                        extensions=[hilite, extras])
        else:
            markdown_content = markdown(self.content[:limit - 3] + "&hellip;",
                                        extensions=[hilite, extras])

        oembed_content = parse_html(markdown_content,
                                    oembed_providers,
                                    urlize_all=True,
                                    maxwidth=app.config["SITE_WIDTH"])
        return Markup(oembed_content)
Exemple #22
0
    def get_html_content(self):
        """
        Return the body of the post with markdown converted to HTML
        """

        hilite = codehilite.CodeHiliteExtension(
            linenums=False,
            css_class='highlight'
        )
        extras = extra.ExtraExtension()
        markdown_content = markdown.markdown(
            self.body,
            extensions=[hilite, extras]
        )
        oembed_content = micawber.parse_html(
            markdown_content,
            app.oembed_providers,
            urlize_all=True,
            # TODO maxwidth
            # maxwidth=app.config['SITE_WIDTH']
        )
        return flask.Markup(oembed_content)
Exemple #23
0
    def html_content(self):

        # used for code/syntax highlighting
        # css_class -- name of css class used for div
        hilite = CodeHiliteExtension(linenums=True, css_class='highlight')

        # all the extensions found here:
        # https://python-markdown.github.io/extensions/extra/
        extras = ExtraExtension()

        # utilizes the above extensions and converts the markdown to html
        markdown_content = markdown(self.content, extensions=[hilite, extras])

        # parse_html -- Parse HTML intelligently, rendering items on their own
        # within block elements as full content (e.g. a video player)
        # urlize_all -- constructs a simple link when provider is not found
        oembed_content = parse_html(markdown_content,
                                    oembed_providers,
                                    urlize_all=True,
                                    maxwidth=app.config['SITE_WIDTH'])

        # Markup returns a string that is ready to be safely inserted into
        # an HTML document
        return Markup(oembed_content)
Exemple #24
0
    def html_content(self):
        code_css_class = "friendly"
        hilite = CodeHiliteExtension(linenums=False,
                                     noclasses=True,
                                     pygments_style=code_css_class)
        extras = ExtraExtension()

        pre_sanistised_markup = Markup(self.content)

        markdown_content = markdown(pre_sanistised_markup,
                                    extensions=[hilite, extras])
        post_sanitised_markup = bleach.clean(markdown_content,
                                             tags=markdown_tags,
                                             attributes=markdown_attributes,
                                             styles=markdown_styles,
                                             strip=False)

        oembed_content = parse_html(post_sanitised_markup,
                                    oembed_providers,
                                    urlize_all=True,
                                    maxwidth=app.config['SITE_WIDTH'])

        post_markup = Markup(oembed_content)
        return post_markup
Exemple #25
0
 def html(self):
     html = parse_html(markdown(self.content),
                       oembed,
                       maxwidth=300,
                       urlize_all=True)
     return Markup(html)