How to use the markdown.Markdown function in Markdown

To help you get started, we’ve selected a few Markdown examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github django-wiki / django-wiki / tests / core / test_markdown.py View on Github external
def setUp(self):
        super().setUp()
        self.md = markdown.Markdown(extensions=[
            'extra',
            ResponsiveTableExtension()
        ])
        self.md_without = markdown.Markdown(extensions=['extra'])
github kianby / stacosys / stacosys / core / rss.py View on Github external
def generate_site(token):

    site = Site.select().where(Site.token == token).get()
    rss_title = get_template('rss_title_message').render(site=site.name)
    md = markdown.Markdown()

    items = []
    for row in (
        Comment.select()
        .join(Site)
        .where(Site.token == token, Comment.published)
        .order_by(-Comment.published)
        .limit(10)
    ):
        item_link = '%s://%s%s' % (config.get(config.RSS_PROTO), site.url, row.url)
        items.append(
            PyRSS2Gen.RSSItem(
                title='%s - %s://%s%s'
                % (config.get(config.RSS_PROTO), row.author_name, site.url, row.url),
                link=item_link,
                description=md.convert(row.content),
github ogom / python-mcider / mcider / converter.py View on Github external
def _get_slide_io2012(self, contents=None, extensions=[]):
        """ io-2012 style """
        md = Markdown(extensions=extensions)
        splits = [
            {'horizon': '----', 'style': 'none'},
            {'horizon': '____', 'style': 'smaller'},
            {'horizon': '****', 'style': 'fill'}
        ]

        styles = []
        for split in splits:
            styles.append(split['style'])
            horizon = '\n' + split['horizon'] + '\n'
            contents = contents.replace(horizon, '\n---\n' + split['style'] + '\n')

        pages = contents.split('\n---\n')

        # from pages to slides
        slides = []
github airbnb / knowledge-repo / knowledge_repo / converters / html.py View on Github external
"""
        # Copy urlmappers locally so we can modify it without affecting global
        # state
        urlmappers = urlmappers[:]
        if images_base64_encode:
            urlmappers.insert(0, self.base64_encode_image_mapper)

        # proxy posts are assumed to be embeddable links
        if 'proxy' in self.kp.headers:
            return None, '<a href="{0}">Linked Post</a>\n'.format(self.kp.headers['proxy'].strip())

        html = ''
        if not skip_headers:
            html += self.render_headers()

        md = markdown.Markdown(extensions=MARKDOWN_EXTENSIONS)
        html += md.convert(self.kp.read())

        html = self.apply_url_remapping(html, urlmappers)

        return md, html
github AcidWeb / CurseBreaker / CB / Wago.py View on Github external
def __init__(self, username, accountname, apikey):
        self.username = username
        self.accountName = accountname
        self.apiKey = apikey
        self.bbParser = bbcode.Parser()
        Markdown.output_formats['plain'] = markdown_unmark_element
        self.mdParser = Markdown(output_format='plain')
        self.mdParser.stripTopLevelTags = False
        if self.username == 'DISABLED':
            self.username = ''
github huyng / Foundation / docs / build.py View on Github external
def render_markdown(fpath):
    md = markdown.Markdown( extensions = ['meta','codehilite','tables','toc'] )
    with open(fpath, 'r') as mdfile:
        html = md.convert(mdfile.read())
    return (html, md)
github JeffVandrewJr / patron / app / email.py View on Github external
def email_post(post):
    '''
    Takes a blog post, uses the Markdown engine to render it to HTML,
    then creates an email message from the HTML. The msg is then passed
    to send_bulkmail function.
    '''
    mail = Email.query.first()
    try:
        markdown = Markdown()
        post['rendered_text'] = markdown.convert(post['text'])
        html_body = render_template(
            'email/email_post.html',
            post=post,
        )
        text_body = render_template(
            'email/email_post.txt',
            post=post,
        )
        site = current_app.config.get('BLOGGING_SITENAME')
        users = User.query.filter_by(mail_opt_out=False).all()
        send_bulkmail(
            f'New Update from {site}',
            sender=mail.default_sender,
            users=users,
            html_body=html_body,
github savuir / blo / blo / page_generator.py View on Github external
def __init__(self, config):
        self.config = config
        self.jinja_env = jinja2.Environment(
            loader=jinja2.FileSystemLoader(self.config['template_dir']))
        self.md = markdown.Markdown(
            extensions=['markdown.extensions.meta',
                        'markdown.extensions.codehilite'])
        self.content_aggregator = ContentAggregator(config)
github Pagure / pagure / pagure / lib / __init__.py View on Github external
# Some extensions are disabled for READMEs and enabled otherwise
    if readme:
        extensions.extend([
            'markdown.extensions.abbr',
            'markdown.extensions.footnotes',
            'markdown.extensions.toc',
        ])
    else:
        extensions.append(
            'markdown.extensions.nl2br',
        )
    if extended:
        # Install our markdown modifications
        extensions.append('pagure.pfmarkdown')

    md_processor = markdown.Markdown(
        safe_mode="escape",
        extensions=extensions,
        extension_configs={
            'markdown.extensions.codehilite': {
                'guess_lang': False,
            }
        }
    )

    if text:
        try:
            text = _convert_markdown(md_processor, text)
        except Exception:
            _log.debug(
                'A markdown error occured while processing: ``%s``',
                str(text))
github DCASE-REPO / dcase_util / dcase_util / tools / datasets.py View on Github external
try:
            import jinja2
        except ImportError:
            message = '{name}: Unable to import jinja2 module. You can install it with `pip install jinja2`.'.format(
                name=self.__class__.__name__
            )

            self.logger.exception(message)
            raise ImportError(message)

        f = codecs.open(source_filename, mode='r', encoding='utf-8')
        md_data = f.read()
        f.close()

        md = markdown.Markdown(
            extensions=[
                'extra',
                'markdown.extensions.meta'
            ],
        )

        html = md.convert(md_data)
        html = html.replace('', '<table></table><table class="table table-striped table-hover table-sm"></table>')

        if hasattr(md, 'Meta'):
            title = md.Meta['title'][0]

        else:
            title = None

        doc = jinja2.Template(self.md_to_html_template).render(