Beispiel #1
0
def add_related(joined_aug):
    res = AugmentedResult()
    res.merge(joined_aug)
    soup = bs_entire_document(joined_aug.get_result())
    add_related_(soup, res)
    res.set_result(to_html_entire_document(soup))
    return res
Beispiel #2
0
def add_likebtn(joined_aug, likebtn):
    res = AugmentedResult()
    res.merge(joined_aug)
    soup = bs_entire_document(joined_aug.get_result())
    add_likebtn_(soup, likebtn)
    res.set_result(to_html_entire_document(soup))
    return res
Beispiel #3
0
def mark_errors_and_rest(joined_aug):
    soup = bs_entire_document(joined_aug.get_result())
    mark_in_html(joined_aug, soup)
    res = AugmentedResult()
    res.merge(joined_aug)
    res.set_result(to_html_entire_document(soup))
    return res
Beispiel #4
0
def create_split_jobs(context,
                      data_aug,
                      mathjax,
                      preamble,
                      output_dir,
                      nworkers=0,
                      extra_panel_content=None,
                      add_toc_if_not_existing=True,
                      output_crossref=None,
                      permalink_prefix=None,
                      only_refs=False,
                      reveal=True):
    data = data_aug.get_result()
    if nworkers == 0:
        nworkers = max(1, cpu_count() - 2)

    res = AugmentedResult()
    res.merge(data_aug)

    h = get_md5(data)[-4:]
    jobs = []

    assets_dir = os.path.join(output_dir, 'assets')

    with timeit("preprocess"):
        soup = bs_entire_document(data)
        embed_css_files(soup)
        fo = os.path.join(output_dir, 'dummy.html')
        save_css(soup, fo, assets_dir)
        data = to_html_entire_document(soup)

    for i in range(nworkers):
        promise = context.comp_dynamic(
            go,
            i,
            nworkers,
            data,
            mathjax,
            preamble,
            output_dir,
            add_toc_if_not_existing=add_toc_if_not_existing,
            assets_dir=assets_dir,
            extra_panel_content=extra_panel_content,
            output_crossref=output_crossref,
            permalink_prefix=permalink_prefix,
            only_refs=only_refs,
            job_id='worker-%d-of-%d-%s' % (i, nworkers, h))
        jobs.append(promise)

        if only_refs:
            break

    if reveal:
        jobs.append(context.comp(download_reveal, output_dir))

    return context.comp(notification, res, jobs, output_dir)
Beispiel #5
0
def do_it(f, rel, current_slug):
    f2 = f + '.old'
    if not os.path.exists(f2):
        shutil.copy(f, f2)
    orig = open(f2).read()

    soup = bs_entire_document(orig)
    soup2 = make_changes(soup, f, rel, current_slug)
    data = to_html_entire_document(soup2)

    data = data.replace('<body>', '<body>\n<?php header1() ?>\n')
    write_data_to_file(data, f, quiet=True)
Beispiel #6
0
def prerender(joined_aug, symbols):
    joined = joined_aug.get_result()
    soup = bs_entire_document(joined)
    for details in soup.select('details'):
        details.name = 'div'
        add_class(details, 'transmuted-details')
        # details.attrs['open'] = 1

    joined = to_html_entire_document(soup)
    res = AugmentedResult()
    result = prerender_mathjax(joined, symbols=symbols, res=res)
    res.set_result(result)
    return res
Beispiel #7
0
def add_style(data_aug, stylesheet):
    soup = bs_entire_document(data_aug.get_result())
    head = soup.find('head')
    assert head is not None
    link = Tag(name='link')
    link['rel'] = 'stylesheet'
    link['type'] = 'text/css'
    from mcdp_report.html import get_css_filename
    link['href'] = get_css_filename('compiled/%s' % stylesheet)
    head.append(link)
    html = to_html_entire_document(soup)
    res = AugmentedResult()
    res.merge(data_aug)
    res.set_result(html)
    return res
Beispiel #8
0
def parse_main_template(fn):
    template = open(fn).read()

    soup = bs_entire_document(template)
    base_dir = os.path.dirname(fn)
    embed_css_files(soup, base_dir)

    head = soup.find('head')
    if head is None:
        msg = 'Could not find <head> in template'
        logger.error(msg)
        logger.error(str(soup))
        raise Exception(msg)

    template = to_html_entire_document(soup)
    return template