def run_convert_to_html():
    for md_file_path, save_file_path in get_open_save_file_paths():
        with open(md_file_path, 'r') as f:
            html = render_content(f.read())

        html = html.replace('<pre><code>', '<pre>')
        html = html.replace('</code></pre>', '</pre>')
        html = html[html.find('<body>')+len('<body>'):] # chop off the generated header
        html = html[:html.rfind('</body>')] # chop off </body></html>

        head = header
        if 'func_groups' in save_file_path:
            head = head.replace('"index.html"', '"../index.html"')
            head = head.replace('"doc_index.html"', '"../doc_index.html"')
            head = head.replace('"stylesheets/', '"../stylesheets/')

        lines = html.split('\n')
        for i, line in enumerate(lines):
            if 'FLOAT_RIGHT' in line:
                line = line.replace('FLOAT_RIGHT', '')
                lines[i] = line.replace('<a ', '<a class="float-right" ')
        html = ''.join([head, '\n'.join(lines), footer])

        with open(save_file_path, 'w') as f:
            f.write(html)
Example #2
0
def run_convert_to_html():
    for md_file_path, save_file_path in get_open_save_file_paths():
        with open(md_file_path, 'r') as f:
            html = render_content(f.read())

        html = html.replace('<pre><code>', '<pre>')
        html = html.replace('</code></pre>', '</pre>')
        html = html[html.find('<body>') +
                    len('<body>'):]  # chop off the generated header
        html = html[:html.rfind('</body>')]  # chop off </body></html>

        head = header
        if 'func_groups' in save_file_path:
            head = head.replace('"index.html"', '"../index.html"')
            head = head.replace('"doc_index.html"', '"../doc_index.html"')
            head = head.replace('"stylesheets/', '"../stylesheets/')

        lines = html.split('\n')
        for i, line in enumerate(lines):
            if 'FLOAT_RIGHT' in line:
                line = line.replace('FLOAT_RIGHT', '')
                lines[i] = line.replace('<a ', '<a class="float-right" ')
        html = ''.join([head, '\n'.join(lines), footer])

        with open(save_file_path, 'w') as f:
            f.write(html)
Example #3
0
 def hack_markdown(self, content):
     content = unicode(content, 'utf-8')
     return (
         "<html><head><style type=\"text/css\">" +
         open("markdown.css").read() +
         "</style></head>" +
         grip.render_content(content) +
         "</body></html>"
     )
Example #4
0
    def list_directory(self, path):
        """Helper to produce a directory listing (absent index.html).

        Return value is either a file object, or None (indicating an
        error).  In either case, the headers are sent, making the
        interface the same as for send_head().

        """
        try:
            list = os.listdir(path)
        except os.error:
            self.send_error(404, "No permission to list directory")
            return None
        list.sort(key=lambda a: a.lower())
        f = StringIO()
        displaypath = cgi.escape(urllib.unquote(self.path))
        f.write('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">')
        f.write("<html>\n<head>\n<title>Directory listing for %s</title>\n"
                % displaypath)
        f.write("<style type=\"text/css\">" +
            open("markdown.css").read() +
            "</style></head>"
        )
        f.write("<body>\n<h2>Directory listing for %s</h2>\n" % displaypath)
        f.write("<hr>\n<ul>\n")
        for name in list:
            fullname = os.path.join(path, name)
            displayname = linkname = name
            # Append / for directories or @ for symbolic links
            if os.path.isdir(fullname):
                if name == ".git":
                    continue
                displayname = name + "/"
                linkname = name + "/"
            if os.path.islink(fullname):
                displayname = name + "@"
                # Note: a link to a directory displays with @ and links with /
            f.write('<li><a href="%s">%s</a>\n'
                    % (urllib.quote(linkname), cgi.escape(displayname)))
        f.write("</ul>\n<hr>\n")
        fname = path + '/README.md'
        if os.path.isdir(path) and os.path.isfile(fname):
            f.write(grip.render_content(unicode(open(fname).read())))
        f.write("</body>\n</html>\n")
        length = f.tell()
        f.seek(0)
        self.send_response(200)
        encoding = sys.getfilesystemencoding()
        self.send_header("Content-type", "text/html; charset=%s" % encoding)
        self.send_header("Content-Length", str(length))
        self.end_headers()
        return f
Example #5
0
    def write_problem_page(problem, results, template):
        out_filename = p.join(config.problem_html_dir, problem.id + '.html')
        submissions = results.bots
        add_youtube_embed(submissions)
        add_ride_description(submissions)
        add_closest_vehicle_display(submissions)
        if blconfig.is_test:
            readme = 'Skipped readme gen in test, record it to avoid 403s.'
        else:
            readme = ''
            tries = 0
            while not readme and tries < 5:
                try:
                    readme = grip.render_content(problem.readme,
                                                 username='******',
                                                 password=blconfig.github_token)
                except Exception as e:
                    log.error('Grip render call failed, retrying in 10 seconds')
                    time.sleep(10)
                tries += 1
            if not readme:
                log.error('Could not render new readme via github api, '
                          'skipping')
                # TODO: Use offline renderer when it works
                # readme = grip.render_content(problem.readme,
                #                              render_offline=True)

        problem_video = ''
        if 'youtube' in problem.definition:
            problem_video = get_youtube_embed_url(problem.definition['youtube'])
        write_template(out_filename, template, data=dict(
            # problem_domain=problem.definition['display_name'],
            problem_name=problem.definition['display_name'],
            problem_readme=readme,
            problem_video=problem_video,
            submissions=submissions))
Example #6
0
import os
from grip import render_content

# Compile markdown to html (this could exceed the github api rate limits)
for m in range(3,4):
	month = '0' + str(m) if m < 10 else str(m)
	days = os.listdir('months/' + month + '/')
	for day in days:
		from_path = 'months/' + month + '/' + day
		to_path = 'html/' + month + '-' + day[0:2] + '.html'
		print 'Converting ' + from_path + ' to ' + to_path + '...'

		html_output = render_content(open(from_path).read(), gfm = True)
		open(to_path, 'w').write(html_output.encode('utf-8'))
Example #7
0
 def on_changed_body(target, value, oldvalue, initiator):
     target.body_html = render_content(value)