Example #1
0
def get_minimal_document(body_contents, add_markdown_css=False):
    """ Creates the minimal html document with MCDPL css. """
    soup = bs("<html></html>")
    html = soup.html
    head = soup.new_tag('head')
    body = soup.new_tag('body')
    css = soup.new_tag('style', type='text/css')
    # <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    meta = soup.new_tag('meta')
    meta['http-equiv'] = "Content-Type"
    meta['content'] = "text/html; charset=utf-8"
    head.append(meta)
    from mcdp_report.html import get_language_css
    mcdp_css = get_language_css()
    markdown_css = get_markdown_css() if add_markdown_css else ""
    allcss = mcdp_css + '\n' + markdown_css
    css.append(NavigableString(allcss))
    head.append(css)
    body.append(bs(body_contents))
    html.append(head)
    html.append(body)
    s = str(html)
    return s
Example #2
0
def manual_join(files_contents):

    template = """
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <title>PyMCDP manual</title>
        <meta charset="utf-8">
        <style type='text/css'>CSS</style>

        <script src='https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script>

        <script type="text/x-mathjax-config">
            MathJax.Hub.Config({
              tex2jax: {inlineMath: [['$','$']]}
            });
        </script>

    </head>
    <body>
    <h1 id='booktitle'>The PyMCDP user manual</h1>
    <div id='toc'/>
    <div id='body'/>
    </body>
    </html>
    """

    # css = urllib2.urlopen('http://127.0.0.1:8080/static/css/mcdp_language_highlight.css').read()
    # other = urllib2.urlopen('http://127.0.0.1:8080/static/css/markdown.css').read()
#     extra = open('manual.css').read()
    markdown_css = get_markdown_css()
    mcdp_css = get_language_css()
    template = template.replace('CSS', mcdp_css + '\n' + manual_css + '\n' + markdown_css)
    d = BeautifulSoup(template, 'lxml')
    main_body = BeautifulSoup("", 'lxml')

    for (_libname, docname), data in files_contents:
        doc = BeautifulSoup(data, 'lxml', from_encoding='utf-8')

        body = doc.body
        body.name = 'div'
        body['id'] = docname
        main_body.append(body)

    for tag in main_body.select("a"):
        href = tag['href']
        # debug(href)
        # http://127.0.0.1:8080/libraries/tour1/types.html
        if href.endswith('html'):
            page = href.split('/')[-1]
            new_ref = '#%s' % page
            tag['href'] = new_ref

    toc = generate_doc(main_body)
    toc = BeautifulSoup(toc, 'lxml')
    toc['class'] = 'toc'
    toc['id'] = 'toc'
    toc_place = d.select('div#toc')[0]
    body_place = d.select('div#body')[0]
    toc_place.replaceWith(toc)

    body_place.replaceWith(main_body)

    return str(d)