Beispiel #1
0
def get_split_test_document():
    md = test_md
    library = MCDPLibrary()
    realpath = 'internal'
    raise_errors = True
    rendered = render_complete(library=library,
                               s=md,
                               raise_errors=raise_errors,
                               realpath=realpath,
                               generate_pdf=False,
                               check_refs=True,
                               filter_soup=None)

    files_contents = [
        DocToJoin(docname='unused', source_info=None, contents=rendered)
    ]
    stylesheet = None
    template = """<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        </head>
        <style>
        
        </style>
        <body></body></html>
        """
    complete = manual_join(template=template,
                           files_contents=files_contents,
                           stylesheet=stylesheet,
                           remove=None,
                           extra_css=None,
                           hook_before_toc=None)

    return complete
Beispiel #2
0
def render(library, docname, data, realpath, out_dir, generate_pdf,
           stylesheet):

    if MCDPConstants.pdf_to_png_dpi < 300:
        msg = (
            'Note that pdf_to_png_dpi is set to %d, which is not suitable for printing'
            % MCDPConstants.pdf_to_png_dpi)
        mcdp_dev_warning(msg)

    from mcdp_docs.pipeline import render_complete

    out = os.path.join(out_dir, docname + '.html')

    html_contents = render_complete(library=library,
                                    s=data,
                                    raise_errors=True,
                                    realpath=realpath,
                                    generate_pdf=generate_pdf)

    title = docname

    doc = get_minimal_document(html_contents,
                               title=title,
                               stylesheet=stylesheet,
                               add_markdown_css=True,
                               add_manual_css=True)

    d = os.path.dirname(out)
    if not os.path.exists(d):
        os.makedirs(d)
    with open(out, 'w') as f:
        f.write(doc)

    logger.info('Written %s ' % out)
    return out
Beispiel #3
0
def render_book(src_dirs,
                generate_pdf,
                data,
                realpath,
                main_file,
                use_mathjax,
                out_part_basename,
                raise_errors,
                filter_soup=None,
                extra_css=None,
                symbols=None):
    from mcdp_docs.pipeline import render_complete

    librarian = get_test_librarian()
    # XXX: these might need to be changed
    if not MCDPConstants.softy_mode:
        librarian.find_libraries('.')

    load_library_hooks = [librarian.load_library]
    library = MCDPLibrary(load_library_hooks=load_library_hooks)

    for src_dir in src_dirs:
        library.add_search_dir(src_dir)

    d = tempfile.mkdtemp()
    library.use_cache_dir(d)

    def filter_soup0(soup, library):
        if filter_soup is not None:
            filter_soup(soup=soup, library=library)
        add_edit_links(soup, realpath)

    try:
        html_contents = render_complete(library=library,
                                        s=data,
                                        raise_errors=raise_errors,
                                        realpath=realpath,
                                        use_mathjax=use_mathjax,
                                        symbols=symbols,
                                        generate_pdf=generate_pdf,
                                        filter_soup=filter_soup0)
    except DPSyntaxError as e:
        msg = 'Could not compile %s' % realpath
        raise_wrapped(DPSyntaxError, e, msg, compact=True)

    doc = get_minimal_document(html_contents,
                               add_markdown_css=True,
                               extra_css=extra_css)
    dirname = main_file + '.parts'
    if dirname and not os.path.exists(dirname):
        try:
            os.makedirs(dirname)
        except:
            pass
    fn = os.path.join(dirname, '%s.html' % out_part_basename)
    write_data_to_file(doc, fn)

    return html_contents
Beispiel #4
0
def render_book(src_dir,
                docname,
                generate_pdf,
                main_file,
                out_part_basename,
                filter_soup=None,
                extra_css=None):
    from mcdp_docs.pipeline import render_complete

    librarian = get_test_librarian()
    librarian.find_libraries('.')

    load_library_hooks = [librarian.load_library]
    library = MCDPLibrary(load_library_hooks=load_library_hooks)
    library.add_search_dir(src_dir)
    #
    #     data = dict(path=dirname, library=l)
    #     l.library_name = library_name
    #
    #     library = librarian.load_library(libname)
    #
    #     l = library.load_library(libname)

    d = tempfile.mkdtemp()
    library.use_cache_dir(d)

    basename = docname + '.' + MCDPConstants.ext_doc_md
    f = library._get_file_data(basename)
    data = f['data']
    realpath = f['realpath']

    def filter_soup0(soup, library):
        if filter_soup is not None:
            filter_soup(soup=soup, library=library)
        add_edit_links(soup, realpath)

    html_contents = render_complete(library=library,
                                    s=data,
                                    raise_errors=True,
                                    realpath=realpath,
                                    generate_pdf=generate_pdf,
                                    filter_soup=filter_soup0)

    doc = get_minimal_document(html_contents,
                               add_markdown_css=True,
                               extra_css=extra_css)
    dirname = main_file + '.parts'
    if dirname and not os.path.exists(dirname):
        try:
            os.makedirs(dirname)
        except:
            pass
    fn = os.path.join(dirname, '%s.html' % out_part_basename)
    with open(fn, 'w') as f:
        f.write(doc)

    return (('unused', docname), html_contents)
Beispiel #5
0
def render(library, docname, data, realpath, out_dir, generate_pdf, stylesheet,
           symbols, raise_errors, use_mathjax, do_slides):
    res = AugmentedResult()
    if MCDPConstants.pdf_to_png_dpi < 300:
        msg = (
            'Note that pdf_to_png_dpi is set to %d, which is not suitable for printing'
            % MCDPConstants.pdf_to_png_dpi)
        mcdp_dev_warning(msg)

    from mcdp_docs.pipeline import render_complete

    out = os.path.join(out_dir, docname + '.html')

    html_contents = render_complete(library=library,
                                    s=data,
                                    raise_errors=raise_errors,
                                    realpath=realpath,
                                    generate_pdf=generate_pdf,
                                    symbols=symbols,
                                    use_mathjax=use_mathjax)

    title = docname

    doc = get_minimal_document(html_contents,
                               title=title,
                               stylesheet=stylesheet,
                               add_markdown_css=True,
                               add_manual_css=True)

    soup = bs_entire_document(doc)

    document_final_pass_before_toc(soup,
                                   remove=None,
                                   remove_selectors=[],
                                   res=res)
    generate_and_add_toc(soup, res=res)
    document_final_pass_after_toc(soup, res=res)

    if use_mathjax and symbols:
        add_mathjax_preamble(soup, symbols)

    if do_slides:
        create_reveal(soup, res)

    doc = to_html_entire_document(soup)

    d = os.path.dirname(out)
    if not os.path.exists(d):
        os.makedirs(d)
    with open(out, 'w') as f:
        f.write(doc)

    logger.info('Written %s ' % out)
    return out
Beispiel #6
0
def tryit(s, write_to=None, forbid=[]):
    library = MCDPLibrary()
    raise_errors = True
    realpath = 'transformations.py'
    s2 = render_complete(library,
                         s,
                         raise_errors,
                         realpath,
                         generate_pdf=False)

    if False:
        if write_to is not None:
            doc = get_minimal_document(s2, add_manual_css=True)
            with open(write_to, 'wb') as f:
                f.write(doc)
            print('written to %s' % write_to)

    tests = {
        'doctype': not 'DOCTYPE' in s2,
        'warn_caption': not 'caption' in s2,
        'warn_centering': not 'centering' in s2,
        'warn_tabular': not 'tabular' in s2,
        'funny': not '&amp;#96;' in s2,
        'dollarfix': not TAG_DOLLAR in s2,
        #     assert not '&#96;' in s2
        #     assert not '&amp;' in s2
    }
    for x in forbid:
        tests['contains %r' % x] = not x in s2
    msg = ''
    summary = {'warn': 0, 'error': 0}
    for k in sorted(tests):
        level = 'warn' if 'warn' in k else 'error'
        passed = tests[k]
        if not passed:
            summary[level] += 1
        mark = '✓' if passed else 'no'
        msg += '\n %20s : %s' % (k, mark)

    if summary['error']:
        if len(s2) < 10000:
            msg += '\n\n' + indent(s2, '> ')

        if write_to is not None:
            msg += '\nSee output in %s' % (write_to)
        raise_desc(Exception, msg)

    return s2
Beispiel #7
0
def check_rendering(libname, filename):
    library = get_test_library(libname)
    data = read_file_encoded_as_utf8(filename)

    expected = get_expected_exceptions(data)

    with with_library_cache_dir(library):
        try:
            contents = render_complete(library,
                                       data,
                                       raise_errors=True,
                                       realpath=filename)
            # write html
            html = get_minimal_document(contents, add_markdown_css=True)
            basename = os.path.basename(filename)
            fn = os.path.join('out', 'check_rendering', libname,
                              basename + '.html')
            write_file_encoded_as_utf8(fn, html)
        except expected:
            return
Beispiel #8
0
def tags_in_titles2():
    template = """
    <html>
    <head>
        </head>
    <body>
        <div id='toc'></div>
    </body>
    </html>
"""
    s = """


<span id='frag'>I will refer to <a href="#two" class='number_name'></a></span>

# One is ok {#one}

Ignore

# Two with `program` {#two}

Another.
 
    
"""
    library = MCDPLibrary()
    raise_errors = True
    realpath = 'transformations.py'
    s2 = render_complete(library, s, raise_errors, realpath, generate_pdf=False)
    files_contents= [DocToJoin(docname='one', contents=s2, source_info=None)]
    stylesheet = 'v_manual_blurb_ready'
    res_aug = manual_join(template, files_contents,
                stylesheet, remove=None, extra_css=None,
                remove_selectors=None,
                hook_before_toc=None)

    soup = bs(res_aug.get_result())
    element = soup.find(id='main_toc')
    print element
    if 'fragment' in str(element):
        raise Exception(str(element))
Beispiel #9
0
def tags_in_titles1():
    template = """
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
    <html lang="en">
    <head>
        <title>The Duckietown book</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    </head>
<body>
</body>
</html>
"""
    s = """


<span id='frag'>I will refer to <a href="#two" class='number_name'></a></span>

# Two with `program` {#two}

Another.
 
    
"""
    library = MCDPLibrary()
    raise_errors = True
    realpath = 'transformations.py'
    s2 = render_complete(library, s, raise_errors, realpath, generate_pdf=False)
    files_contents= [DocToJoin(docname='one', contents=s2, source_info=None)]
    stylesheet = 'v_manual_blurb_ready'
    res_aug = manual_join(template=template, files_contents=files_contents,
                stylesheet=stylesheet, remove=None, extra_css=None,
                remove_selectors=None,
                hook_before_toc=None)
    soup = bs(res_aug.get_result())
    element = soup.find(id='frag')
    print element
    if '&lt;code&gt;' in str(element):
        raise Exception(str(element))
Beispiel #10
0
def get_split_test_document():
    md = test_md
    library = MCDPLibrary()
    realpath = 'internal'
    raise_errors = True
    rendered = render_complete(library, md, raise_errors, realpath, generate_pdf=False,
                    check_refs=True, do_math=True, filter_soup=None,
                    raise_missing_image_errors = False)
    
    files_contents = [(('unused', 'unusued'), rendered)]
    bibfile = None
    stylesheet = None
    template = """<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        </head>
        <style>
        
        </style>
        <body></body></html>
        """
    complete =  manual_join(template, files_contents, bibfile, stylesheet, remove=None, extra_css=None,
                            hook_before_toc=None)
        
    return complete
Beispiel #11
0
def test_toc_numbers1():
    s = r"""
    
<div id='toc'></div>

# Part One {#part:one}

# Chapter One

## Sub One_point_One

Referring to [](#fig:One) and [](#fig:Two) and [](#tab:One).

Also referring only with numbers: 
<a href="#fig:One" class='only_number'></a>,
<a href="#fig:Two" class='only_number'></a>,
<a href="#tab:One" class='only_number'></a>.

<s figure-id="fig:One">Figure One</s>

### Sub sub One_point_One_point_One
#### Par a
#### Par b


## Sub One_point_Two

Referring to subfigures [](#subfig:child1) and [](#subfig:child2).
  
<div figure-id="fig:parent">
    <div figure-id="subfig:child1" figure-caption="child1">
    child1
    </div>
    <div figure-id="subfig:child2" figure-caption="child2">
    child2
    </div>
</div>


<div figure-id="code:code1">
    <pre><code>code1</code></pre>
</div>

## Sub with `code` in the <k>name</k>

# Chapter Two 

<s figure-id="fig:Two">Figure Two</s>

<s figure-id="tab:One">Table One</s>

## Sub Two_point_One

# Part Two {#part:two}

# Chapter Three

\begin{definition}[DefinitionA]\label{def:A}Definition A\end{definition}
\begin{defn}[DefinitionA2]\label{def:A2}Definition A2\end{defn}

\begin{proposition}[PropositionB]\label{prop:B}Proposition B\end{proposition}

\begin{problem}[ProblemC]\label{prob:C}Problem C\end{problem}

\begin{example}[exampleD]\label{exa:D}...\end{example}
\begin{remark}[remarkE]\label{rem:E}...\end{remark}
\begin{lemma}[lammaF]\label{lem:F}...\end{lemma}
\begin{theorem}[theoremG]\label{thm:G}...\end{theorem}
\begin{thm}[theoremG2]\label{thm:G2}...\end{thm}

Citing: 
[](#def:A),
[](#prop:B),
[](#prob:C),
[](#exa:D),
[](#rem:E),
[](#lem:F),
[](#thm:G).

Citing full name:
<a href="#def:A" class="number_name"></a>,
<a href="#prop:B" class="number_name"></a>,
<a href="#prob:C" class="number_name"></a>,
<a href="#exa:D" class="number_name"></a>,
<a href="#rem:E" class="number_name"></a>,
<a href="#lem:F" class="number_name"></a>,
<a href="#thm:G" class="number_name"></a>.

Citing only name:
<a href="#def:A" class="only_name"></a>,
<a href="#prop:B" class="only_name"></a>,
<a href="#prob:C" class="only_name"></a>,
<a href="#exa:D" class="only_name"></a>,
<a href="#rem:E" class="only_name"></a>,
<a href="#lem:F" class="only_name"></a>,
<a href="#thm:G" class="only_name"></a>.


Citing only number:
<a href="#def:A" class="only_number"></a>,
<a href="#prop:B" class="only_number"></a>,
<a href="#prob:C" class="only_number"></a>,
<a href="#exa:D" class="only_number"></a>,
<a href="#rem:E" class="only_number"></a>,
<a href="#lem:F" class="only_number"></a>,
<a href="#thm:G" class="only_number"></a>.


# Appendices {#part:appendices}

# Appendix A {#app:A}
# Appendix B {#app:B}
## App sub B_point_One 
### App subsub B_point_One_point_One

    """
    library = MCDPLibrary()
    raise_errors = True
    realpath = __name__
    s = render_complete(library, s, raise_errors, realpath)

    template = """<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        </head><body></body></html>
        """
    files_contents = [(('a', 'b'), s)]
    stylesheet = 'v_manual_blurb_ready'
    res = manual_join(template=template,
                      files_contents=files_contents,
                      bibfile=None,
                      stylesheet=stylesheet)

    fn = 'out/comptests/test_toc_numbers1.html'  # XXX: write on test folder
    logger.info('written on %s' % fn)
    with open(fn, 'w') as f:
        f.write(res)
Beispiel #12
0
def render_book(
    src_dirs,
    generate_pdf,
    data,
    realpath,
    use_mathjax,
    raise_errors,
    filter_soup=None,
    symbols=None,
    ignore_ref_errors=False,
):
    """ Returns an AugmentedResult(str) """
    res = AugmentedResult()
    from mcdp_docs.pipeline import render_complete

    librarian = get_test_librarian()
    # XXX: these might need to be changed
    if not MCDPConstants.softy_mode:
        for src_dir in src_dirs:
            librarian.find_libraries(src_dir)

    load_library_hooks = [librarian.load_library]
    library_ = MCDPLibrary(load_library_hooks=load_library_hooks)

    for src_dir in src_dirs:
        library_.add_search_dir(src_dir)

    d = tempfile.mkdtemp()
    library_.use_cache_dir(d)

    location = LocalFile(realpath)

    # print('location:\n%s' % location)

    def filter_soup0(soup, library):
        if filter_soup is not None:
            filter_soup(soup=soup, library=library)
        add_edit_links2(soup, location)
        add_last_modified_info(soup, location)

    try:
        html_contents = render_complete(library=library_,
                                        s=data,
                                        raise_errors=raise_errors,
                                        realpath=realpath,
                                        use_mathjax=use_mathjax,
                                        symbols=symbols,
                                        generate_pdf=generate_pdf,
                                        filter_soup=filter_soup0,
                                        location=location,
                                        res=res,
                                        ignore_ref_errors=ignore_ref_errors)
    except DPSyntaxError as e:
        msg = 'Could not compile %s' % realpath
        location0 = LocationInString(e.where, location)
        res.note_error(msg, locations=location0)
        fail = "<p>This file could not be compiled</p>"
        res.set_result(fail)
        return res
        # raise_wrapped(DPSyntaxError, e, msg, compact=True)

    if False:  # write minimal doc
        doc = get_minimal_document(html_contents,
                                   add_markdown_css=True,
                                   extra_css=extra_css)
        dirname = main_file + '.parts'
        if dirname and not os.path.exists(dirname):
            try:
                os.makedirs(dirname)
            except:
                pass
        fn = os.path.join(dirname, '%s.html' % out_part_basename)
        write_data_to_file(doc, fn)

    res.set_result(html_contents)
    return res