Directory: | ./ |
---|---|
File: | tmp_project/PhoenixTex2Html/src/PLatexObj/platexobj_menu.cpp |
Date: | 2025-03-24 18:12:43 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 87 | 88 | 98.9% |
Branches: | 146 | 155 | 94.2% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /*************************************** | ||
2 | Auteur : Pierre Aubert | ||
3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
4 | Licence : CeCILL-C | ||
5 | ****************************************/ | ||
6 | |||
7 | #include "platexobj_html.h" | ||
8 | #include "platexobj_text.h" | ||
9 | |||
10 | #include "platexobj_menu.h" | ||
11 | |||
12 | |||
13 | ///Convert a PLatexObj into a menu | ||
14 | /** @param[out] menu : PFullMenu | ||
15 | * @param obj : PLatexObj | ||
16 | */ | ||
17 | 251 | void platexobj_toMenuAll(PFullMenu & menu, const PLatexObj & obj){ | |
18 |
2/2✓ Branch 1 taken 251 times.
✓ Branch 4 taken 251 times.
|
251 | PString complextTitle(platexobj_text(obj.getComplexTitle())); |
19 |
6/6✓ Branch 1 taken 251 times.
✓ Branch 4 taken 251 times.
✓ Branch 7 taken 251 times.
✓ Branch 10 taken 251 times.
✓ Branch 13 taken 251 times.
✓ Branch 16 taken 251 times.
|
502 | PString objTitle("<strong aria-hidden=\"true\">" + vecNumberToString(obj.getVecSecNumber()) + ".</strong> " + complextTitle); //Content of the section title |
20 |
1/1✓ Branch 1 taken 251 times.
|
251 | PLatexType::PLatexType type(obj.getType()); |
21 |
2/2✓ Branch 1 taken 251 times.
✓ Branch 4 taken 251 times.
|
251 | menu.setLink(obj.getLink()); |
22 |
3/3✓ Branch 0 taken 24 times.
✓ Branch 1 taken 227 times.
✓ Branch 3 taken 24 times.
|
251 | if(type == PLatexType::PART){menu.setText(/*"Part " +*/ objTitle);} |
23 |
3/3✓ Branch 0 taken 30 times.
✓ Branch 1 taken 197 times.
✓ Branch 3 taken 30 times.
|
227 | else if(type == PLatexType::CHAPTER){menu.setText(/*"Chapter " +*/ objTitle);} |
24 |
3/3✓ Branch 0 taken 66 times.
✓ Branch 1 taken 131 times.
✓ Branch 3 taken 66 times.
|
197 | else if(type == PLatexType::SECTION){menu.setText(objTitle);} |
25 |
3/3✓ Branch 0 taken 118 times.
✓ Branch 1 taken 13 times.
✓ Branch 3 taken 118 times.
|
131 | else if(type == PLatexType::SUBSECTION){menu.setText(objTitle);} |
26 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
13 | else if(type == PLatexType::SUBSUBSECTION){menu.setText(objTitle);} |
27 |
4/4✓ Branch 0 taken 11 times.
✓ Branch 1 taken 2 times.
✓ Branch 3 taken 11 times.
✓ Branch 6 taken 11 times.
|
13 | else if(type == PLatexType::FILE){menu.setText(obj.getName());} |
28 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | else if(type == PLatexType::BOOKPARTSEPARATOR){ |
29 |
1/1✓ Branch 1 taken 2 times.
|
2 | menu.setText(complextTitle); |
30 |
1/1✓ Branch 1 taken 2 times.
|
2 | menu.setIsSeparator(true); |
31 | } | ||
32 | |||
33 |
1/1✓ Branch 1 taken 251 times.
|
251 | const std::vector<PLatexObj> & vecChildren = obj.getVecContent(); |
34 |
2/2✓ Branch 4 taken 3168 times.
✓ Branch 5 taken 251 times.
|
3419 | for(std::vector<PLatexObj>::const_iterator it(vecChildren.begin()); it != vecChildren.end(); ++it){ |
35 |
3/3✓ Branch 2 taken 3168 times.
✓ Branch 4 taken 2928 times.
✓ Branch 5 taken 240 times.
|
3168 | if(!isSectionOrSeparator(*it)){continue;} |
36 |
1/1✓ Branch 1 taken 240 times.
|
240 | PFullMenu subMenu; |
37 |
1/1✓ Branch 2 taken 240 times.
|
240 | platexobj_toMenuAll(subMenu, *it); |
38 |
2/2✓ Branch 1 taken 240 times.
✓ Branch 4 taken 240 times.
|
240 | menu.getVecSubMenu().push_back(subMenu); |
39 | 240 | } | |
40 | 251 | } | |
41 | |||
42 | |||
43 | ///Convert a PLatexObj into a menu | ||
44 | /** @param obj : PLatexObj to be used | ||
45 | * @param mainPageLink : main page link if updated | ||
46 | * @return PFullMenu | ||
47 | */ | ||
48 | 11 | PFullMenu platexobj_toMenu(const PLatexObj & obj, const PLatexObj & mainPageLink){ | |
49 | 11 | PFullMenu menu; | |
50 |
1/1✓ Branch 1 taken 11 times.
|
11 | platexobj_toMenuAll(menu, obj); |
51 |
3/3✓ Branch 1 taken 11 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 9 times.
|
11 | if(mainPageLink.getType() == PLatexType::BOOKMAINPAGELINK){ |
52 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | PString textMainPage(platexobj_text(mainPageLink.getVecContent())); |
53 |
2/3✓ Branch 1 taken 2 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
|
2 | if(textMainPage != ""){ |
54 |
1/1✓ Branch 1 taken 2 times.
|
2 | menu.setMainPageLink(textMainPage); |
55 | }else{ | ||
56 | ✗ | menu.setMainPageLink("Main Page"); | |
57 | } | ||
58 | 2 | }else{ | |
59 |
2/2✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
|
9 | menu.setMainPageLink("Main Page"); |
60 | } | ||
61 | 11 | return menu; | |
62 | } | ||
63 | |||
64 | ///Convert a PFullMenu to html | ||
65 | /** @param menu : PFullMenu to be converted | ||
66 | * @param indentation : display indentation | ||
67 | * @return corresponding html | ||
68 | */ | ||
69 | 19858 | PString platexobj_menuToHtmlChapter(const PFullMenu & menu, const PString & indentation){ | |
70 |
5/5✓ Branch 1 taken 19858 times.
✓ Branch 4 taken 19858 times.
✓ Branch 7 taken 19858 times.
✓ Branch 10 taken 19858 times.
✓ Branch 13 taken 19858 times.
|
19858 | PString body(""), link(menu.getLink()), text(menu.getText()); |
71 |
1/1✓ Branch 1 taken 19858 times.
|
19858 | PString displayList(""); |
72 |
3/3✓ Branch 1 taken 19858 times.
✓ Branch 3 taken 14 times.
✓ Branch 4 taken 19844 times.
|
19858 | if(menu.getIsSeparator()){ |
73 |
4/4✓ Branch 1 taken 14 times.
✓ Branch 4 taken 14 times.
✓ Branch 7 taken 14 times.
✓ Branch 10 taken 14 times.
|
14 | body += indentation + "<li class=\"chapter-item affix \"><li class=\"part-title\">"+text+"</li>\n"; |
74 | }else{ | ||
75 |
3/3✓ Branch 1 taken 19844 times.
✓ Branch 3 taken 718 times.
✓ Branch 4 taken 19126 times.
|
19844 | if(menu.getIsExpanded()){ |
76 |
1/1✓ Branch 1 taken 718 times.
|
718 | displayList = "expanded"; |
77 |
3/3✓ Branch 1 taken 718 times.
✓ Branch 3 taken 238 times.
✓ Branch 4 taken 480 times.
|
718 | if(menu.getIsFirstExpanded()){ |
78 |
1/1✓ Branch 1 taken 238 times.
|
238 | displayList += " active"; |
79 | } | ||
80 | } | ||
81 |
8/8✓ Branch 1 taken 19844 times.
✓ Branch 4 taken 19844 times.
✓ Branch 7 taken 19844 times.
✓ Branch 10 taken 19844 times.
✓ Branch 13 taken 19844 times.
✓ Branch 16 taken 19844 times.
✓ Branch 19 taken 19844 times.
✓ Branch 22 taken 19844 times.
|
19844 | body += indentation + "<li class=\"chapter-item "+displayList+"\"><a href=\""+link+"\">"+text+"</a>"; |
82 | |||
83 |
1/1✓ Branch 1 taken 19844 times.
|
19844 | const std::vector<PFullMenu> & vecSubMenu = menu.getVecSubMenu(); |
84 |
2/2✓ Branch 1 taken 5191 times.
✓ Branch 2 taken 14653 times.
|
19844 | if(vecSubMenu.size() != 0lu){ |
85 |
1/1✓ Branch 1 taken 5191 times.
|
5191 | body += "<a class=\"toggle\"><div>❱</div></a></li>\n"; |
86 |
2/2✓ Branch 1 taken 5191 times.
✓ Branch 4 taken 5191 times.
|
5191 | body += indentation + "<li>\n"; |
87 |
2/2✓ Branch 1 taken 5191 times.
✓ Branch 4 taken 5191 times.
|
5191 | body += indentation + "\t<ol class=\"section\">\n"; |
88 |
2/2✓ Branch 3 taken 19377 times.
✓ Branch 4 taken 5191 times.
|
24568 | for(std::vector<PFullMenu>::const_iterator it(vecSubMenu.begin()); it != vecSubMenu.end(); ++it){ |
89 |
4/4✓ Branch 1 taken 19377 times.
✓ Branch 4 taken 19377 times.
✓ Branch 8 taken 19377 times.
✓ Branch 11 taken 19377 times.
|
19377 | body += platexobj_menuToHtmlChapter(*it, indentation + "\t\t"); |
90 | } | ||
91 |
2/2✓ Branch 1 taken 5191 times.
✓ Branch 4 taken 5191 times.
|
5191 | body += indentation + "\t</ol>\n"; |
92 |
2/2✓ Branch 1 taken 5191 times.
✓ Branch 4 taken 5191 times.
|
5191 | body += indentation + "</li>\n"; |
93 | }else{ | ||
94 |
1/1✓ Branch 1 taken 14653 times.
|
14653 | body += "</li>\n"; |
95 | } | ||
96 | } | ||
97 | 39716 | return body; | |
98 | 19858 | } | |
99 | |||
100 | ///Say if the current menu has to be extended | ||
101 | /** @param menu : PFullMenu to be checked | ||
102 | * @param currentLink : link of the menu to be expanded | ||
103 | */ | ||
104 | 10181 | bool platexobg_isMenuExtanded(const PFullMenu & menu, const PString & currentLink){ | |
105 | 10181 | return menu.getLink() == currentLink; | |
106 | } | ||
107 | |||
108 | ///Update menus which are supposed to be extended | ||
109 | /** @param menu : PFullMenu to be converted | ||
110 | * @param currentLink : link of the current menu | ||
111 | */ | ||
112 | 10181 | void platexobj_makeExpandMenu(PFullMenu & menu, const PString & currentLink){ | |
113 |
1/1✓ Branch 1 taken 10181 times.
|
10181 | bool isFirstExtended(platexobg_isMenuExtanded(menu, currentLink)); //Check if the current section has to be expanded |
114 |
1/1✓ Branch 1 taken 10181 times.
|
10181 | menu.setIsFirstExpanded(isFirstExtended); |
115 | 10181 | bool isExtended(isFirstExtended); | |
116 |
1/1✓ Branch 1 taken 10181 times.
|
10181 | std::vector<PFullMenu> & vecSubMenu = menu.getVecSubMenu(); |
117 | 10181 | std::vector<PFullMenu>::iterator it(vecSubMenu.begin()); | |
118 |
6/6✓ Branch 0 taken 19146 times.
✓ Branch 1 taken 967 times.
✓ Branch 4 taken 9932 times.
✓ Branch 5 taken 9214 times.
✓ Branch 6 taken 9932 times.
✓ Branch 7 taken 10181 times.
|
20113 | while(!isExtended && it != vecSubMenu.end()){ |
119 |
1/1✓ Branch 2 taken 9932 times.
|
9932 | platexobj_makeExpandMenu(*it, currentLink); |
120 |
1/1✓ Branch 2 taken 9932 times.
|
9932 | isExtended = it->getIsExpanded(); |
121 | 9932 | ++it; | |
122 | } | ||
123 |
1/1✓ Branch 1 taken 10181 times.
|
10181 | menu.setIsExpanded(isExtended); |
124 | 10181 | } | |
125 | |||
126 | ///Convert a PFullMenu to html | ||
127 | /** @param menu : PFullMenu to be converted | ||
128 | * @param currentLink : link of the current menu | ||
129 | * @param isBibliography : true if there is a bibliography, false if not | ||
130 | * @return corresponding html | ||
131 | */ | ||
132 | 249 | PString platexobj_menuToHtml(const PFullMenu & menu, const PString & currentLink, bool isBibliography){ | |
133 |
1/1✓ Branch 1 taken 249 times.
|
249 | PFullMenu expandedMenu(menu); |
134 |
1/1✓ Branch 1 taken 249 times.
|
249 | platexobj_makeExpandMenu(expandedMenu, currentLink); |
135 | |||
136 |
2/2✓ Branch 1 taken 249 times.
✓ Branch 4 taken 249 times.
|
249 | PString body(""), indentation("\t\t"); |
137 |
2/2✓ Branch 1 taken 249 times.
✓ Branch 4 taken 249 times.
|
249 | body += indentation+"<nav id=\"sidebar\" class=\"sidebar\" aria-label=\"Table of contents\">\n"; |
138 |
2/2✓ Branch 1 taken 249 times.
✓ Branch 4 taken 249 times.
|
249 | body += indentation+"\t<div class=\"sidebar-scrollbox\">\n"; |
139 |
2/2✓ Branch 1 taken 249 times.
✓ Branch 4 taken 249 times.
|
249 | body += indentation+"\t\t<ol class=\"chapter\">\n"; |
140 |
5/5✓ Branch 1 taken 249 times.
✓ Branch 4 taken 249 times.
✓ Branch 7 taken 249 times.
✓ Branch 10 taken 249 times.
✓ Branch 13 taken 249 times.
|
249 | body += indentation + "\t\t\t<li class=\"chapter-item \"><a href=\"index.html\">"+menu.getMainPageLink()+"</a></li>\n"; |
141 |
1/1✓ Branch 1 taken 249 times.
|
249 | const std::vector<PFullMenu> & vecSubMenu = expandedMenu.getVecSubMenu(); |
142 |
2/2✓ Branch 3 taken 481 times.
✓ Branch 4 taken 249 times.
|
730 | for(std::vector<PFullMenu>::const_iterator it(vecSubMenu.begin()); it != vecSubMenu.end(); ++it){ |
143 |
4/4✓ Branch 1 taken 481 times.
✓ Branch 4 taken 481 times.
✓ Branch 8 taken 481 times.
✓ Branch 11 taken 481 times.
|
481 | body += platexobj_menuToHtmlChapter(*it, indentation+"\t\t\t"); |
144 | } | ||
145 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 242 times.
|
249 | if(isBibliography){ |
146 |
2/2✓ Branch 1 taken 7 times.
✓ Branch 4 taken 7 times.
|
7 | body += indentation + "\t\t\t<li class=\"chapter-item \"><a href=\"bibliography.html\">Bibliography</a></li>\n"; |
147 | } | ||
148 | |||
149 |
2/2✓ Branch 1 taken 249 times.
✓ Branch 4 taken 249 times.
|
249 | body += indentation+"\t\t</ol>\n"; |
150 |
2/2✓ Branch 1 taken 249 times.
✓ Branch 4 taken 249 times.
|
249 | body += indentation+"\t</div>\n"; |
151 |
2/2✓ Branch 1 taken 249 times.
✓ Branch 4 taken 249 times.
|
249 | body += indentation+"\t<div id=\"sidebar-resize-handle\" class=\"sidebar-resize-handle\"></div>\n"; |
152 |
2/2✓ Branch 1 taken 249 times.
✓ Branch 4 taken 249 times.
|
249 | body += indentation+"</nav>\n"; |
153 | 498 | return body; | |
154 | 249 | } | |
155 | |||
156 | |||
157 |