Exemple #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
Exemple #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
Exemple #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
Exemple #4
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)
Exemple #5
0
def prerender_main():
    f0 = sys.argv[1]
    f1 = sys.argv[2]
    html = open(f0).read()
    parsed = bs_entire_document(html)
    body = parsed.html.body
    body_string = str(body)
    res = AugmentedResult()
    body2_string = prerender_mathjax_(body_string, res)
    body2 = bs(body2_string)
    parsed.html.body.replace_with(body2)
    html2 = str(parsed)
    write_data_to_file(html2, f1)
Exemple #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
Exemple #7
0
def compose_go(compose_config):
    input_ = compose_config.input
    output = compose_config.output
    recipe = compose_config.recipe
    remove_status = compose_config.remove_status
    show_removed = compose_config.show_removed
    data = open(input_).read()
    soup = bs_entire_document(data)
    permalink_prefix = compose_config.purl_prefix
    aug = compose_go2(soup, recipe, permalink_prefix, remove_status,
                      show_removed)
    soup = aug.get_result()
    results = str(soup)
    write_data_to_file(results, output)
Exemple #8
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
Exemple #9
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
Exemple #10
0
def make_composite(compose_config, joined_aug):
    data = joined_aug.get_result()
    soup = bs_entire_document(data)
    recipe = compose_config.recipe
    remove_status = compose_config.remove_status
    show_removed = compose_config.show_removed
    permalink_prefix = compose_config.purl_prefix
    aug = compose_go2(soup, recipe, permalink_prefix, remove_status,
                      show_removed)
    soup = aug.get_result()
    results = str(soup)
    res = AugmentedResult()
    res.merge(joined_aug)
    res.merge(aug)
    res.set_result(results)
    return res
Exemple #11
0
def write_crossref_info(data, id2filename, output_crossref, permalink_prefix):
    soup = bs_entire_document(data)

    cross = Tag(name='body')

    container = Tag(name='div')
    container.attrs['id'] = 'container'
    cross.append(container)

    for e in soup.select('[label-name]'):
        # logger.debug('considering %s' % e)
        if not 'id' in e.attrs:
            continue

        id_ = e.attrs['id']
        if id_.startswith('bib:'):
            # logger.warn('Excluding %r from cross refs' % id_)
            continue

        e2 = get_crossref_copy(e)
        e2.attrs[MCDPManualConstants.ATTR_BASE_URL] = permalink_prefix

        if id_ in id2filename:
            basename = id2filename[id_]

            e2.attrs['url'] = '%s/%s#%s' % (permalink_prefix, basename, id_)
            # print e2.attrs['url']
            a = Tag(name='a')

            a.attrs['href'] = e2.attrs['url']
            if not 'autoid' in id_:
                code = Tag(name='code')
                code.append(id_)
                a.append(code)
                a.append(' ')
                a.append(br())
            a.append(e2.attrs['label-name'])
            # e2.insert(0, Tag(name='br'))
            # e2.insert(0, ' ')
            e2.insert(0, a)
        else:
            logger.error('Cannot find url for %s' % id_)

        cross.append('\n\n\n')
        cross.append(e2)

    for img in list(cross.find_all('img')):
        img.extract()

    # print('writing cross ref info')
    html = Tag(name='html')
    html.append(cross)
    head = Tag(name='head')
    style = Tag(name='style')
    style.append(CROSSREF_CSS)
    head.append(style)
    html.append(head)

    script = Tag(name='script')
    script.append(CROSSREF_SCRIPT)
    cross.append(script)
    # XXX: we are doing this multiple times
    write_data_to_file(str(html), output_crossref, quiet=True)
Exemple #12
0
def composing1():

    data1 = """

docs:
    file0.md: |

        <div id='toc'></div>

        # All units {#part:all}

    file1.md: |

        # Audacious {#sa status=ready}

        This is section Audacious.

        Linking to:

        - (number name) <a href="#sa" class="number_name"></a>; (empty) [](#sa)
        - (number name) <a href="#sb" class="number_name"></a>; (empty) [](#sb)
        - (number name) <a href="#sc" class="number_name"></a>; (empty) [](#sc)
        - And linking to [](#elephant).

    file2.md: |

        # Bumblebee {#sb status=ready}

        This is section Bumblebee.

        Linking to:

        - (number name) <a href="#sa" class="number_name"></a>; (empty) [](#sa)
        - (number name) <a href="#sb" class="number_name"></a>; (empty) [](#sb)
        - (number name) <a href="#sc" class="number_name"></a>; (empty) [](#sc)
        - And linking to [](#elephant).

        ## This one will be removed {#to-remove}

        I don't like this section

        # Elephant {#elephant status=draft}

        Section Elephant is not ready.


    file3.md: |

        # The cat section {#sc status=ready}

        This is section Cat.

        Linking to:

        - (number name) <a href="#sa" class="number_name"></a>; (empty) [](#sa)
        - (number name) <a href="#sb" class="number_name"></a>; (empty) [](#sb)
        - (number name) <a href="#sc" class="number_name"></a>; (empty) [](#sc)

    00_main_template.html: |

        <html>
            <head></head>
            <body</body>
        </html>

book.version.yaml: |
    input: dist/master/book.html
    recipe:
        - toc
        - make-part: part1
          title: First part
          contents:
          - add: sb
            except: to-remove
        - make-part: part2
          title: Second part
          contents:
          - add: sa
          - add: elephant
    output: dist/version/book.html
    purl_prefix: http://purl.org/dt/fall2017/
    remove_status: [draft]

.compmake.rc:
    config echo 1

"""
    use = None
    # to use a specific dir for debugging:
    # use = '/tmp/composing1'

    with with_dir_content(data1, use_dir=use):

        repo = Repo.init('.')
        fn = 'readme'
        write_data_to_file('', fn)
        repo.index.add([fn])
        repo.index.commit("initial commit")

        url = '[email protected]:AndreaCensi/example.git'
        repo.create_remote('origin', url)

        res = 'dist/master/book.html'
        run_app(RenderManual, [
            '--src', 'docs', '--stylesheet', 'v_manual_split', '--mathjax',
            '0', '-o', 'out/out1', '--no_resolve_references', '--output_file',
            res
        ])

        assert os.path.exists(res)
        data = bs_entire_document(open(res).read())
        assert data.find(id='sa:section') is not None
        assert data.find(id='sb:section') is not None
        assert data.find(id='to-remove:section') is not None

        run_app(Split, [
            '--filename', 'dist/master/book.html', '--output_dir',
            'dist/master/book'
        ])
        run_app(Compose, ['--config', 'book.version.yaml'])
        version_whole = bs_entire_document(
            open('dist/version/book.html').read())
        assert version_whole.find(id='sa:section') is not None
        assert version_whole.find(id='sb:section') is not None
        assert version_whole.find(id='to-remove:section') is None
        # Now it's preserved
        # assert version_whole.find(id='elephant:section') is None

        run_app(Split, [
            '--filename', 'dist/version/book.html', '--output_dir',
            'dist/version/book'
        ])
Exemple #13
0
def go(compose_config):
    input_ = compose_config.input
    output = compose_config.output
    recipe = compose_config.recipe
    permalink_prefix = compose_config.purl_prefix

    # Read input file
    logger.info('Reading %s' % input_)
    data = open(input_).read()
    soup = bs_entire_document(data)
    # Create context
    doc = soup.__copy__()
    body = Tag(name='body')
    doc.body.replace_with(body)
    elements = recipe.make(RecipeContext(soup=soup))
    check_isinstance(elements, list)
    append_all(body, elements)

    # Now remove stuff
    for status in compose_config.remove_status:
        removed = []
        for section in list(body.select('section[status=%s]' % status)):
            level = section.attrs['level']
            if not level in ['sec', 'part']:
                continue

            section_id = section.attrs['id']
            pure_id = section_id.replace(':section', '')
            removed.append(section.attrs['id'])

            if compose_config.show_removed:
                # remove everything that is not a header
                keep = ['h1', 'h2', 'h3', 'h4', 'h5']
                for e in list(section.children):
                    if e.name not in keep:
                        e.extract()
                    else:
                        e.append(' [%s]' % status)

                p = Tag(name='p')
                p.append(
                    "This section has been removed because it is in status %r. "
                    % (status))
                a = Tag(name='a')
                a.attrs['href'] = 'http://purl.org/dt/master/%s' % pure_id
                a.append(
                    "If you are feeling adventurous, you can read it on master."
                )
                p.append(a)

                section.append(p)

                p = Tag(name='p')
                p.append(
                    "To disable this behavior, and completely hide the sections, "
                )
                p.append(
                    "set the parameter show_removed to false in fall2017.version.yaml."
                )
                section.append(p)
            else:
                section.extract()


#             section.replace_with(div)

        if not removed:
            logger.info('Found no section with status = %r to remove.' %
                        status)
        else:
            logger.info('I removed %d sections with status %r.' %
                        (len(removed), status))
            logger.debug('Removed: %s' % ", ".join(removed))

    add_github_links_if_edit_url(doc, permalink_prefix=permalink_prefix)

    generate_and_add_toc(doc)
    doc = doc.__copy__()

    #     generate_and_add_toc(soup)
    #     substituting_empty_links(soup)
    raise_errors = False
    find_links_from_master(master_soup=soup,
                           version_soup=doc,
                           raise_errors=raise_errors)

    document_final_pass_after_toc(doc)
    results = str(doc)
    write_data_to_file(results, output)