Example #1
0
	def GET(self,page):
		cwd = os.getcwd()
		if page == '':
			# Main api docs page
			htmldoc = markdown2.markdown_path(cwd+'/templates/main.md')
			return templates.docs(htmldoc)
		else:
			# Politician api docs page
			htmldoc = markdown2.markdown_path(cwd+'/templates/'+page+'.md')
			return templates.docs(htmldoc)
Example #2
0
def load_pagefile(name):
    if os.path.isdir(flatfiles_path + name):
        flatfiles = os.listdir(flatfiles_path + name)
        if 'index' in flatfiles:
            return markdown2.markdown_path(flatfiles_path + name + '/index')
        else:
            return False
    else:
        if os.path.isfile(flatfiles_path + name):
            return markdown2.markdown_path(flatfiles_path + name)
        else:
            return False
Example #3
0
def load_pagefile(name):
	if os.path.isdir(flatfiles_path+name):
		flatfiles = os.listdir(flatfiles_path+name)
		if 'index' in flatfiles:
			return markdown2.markdown_path(flatfiles_path+name+'/index')
		else:
			return False
	else:
		if os.path.isfile(flatfiles_path+name):
			return markdown2.markdown_path(flatfiles_path+name)
		else:
			return False
Example #4
0
    def get_body_html(self):
        obs_sq_html = f'''
<section id="{self.lang_code}-obs-sq">
    <div class="resource-title-page">
        <img src="{self.resources['obs-sq'].logo_url}" class="logo" alt="OBS">
        <h1 class="section-header">{self.simple_title}</h1>
    </div>
'''
        files = sorted(glob(os.path.join(self.main_resource.repo_dir, 'content', '*.md')))
        for file in files:
            chapter_num = os.path.splitext(os.path.basename(file))[0]
            chapter_html = markdown2.markdown_path(file)
            chapter_html = html_tools.increment_headers(chapter_html)
            soup = BeautifulSoup(chapter_html, 'html.parser')
            headers = soup.find_all(re.compile(r'^h\d'))
            top_header = headers[0]
            title = top_header.text
            header_count = 1
            for header in headers:
                header['class'] = 'section-header'
                header['id'] = f'{self.lang_code}-obs-sq-{chapter_num}-{header_count}'
                header_count += 1
            # HANDLE OBS SQ RC CHAPTER LINKS
            obs_sq_rc_link = f'rc://{self.lang_code}/obs-sq/help/{chapter_num}'
            obs_sq_rc = self.add_rc(obs_sq_rc_link, title=title, article=chapter_html)
            chapter_data = obs_tools.get_obs_chapter_data(self.resources['obs'].repo_dir, chapter_num)
            if len(chapter_data['frames']):
                frames_html = '<div class="obs-frames">\n'
                for idx, frame in enumerate(chapter_data['frames']):
                    frame_num = str(idx+1).zfill(2)
                    frame_title = f'{chapter_num}:{frame_num}'
                    # HANDLE FRAME RC LINKS FOR OBS
                    frame_rc_link = f'rc://{self.lang_code}/obs/book/obs/{chapter_num}/{frame_num}'
                    frame_rc = self.add_rc(frame_rc_link, title=frame_title)
                    frames_html += f'''
    <div id={frame_rc.article_id} class="obs-frame">
        <div class="obs-frame-title">
            {frame_title}
        </div>
        <div class="obs-frame-text">
            {frame['text']}
        </div>
    </div>
'''
                frames_html += '</div>\n'
                top_header.insert_after(BeautifulSoup(frames_html, 'html.parser'))
                bible_reference_html = f'''
    <div class="bible-reference">
        {chapter_data['bible_reference']}
    </div>
'''
                top_header.insert_after(BeautifulSoup(bible_reference_html, 'html.parser'))

            article_html = f'''
    <article id="{obs_sq_rc.article_id}">
        {str(soup)}
    </article>
'''
            obs_sq_html += article_html
        return obs_sq_html
Example #5
0
def main():
    parser = argparse.ArgumentParser( \
        formatter_class=argparse.RawDescriptionHelpFormatter, \
        description='Generate a performance report (EXPERIMENTAL) \n\n{}'.format(PREREQUISITE))
    parser.add_argument('--report_dir', metavar='DIR', required=True, \
        help='a figures directory')
    parser.add_argument('--release', required=True, help='e.g. 0.00')
    parser.add_argument('--test_date', required=True, help='e.g. December 2020')
    args = vars(parser.parse_args())

    # convert content parts from markdown to HTML
    contents = {}
    for name in CONTENTS:
        if not os.path.isfile(f'{SEARCHPATH}/{name}.md'):
            contents[name] = f'<i>no {SEARCHPATH}/{name}.md</i><br/>'
            continue
        contents[name] = markdown2.markdown_path(f'{SEARCHPATH}/{name}.md', \
                extras=['tables'])

    # replace the variables with appropriate values
    for name, var_names in CONTENTS_VARIABLES.items():
        tmpl = Template(contents[name])
        # get variable values from either args or contents
        tmpl_vars = {k: args.get(k, contents.get(k, 'no data')) for k in var_names}
        contents[name] = tmpl.render(tmpl_vars)

    # render the report with the complete layout
    env = Environment(loader=FileSystemLoader(SEARCHPATH))
    layout_tmpl = env.get_template('layout.html')
    report = layout_tmpl.render(contents)

    # prepare output file and write the result
    output_file = os.path.join(args['report_dir'], 'report.html')
    with open(output_file, 'w') as f:
        f.write(report)
Example #6
0
    def render_file(self, pdf: PDF, filename, blank=False):
        '''
            Renders a file to a pdf. Does not start a fresh page.
            Pads out the pages with blank pages if the file does not exist
        '''
        path = self.files.get(filename, False)
        start = pdf.page_no()
        render_part_header(pdf, filename)

        if path:
            start = pdf.page_no()
            ext = os.path.splitext(path)[1][1:]
            font = get_cfg('font', 'code') if ext in get_cfg(
                'files', 'code') else get_cfg('font', 'body')
            pdf.set_font(font['font'], size=font['size'])
            if blank:
                pdf.cell(lineWidth, txt="This is a sample student answer.")
            elif ext in get_cfg('files', 'md'):
                pdf.write_html(to_latin1(markdown2.markdown_path(path)))
            elif ext in get_cfg('files', 'pics'):
                pdf.image(path, w=lineWidth)
            else:
                for line in open(path, 'r'):
                    pdf.multi_cell(lineWidth, lineHeight, txt=to_latin1(line))
        self.pad_from(pdf, start, filename)
Example #7
0
def getrecents(path):
    files = [path + f for f in os.listdir(blog) if f not in ["_index.md", "feed.xml"]]
    files.sort(
        key=lambda f: markdown_path(f, extras=["metadata"]).metadata["date"],
        reverse=True,
    )
    return files
Example #8
0
def convert_mds(source, target, link, yaml):
    listing = os.listdir(source)
    for infile in listing:
	if infile[0] != '.':
	    filepath = os.path.join(source, infile)
	    filename, fileext = os.path.splitext(infile)
	    
	    outfilepath = os.path.join(target, "{}.html".format(filename))
	    outlink =  os.path.join(link, "{}.html".format(filename))
	    outfile = open(outfilepath, 'w')
	    output = markdown_path(filepath, extras=['metadata', 'fenced-code-blocks', 'tables'])
	    
	    if yaml:
		gather_metadata(output.metadata, outlink)
		content = '''
{{% extends "base.html" %}}
{{% block content %}}
<span class="label label-primary">{}</span>
<span class="label label-info">{}</span>
{}
{{% endblock %}}
'''.format(output.metadata['date'], output.metadata['tag'], output)

	    else:			
		content = '''
{{% extends "base.html" %}}
{{% block content %}}
{}
{{% endblock %}}
'''.format(output)
	    outfile.write(content)
	    outfile.close()
Example #9
0
def convert_to_html():
    PATH = 'templates/news/content/'
    dirs = os.listdir(PATH)
    news = []
    for arq in dirs:
        news.append(markdown.markdown_path(PATH + arq))
    return news
Example #10
0
def convert_mds(source):
    listing = os.listdir(source)
    for infile in listing:
        if infile[0] != '.':
            if infile[0] == 'index.md':
                create_index()
            else:
                filepath = os.path.join(source, infile)
                filename, fileext = os.path.splitext(infile)

                directory = filename
                if not os.path.exists(directory):
                    os.makedirs(os.path.join(directory, 'templates'))
                shutil.copy(os.path.join('.', 'templates', 'base.html'),
                            os.path.join(directory, 'templates'))
                outfilepath = os.path.join('.', directory, 'templates',
                                           'index.html')
                outlink = os.path.join('.', directory)
                outfile = open(outfilepath, 'w')
                output = markdown_path(
                    filepath,
                    extras=['metadata', 'fenced-code-blocks', 'tables'])

                content = '''
    {{% extends "base.html" %}}
    {{% block content %}}
    {}
    {{% endblock %}}
    '''.format(output)
                outfile.write(content)
                outfile.close()
def m_t_h(input_file, output_directory, titre):

    ifile = input_file
    path, filename = os.path.split(ifile)
    file_name, file_extension = os.path.splitext(filename)
    link_patterns = [(
        re.compile(
            r"((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+(:[0-9]+)?|(?:www\.|[\-;:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+~%\/\.\w\-_]*)?\??(?:[\-\+=&;%@\.\w_]*)#?(?:[\.\!\/\\\w]*))?)"
        ),
        r"\1",
    )]

    odir = output_directory
    if os.path.exists(odir) == False:
        os.mkdir(odir)
        pass
    else:
        pass

    html_head = (
        '<!DOCTYPE html>\n<html>\n<head>\n<meta charset="UTF-8">\n<title>' +
        titre + "</title>\n</head>\n<body>\n")
    html_foot = "</body>\n</html>"
    md_conv = markdown2.markdown_path(ifile,
                                      extras=["link-patterns"],
                                      link_patterns=link_patterns)
    html = html_head + md_conv + html_foot

    f = open("{}{}.html".format(odir, file_name), "w+",
             encoding="utf-8").write(html)
Example #12
0
def md_to_html(ifile,ofile):
    tpl=u'''
    <html>
	<head>
	    <meta charset="utf-8">
	    <meta name="viewport" content="width=device-width">
            <link rel="stylesheet" href="./{css}">
            <link rel="stylesheet" href="./{code_css}">
            <title>{title}</title>
	</head>
	<body class="publisher">
            <div class="container">
                <article id="preview-contents">
	        {body} 
                </article>
            </div>
	</body>
    </html>
    '''
    css='agroup.css'
    code_css='github.css'
    title=''
    reg=re.compile(r'^#\s*([^#]+)')
    m=reg.search(file(ifile,'r').read())
    if m:
        title=m.group(1).decode('utf8')
    body=markdown2.markdown_path(ifile,extras=[
        "fenced-code-blocks",
        "tables",
        "toc",
    ])
    html=tpl.format(**locals())
    file(ofile,'w').write(html.encode('utf8'))
Example #13
0
def generate_help():
    output = """
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <style type="text/css">
"""
    with open('app/static/markdown.css', 'r') as f:
        output += f.read()

    output += """
</style>
</head>

<body>
"""
    output += mod_wsgi.process_group
    output += markdown2.markdown_path('README.md', extras=["code-color", "tables", "fenced-code-blocks"])
    output += """
</body>

</html>
"""
    return output
Example #14
0
def item(category, item_slug):
    """
    A single specific item.

    """

    try:
        path = category + '/' + item_slug + '.md'
        html = markdown2.markdown_path(path, extras=["metadata"])

        metadata = html.metadata
        if 'template' in metadata.keys():
            template = metadata['template']
        else:
            template = 'templates/item.html'

        render_data = metadata.copy()
        render_data[u'body'] = html
        render_data[u'category'] = category
        render_data[u'item_slug'] = item_slug

        rendered = jenv.get_template(template).render(render_data)
        return rendered

    except IOError as e:
        return render_template('404.html'), 404
Example #15
0
def convert_md_2_pdf(filepath, output=None, theme=None, codecss=None):
    BASE_DIR = os.path.abspath(os.path.dirname(__file__))
    html = markdown_path(filepath, extras=["code-friendly", "fenced-code-blocks"])
    css_file_list = []
    if output and os.path.isdir(output):
        output = os.path.join(output, '.'.join([os.path.basename(filepath).rsplit('.', 1)[0], 'pdf']))
    elif output is None:
        output = '.'.join([filepath.rsplit('.', 1)[0], 'pdf'])
    if theme is not None:
        css_file = theme
        if not os.path.exists(css_file):
            css_file = os.path.join(BASE_DIR, 'themes/'+theme+'.css')
        print 'theme_css:', css_file
        css_file_list.append(css_file)
        # HTML(string=html).write_pdf(output, stylesheets=[css_file])
    
    if codecss is not None:
        css_file = codecss
        if not os.path.exists(css_file):
            css_file = os.path.join(BASE_DIR, 'pygments-css/'+codecss+'.css')
        print 'code_css:', css_file
        css_file_list.append(css_file)

    print 'output file:', output
    if css_file_list:
        HTML(string=html).write_pdf(output, stylesheets=css_file_list)
    else:
        HTML(string=html).write_pdf(output)
Example #16
0
def generate_index():
    files = [f for f in listdir(path) if isfile(join(path, f))]
    files = sorted(files, reverse=True)
    files.remove('index.md')

    titles = []
    for f in files:
        f = f.replace(".md", "")
        titles.append(f[7:])
    
    posts = zip(files, titles)

    def print_ul(elements):
        html = '<h2>Artikelen</h2>\n<ul>\n'
        for link, title in elements:
            html = html + "<li><a href=\"" + title.lower() + ".html\">" + str(title) + "</a></li>\n"
        html = html + "</ul>\n"
        return html

    blogposts = print_ul(posts)
    

    html = markdown2.markdown_path('posts/index.md')

    with open('header.html', 'r') as file:
        header = file.read()

    with open('footer.html', 'r') as file:
        footer = file.read()

    f = open( 'index.html', 'w' )
    f.write(header + '\n' + html + '\n' + blogposts + '\n' + footer)
    f.close()
Example #17
0
def md2pdf(pdf_file_path, md_content=None, md_file_path=None,
           css_file_path=None, base_url=None):
    """
    Convert markdown file to pdf with styles
    """

    # Convert markdown to html
    raw_html = ""
    extras = ["cuddled-lists"]
    if md_file_path:
        raw_html = markdown_path(md_file_path, extras=extras)
    elif md_content:
        raw_html = markdown(md_content, extras=extras)

    if not len(raw_html):
        raise ValidationError('Input markdown seems empty')

    # Weasyprint HTML object
    html = HTML(string=raw_html, base_url=base_url)

    # Get styles
    css = []
    if css_file_path:
        css.append(CSS(filename=css_file_path))

    # Generate PDF
    html.write_pdf(pdf_file_path, stylesheets=css)

    return
def get_obs_chapter_data(obs_dir, chapter_num):
    obs_chapter_data = {'title': None, 'frames': [], 'bible_reference': None}
    obs_chapter_file = os.path.join(obs_dir, 'content', f'{chapter_num}.md')
    if os.path.isfile(obs_chapter_file):
        soup = BeautifulSoup(
            markdown2.markdown_path(
                os.path.join(obs_dir, 'content', f'{chapter_num}.md')),
            'html.parser')
        obs_chapter_data['title'] = soup.h1.text
        paragraphs = soup.find_all('p')
        frame = {'image': '', 'text': ''}
        for idx, p in enumerate(paragraphs):
            if p.img:
                src = p.img['src'].split('?')[0]
                if frame['image']:
                    obs_chapter_data['frames'].append(frame)
                    frame = {'image': '', 'text': ''}
                frame['image'] = src
                p.img.extract()
            if p.text:
                if idx == len(paragraphs) - 1 and frame['text']:
                    obs_chapter_data['bible_reference'] = p.text
                else:
                    frame['text'] += str(p)
        if frame['image']:
            obs_chapter_data['frames'].append(frame)
    return obs_chapter_data
Example #19
0
async def docs(doc):
    async with asyncio.Lock():
        markdown = markdown2.markdown_path(f'docs/{doc.lower()}.md')

    return await render_template('doc.html',
                                 doc=markdown,
                                 doc_title=doc.lower().capitalize())
Example #20
0
def md2pdf(pdf_file_path,
           md_content=None,
           md_file_path=None,
           css_file_path=None,
           base_url=None):
    """
    Convert markdown file to pdf with styles
    """

    # Convert markdown to html
    raw_html = ""
    extras = ["cuddled-lists"]
    if md_file_path:
        raw_html = markdown_path(md_file_path, extras=extras)
    elif md_content:
        raw_html = markdown(md_content, extras=extras)

    if not len(raw_html):
        raise ValidationError('Input markdown seems empty')

    # Weasyprint HTML object
    html = HTML(string=raw_html, base_url=base_url)

    # Get styles
    css = []
    if css_file_path:
        css.append(CSS(filename=css_file_path))

    # Generate PDF
    html.write_pdf(pdf_file_path, stylesheets=css)

    return
Example #21
0
def index():
    """
    The landing page.
    """

    try:
        html = markdown2.markdown_path(BASE_DIR + '/index.md', extras=["metadata"])

        items = []

        # Find the folders (categories) in the folder sites
        for dirname in os.listdir(SITES_DIR):
            items.append(dirname)

        metadata = html.metadata
        if 'template' in metadata.keys():
            template = metadata['template']
        else:
            template = 'templates/index.html'

        render_data = metadata.copy()
        render_data[u'body'] = html
        render_data[u'items'] = items

        rendered = jenv.get_template(template).render(render_data)
        return rendered

    except IOError as e:
        print(e)
        return render_template('404.html'), 404
Example #22
0
def help_page(page_slug='_index'):
    if page_slug not in app.config['HELP_PAGES'].keys():
        abort(404)
    html = markdown2.markdown_path(
        os.path.join(app.config['HELP_DIR'], page_slug + '.md'),
        extras=["metadata", "fenced-code-blocks", "tables"])
    return render_template('help.html', help_html=html, page_slug=page_slug)
Example #23
0
def populateWords():
    for category in twOrder:
        terms[category] = {}
        dir = os.path.join(twRoot, 'content', category)
        files = glob(os.path.join(dir, '*.md'))
        ta_links = re.compile(
            '"https://git.door43.org/Door43/(en-ta-([^\/"]+?)-([^\/"]+?))/src/master/content/([^\/"]+?).md"')
        for f in files:
            term = os.path.splitext(os.path.basename(f))[0]
            content = markdown2.markdown_path(f)
            content = u'<div id="{0}-{1}" class="word">'.format(category, term)+content+u'</div>'
            parts = ta_links.split(content)
            if len(parts) == 6 and parts[1] in taManualUrls:
                content = parts[0]+'"{0}/{1}#{2}_{3}_{4}"'.format(taUrl, taManualUrls[parts[1]], parts[3], parts[2], parts[4])+parts[5]
            content = re.sub(r'href="\.\.\/([^\/"]+)\/([^"]+)\.md"', r'href="#\1-\2"', content)
            soup = BeautifulSoup(content)
            if soup.h1:
                title = soup.h1.text
            else:
                title = term
                print title
            for i in reversed(range(1, 4)):
                for h in soup.select('h{0}'.format(i)):
                    h.name = 'h{0}'.format(i+1)
            content = str(soup.div)
            word = TwTerm(term, title, content)
            terms[category][term] = word
def generate_report():
    df_final = predictionsPerSecond()
    explode = (0.1, 0.1, 0.1)
    plt.pie(df_final.Label.value_counts(),
            explode=explode,
            labels=df_final.Label.value_counts().index.to_list(),
            autopct='%1.1f%%',
            shadow=True,
            startangle=90)
    plt.title('Tiempo de uso de mascarilla')
    plt.savefig('predictions.png')
    mdFile = MdUtils(
        file_name='report',
        title='Reporte de predicción de uso correcto de mascarilla')
    mdFile.new_line(
        mdFile.new_inline_image(text='Predicciones', path='predictions.png'))
    mdFile.new_header(title='Tablas de resultados', level=1)
    mdFile.new_line('Juan Pablo Carranza Hurtado')
    mdFile.new_line('José Alberto Ligorría Taracena')
    mdFile.create_md_file()
    f = open("report.html", "w")
    f.write(markdown2.markdown_path('report.md'))
    f.write(pd.crosstab(df_final.Time, df_final.Label).to_html())
    f.write('<h1> Cantidad de segundos de utilización de mascarilla </h1>')
    f.write(pd.DataFrame(df_final.Label.value_counts()).to_html())
    f.close()
Example #25
0
def main():
    parser = argparse.ArgumentParser( \
        formatter_class=argparse.RawDescriptionHelpFormatter, \
        description='Generate a performance report (EXPERIMENTAL) \n\n{}'.format(PREREQUISITE))
    parser.add_argument('--report_dir', metavar='DIR', required=True, \
        help='a figures directory')
    parser.add_argument('--release', required=True, help='e.g. 0.00')
    args = parser.parse_args()

    # convert the report to HTML
    content_tmpl_in = markdown2.markdown_path(f'{SEARCHPATH}/report.md', \
        extras=['tables'])

    # render the report body
    content_tmpl = Template(content_tmpl_in)
    tmpl_vars = {'release': args.release}
    content = content_tmpl.render(tmpl_vars)

    # render the report with the complete layout
    env = Environment(loader=FileSystemLoader(SEARCHPATH))
    layout_tmpl = env.get_template('layout.html')
    tmpl_vars = {'report': content}
    report = layout_tmpl.render(tmpl_vars)

    # prepare output file and write the result
    output_file = os.path.join(args.report_dir, 'report.html')
    with open(output_file, 'w') as f:
        f.write(report)
Example #26
0
def category(category='posts'):
    """
    This is the list of posts that are shown in '/'
    """
    try:
        # Get the markdown files in 'posts' directory
        items = []

        for filename in os.listdir(category):
            if 'index.md' in filename:
                continue
            if filename[-3:] == '.py':
                continue

            item = markdown2.markdown_path('{0}/{1}'.format(category,
                                           filename), extras=['metadata'])
            item.metadata['slug'] = filename.split('/')[-1].replace('.md', '')

            items.append(item)

        # Display list of posts in '/'
        template = 'templates/category.html'
        render_data = {}
        render_data[u'title'] = 'Jack of All Trades, Master of None'
        render_data[u'category'] = category
        render_data[u'items'] = sorted(items, key=lambda item: parse(
                                       item.metadata.get('date_created', '')),
                                       reverse=True)

        rendered = jenv.get_template(template).render(render_data)

        return rendered
    except IOError as e:
        print(e)
        return render_template('404.html'), 404
Example #27
0
    def get_context_data(self, *args, **kwargs):
        context = super(RepoDetailView, self).get_context_data(*args, **kwargs)
        repo_full_name = "{}/{}".format(
                self.object.owner_name,
                self.object.repo_name)

        repo = github_api.get_repo(repo_full_name)
        encod_readme = repo.get_readme().content

        readme = base64.b64decode(encod_readme)

        directory = MEDIA_ROOT
        if not os.path.exists(directory):
            os.makedirs(directory)

        f = open('{}/{}.md'.format(directory, self.object.repo_name), 'wb+')
        f.write(readme)
        f.close()

        test = markdown2.markdown_path(
                '{}/{}.md'.format(MEDIA_ROOT, self.object.repo_name),
                extras=[
                    "fenced-code-blocks",
                    "code-friendly",
                    "pyshell",
                    "pygments",
                    ])

        context['readme'] = test

        return context
Example #28
0
def help_page(page_slug='_index'):
    if page_slug not in app.config['HELP_PAGES'].keys():
        abort(404)
    html = markdown2.markdown_path(
        os.path.join(app.config['HELP_DIR'], page_slug + '.md'),
        extras=["metadata", "fenced-code-blocks", "tables"])
    return render_template('help.html', help_html=html, page_slug=page_slug)
Example #29
0
def search(request):
    if request.method == "POST":
        name = request.POST.get('q')
        if name in list_entries():
            if get_entry(name) == None:
                messages.add_message(request, messages.ERROR, 'No such entry exists')
                return render(request, "encyclopedia/error.html")
            else:
                return render(request, "encyclopedia/test.html", {
                    "file": markdown2.markdown_path(f"entries/{name}.md"),
                    "name": name
                })
        else:
            new_list = []
            for i in range(len(list_entries())):
                if name in list_entries()[i] or name.upper() in list_entries()[i] or name.lower() in list_entries()[i]:
                    new_list.append(list_entries()[i])
                    i += 1
                else:
                    i += 1
            if new_list == []:
                messages.add_message(request, messages.ERROR, 'No such entries exist')
                return render(request, "encyclopedia/error.html")
            else:
                messages.add_message(request, messages.SUCCESS, 'Entry(ies) found')
                return render(request, "encyclopedia/index.html", {
                    "entries": new_list
                })
Example #30
0
def markdown_render(filename):
    html = markdown_path(os.path.join(PAGES_PATH, filename),
                         extras=[
                             'metadata', 'fenced-code-blocks', 'header-ids',
                             'footnotes', 'smarty-pants'
                         ])
    return html
Example #31
0
def item(category, item_slug):
    """
    A single specific item.

    """

    try:
        path = category + '/' + item_slug + '.md'
        html = markdown2.markdown_path(path, extras=["metadata"])

        metadata = html.metadata
        if 'template' in metadata.keys():
            template = metadata['template']
        else:
            template = 'templates/item.html'

        render_data = metadata.copy()
        render_data[u'body'] = html
        render_data[u'category'] = category
        render_data[u'item_slug'] = item_slug

        rendered = jenv.get_template(template).render(render_data)
        return rendered

    except IOError as e:
        return render_template('404.html'), 404
Example #32
0
 def README(self):
     readme = '''
             <div class = "README">
     ''' + str(markdown2.markdown_path("README.md")).replace("<em>", "").replace("</em>", "") +'''
             </div>
     '''
     return readme
Example #33
0
def markdown(requested_uri):
    """

    :param requested_uri: The Uri info to be redirected.
    :type requested_uri: dict
    :returns: Global options, and the clients Request information.markdown
    :rtype: dict
    """
    title = ''
    if requested_uri['value']:
        title = requested_uri['value']
    else:
        return False

    data = _build_base_data(requested_uri)
    md = ''
    markdown_template = os.path.join('/data/hosted_files',
                                     requested_uri['value'])
    try:
        if os.path.exists(markdown_template):
            md = markdown2.markdown_path(markdown_template)
        else:
            md = markdown2.markdown(requested_uri['value'])
    except Exception as e:
        app.app.logger.error("Error on rendering 'markdown': %s for uri: %s" %
                             (e, requested_uri))
        return nothing()

    data['title'] = title
    data['markdown'] = Markup(md)
    data['style_file'] = '/static/vendor/github_markdown.css'
    return render_template('uris/markdown.html', **data)
Example #34
0
def populate_contents(contents, parts_html, parts_md, args):
    # load the HTML content parts
    for name in parts_html:
        tmpl = args['env'].get_template(f'{name}.html')
        contents[name] = tmpl.render()

    # convert content parts from markdown to HTML
    for name in parts_md:
        # possible paths
        paths = [ \
            f'{args["report_dir"]}/{name}.md', \
            f'{SEARCHPATH}/{name}.md' ]
        # lookup
        for path in paths:
            if not os.path.isfile(path):
                continue
            # the file is found
            contents[name] = markdown2.markdown_path(path, extras=['tables'])
        # if the file is not found
        if name not in contents.keys():
            contents[name] = f'<i>no {name}.md</i><br/>'

    # replace the variables with appropriate values
    for name, var_names in CONTENTS_VARIABLES.items():
        if name not in contents.keys():
            continue
        tmpl = Template(contents[name])
        # get variable values from either args or contents
        tmpl_vars = {k: args.get(k, contents.get(k, 'no data')) for k in var_names}
        contents[name] = tmpl.render(tmpl_vars)

    return contents
Example #35
0
def make_stats(filename):
    createfolder(filename)

    f = open(get_name_report(), "w", encoding="utf-8")
    f.write("## Report for the file " + os.path.relpath(".", ".."))
    f.close()
    print("*** Parsing file", filename, "***")
    tab_Spending = []
    csv_parser(tab_Spending, filename)

    print("*** Gathering Data ***")
    tab_money = []
    tab_name = []
    tab_visit = []

    dict_buy = gather_account(tab_Spending)

    for key, account in dict_buy.items():
        tab_money.append(account.balance)
        tab_name.append(str(key))
        tab_visit.append(account.nb_visit)

    draw_pie_charts(tab_name, tab_money, tab_visit)

    tab_year = []
    dict_Spending = dict()
    for ss in tab_Spending:
        year = ss.date.year
        if year not in tab_year:
            tab_year.append(year)
            dict_Spending.update({year: []})
        dict_Spending[year].append(ss)

    plot_all_year(tab_Spending)

    for year, spending in dict_Spending.items():
        print("*** Building plots for", year, "***")
        str_year = str(year)
        f = open(get_name_report(), "a")
        f.write("\n\n### Plot for the year " + str_year + "\n")
        f.close()

        if os.path.exists(str_year):
            shutil.rmtree(str_year)
        os.mkdir(str_year)
        plot_year(spending, str_year)

    html = open(get_name_report_html(), "w",  encoding="utf-8")
    html.write("<!DOCTYPE html>\n<html lang=\"en\">\n<head>"
               + "\n<title>Report " + get_name_report_html() + "</title>"
               + "<link rel=\"stylesheet\" href=\"modest.css\">"
               + "\n<meta charset=\"UTF-8\"></head>\n</body>\n")

    html.write(markdown2.markdown_path(get_name_report(), encoding="utf-8"))
    html.write("\n</body>\n</html>")
    html.close()

    path_wkthmltopdf = r'C:\_Installs\wkhtmltopdf\bin\wkhtmltopdf.exe'
    config = pdfkit.configuration(wkhtmltopdf=path_wkthmltopdf)
    pdfkit.from_file(get_name_report_html(), get_name_report_pdf(), configuration=config)
Example #36
0
def populateManualDict():
    global taRoot, manualDict, moduleDict

    manuals = next(os.walk(taRoot))[1]
    manuals[:] = [
        manual for manual in manuals
        if os.path.isdir(taRoot + os.path.sep + manual + os.path.sep +
                         "content") and os.path.exists(taRoot + os.path.sep +
                                                       manual + os.path.sep +
                                                       "toc.yaml")
        and os.path.exists(taRoot + os.path.sep + manual + os.path.sep +
                           "meta.yaml")
    ]

    for manual in manuals:
        manualDir = taRoot + os.path.sep + manual + os.path.sep
        metaFile = open(manualDir + 'meta.yaml', 'r')
        meta = yaml.load(metaFile)
        metaFile.close()
        tocFile = open(manualDir + 'toc.yaml', 'r')
        toc = yaml.load(tocFile)
        tocFile.close()
        license = markdown2.markdown_path(manualDir + 'LICENSE.md')
        meta['slug'] = u'vol' + meta['volume'] + u'_' + meta['manual']
        manualDict[manual] = {
            'meta': meta,
            'toc': toc,
            'license': license,
        }
Example #37
0
def package_bundle(bundle_path, zip_parent):
    """Package a bundle and create the appcast, input:
    
       * A built bundle with Contents/Info.plist, must have SUFeedURL
         for Sparkle.
       * ~/.ssh/<bundleNameInLowercase>.private.pem to sign the zip"""

    plist = plistlib.readPlist("%s/Contents/Info.plist" % bundle_path)
    bundle_name = plist["CFBundleName"]
    appcast_url = plist["SUFeedURL"]
    bundle_version = plist["CFBundleVersion"]
    zip = "%s-%s.zip" % (bundle_name, bundle_version)
    zip_url = "%s/%s" % (zip_parent, zip)
    priv_key = os.path.expanduser("~/.ssh/%s.private.pem" % bundle_name.lower())
    date = time.strftime("%a, %d %b %Y %H:%M:%S %z")

    print "[PACK] Building %s..." % zip

    cwd = os.getcwd()
    os.chdir(os.path.dirname(bundle_path))
    os.system("zip -qry %s/%s %s" % (cwd, zip, os.path.basename(bundle_path)))
    os.chdir(cwd)

    print "[PACK] Signing %s..." % zip
    signed = commands.getoutput(
        'openssl dgst -sha1 -binary < "%s" | '
        'openssl dgst -dss1 -sign "%s" | '
        "openssl enc -base64" % (zip, priv_key)
    )

    env = Environment(loader=FileSystemLoader(sys.path[0]))
    template = env.get_template("appcast.template.xml")

    for lang in ["en", "zh_CN", "zh_TW"]:
        if lang == "en":
            suffix = ""
        else:
            suffix = ".%s" % lang
        relnotes = markdown2.markdown_path("Changelog%s.markdown" % suffix)
        appcast = "%s%s.xml" % (bundle_name, suffix)
        print "[PACK] Generating %s..." % appcast
        output = open(appcast, "w")

        output.write(
            template.render(
                appName=bundle_name,
                link=appcast_url,
                relNotes=relnotes,
                url=zip_url,
                date=date,
                version=bundle_version,
                length=os.path.getsize(zip),
                signed=signed,
            ).encode("utf-8")
        )

        output.close()

    print "Done! Please publish %s to %s." % (zip, zip_url)
Example #38
0
def view_entry(request, ent_name):
    try:
        a = markdown_path('entries/' + ent_name + '.md')
        a += "<p style='margin-top:50px;margin-left:4px;'><a href='/edit/{}' > Edit</a></p>".format(
            ent_name)
        return HttpResponse(a)
    except:
        return HttpResponse('sorry requested page not found')
Example #39
0
def home(request):
    markup = markdown2.markdown_path(README_PATH)
    markup = fix_markup(markup)
    return render_to_response('home.html',
            { 
                'markup': markup,
            },
            RequestContext(request))
Example #40
0
def convert():
    print "Converting"
    in_file = TEST_DIR + "/" + IN_FILE
    out_file = OUT_DIR + "/" + OUT_FILE
    html = markdown2.markdown_path(in_file)
    header = read_file(HEADER)
    footer = read_file(FOOTER)
    write_file(out_file, header + html + footer )
Example #41
0
 def ext_md(self, fname):
     logger.debug("load markdown file (ext_md)")
     html = markdown2.markdown_path(
         fname, extras=["metadata", "markdown-in-html", "tables"]
     )
     if "skip" in html.metadata.keys() and html.metadata["skip"] == "1":
         html = "skip"
     return html
Example #42
0
def help_page(page_slug='_index'):
    if page_slug not in app.config['HELP_PAGES']:
        abort(404)
    html = markdown2.markdown_path(
        os.path.join(app.config['HELP_DIR'], page_slug + '.md'),
        extras=['fenced-code-blocks', 'tables'])
    return render_template('help.html', page_slug=page_slug,
                           help_html=render_template_string(html))
Example #43
0
 def get(self):
     template = env.get_template('help.html')
     rendered = template.render(fragment=markdown2.markdown_path("helpPage.md",
                                                                 extras=['fenced-code-blocks',
                                                                         'code-friendly',
                                                                         'target-blank-links',
                                                                         'toc',
                                                                         'tables']))
     self.write(rendered)
Example #44
0
def page(request, title):
    if util.get_entry(title) == None:
        return render(request, 'encyclopedia/not_found.html')
    else:
        page_rendered = markdown2.markdown_path("entries\\{}.md".format(title))
        return render(request, 'encyclopedia/page.html', {
            "page": page_rendered,
            "title": title
        })
Example #45
0
def discover_help_pages():
    app.config['HELP_PAGES'] = {}
    for page in os.listdir(app.config['HELP_DIR']):
        html = markdown2.markdown_path(
            os.path.join(app.config['HELP_DIR'], page), extras=["metadata"])
        slug = os.path.splitext(os.path.basename(page))[0]
        title = html.metadata['title']

        app.config['HELP_PAGES'][slug] = title
Example #46
0
def markdown_file(markdown_file_path):
    html = markdown2.markdown_path(markdown_file_path)
    lines = html.splitlines()
    nlines = []

    for l in lines:
        nl = _md_convert(l)
        nlines.append(nl)

    return os.linesep.join(nlines)
Example #47
0
def category(category):
    """
    Categories of items.

    Essentially a 'directory listing' page. 

    Returns to the items to the 'index'.

    """

    try:

        # First do the items
        items = []
        for filename in os.listdir(category):
            if 'index.md' in filename: 
                continue
            item = markdown2.markdown_path(category + '/' + filename, extras=["metadata"])
            item.metadata['slug'] = filename.split('/')[-1].replace('.md', '')
            items.append(item)

        # Then do the index
        path = category + '/index.md'
        html = markdown2.markdown_path(path, extras=["metadata"])

        metadata = html.metadata
        if 'template' in metadata.keys():
            template = metadata['template']
        else:
            template = 'templates/category.html'

        render_data = metadata.copy()
        render_data[u'body'] = html
        render_data[u'items'] = items
        render_data[u'category'] = category

        rendered = jenv.get_template(template).render(render_data)
        return rendered

    except IOError as e:
        print(e)
        return render_template('404.html'), 404
Example #48
0
def help_page(page_slug='_index'):
    """Fava's included documentation."""
    if page_slug not in app.config['HELP_PAGES']:
        abort(404)
    html = markdown2.markdown_path(
        os.path.join(resource_path('help'), page_slug + '.md'),
        extras=['fenced-code-blocks', 'tables'])
    return render_template(
        'help.html',
        page_slug=page_slug,
        help_html=render_template_string(html))
Example #49
0
def processmkd(filename):
    theHead = ''
    thehtml = markdown2.markdown_path(filename)
    theTitle = unicode(filename,"utf-8")
    fileHandle = open(filename+'.html', "w")
    theHead = '<!DOCTYPE html>'
    theHead += '<html><head><meta charset="utf-8"/><title>' + theTitle + '</title><link href="demo.css" type="text/css" rel="stylesheet"/></head><body>'
    theHead += thehtml
    theHead += '</body></html>\n'
    theHTML =  theHead.encode('utf-8')
    fileHandle.write(theHTML)
    fileHandle.close()
Example #50
0
def list_help_pages():
    help_pages = []

    for page in os.listdir(app.docs_dir):
        html = markdown2.markdown_path(os.path.join(app.docs_dir, page),
                                       extras=["metadata"])
        slug = "help/{}".format(os.path.splitext(os.path.basename(page))[0])
        title = html.metadata['title']

        help_pages.append((slug, title, None))

    return sorted(help_pages, key=lambda x: x[1] == 'Index', reverse=True)
Example #51
0
def md_viewer(session, pad, mode):
    with open('config.json', 'r') as f:
        published = json.load(f)['published']
    if pad in published or session.get('in'):
        path = 'pads/{0}.md'.format(pad)
        if mode == 'html':
            return markdown2.markdown_path(path)
        else:
            with open(path, 'r') as f:
                bottle.response.content_type = 'text/plain'
                return f.read()
    else:
        bottle.abort(404)
Example #52
0
def generate_cache():
    "Generates the cache of the sections and their entries."
    print "Generating cache..."
    # The cache we are building.
    cache = {}
    sections = list_sections()

    # Add the index to the cache.
    check_index()
    cache['index'] = {'html': markdown2.markdown_path('sections/index.md')}

    for section in sections:
        cache[section] = {'name': human_name(section),
                          'filename': section,
                          'path': build_path(section),
                          'items': []}

        # Get all the items for each section.
        items = list_items(section)

        # Journal entries should be sorted in reverse
        if section == 'journal-excerpts':
            items.sort(reverse=True)

        # Generate HTML from markdown files.
        for item in items:
            filename = item.split('/')[-1].split('.')[0]
            slug = filename.split("_")[-1].lower()
            item_cache = {'name': human_name(filename, title=False),
                          'filename': filename,
                          'slug': slug,
                          'path': build_path(slug, section),
                          'html': markdown2.markdown_path(item)}

            cache[section]['items'].append(item_cache)

    print "Cache succesfully generated with %s sections." % len(sections)
    return cache
Example #53
0
def makeHTML():
    html =""
    with open("res/htmlhead.tmpl") as infile:
        for line in infile:
            html+=line
    body = markdown_path(TMPFILE, extras=MDEXTRAS, link_patterns=PATTERNS)
    html += body
    with open("res/htmlfooter.tmpl") as infile:
        for line in infile:
            html+=line

    with open(HTMLOUT, 'w') as outfile:
        for line in html:
                outfile.write(line)
    jinja(HTMLOUT)  #a second time, needed.
Example #54
0
def convert_md_2_pdf(filename, output=None, theme=None):
    html = markdown_path(filename)
    if not output:
        output = '.'.join([filename.rsplit('.', 1)[0], 'pdf'])

    if theme is not None:
        BASE_DIR = os.path.abspath(os.path.dirname(__file__))
        css_file = theme
        if not os.path.exists(css_file):
            css_file = os.path.join(BASE_DIR, 'themes/'+theme+'.css')

        print(css_file)
        HTML(string=html).write_pdf(output, stylesheets=[css_file])
    else:
        HTML(string=html).write_pdf(output)
Example #55
0
def populate_page_dict(current_manual, data):
    slug = title = ''

    if 'title' in data:
        title = data['title']
    if 'slug' in data:
        slug = data['slug']
        filepath = os.path.join(source_dir, 'content', slug+'.md')
        html = markdown2.markdown_path(filepath, extras=["tables", "metadata"])
        page_dict[slug] = {
            'title': title,
            'html': html,
            'manual': current_manual,
            'meta': html.metadata
        }
    if 'subitems' in data:
       for subitem in data['subitems']:
           populate_page_dict(current_manual, subitem)
Example #56
0
 def index(self):
     '''exposed method: spash page for SlingshotSMS information & status'''
     
     try:
         # Compile the ReST file into an HTML fragment
         documentation = markdown2.markdown_path('README.md')
         return """
         <html>
             <head>
                 <title>SlingshotSMS</title>
                 <link rel="stylesheet" type="text/css" href="web/style.css" />
             </head>
             <body>
             <div class="doc">%s</div>
             </body>
         </html>""" % (documentation)
     except Exception, e:
         print e
         return "<html><body><h1>SlingshotSMS</h1>README File not found</body></html>"
Example #57
0
def md2pdf(pdf_file_path, md_content=None, md_file_path=None,
           css_file_path=None, base_url=None):
    """
    Converts input markdown to styled HTML and renders it to a PDF file.

    Args:
        pdf_file_path: output PDF file path.
        md_content: input markdown raw string content.
        md_file_path: input markdown file path.
        css_file_path: input styles path (CSS).
        base_url: absolute base path for markdown linked content (as images).

    Returns:
        None

    Raises:
        ValidationError: if md_content and md_file_path are empty.
    """

    # Convert markdown to html
    raw_html = ''
    extras = ['cuddled-lists', 'tables']
    if md_file_path:
        raw_html = markdown_path(md_file_path, extras=extras)
    elif md_content:
        raw_html = markdown(md_content, extras=extras)

    if not len(raw_html):
        raise ValidationError('Input markdown seems empty')

    # Weasyprint HTML object
    html = HTML(string=raw_html, base_url=base_url)

    # Get styles
    css = []
    if css_file_path:
        css.append(CSS(filename=css_file_path))

    # Generate PDF
    html.write_pdf(pdf_file_path, stylesheets=css)

    return
Example #58
0
def populateManualDict():
    global taRoot, manualDict, moduleDict

    manuals = next(os.walk(taRoot))[1]
    manuals[:] = [manual for manual in manuals if os.path.isdir(taRoot+os.path.sep+manual+os.path.sep+"content") and os.path.exists(taRoot+os.path.sep+manual+os.path.sep+"toc.yaml") and os.path.exists(taRoot+os.path.sep+manual+os.path.sep+"meta.yaml")]

    for manual in manuals:
        manualDir = taRoot+os.path.sep+manual+os.path.sep
        metaFile = open(manualDir+'meta.yaml', 'r')
        meta = yaml.load(metaFile)
        metaFile.close()
        tocFile = open(manualDir+'toc.yaml', 'r')
        toc = yaml.load(tocFile)
        tocFile.close()
        license = markdown2.markdown_path(manualDir+'LICENSE.md')
        meta['slug'] = u'vol'+meta['volume']+u'_'+meta['manual']
        manualDict[manual] = {
            'meta': meta,
            'toc': toc,
            'license': license,
        }
Example #59
0
def index():
    """
    The landing page.
    """

    try:
        path = 'index.md'
        html = markdown2.markdown_path(path, extras=["metadata"])

        metadata = html.metadata
        if 'template' in metadata.keys():
            template = metadata['template']
        else:
            template = 'templates/index.html'

        render_data = metadata.copy()
        render_data[u'body'] = html

        rendered = jenv.get_template(template).render(render_data)
        return rendered

    except IOError as e:
        return render_template('404.html'), 404
 def help(self):
     html = markdown2.markdown_path(os.path.join(self.helpPath,'Calculate Network Cost From Time.md'))
     return True, html