Ejemplo n.º 1
0
    def get_all_published(cls, is_need_summary=False):
        entries = []

        db = get_db()
        cur = db.execute(
            "select title, content, slug, status, create_time"
            " from entries where status is not ? "
            "order by create_time desc",
            ("draft",),
        )

        for row in cur.fetchall():
            status = row["status"]
            title = row["title"]
            date = row["create_time"]
            id = row["slug"]
            status = row["status"]

            if is_need_summary:
                _content = row["content"].split("<!--more-->")[0]
            else:
                _content = row["content"]

            content = markdown(_content)
            slug = row["slug"]

            entry = dict(title=title, content=content, date=date, id=id, status=status, slug=slug)
            entries.append(entry)

        return entries
Ejemplo n.º 2
0
    def get_page(cls, page=1):
        entries = []
        perpage = 5
        start = (page - 1) * 5

        db = get_db()
        cur = db.execute(
            "select title, id, content, create_time, "
            "status, slug from entries "
            "order by create_time desc limit ? offset ?",
            (perpage, start),
        )

        for _entry in cur.fetchall():
            _content = _entry["content"].split("<!--more-->")[0]
            content = markdown(_content)
            date = _entry["create_time"]
            status = _entry["status"]
            slug = _entry["slug"]

            entry = dict(title=_entry["title"], id=_entry["id"], content=content, date=date, status=status, slug=slug)

            entries.append(entry)

        return entries
Ejemplo n.º 3
0
    def get_published_page(cls, page=1):
        perpage = 5
        start = (page - 1) * 5
        entries = []

        db = get_db()
        cur = db.execute(
            "select title, content, status, create_time, id, "
            "slug from entries where status is not ? "
            "order by create_time desc limit ? offset ?",
            ("draft", perpage, start),
        )

        for row in cur.fetchall():
            status = row["status"]
            title = row["title"]
            date = row["create_time"]
            id = row["slug"]
            status = row["status"]
            _content = row["content"].split("<!--more-->")[0]
            content = markdown(_content)

            entry = dict(title=title, content=content, date=date, id=id, status=status)
            entries.append(entry)

        return entries
Ejemplo n.º 4
0
def build_feed():
    feed = AtomFeed(current_app.config['SITE_NAME'],
                    feed_url=current_app.config['DOMAIN'] + 'rss.xml',
                    url=current_app.config['DOMAIN'],
                    subtitle=current_app.config['SUBTITLE'],
                    author=current_app.config['AUTHOR'],
                    updated=datetime.datetime.now())

    entries = Entry.get_all_published()

    for _entry in entries:
        time = datetime.datetime.strptime(_entry['date'], '%Y-%m-%d %H:%M:%S')

        feed.add(unicode(_entry['title']),
                 unicode(markdown(_entry['content'])),
                 content_type='html',
                 author=current_app.config['AUTHOR'],
                 published=time,
                 updated=time,
                 id=current_app.config['DOMAIN'] + _entry['slug'] + '/',
                 url=current_app.config['DOMAIN'] + 'posts/' + _entry['slug'] +
                 '/')

    with codecs.open(BASE_DIR + '/rss.xml', 'w', 'utf-8-sig') as f:
        f.write(feed.to_string())
Ejemplo n.º 5
0
def build_posts():
    lookup = TemplateLookup(directories=['./fe/template'])
    template = Template(filename='./fe/template/entry.html', lookup=lookup)

    entries = Entry.get_all_published()

    for _entry in entries:
        post_title = _entry['title']
        post_content = markdown(_entry['content'])
        post_slug = _entry['slug']
        date = _entry['date']
        status = _entry['status']

        entry = dict(title=post_title,
                     content=post_content,
                     date=date,
                     id=_entry['slug'],
                     status=status)

        html_content = template.render(entry=entry)

        os.mkdir(os.path.join('./ghpages/posts', post_slug))

        dist = os.path.join('./ghpages/posts', post_slug + '/index.html')

        with codecs.open(dist, 'w', 'utf-8-sig') as f:
            f.write(html_content)
Ejemplo n.º 6
0
def build_posts():
    lookup = TemplateLookup(directories=['./fe/template'])
    template = Template(
        filename='./fe/template/entry.html', lookup=lookup)

    entries = Entry.get_all_published()

    for _entry in entries:
        post_title = _entry['title']
        post_content = markdown(_entry['content'])
        post_slug = _entry['slug']
        date = _entry['date']
        status = _entry['status']

        entry = dict(
            title=post_title,
            content=post_content,
            date=date,
            id=_entry['slug'],
            status=status
        )

        html_content = template.render(entry=entry)

        os.mkdir(os.path.join('./ghpages/posts', post_slug))

        dist = os.path.join('./ghpages/posts', post_slug + '/index.html')

        with codecs.open(dist, 'w', 'utf-8-sig') as f:
            f.write(html_content)
Ejemplo n.º 7
0
    def get_page(cls, page=1):
        entries = []
        perpage = 5
        start = (page - 1) * 5

        db = get_db()
        cur = db.execute('select title, id, content, create_time, '
                         'status, slug from entries '
                         'order by create_time desc limit ? offset ?',
                         (perpage, start,))

        for _entry in cur.fetchall():
            _content = _entry['content'].split('<!--more-->')[0]
            content = markdown(_content)
            date = _entry['create_time']
            status = _entry['status']
            slug = _entry['slug']

            entry = dict(
                title=_entry['title'],
                id=_entry['id'],
                content=content,
                date=date,
                status=status,
                slug=slug
            )

            entries.append(entry)

        return entries
Ejemplo n.º 8
0
    def get_published_page(cls, page=1):
        perpage = 5
        start = (page - 1) * 5
        entries = []

        db = get_db()
        cur = db.execute('select title, content, status, create_time, id, '
                         'slug from entries where status is not ? '
                         'order by create_time desc limit ? offset ?',
                         ('draft', perpage, start,))

        for row in cur.fetchall():
            status = row['status']
            title = row['title']
            date = row['create_time']
            id = row['slug']
            status = row['status']
            _content = row['content'].split('<!--more-->')[0]
            content = markdown(_content)

            entry = dict(
                title=title,
                content=content,
                date=date,
                id=id,
                status=status
            )
            entries.append(entry)

        return entries
Ejemplo n.º 9
0
def post(name):
    path = '{}/{}'.format(POST_DIR, name)
    post = flatpages.get_or_404(path)
    text = post.html  # Passing HTML is destroying the latex math
    text = markdown(text, math=True)
    print text
    return render_template('post.html', post=post, text=text)
Ejemplo n.º 10
0
def build_feed():
    feed = AtomFeed(current_app.config['SITE_NAME'],
                    feed_url=current_app.config['DOMAIN'] + 'rss.xml',
                    url=current_app.config['DOMAIN'],
                    subtitle=current_app.config['SUBTITLE'],
                    author=current_app.config['AUTHOR'],
                    updated=datetime.datetime.now())

    entries = Entry.get_all_published()

    for _entry in entries:
        time = datetime.datetime.strptime(_entry['date'], '%Y-%m-%d %H:%M:%S')

        feed.add(unicode(_entry['title']),
                 unicode(markdown(_entry['content'])),
                 content_type='html',
                 author=current_app.config['AUTHOR'],
                 published=time,
                 updated=time,
                 id=current_app.config['DOMAIN'] + _entry['slug'] + '/',
                 url=current_app.config['DOMAIN'] + 'posts/' + _entry['slug'] + '/'
                 )

    with codecs.open(BASE_DIR + '/rss.xml', 'w', 'utf-8-sig') as f:
        f.write(feed.to_string())
Ejemplo n.º 11
0
def build_feed():
    feed = AtomFeed(SITE_NAME,
                    feed_url=DOMAIN + 'rss.xml',
                    url=DOMAIN,
                    subtitle=SUBTITLE,
                    author=AUTHOR,
                    updated=datetime.datetime.now())

    entries = Entry.get_all_published()

    for _entry in entries:
        time = datetime.datetime.strptime(_entry['date'], '%Y-%m-%d %H:%M:%S')

        feed.add(unicode(_entry['title']),
                 unicode(markdown(_entry['content'])),
                 content_type='html',
                 author=AUTHOR,
                 published=time,
                 updated=time,
                 id=DOMAIN + _entry['slug'] + '/',
                 url=DOMAIN + 'posts/' +  _entry['slug'] + '/'
                 )

    with codecs.open('./ghpages/rss.xml', 'w', 'utf-8-sig') as f:
        f.write(feed.to_string())
Ejemplo n.º 12
0
    def get_all_published(cls, is_need_summary=False):
        entries = []

        db = get_db()
        cur = db.execute('select title, content, slug, status, create_time'
                         ' from entries where status is not ? '
                         'order by create_time desc', ('draft',))

        for row in cur.fetchall():
            status = row['status']
            title = row['title']
            date = row['create_time']
            id = row['slug']
            status = row['status']

            if is_need_summary:
                _content = row['content'].split('<!--more-->')[0]
            else:
                _content = row['content']

            content = markdown(_content)
            slug = row['slug']

            entry = dict(
                title=title,
                content=content,
                date=date,
                id=id,
                status=status,
                slug=slug
            )
            entries.append(entry)

        return entries
Ejemplo n.º 13
0
 def on_changed_body(target, value, oldvalue, initiator):
     """When user change body post, we update body_html to display them
     """
     allowed_tags = ['a', 'abbr', 'acronym', 'b', 'blockquote', 'code',
                     'em', 'i', 'li', 'ol', 'pre', 'strong', 'ul', 'p',]
     target.story_html = bleach.clean(markdown(value),
                                      tags=allowed_tags,
                                      strip=True)
Ejemplo n.º 14
0
 def html(self):
     """
     Converts markdown syntax to plain html
     :return: html string
     """
     with open(self.path, "r") as fin:
         content = fin.read().split("---", 1)[1].strip()
     return markdown(content, fenced_code=True, space_headers=True, strikethrough=True, tables=True)
Ejemplo n.º 15
0
def read_tutorial(cat_id, page):
    tut = read_tutorial_page(cat_id, page)
    if tut is None:
        app.logger.info("No tutorial available for %s/%s" %
                        (cat_id, str(page)))
        return None
    content = markdown(tut.text, fenced_code=True)

    # automatically add event handler for highlighting DOM elements
    tmp = re.findall('<em>(.*?)</em>', str(content))
    for t in tmp:
        if 'hl_' in t:
            text = t.split(' hl_')[0]
            idname = t.split(' hl_')[1]
            content = re.sub(
                '<em>{} hl_{}</em>'.format(text, idname),
                '<em onmouseover="highlightElement(&#39;{0}&#39;, &#39;id&#39;, true)" onmouseout="highlightElement(&#39;{0}&#39;, &#39;id&#39;, false)">{1}</em>'
                .format(idname, text), str(content))
        elif 'hlc_' in t:
            text = t.split(' hlc_')[0]
            classname = t.split(' hlc_')[1]
            content = re.sub(
                '<em>{} hlc_{}</em>'.format(text, classname),
                '<em onmouseover="highlightElement(&#39;{0}&#39;, &#39;class&#39;, true)" onmouseout="highlightElement(&#39;{0}&#39;, &#39;class&#39;, false)">{1}</em>'
                .format(classname, text), str(content))

    # automatically add "ask as query" links after code blocks
    content = re.sub(
        '</code>(\s)?</pre>',
        "</code></pre><div class='show_code'><a href='#' class='show_code'>Ask as query</a></div>",
        str(content))
    content = Markup(content)
    # check whether there is another tutorial in this category
    nxt = read_tutorial_page(cat_id, int(page) + 1)
    prev = read_tutorial_page(cat_id, int(page) - 1)

    out = dict()
    out['this'] = {
        'cat_id': tut.cat_title,
        'page': tut.page,
        'title': tut.title,
        'text': content
    }
    if nxt is not None:
        out['next'] = {
            'cat_id': nxt.cat_id,
            'page': nxt.page,
            'title': nxt.title
        }
    if prev is not None:
        out['prev'] = {
            'cat_id': prev.cat_id,
            'page': prev.page,
            'title': prev.title
        }

    return out
Ejemplo n.º 16
0
    def test_inverse_render(self, html):
        ext, flags = 0, HTML_SKIP_STYLE

        result = markdown(TEST_MD, style=False)

        html.assert_called_with(TEST_MD, extensions=ext, render_flags=flags)
        self.assertIsInstance(result, Markup)
        self.assertEqual(result, misaka.html(TEST_MD,
            extensions=ext, render_flags=flags))
Ejemplo n.º 17
0
    def test_defaults(self, html):
        ext, flags = 0, 0

        result = markdown(TEST_MD)

        html.assert_called_with(TEST_MD, extensions=ext, render_flags=flags)
        self.assertIsInstance(result, Markup)
        self.assertEqual(result, misaka.html(TEST_MD,
            extensions=ext, render_flags=flags))
Ejemplo n.º 18
0
    def test_undefined_option(self, html):
        ext, flags = 0, 0

        result = markdown(TEST_MD, fireworks=True)

        html.assert_called_with(TEST_MD, extensions=ext, render_flags=flags)
        self.assertIsInstance(result, Markup)
        self.assertEqual(result, misaka.html(TEST_MD,
            extensions=ext, render_flags=flags))
Ejemplo n.º 19
0
    def test_defined_and_undefined_options(self, html):
        ext, flags = 0, HTML_SMARTYPANTS

        result = markdown(TEST_MD, smartypants=True, stupidpants=False)

        html.assert_called_with(TEST_MD, extensions=ext, render_flags=flags)
        self.assertIsInstance(result, Markup)
        self.assertEqual(result, misaka.html(TEST_MD,
            extensions=ext, render_flags=flags))
Ejemplo n.º 20
0
    def test_two_render(self, html):
        ext, flags = 0, HTML_HARD_WRAP | HTML_SAFELINK

        result = markdown(TEST_MD, wrap=True, safelink=True)

        html.assert_called_with(TEST_MD, extensions=ext, render_flags=flags)
        self.assertIsInstance(result, Markup)
        self.assertEqual(result, misaka.html(TEST_MD,
            extensions=ext, render_flags=flags))
Ejemplo n.º 21
0
    def test_inverse(self, html):
        ext, flags = EXT_NO_INTRA_EMPHASIS, 0

        result = markdown(TEST_MD, intra_emphasis=False)

        html.assert_called_with(TEST_MD, extensions=ext, render_flags=flags)
        self.assertIsInstance(result, Markup)
        self.assertEqual(result, misaka.html(TEST_MD,
            extensions=ext, render_flags=flags))
Ejemplo n.º 22
0
    def test_one_ext_one_render(self, html):
        ext, flags = EXT_NO_INTRA_EMPHASIS, HTML_SKIP_HTML

        result = markdown(TEST_MD, no_intra_emphasis=True, no_html=True)

        html.assert_called_with(TEST_MD, extensions=ext, render_flags=flags)
        self.assertIsInstance(result, Markup)
        self.assertEqual(result, misaka.html(TEST_MD,
            extensions=ext, render_flags=flags))
Ejemplo n.º 23
0
    def test_one_ext(self, html):
        ext, flags = EXT_AUTOLINK, 0

        result = markdown(TEST_MD, autolink=True)

        html.assert_called_with(TEST_MD, extensions=ext, render_flags=flags)
        self.assertIsInstance(result, Markup)
        self.assertEqual(result, misaka.html(TEST_MD,
            extensions=ext, render_flags=flags))
Ejemplo n.º 24
0
    def test_one_render(self, html):
        ext, flags = 0, HTML_ESCAPE

        result = markdown(TEST_MD, escape=True)

        html.assert_called_with(TEST_MD, extensions=ext, render_flags=flags)
        self.assertIsInstance(result, Markup)
        self.assertEqual(result, misaka.html(TEST_MD,
            extensions=ext, render_flags=flags))
Ejemplo n.º 25
0
    def test_two_ext(self, html):
        ext, flags = EXT_FENCED_CODE | EXT_LAX_HTML_BLOCKS, 0

        result = markdown(TEST_MD, fenced_code=True, lax_html=True)

        html.assert_called_with(TEST_MD, extensions=ext, render_flags=flags)
        self.assertIsInstance(result, Markup)
        self.assertEqual(result, misaka.html(TEST_MD,
            extensions=ext, render_flags=flags))
Ejemplo n.º 26
0
 def get(self):
     with open(join(dirname(pybots.__file__), '../README.md')) as f:
         readme_md = '\n\r'.join(f.readlines()).replace('```json', '').replace('```', '').replace('{',
                                                                                                  "\t{").replace('}',
                                                                                                                 "\t}")
         readme_html = markdown(
             readme_md,
             autolink=True,
             disable_indented_code=False,
         )
         return render_template('index.html', readme_html=readme_html)
Ejemplo n.º 27
0
    def test_two_ext_two_render(self, html):
        ext = EXT_STRIKETHROUGH | EXT_SUPERSCRIPT
        flags = HTML_SKIP_LINKS | HTML_SKIP_STYLE

        result = markdown(TEST_MD, strikethrough=True, superscript=True,
            skip_links=True, no_style=True)

        html.assert_called_with(TEST_MD, extensions=ext, render_flags=flags)
        self.assertIsInstance(result, Markup)
        self.assertEqual(result, misaka.html(TEST_MD,
            extensions=ext, render_flags=flags))
Ejemplo n.º 28
0
 def get(self):
     with open(join(dirname(pybots.__file__), '../README.md')) as f:
         readme_md = '\n\r'.join(f.readlines()).replace(
             '```json',
             '').replace('```', '').replace('{', "\t{").replace('}', "\t}")
         readme_html = markdown(
             readme_md,
             autolink=True,
             disable_indented_code=False,
         )
         return render_template('index.html', readme_html=readme_html)
Ejemplo n.º 29
0
def make_blogposts():
    blogposts = []
    search_dir = "./blogposts/"
    files = filter(os.path.isfile, glob.glob(search_dir + "*.blog"))
    files.sort(key=lambda x: -1.0*os.path.getctime(x))
    for blogpost in files:
        with open(blogpost, "r") as myfile:
            data = Markup(markdown(myfile.read()))
            blogposts.append( {"text": data,
                               "mdate":datetime.utcfromtimestamp(os.path.getmtime(blogpost))})
    return blogposts
Ejemplo n.º 30
0
    def get_text(self):
        if hasattr(self, 'body'):
            text = self.body
        elif hasattr(self, 'description'):
            text = self.description
        else:
            text = self.summary

        if self.content_format == "markdown":
            return markdown(text)
        else:
            return text
Ejemplo n.º 31
0
    def _build(self, path):
        # TODO: Allow other file types
        if not path.endswith('.md'):
            raise ValueError('Skipping non-markdown file.')

        with open(path) as f:
            meta, content = self._parse_metadata(f.readlines())

        if datetime.now() < meta['date']:
            raise ValueError("Skipping until published")

        # TODO: Pass config[markdown] to the markdown parser
        return (meta, self._embed_templating(markdown(content), meta))
Ejemplo n.º 32
0
def read_tutorial(cat_id, page):
    tut = read_tutorial_page(cat_id, page)
    if tut==None:
        app.logger.info("No tutorial available for %s/%s" % (cat_id, str(page)))
        return None
    content = markdown(tut.text, fenced_code=True)

    # automatically add event handler for highlighting DOM elements
    tmp = re.findall('<em>(.*?)</em>', str(content))
    for t in tmp:
        if 'hl_' in t:
            text = t.split(' hl_')[0]
            idname = t.split(' hl_')[1]
            content = re.sub('<em>{} hl_{}</em>'.format(text, idname), '<em onmouseover="highlightElement(&#39;{0}&#39;, &#39;id&#39;, true)" onmouseout="highlightElement(&#39;{0}&#39;, &#39;id&#39;, false)">{1}</em>'.format(idname, text), str(content))
        elif 'hlc_' in t:
            text = t.split(' hlc_')[0]
            classname = t.split(' hlc_')[1]
            content = re.sub('<em>{} hlc_{}</em>'.format(text, classname), '<em onmouseover="highlightElement(&#39;{0}&#39;, &#39;class&#39;, true)" onmouseout="highlightElement(&#39;{0}&#39;, &#39;class&#39;, false)">{1}</em>'.format(classname, text), str(content))

    # automatically add "ask as query" links after code blocks
    content = re.sub('</code>(\s)?</pre>', "</code></pre><div class='show_code'><a href='#' class='show_code'>Ask as query</a></div>", str(content))
    content = Markup(content)
    # check whether there is another tutorial in this category
    nxt  = read_tutorial_page(cat_id, int(page)+1)
    prev = read_tutorial_page(cat_id, int(page)-1)
    
    out = {}
    out['this'] = {
        'cat_id': tut.cat_title,
        'page': tut.page,
        'title': tut.title,
        'text': content
    }
    if(nxt != None):
        out['next'] = {
            'cat_id': nxt.cat_id,
            'page': nxt.page,
            'title': nxt.title
        }
    if(prev != None):
        out['prev'] = {
            'cat_id': prev.cat_id,
            'page': prev.page,
            'title': prev.title
        }
    
    return out
Ejemplo n.º 33
0
def tutorials(cat_id='getting_started', page=1):
    session['video'] = 0

    error = ""
    # determine hostname/IP we are currently using
    # (needed for accessing container)
    host_url = urlparse(request.host_url).hostname
    container_name = 'tutorials'
    show_south_pane = False
    readonly = True
    authentication = False

    tut = read_tutorial_page(cat_id, page)
    content = markdown(tut.text, fenced_code=True)

    # automatically add event handler for highlighting DOM elements
    tmp = re.findall('<em>(.*?)</em>', str(content))
    for t in tmp:
        if 'hl_' in t:
            text = t.split(' hl_')[0]
            idname = t.split(' hl_')[1]
            content = re.sub(
                '<em>{} hl_{}</em>'.format(text, idname),
                '<em onmouseover="knowrob.highlight_element(&#39;{0}&#39;, &#39;id&#39;, true)" onmouseout="knowrob.highlight_element(&#39;{0}&#39;, &#39;id&#39;, false)">{1}</em>'
                .format(idname, text), str(content))
        elif 'hlc_' in t:
            text = t.split(' hlc_')[0]
            classname = t.split(' hlc_')[1]
            content = re.sub(
                '<em>{} hlc_{}</em>'.format(text, classname),
                '<em onmouseover="knowrob.highlight_element(&#39;{0}&#39;, &#39;class&#39;, true)" onmouseout="knowrob.highlight_element(&#39;{0}&#39;, &#39;class&#39;, false)">{1}</em>'
                .format(classname, text), str(content))

    # automatically add "ask as query" links after code blocks
    content = re.sub(
        '</code>(\s)?</pre>',
        "</code></pre><div class='show_code'><a href='#' class='show_code'>Ask as query</a></div>",
        str(content))
    content = Markup(content)

    # check whether there is another tutorial in this category
    nxt = read_tutorial_page(cat_id, int(page) + 1)
    prev = read_tutorial_page(cat_id, int(page) - 1)

    return render_template('knowrob_tutorial.html', **locals())
Ejemplo n.º 34
0
def get_tutorial_data():
    data = json.loads(request.data)

    # TODO: validate that tut_id is not a path
    tut_id = data['tutorial']
    tut_file = '/opt/webapp/webrob/tutorials/'+tut_id+'.md'

    # read tutorial md data
    page_data = ""
    with open(tut_file, 'r') as f:
        page_data = f.read()
    # convert to HTML
    page_data = Markup(markdown(page_data, fenced_code=True))
    # split into pages at <h2> tags
    pages = page_data.split('<h2>')[1:]
    pages = map(lambda p: p.split('</h2>'), pages)

    return jsonify({'pages': pages})
Ejemplo n.º 35
0
def tutorials(cat_id='getting_started', page=1):
    # determine hostname/IP we are currently using
    # (needed for accessing container)
    host_url = urlparse(request.host_url).hostname
    container_name = 'tutorials'
    show_south_pane = True

    tut = read_tutorial_page(cat_id, page)
    content = markdown(tut['text'], fenced_code=True)

    # automatically add "ask as query" links after code blocks
    content = re.sub('</code>(\s)?</pre>', "</code></pre><div class='show_code'><a href='#' class='show_code'>Ask as query</a></div>", str(content))
    content = Markup(content)

    # check whether there is another tutorial in this category
    nxt  = read_tutorial_page(cat_id, int(page)+1)
    prev = read_tutorial_page(cat_id, int(page)-1)

    return render_template('knowrob_tutorial.html', **locals())
Ejemplo n.º 36
0
def get_task_():
    data = json.loads(request.data)
    exercise_id = data['exercise_id']
    task_number = data['task_number']

    task = get_task(exercise_id, task_number)
    if task is None:
        return jsonify(None)
    content = markdown(task.text, fenced_code=True)

    # automatically add "ask as query" links after code blocks
    content = re.sub(
        '</code>(\s)?</pre>',
        "</code></pre><div class='show_code'><a href='#' class='show_code'>Ask as query</a></div>",
        str(content))
    content = Markup(content)
    # check whether there is another task in this exercise
    nxt = get_task(exercise_id, task_number + 1)
    prev = get_task(exercise_id, task_number - 1)

    out = dict()
    out['this'] = {
        'exercise_id': task.exercise_id,
        'number': task.number,
        'title': task.title,
        'text': content
    }
    if nxt is not None:
        out['next'] = {
            'exercise_id': nxt.exercise_id,
            'number': nxt.number,
            'title': nxt.title
        }
    if prev is not None:
        out['prev'] = {
            'exercise_id': prev.exercise_id,
            'number': prev.number,
            'title': prev.title
        }

    return jsonify(out)
Ejemplo n.º 37
0
def tutorials(cat_id='getting_started', page=1):
    # determine hostname/IP we are currently using
    # (needed for accessing container)
    host_url = urlparse(request.host_url).hostname
    container_name = 'tutorials'
    show_south_pane = True

    tut = read_tutorial_page(cat_id, page)
    content = markdown(tut['text'], fenced_code=True)

    # automatically add "ask as query" links after code blocks
    content = re.sub(
        '</code>(\s)?</pre>',
        "</code></pre><div class='show_code'><a href='#' class='show_code'>Ask as query</a></div>",
        str(content))
    content = Markup(content)

    # check whether there is another tutorial in this category
    nxt = read_tutorial_page(cat_id, int(page) + 1)
    prev = read_tutorial_page(cat_id, int(page) - 1)

    return render_template('knowrob_tutorial.html', **locals())
Ejemplo n.º 38
0
def tutorials(cat_id='getting_started', page=1):
    session['video'] = 0
    #if not ensure_application_started('knowrob/hydro-knowrob-daemon'):
    #    return redirect(url_for('user.logout'))
    
    error=""
    # determine hostname/IP we are currently using
    # (needed for accessing container)
    host_url = urlparse(request.host_url).hostname
    container_name = 'tutorials'
    show_south_pane = False
    readonly = True
    authentication = False

    tut = read_tutorial_page(cat_id, page)
    content = markdown(tut.text, fenced_code=True)

    # automatically add event handler for highlighting DOM elements
    tmp = re.findall('<em>(.*?)</em>', str(content))
    for t in tmp:
        if 'hl_' in t:
            text = t.split(' hl_')[0]
            idname = t.split(' hl_')[1]
            content = re.sub('<em>{} hl_{}</em>'.format(text, idname), '<em onmouseover="knowrob.highlight_element(&#39;{0}&#39;, &#39;id&#39;, true)" onmouseout="knowrob.highlight_element(&#39;{0}&#39;, &#39;id&#39;, false)">{1}</em>'.format(idname, text), str(content))
        elif 'hlc_' in t:
            text = t.split(' hlc_')[0]
            classname = t.split(' hlc_')[1]
            content = re.sub('<em>{} hlc_{}</em>'.format(text, classname), '<em onmouseover="knowrob.highlight_element(&#39;{0}&#39;, &#39;class&#39;, true)" onmouseout="knowrob.highlight_element(&#39;{0}&#39;, &#39;class&#39;, false)">{1}</em>'.format(classname, text), str(content))

    # automatically add "ask as query" links after code blocks
    content = re.sub('</code>(\s)?</pre>', "</code></pre><div class='show_code'><a href='#' class='show_code'>Ask as query</a></div>", str(content))
    content = Markup(content)

    # check whether there is another tutorial in this category
    nxt  = read_tutorial_page(cat_id, int(page)+1)
    prev = read_tutorial_page(cat_id, int(page)-1)

    return render_template('knowrob_tutorial.html', **locals())
Ejemplo n.º 39
0
def get_task_():
    data = json.loads(request.data)
    exercise_id = data['exercise_id']
    task_number = data['task_number']
    
    task = get_task(exercise_id, task_number)
    if task==None: return jsonify(None)
    content = markdown(task.text, fenced_code=True)
    
    # automatically add "ask as query" links after code blocks
    content = re.sub('</code>(\s)?</pre>', "</code></pre><div class='show_code'><a href='#' class='show_code'>Ask as query</a></div>", str(content))
    content = Markup(content)
    # check whether there is another task in this exercise
    nxt  = get_task(exercise_id, task_number+1)
    prev = get_task(exercise_id, task_number-1)
    
    out = {}
    out['this'] = {
        'exercise_id': task.exercise_id,
        'number': task.number,
        'title': task.title,
        'text': content
    }
    if(nxt != None):
        out['next'] = {
            'exercise_id': nxt.exercise_id,
            'number': nxt.number,
            'title': nxt.title
        }
    if(prev != None):
        out['prev'] = {
            'exercise_id': prev.exercise_id,
            'number': prev.number,
            'title': prev.title
        }
    
    return jsonify(out)
Ejemplo n.º 40
0
def build_feed():
    feed = AtomFeed(SITE_NAME,
                    feed_url=DOMAIN + 'rss.xml',
                    url=DOMAIN,
                    subtitle=SUBTITLE,
                    author=AUTHOR,
                    updated=datetime.datetime.now())

    entries = Entry.get_all_published()

    for _entry in entries:
        time = datetime.datetime.strptime(_entry['date'], '%Y-%m-%d %H:%M:%S')

        feed.add(unicode(_entry['title']),
                 unicode(markdown(_entry['content'])),
                 content_type='html',
                 author=AUTHOR,
                 published=time,
                 updated=time,
                 id=DOMAIN + _entry['slug'] + '/',
                 url=DOMAIN + 'posts/' + _entry['slug'] + '/')

    with codecs.open('./ghpages/rss.xml', 'w', 'utf-8-sig') as f:
        f.write(feed.to_string())
Ejemplo n.º 41
0
def show_entry(id):
    entry = Entry.get(id)
    entry['content'] = markdown(entry['content'])

    return render_template('entry.html', **locals())
Ejemplo n.º 42
0
 def get_text(self):
     if self.content_format == "markdown":
         return markdown(self.description)
     else:
         return self.description