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)
# Create a Flask WSGI app and configure it using values from the module. app = Flask(__name__) app.config.from_object(__name__) # FlaskDB is a wrapper for a peewee database that sets up pre/post-request # hooks for managing database connections. flask_db = FlaskDB(app) # The `database` is the actual peewee database, as opposed to flask_db which is # the wrapper. database = flask_db.database # Configure micawber with the default OEmbed providers (YouTube, Flickr, etc). # We'll use a simple in-memory cache so that multiple requests for the same # video don't require multiple network requests. oembed_providers = bootstrap_basic(OEmbedCache()) class Entry(flask_db.Model): title = CharField() slug = CharField(unique=True) content = TextField() published = BooleanField(index=True) timestamp = DateTimeField(default=datetime.datetime.now, index=True) @property 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.
""" Carafe Database """ from flask import Markup from markdown import markdown from markdown.extensions.codehilite import CodeHiliteExtension from markdown.extensions.extra import ExtraExtension from micawber import bootstrap_basic, parse_html from micawber.cache import Cache as OEmbedCache from bs4 import BeautifulSoup OEMBED_PROVIDERS = bootstrap_basic(OEmbedCache()) class UserContent: """ UserContent class """ @property 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) @property def clean_text(self): """ cleans text of html """ html = markdown(self.text)