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
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))
def test_toc_first(): s = """ <p>Before everything</p> <h1 id='booktitle' nonumber="1" notoc="1">Booktitle</h1> <p>A figure</p> <h1 id='mtoc' nonumber="1" notoc="1">toc</h1> <p> This is my toc </p> <h1 id='part:part1'>Part1</h1> <p>a</p> <h1 id='sec:one'>One</h1> <p>a</p> """ files_contents = [DocToJoin(docname='a', contents=s, source_info=None)] stylesheet = 'v_manual_blurb_ready' res = manual_join(template=template, files_contents=files_contents, stylesheet=stylesheet) soup = bs(res) # print(indent(soup.prettify(), 't > ')) # body = soup.find('body') filename2contents = split_in_files(soup) print list(filename2contents.keys()) index = filename2contents['index.html'] print indent(index, 'index > ') s = str(index) assert 'Before everything' in s
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 '<code>' in str(element): raise Exception(str(element))
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) files_contents = [DocToJoin(docname='a', contents=s, source_info=None)] stylesheet = 'v_manual_blurb_ready' res = manual_join(template=template, files_contents=files_contents, stylesheet=stylesheet) fn = 'out/comptests/test_toc_numbers1.html' # XXX: write on test folder make_sure_dir_exists(fn) logger.info('written on %s' % fn) with open(fn, 'w') as f: f.write(res)