Skip to content

Commit

Permalink
correct problem with nested chapters
Browse files Browse the repository at this point in the history
add out.html as a test
  • Loading branch information
vanilla-extracts committed Mar 23, 2022
1 parent 5dc2e86 commit d18562f
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@ _build/
_build/*
*.py
*.tex
out.html
repl_utils.ml
3 changes: 2 additions & 1 deletion lib/htmlgen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ let prepare_body name str toc =
in read_preamble p;
let doc = separate_sections doc
in let doc = calculate_environments doc
in let doc = Mathgen.re_calculate_env doc in
in let doc = Mathgen.re_calculate_env doc
in
(match (Hashtbl.find_opt preamble "glossary") with
| Some s -> init_glossary s
| None -> (););
Expand Down
20 changes: 20 additions & 0 deletions lib/mathgen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,25 @@ let re_calculate_env ast =
let ast = List.rev ast
in let env = Env(s,ast)
in aux (env::acc) q
| Chapter (s,l)::q
-> let ast = aux [] l in
let ast = List.rev ast
in let c = Chapter(s,ast)
in aux (c::acc) q
| Section (s,l)::q
-> let ast = aux [] l in
let ast = List.rev ast
in let c = Section(s,ast)
in aux (c::acc) q
| Subsection (s,l)::q
-> let ast = aux [] l in
let ast = List.rev ast
in let c = Subsection(s,ast)
in aux (c::acc) q
| Subsubsection (s,l)::q
-> let ast = aux [] l in
let ast = List.rev ast
in let c = Subsubsection(s,ast)
in aux (c::acc) q
| e::q -> aux (e::acc) q
in List.rev (aux [] ast);;
12 changes: 12 additions & 0 deletions lib/parser.ml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,18 @@ let calculate_environments lst =
let env = Env (s1,List.rev env) in
extract_env (env::acc) l
| (OneArgCmd (s,_,_))::q when (String.equal s "end") -> acc,q
| Chapter(s,l)::q -> let l2,q2 = extract_env acc l
in let l2 = List.rev l2
in extract_env ((Chapter(s,l2@q2))::acc) q
| Section(s,l)::q -> let l2,q2 = extract_env acc l
in let l2 = List.rev l2
in extract_env ((Section(s,l2@q2))::acc) q
| Subsection(s,l)::q -> let l2,q2 = extract_env acc l
in let l2 = List.rev l2
in extract_env ((Section(s,l2@q2))::acc) q
| Subsubsection(s,l)::q -> let l2,q2 = extract_env acc l
in let l2 = List.rev l2
in extract_env ((Section(s,l2@q2))::acc) q
| e::q -> extract_env (e::acc) q
in let a,_ = extract_env [] lst in a;;

Expand Down
4 changes: 3 additions & 1 deletion test.html → out.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@
<h1>Generic</h1>
<h2>Table of Content</h2>
<ul>
<li><a href="#c1">Chapter 1 : hello</a></li>

</ul>
</div>
<h1 id="c1">Chapter 1 : hello</h1><br/>
tralalala
</p>

<p>

This is an integral
<img src="https://latex.codecogs.com/svg.image?x"/>
<img src="https://latex.codecogs.com/svg.image?\begin{align*}3y &= 3 \\ 2x &= 4\end{align*}"/>
<div style="margin: auto; text-align: center;">
au center

Expand Down

0 comments on commit d18562f

Please sign in to comment.