Esempio n. 1
0
    def get_html_description(self, is_demo=None):
        raw = self.description
        if is_demo is None:
            us = UserSettings.get_from_user(self.podcast.owner)
            is_demo = us.plan == payment_plans.PLAN_DEMO
        available_flags = self.podcast.get_available_flair_flags(flatten=True)

        if self.flair_tip_jar and FLAIR_TIP_JAR in available_flags:
            raw += "\n\nSupport %s by donating to the [tip jar](https://pinecast.com/payments/tips/%s)." % (
                self.podcast.name,
                self.podcast.slug,
            )

        if self.flair_site_link and FLAIR_SITE_LINK in available_flags:
            raw += "\n\nFind out more at [%s](http://%s.pinecast.co)." % (self.podcast.name, self.podcast.slug)

        if self.flair_feedback and FLAIR_FEEDBACK in available_flags:
            prompt = self.get_feedback_prompt()
            fb_url = "https://pinecast.com%s" % reverse(
                "ep_comment_box", podcast_slug=self.podcast.slug, episode_id=str(self.id)
            )
            raw += "\n\n%s [%s](%s)" % (prompt, fb_url, fb_url)

        if is_demo or self.flair_powered_by and FLAIR_SITE_LINK in available_flags:
            raw += "\n\nThis podcast is powered by " "[Pinecast](https://pinecast.com)."

        markdown = gfm.markdown(raw)
        return sanitize(markdown)
def main():
    logging.basicConfig(level=logging.INFO)
    args = docopt(__doc__, version='PeP et Al. emails v0.0.1')
    database = read_database(args['<database>'])

    config = RawConfigParser()
    successful_files = config.read(args['--config'])
    if not successful_files:
        raise IOError('Could not read config-file')

    backend = args['--backend'] or config.sections()[0]

    if backend == 'smtplib':
        from .backends import SMTPLibMailer
        mailer = SMTPLibMailer(**config['smtplib'])

    elif backend == 'mailgun':
        from .backends import MailgunMailer
        mailer = MailgunMailer(**config['mailgun'])

    else:
        raise ValueError('Unsupported backend: {}'.format(args['--backend']))

    template, metadata = parse_template(args['<template>'])

    for recipient in database.itertuples():
        markdown = template.render(recipient=recipient, metadata=metadata)
        html = gfm.markdown(markdown)
        mailer.send_mail(
            recipient,
            metadata,
            markdown,
            html=html,
            attachments=metadata.get('attachments')
        )
Esempio n. 3
0
    def get_html_description(self, is_demo=None):
        raw = self.description
        if is_demo is None:
            us = UserSettings.get_from_user(self.podcast.owner)
            is_demo = us.plan == payment_plans.PLAN_DEMO
        available_flags = self.podcast.get_available_flair_flags(flatten=True)

        if (self.flair_tip_jar and FLAIR_TIP_JAR in available_flags):
            raw += '\n\nSupport %s by donating to the [tip jar](https://pinecast.com/payments/tips/%s).' % (
                self.podcast.name, self.podcast.slug)

        if (self.flair_site_link and FLAIR_SITE_LINK in available_flags):
            raw += '\n\nFind out more at [%s](http://%s.pinecast.co).' % (
                self.podcast.name, self.podcast.slug)

        if (self.flair_feedback and FLAIR_FEEDBACK in available_flags):
            prompt = self.get_feedback_prompt()
            fb_url = 'https://pinecast.com%s' % reverse(
                'ep_comment_box',
                podcast_slug=self.podcast.slug,
                episode_id=str(self.id))
            raw += '\n\n%s [%s](%s)' % (prompt, fb_url, fb_url)

        if (is_demo or self.flair_powered_by
                and FLAIR_SITE_LINK in available_flags):
            raw += ('\n\nThis podcast is powered by '
                    '[Pinecast](https://pinecast.com).')

        markdown = gfm.markdown(raw)
        return sanitize(markdown)
Esempio n. 4
0
def markdownToSoup(markdownstring):
    """Takes a string of markdown, and returns a rendered bs4 element"""
    renderedMarkdown = markdown(gfm(markdownstring))
    newsoup = BeautifulSoup(renderedMarkdown, bs4parser)
    container = newsoup.body
    container.name = 'span'
    container['class'] = 'mdrender'
    return container
Esempio n. 5
0
 def make_topics_html(self):
     """
     Generate the HTML for the topics for this Session
     from the topics as a string written in Git-Flavored Markdown,
     along with the previously-determined type of this Session:
       -- Exam, Sprint, or Regular
     """
     # Start with the topics:
     self.topics_html = gfm.markdown(self.topics)
Esempio n. 6
0
    def get_episode_text(self, data):
        ep = data['episode']
        if ep.subtitle:
            return ep.subtitle

        return bleach.clean(gfm.markdown(ep.description),
                            tags=[],
                            strip=True,
                            strip_comments=True)[:140]
Esempio n. 7
0
    def make_html_from_topics(self, topics_for_session):
        # Make the session title become a top-level list item,
        # and increase the indentation of all subsequent lines.
        topics_for_session = topics_for_session.replace('\n',
                                                        '\n    ')
        topics_for_session = '+ ' + topics_for_session
#         print(topics_for_session)

        # Convert each topic to HTML using Github Flavored Markdown.
        html = gfm.markdown(topics_for_session)
#         print(html)

        # Add class info to the HTML for topics, tests, and sprints.
        # The following is brittle.
        ul_class = 'topics collapsibleList'
        li_class = 'topic'
        if re.match(r'.*Test [0-9]\..*', html, RE_DOTALL):
            ul_class += ' exam'
            li_class += ' exam'
        elif re.match(r'.*Sprint [0-9].*', html, RE_DOTALL):
            ul_class += ' sprint'
            li_class += ' sprint'

        # CONSIDER: the following adds the class to the FIRST <ul>
        # but to ALL <li>'s.  Is that what we want for sub-lists?
        html = html.replace('<ul>',
                            '<ul class="' + ul_class + '">',
                            1)
        html = html.replace('<li>',
                            '<li class="' + li_class + '">')

        # Add details for Tests.
        for_tests = ExamTopic.EVENING_EXAM_TEMPLATE.substitute()
        html = re.sub(r'(Test [0-9]\.)', r'\1' + for_tests, html)

        # Parenthetical expressions are additional markup:
        DOUBLE_OPEN_PARENTHESES = '!!!START_CANNOT_OCCUR_I_HOPE!!!'
        DOUBLE_CLOSE_PARENTHESES = '!!!END_CANNOT_OCCUR_I_HOPE!!!'
        html = html.replace('((', DOUBLE_OPEN_PARENTHESES)
        html = html.replace('))', DOUBLE_CLOSE_PARENTHESES)
        html = html.replace('(', '<span class=parenthetical>(')
        html = html.replace(')', ')</span>')
        html = html.replace('</span>.', '.</span>')
        html = html.replace(DOUBLE_OPEN_PARENTHESES, '(')
        html = html.replace(DOUBLE_CLOSE_PARENTHESES, ')')

        pretty_html = bs4.BeautifulSoup(html, "html.parser").prettify()

        lines = pretty_html.split('\n')
        for k in range(len(lines)):
            lines[k] = re.sub(r'^( *)', r'\1\1', lines[k])

        final_html = '\n'.join(lines)
        # TODO: Deal with punctuation after a tag end.

        return final_html
Esempio n. 8
0
def _render_markdown(content):
    html = gfm.markdown(content)

    try:
        html = _convert_http_to_https(html)
    except Exception:
        # Leave the readme unparsed.
        pass

    return html
Esempio n. 9
0
 def _render_markdown(self, content):
     """Render markdown for the provided content.
         :content string: Some markdown.
         :returns: HTML as a string.
     """
     html = gfm.markdown(content)
     try:
         html = self._convert_http_to_https(html)
     except Exception:
         # Leave the readme unparsed.
         pass
     return html
Esempio n. 10
0
def entries(journal, count=None):
    """Send back dictionary"""
    # Return all entries
    if not count:
        entries = reversed(journal.entries)
    else:
        entries = list(reversed(journal.entries))[:count]

    rv = []
    for entry in entries:
        e = exporters.to_json(entry)
        e['markdown'] = e['body']
        e['html'] = gfm.markdown(e['body'])
        e['slug'] = slugify.slugify(e['title'])
        del e['body']
        rv.append(e)

    return rv
Esempio n. 11
0
    def make_html(self):
        self.preparation_link = ClassSession.LINK_TO_PREP.format(
            self.session_number)

        title = gfm.markdown(self.title.replace('/', '<br>\n'))

        print('Title:' + title)
        self.html = ClassSession.SESSION_TEMPLATE.substitute(
            SessionPreparationLink=self.preparation_link,
            SessionNumber=self.session_number,
            SessionDate=self.date_as_string(),
            SessionTitle=title)

        if self.session_type == SessionType.EVENING_EXAM:
            self.add_exam_info()

        if SHOW_TOPICS and self.topics.strip():
            self.make_topics_html()
            self.html += ClassSession.SESSION_TOPICS_TEMPLATE.substitute(
                SessionTopics=self.topics_html)
Esempio n. 12
0
def parse_markdown_cell(cell, app):
    html = gfm.markdown(cell['source'])
    # app['outputs'].append({'id':''.format(html)})
    app['code'].append('outputs.append(Div(text="""{html}"""))'.format(html=html))
Esempio n. 13
0
# coding: UTF-8
# convert markdown to html
# in order to get module attributes(argv)
import sys
# markdown
#import markdown
import gfm

# get command line args
args = sys.argv

file_name = args[1]
print("file_name : " + file_name)

# markdown file の読み込み
f = open(file_name, 'r', encoding='utf-8')
text_md = f.read()
f.close()

print("************ markdown **************")
print(text_md)

# markdown file -> html file
#md = markdown.Markdown()
#html = md.convert(text_md)
html = gfm.markdown(text_md)

print("************ html **************")
print(html)
Esempio n. 14
0
 def parsed(self):
     parsed = self.body
     parsed = parse_markup(parsed)
     return markdown(parsed)
Esempio n. 15
0
def get_data(owner, repo):
    projects_data = {}
    url = join(owner, repo)
    projects = get(join('repos', url, 'projects'))
    for project in projects:
        if project['state'] == 'closed':
            continue

        all_projects.setdefault(url, [])
        all_projects[url].append(project)

        this_project = {
            'project': project,
            'columns': {},
            'cards': {},
            'contents_order': [],
            'contents': {},
            'timeline_changes': {}
        }
        columns = get(project['columns_url'])
        for column in columns:
            this_project['columns'][column['id']] = column

            cards = get(column['cards_url'])
            for card in cards:
                # We only want issues and they have a content URL on them.
                if 'content_url' in card:
                    this_project['cards'][card['url']] = card
                    contents = get(card['content_url'])
                    this_project['contents_order'].append(
                        [contents['title'], contents['url']])

                    timeline_url = join('repos', owner, repo, 'issues',
                                        str(contents['number']), 'timeline')
                    contents['timeline_url'] = timeline_url
                    contents['body'] = gfm.markdown(contents['body'])

                    this_project['contents'][contents['url']] = contents

                    timeline = get(timeline_url)
                    timeline_changes = []
                    for line in timeline:
                        if line['event'] in ('labeled', 'commented'):
                            line['created_at'] = parse_date(line['created_at'])
                            if 'body' in line:
                                line['body'] = gfm.markdown(line['body'])

                            timeline_changes.append(line)

                    this_project['timeline_changes'][
                        timeline_url] = timeline_changes[:-1]

                    if contents['milestone'] and contents['milestone'][
                            'id'] not in all_milestones:
                        milestone_url = join(
                            'search', 'issues') + '?q=milestone:"{}"'.format(
                                contents['milestone']['title'])
                        milestone = get(milestone_url)
                        milestone['issue_summary'] = summarize(milestone)
                        all_milestones[contents['milestone']['id']] = milestone

            this_project['contents_order'] = sorted(
                this_project['contents_order'])

        projects_data[project['id']] = this_project

    all_projects[url] = reversed(all_projects[url])
    return projects_data
Esempio n. 16
0
 def item_description(self, item):
     return gfm.markdown(item.body)
Esempio n. 17
0
 def content_markdown(self):
     return gfm.markdown(self.content)
Esempio n. 18
0
def read_markdown(path):
    with open(path, 'r') as file:
        content = file.read().decode('utf8')
    return markdown(content)
Esempio n. 19
0
import os
import sys
import gfm

if len(sys.argv) == 1:
    sys.exit(-1)

with open(sys.argv[1], "r") as fin:
    markdown_content = fin.read()

    markdown_content = gfm.gfm(markdown_content)

    print gfm.markdown(markdown_content)

Esempio n. 20
0
 def item_description(self, item):
     return gfm.markdown(item.body)
Esempio n. 21
0
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
import gfm                      # gfm module (pip install gfm)

arg = sys.argv

### markdown fileの読み込み
# f = open('test.md', 'r')
f = open(arg[1], 'r')
text_md = f.read()
f.close()

# html = gfm.gfm(text_md)
html = gfm.markdown(text_md)
print(html)