Directory: | ./ |
---|---|
File: | tmp_project/PhoenixTex2Html/src/PMarkdownParser.cpp |
Date: | 2025-03-24 18:12:43 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 368 | 411 | 89.5% |
Branches: | 496 | 673 | 73.7% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /*************************************** | ||
2 | Auteur : Pierre Aubert | ||
3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
4 | Licence : CeCILL-C | ||
5 | ****************************************/ | ||
6 | |||
7 | #include "data_all.h" | ||
8 | #include "PMarkdownParser.h" | ||
9 | |||
10 | ///Default constructor of PMarkdownParser | ||
11 | /** @param installPrefix : installation prefix | ||
12 | */ | ||
13 | 2 | PMarkdownParser::PMarkdownParser(const PString & installPrefix) | |
14 | 2 | :PGenericParser(installPrefix) | |
15 | { | ||
16 | 2 | initialisationPMarkdownParser(); | |
17 | 2 | } | |
18 | |||
19 | ///Copy constructor of PMarkdownParser | ||
20 | /** @param other : class to copy | ||
21 | */ | ||
22 | 3 | PMarkdownParser::PMarkdownParser(const PGenericParser & other) | |
23 | 3 | :PGenericParser(other) | |
24 | { | ||
25 | |||
26 | 3 | } | |
27 | |||
28 | ///Copy constructor of PMarkdownParser | ||
29 | /** @param other : class to copy | ||
30 | */ | ||
31 | ✗ | PMarkdownParser::PMarkdownParser(const PMarkdownParser & other) | |
32 | ✗ | :PGenericParser(other) | |
33 | { | ||
34 | ✗ | copyPMarkdownParser(other); | |
35 | } | ||
36 | |||
37 | ///Destructor of PMarkdownParser | ||
38 | 10 | PMarkdownParser::~PMarkdownParser(){ | |
39 | |||
40 | } | ||
41 | |||
42 | ///Definition of equal operator of PMarkdownParser | ||
43 | /** @param other : class to copy | ||
44 | * @return copied class | ||
45 | */ | ||
46 | ✗ | PMarkdownParser & PMarkdownParser::operator = (const PMarkdownParser & other){ | |
47 | ✗ | copyPMarkdownParser(other); | |
48 | ✗ | return *this; | |
49 | } | ||
50 | |||
51 | ///Copy function of PMarkdownParser | ||
52 | /** @param other : class to copy | ||
53 | */ | ||
54 | ✗ | void PMarkdownParser::copyPMarkdownParser(const PMarkdownParser & other){ | |
55 | |||
56 | } | ||
57 | |||
58 | ///Parse the input file | ||
59 | /** @return true on success, false otherwise | ||
60 | */ | ||
61 | 5 | bool PMarkdownParser::parseFile(){ | |
62 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | if(!p_run) return false; |
63 |
1/1✓ Branch 1 taken 5 times.
|
5 | p_currentSource.setType(PLatexType::FILE); |
64 |
1/1✓ Branch 2 taken 5 times.
|
5 | p_currentSource.setLink("index.html"); |
65 |
1/1✓ Branch 2 taken 5 times.
|
5 | p_currentSource.setSourceFile(p_parser->getFileName()); |
66 | 5 | p_currentSource.setSourceLine(1lu); | |
67 |
3/3✓ Branch 2 taken 5 times.
✓ Branch 5 taken 5 times.
✓ Branch 8 taken 5 times.
|
5 | p_currentSource.setName(p_parser->getFileName().getFileName().eraseExtension()); |
68 | |||
69 | //To parse the file we need to read char by char until we get something we know | ||
70 |
5/6✓ Branch 1 taken 2630 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 2630 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2630 times.
✓ Branch 6 taken 5 times.
|
2635 | while(!p_parser->isEndOfFile() && p_run){ //If we are not at the end of the file |
71 |
2/2✓ Branch 1 taken 2376 times.
✓ Branch 2 taken 254 times.
|
2630 | if(parseAllLatexObj(p_currentSource, p_currentText)){} |
72 | else{ | ||
73 | 2376 | incrementCurrentChar(p_currentText); | |
74 | } | ||
75 | } | ||
76 | 5 | playTextLatexObj(p_currentSource, p_currentText); | |
77 | 5 | return true; | |
78 | } | ||
79 | |||
80 | ///Initialisation to be done just before loading a file | ||
81 | 5 | void PMarkdownParser::preLoadFile(){ | |
82 | //Save the current source | ||
83 | 5 | clearLatexObj(p_currentSource); | |
84 | 5 | clearLatexObj(p_currentText); | |
85 |
1/1✓ Branch 2 taken 5 times.
|
5 | p_parser->setWhiteSpace(""); |
86 |
1/1✓ Branch 2 taken 5 times.
|
5 | p_parser->setSeparator(""); |
87 | 5 | } | |
88 | |||
89 | ///Initialisation to be done just after loading a file | ||
90 | 5 | void PMarkdownParser::postLoadFile(){ | |
91 | |||
92 | 5 | } | |
93 | |||
94 | ///Initialisation function of the class PMarkdownParser | ||
95 | 2 | void PMarkdownParser::initialisationPMarkdownParser(){ | |
96 | |||
97 | 2 | } | |
98 | |||
99 | ///Parse all the functions which have complex mono parameter in braces {...} | ||
100 | /** @param[out] parent : parent PLatexObj | ||
101 | * @param[out] textObj : PLatexObj to deal with text | ||
102 | * @param functionName : name of the expected function | ||
103 | * @param type : type of the expected function | ||
104 | * @return true on success, false otherwise | ||
105 | */ | ||
106 | 8676 | bool PMarkdownParser::parseComplexMonoParam(PLatexObj & parent, PLatexObj & textObj, const PString & functionName, PLatexType::PLatexType type){ | |
107 |
2/3✓ Branch 1 taken 8676 times.
✓ Branch 3 taken 8676 times.
✗ Branch 4 not taken.
|
8676 | if(!p_parser->isMatchToken(functionName)){return false;} |
108 | ✗ | playTextLatexObj(parent, textObj); | |
109 | ✗ | PLatexObj tmp; | |
110 | ✗ | tmp.setType(type); | |
111 | |||
112 | ✗ | PString textOption(getOptionStringBetweenHook()); | |
113 | ✗ | tmp.setText(textOption); | |
114 | |||
115 | ✗ | parseVecLatexObj(tmp, textObj, "{", "}"); | |
116 | |||
117 | ✗ | addLatexObj(parent, tmp); | |
118 | ✗ | return true; | |
119 | } | ||
120 | |||
121 | ///Parse all the latex obj, but in markdown style | ||
122 | /** @param[out] parent : parent PLatexObj | ||
123 | * @param[out] textObj : PLatexObj to deal with text | ||
124 | * @return true on success, false otherwise | ||
125 | */ | ||
126 | 4414 | bool PMarkdownParser::parseAllLatexObj(PLatexObj & parent, PLatexObj & textObj){ | |
127 |
3/3✓ Branch 2 taken 4414 times.
✓ Branch 5 taken 4410 times.
✓ Branch 6 taken 4 times.
|
4414 | if(parseSectionTitle(parent, textObj, "##### ", PLatexType::SUBSUBSECTION)){} |
128 |
3/3✓ Branch 2 taken 4410 times.
✓ Branch 5 taken 4406 times.
✓ Branch 6 taken 4 times.
|
4410 | else if(parseSectionTitle(parent, textObj, "#### ", PLatexType::SUBSECTION)){} |
129 |
3/3✓ Branch 2 taken 4406 times.
✓ Branch 5 taken 4402 times.
✓ Branch 6 taken 4 times.
|
4406 | else if(parseSectionTitle(parent, textObj, "### ", PLatexType::SECTION)){} |
130 |
3/3✓ Branch 2 taken 4402 times.
✓ Branch 5 taken 4398 times.
✓ Branch 6 taken 4 times.
|
4402 | else if(parseSectionTitle(parent, textObj, "## ", PLatexType::CHAPTER)){} |
131 |
3/3✓ Branch 2 taken 4398 times.
✓ Branch 5 taken 4386 times.
✓ Branch 6 taken 12 times.
|
4398 | else if(parseSectionTitle(parent, textObj, "# ", PLatexType::PART)){} |
132 | |||
133 |
2/2✓ Branch 1 taken 4366 times.
✓ Branch 2 taken 20 times.
|
4386 | else if(parseExtraEnvironement(parent, textObj)){} |
134 |
2/2✓ Branch 1 taken 4354 times.
✓ Branch 2 taken 12 times.
|
4366 | else if(parseExtraParser(parent, textObj)){} |
135 |
2/2✓ Branch 1 taken 4350 times.
✓ Branch 2 taken 4 times.
|
4354 | else if(parseWip(parent, textObj)){} |
136 |
5/5✓ Branch 2 taken 4350 times.
✓ Branch 5 taken 4350 times.
✓ Branch 8 taken 4350 times.
✓ Branch 13 taken 4342 times.
✓ Branch 14 taken 8 times.
|
4350 | else if(parseEnvDecoration(parent, textObj, "```", "terminal", PLatexType::ENVIRONEMENT, "pre")){} |
137 | |||
138 |
2/2✓ Branch 1 taken 4338 times.
✓ Branch 2 taken 4 times.
|
4342 | else if(parseGenericLatexObj(parent, textObj)){} |
139 |
2/3✓ Branch 2 taken 4338 times.
✓ Branch 5 taken 4338 times.
✗ Branch 6 not taken.
|
4338 | else if(parseComplexMonoParam(parent, textObj, "\\footnote", PLatexType::FOOTNOTE)){} |
140 |
2/3✓ Branch 2 taken 4338 times.
✓ Branch 5 taken 4338 times.
✗ Branch 6 not taken.
|
4338 | else if(parseComplexMonoParam(parent, textObj, "\\caption", PLatexType::CAPTION)){} |
141 | |||
142 |
2/2✓ Branch 1 taken 4156 times.
✓ Branch 2 taken 182 times.
|
4338 | else if(parseEnvLatexObj(parent, textObj)){} |
143 | else{ | ||
144 | 4156 | return false; | |
145 | } | ||
146 | 258 | return true; | |
147 | } | ||
148 | |||
149 | ///Parse all the latex obj in environement, but in markdown style | ||
150 | /** @param[out] parent : parent PLatexObj | ||
151 | * @param[out] textObj : PLatexObj to deal with text | ||
152 | * @return true on success, false otherwise | ||
153 | */ | ||
154 | 4886 | bool PMarkdownParser::parseEnvLatexObj(PLatexObj & parent, PLatexObj & textObj){ | |
155 |
2/2✓ Branch 1 taken 4874 times.
✓ Branch 2 taken 12 times.
|
4886 | if(parseItemize(parent, textObj)){} |
156 |
2/2✓ Branch 1 taken 4870 times.
✓ Branch 2 taken 4 times.
|
4874 | else if(parseEnumerate(parent, textObj)){} |
157 |
2/2✓ Branch 1 taken 4726 times.
✓ Branch 2 taken 144 times.
|
4870 | else if(parseNewLine(parent, textObj)){} |
158 |
2/2✓ Branch 1 taken 4688 times.
✓ Branch 2 taken 38 times.
|
4726 | else if(parseItemLatexObj(parent, textObj)){} |
159 | else{ | ||
160 | 4688 | return false; | |
161 | } | ||
162 | |||
163 | 198 | return true; | |
164 | } | ||
165 | |||
166 | ///Parse all the latex obj in item, but in markdown style | ||
167 | /** @param[out] parent : parent PLatexObj | ||
168 | * @param[out] textObj : PLatexObj to deal with text | ||
169 | * @return true on success, false otherwise | ||
170 | */ | ||
171 | 6282 | bool PMarkdownParser::parseItemLatexObj(PLatexObj & parent, PLatexObj & textObj){ | |
172 |
2/2✓ Branch 1 taken 6278 times.
✓ Branch 2 taken 4 times.
|
6282 | if(parseComment(parent, textObj)){} |
173 |
5/5✓ Branch 2 taken 6278 times.
✓ Branch 5 taken 6278 times.
✓ Branch 8 taken 6278 times.
✓ Branch 13 taken 6274 times.
✓ Branch 14 taken 4 times.
|
6278 | else if(parseTextDecoration(parent, textObj, "***", "textbfit", PLatexType::FUNCTION, "span")){} |
174 |
5/5✓ Branch 2 taken 6274 times.
✓ Branch 5 taken 6274 times.
✓ Branch 8 taken 6274 times.
✓ Branch 13 taken 6262 times.
✓ Branch 14 taken 12 times.
|
6274 | else if(parseTextDecoration(parent, textObj, "**", "textbf", PLatexType::FUNCTION, "span")){} |
175 |
5/5✓ Branch 2 taken 6262 times.
✓ Branch 5 taken 6262 times.
✓ Branch 8 taken 6262 times.
✓ Branch 13 taken 6250 times.
✓ Branch 14 taken 12 times.
|
6262 | else if(parseTextDecoration(parent, textObj, "*", "textit", PLatexType::FUNCTION, "span")){} |
176 |
5/5✓ Branch 2 taken 6250 times.
✓ Branch 5 taken 6250 times.
✓ Branch 8 taken 6250 times.
✓ Branch 13 taken 6242 times.
✓ Branch 14 taken 8 times.
|
6250 | else if(parseTextDecoration(parent, textObj, "`", "code", PLatexType::FUNCTION, "span")){} |
177 | |||
178 |
2/2✓ Branch 1 taken 6234 times.
✓ Branch 2 taken 8 times.
|
6242 | else if(parseHref(parent, textObj)){} |
179 |
2/2✓ Branch 1 taken 6228 times.
✓ Branch 2 taken 6 times.
|
6234 | else if(parseIncludeGraphic(parent, textObj)){} |
180 |
2/2✓ Branch 1 taken 6224 times.
✓ Branch 2 taken 4 times.
|
6228 | else if(parseUrl(parent, textObj)){} |
181 |
2/2✓ Branch 1 taken 6220 times.
✓ Branch 2 taken 4 times.
|
6224 | else if(parsePercent(parent, textObj)){} |
182 | else{ | ||
183 | 6220 | return false; | |
184 | } | ||
185 | 62 | return true; | |
186 | } | ||
187 | |||
188 | ///Parse all the functions which have complex mono parameter in braces | ||
189 | /** @param[out] parent : parent PLatexObj | ||
190 | * @param[out] textObj : PLatexObj to deal with text | ||
191 | * @param functionName : name of the expected function | ||
192 | * @param type : type of the expected function | ||
193 | * @return true on success, false otherwise | ||
194 | */ | ||
195 | 22030 | bool PMarkdownParser::parseSectionTitle(PLatexObj & parent, PLatexObj & textObj, const PString & functionName, PLatexType::PLatexType type){ | |
196 |
3/3✓ Branch 1 taken 22030 times.
✓ Branch 3 taken 22002 times.
✓ Branch 4 taken 28 times.
|
22030 | if(!p_parser->isMatch(functionName)){return false;} |
197 |
1/1✓ Branch 1 taken 28 times.
|
28 | playTextLatexObj(parent, textObj); |
198 |
1/1✓ Branch 1 taken 28 times.
|
28 | PLatexObj tmp; |
199 |
1/1✓ Branch 1 taken 28 times.
|
28 | tmp.setType(type); |
200 |
3/3✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
✓ Branch 7 taken 28 times.
|
28 | tmp.setSourceFile(p_parser->getLocation().getFileName()); |
201 |
3/3✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
✓ Branch 7 taken 28 times.
|
28 | tmp.setSourceLine(p_parser->getLocation().getLine()); |
202 | |||
203 |
1/1✓ Branch 1 taken 28 times.
|
28 | PLatexObj objTitle; |
204 |
3/3✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
✓ Branch 7 taken 28 times.
|
28 | parseVecLatexObj(objTitle, textObj, "", "\n"); |
205 |
2/2✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
|
28 | tmp.setComplexTitle(objTitle.getVecContent()); |
206 |
1/1✓ Branch 1 taken 28 times.
|
28 | addLatexObj(parent, tmp); |
207 | 28 | return true; | |
208 | 28 | } | |
209 | |||
210 | ///Parse a text decoration (bold, italic, etc) | ||
211 | /** @param[out] parent : parent PLatexObj | ||
212 | * @param[out] textObj : PLatexObj to deal with text | ||
213 | * @param patern : begin and end patern of the markdown command | ||
214 | * @param cssStyle : css style to put in the PLatexObj | ||
215 | * @param type : type of the object to be parsed | ||
216 | * @param balise : delimitor of the object to be parsed | ||
217 | * @return true on success, false otherwise | ||
218 | */ | ||
219 | 25064 | bool PMarkdownParser::parseTextDecoration(PLatexObj & parent, PLatexObj & textObj, const PString & patern, const PString & cssStyle, | |
220 | PLatexType::PLatexType type, const PString & balise) | ||
221 | { | ||
222 |
4/4✓ Branch 1 taken 25064 times.
✓ Branch 4 taken 25064 times.
✓ Branch 7 taken 4 times.
✓ Branch 8 taken 25060 times.
|
25064 | if(p_parser->isMatch("```")){return false;} |
223 |
3/3✓ Branch 1 taken 25060 times.
✓ Branch 3 taken 25024 times.
✓ Branch 4 taken 36 times.
|
25060 | if(!p_parser->isMatch(patern)){return false;} |
224 |
1/1✓ Branch 1 taken 36 times.
|
36 | playTextLatexObj(parent, textObj); |
225 |
1/1✓ Branch 1 taken 36 times.
|
36 | PLatexObj tmp; |
226 |
1/1✓ Branch 1 taken 36 times.
|
36 | tmp.setType(type); |
227 |
1/1✓ Branch 1 taken 36 times.
|
36 | tmp.setName(cssStyle); |
228 |
1/1✓ Branch 1 taken 36 times.
|
36 | tmp.setBalise(balise); |
229 | |||
230 |
2/2✓ Branch 1 taken 36 times.
✓ Branch 4 taken 36 times.
|
36 | parseVecLatexObj(tmp, textObj, "", patern); |
231 |
1/1✓ Branch 1 taken 36 times.
|
36 | addLatexObj(parent, tmp); |
232 | 36 | return true; | |
233 | 36 | } | |
234 | |||
235 | ///Parse a text decoration (bold, italic, etc) | ||
236 | /** @param[out] parent : parent PLatexObj | ||
237 | * @param[out] textObj : PLatexObj to deal with text | ||
238 | * @param patern : begin and end patern of the markdown command | ||
239 | * @param cssStyle : css style to put in the PLatexObj | ||
240 | * @param type : type of the object to be parsed | ||
241 | * @param balise : delimitor of the object to be parsed | ||
242 | * @return true on success, false otherwise | ||
243 | */ | ||
244 | 4350 | bool PMarkdownParser::parseEnvDecoration(PLatexObj & parent, PLatexObj & textObj, const PString & patern, const PString & cssStyle, | |
245 | PLatexType::PLatexType type, const PString & balise) | ||
246 | { | ||
247 |
3/3✓ Branch 1 taken 4350 times.
✓ Branch 3 taken 4342 times.
✓ Branch 4 taken 8 times.
|
4350 | if(!p_parser->isMatch(patern)){return false;} |
248 |
1/1✓ Branch 1 taken 8 times.
|
8 | playTextLatexObj(parent, textObj); |
249 |
1/1✓ Branch 1 taken 8 times.
|
8 | PLatexObj tmp; |
250 |
1/1✓ Branch 1 taken 8 times.
|
8 | tmp.setType(type); |
251 |
1/1✓ Branch 1 taken 8 times.
|
8 | tmp.setName(cssStyle); |
252 |
1/1✓ Branch 1 taken 8 times.
|
8 | tmp.setBalise(balise); |
253 | |||
254 |
2/2✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
|
8 | parseVecLatexObj(tmp, textObj, "", patern); |
255 |
1/1✓ Branch 1 taken 8 times.
|
8 | addLatexObj(parent, tmp); |
256 | 8 | return true; | |
257 | 8 | } | |
258 | |||
259 | ///Parse the includegraphic command | ||
260 | /** @param[out] parent : parent PLatexObj | ||
261 | * @param[out] textObj : PLatexObj to deal with text | ||
262 | * @return true on success, false otherwise | ||
263 | */ | ||
264 | 6234 | bool PMarkdownParser::parseIncludeGraphic(PLatexObj & parent, PLatexObj & textObj){ | |
265 |
4/4✓ Branch 1 taken 6234 times.
✓ Branch 4 taken 6234 times.
✓ Branch 7 taken 6228 times.
✓ Branch 8 taken 6 times.
|
6234 | if(!p_parser->isMatch("![")){return false;} |
266 |
1/1✓ Branch 1 taken 6 times.
|
6 | playTextLatexObj(parent, textObj); |
267 |
2/2✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
|
6 | PString option(p_parser->getUntilKeyWithoutPatern("]")); |
268 |
3/4✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6 times.
|
6 | if(!p_parser->isMatch("(")){ |
269 | ✗ | errorAt(); | |
270 | ✗ | std::cerr << "PMarkdownParser::parseIncludeGraphic : expect '(' after '!["+option+"]' instead of '"<<p_parser->getNextChar()<<"'" << std::endl; | |
271 | ✗ | stopParsing(); | |
272 | ✗ | return ""; | |
273 | } | ||
274 |
3/3✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
|
12 | PPath imageFile(p_parser->getUntilKeyWithoutPatern(")")); |
275 |
1/1✓ Branch 1 taken 6 times.
|
6 | PLatexObj tmp; |
276 |
1/1✓ Branch 1 taken 6 times.
|
6 | bool isVideo(imageFile.getExtension() == "mp4"); |
277 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
|
6 | if(isVideo){ //This is not an image |
278 |
1/1✓ Branch 1 taken 2 times.
|
2 | tmp.setType(PLatexType::VIDEO); |
279 | }else{ | ||
280 |
1/1✓ Branch 1 taken 4 times.
|
4 | tmp.setType(PLatexType::IMAGE); |
281 | } | ||
282 |
1/1✓ Branch 1 taken 6 times.
|
6 | PString outputDir(LATEX_IMAGE_OUTPUT_DIR); |
283 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
|
6 | if(isVideo){ |
284 |
1/1✓ Branch 1 taken 2 times.
|
2 | outputDir = LATEX_VIDEO_OUTPUT_DIR; |
285 | } | ||
286 |
3/3✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
|
12 | PString buildFileName(copyFile(outputDir, imageFile)); |
287 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
|
6 | if(buildFileName == ""){return true;} |
288 |
1/1✓ Branch 1 taken 6 times.
|
6 | tmp.setName(buildFileName); |
289 |
1/1✓ Branch 1 taken 6 times.
|
6 | tmp.setText(option); |
290 | |||
291 |
1/1✓ Branch 1 taken 6 times.
|
6 | addLatexObj(parent, tmp); |
292 | 6 | return true; | |
293 | 6 | } | |
294 | |||
295 | ///Parse latex url | ||
296 | /** @param[out] parent : parent PLatexObj | ||
297 | * @param[out] textObj : PLatexObj to deal with text | ||
298 | * @return true on success, false otherwise | ||
299 | */ | ||
300 | 6228 | bool PMarkdownParser::parseUrl(PLatexObj & parent, PLatexObj & textObj){ | |
301 |
4/4✓ Branch 1 taken 6228 times.
✓ Branch 4 taken 6228 times.
✓ Branch 7 taken 6224 times.
✓ Branch 8 taken 4 times.
|
6228 | if(!p_parser->isMatch("http")){return false;} |
302 |
1/1✓ Branch 1 taken 4 times.
|
4 | playTextLatexObj(parent, textObj); |
303 |
1/1✓ Branch 1 taken 4 times.
|
4 | PLatexObj tmp; |
304 |
1/1✓ Branch 1 taken 4 times.
|
4 | tmp.setType(PLatexType::URL); |
305 | |||
306 |
4/4✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
✓ Branch 10 taken 4 times.
|
8 | PString link("http" + p_parser->getUntilKeyWithoutPatern(" ")); |
307 |
1/1✓ Branch 1 taken 4 times.
|
4 | tmp.setName(link); |
308 | |||
309 |
1/1✓ Branch 1 taken 4 times.
|
4 | addLatexObj(parent, tmp); |
310 | 4 | return true; | |
311 | 4 | } | |
312 | |||
313 | ///Parse latex Href | ||
314 | /** @param[out] parent : parent PLatexObj | ||
315 | * @param[out] textObj : PLatexObj to deal with text | ||
316 | * @return true on success, false otherwise | ||
317 | */ | ||
318 | 6242 | bool PMarkdownParser::parseHref(PLatexObj & parent, PLatexObj & textObj){ | |
319 |
1/1✓ Branch 1 taken 6242 times.
|
6242 | p_parser->pushPosition(); |
320 |
4/4✓ Branch 1 taken 6242 times.
✓ Branch 4 taken 6242 times.
✓ Branch 7 taken 6234 times.
✓ Branch 8 taken 8 times.
|
6242 | if(!p_parser->isMatch("[")){return false;} |
321 |
1/1✓ Branch 1 taken 8 times.
|
8 | playTextLatexObj(parent, textObj); |
322 |
1/1✓ Branch 1 taken 8 times.
|
8 | PLatexObj tmp; |
323 |
1/1✓ Branch 1 taken 8 times.
|
8 | tmp.setType(PLatexType::HREF); |
324 | |||
325 |
3/3✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
✓ Branch 7 taken 8 times.
|
8 | parseVecLatexObj(tmp, textObj, "", "]"); //We alrday parse the begin patern at the begining of this method |
326 |
3/4✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 8 times.
|
8 | if(!p_parser->isMatch("(")){ |
327 | ✗ | p_parser->popPosition(); | |
328 | ✗ | return false; | |
329 | } | ||
330 |
3/3✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
✓ Branch 7 taken 8 times.
|
16 | PString link(p_parser->getUntilKeyWithoutPaternRecurse(")", "(")); |
331 |
1/1✓ Branch 1 taken 8 times.
|
8 | tmp.setName(link); |
332 | |||
333 |
7/23✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
✓ Branch 7 taken 8 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 8 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✓ Branch 23 taken 8 times.
✓ Branch 25 taken 8 times.
✗ Branch 26 not taken.
✗ Branch 28 not taken.
✓ Branch 29 taken 8 times.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
|
8 | if(!tmp.getName().isSameBegining("http") && !tmp.getName().isSameBegining("https")){ |
334 | ✗ | PString buildFileName(copyFile(PPath(LATEX_RESSOURCES_OUTPUT_DIR), link)); | |
335 | ✗ | if(buildFileName == ""){ | |
336 | ✗ | if(PPath(tmp.getName()).getExtension() != "html"){ | |
337 | ✗ | errorAt(); | |
338 | ✗ | std::cerr << "PMarkdownParser::parseHref : cannot copy file '"<<link<<"' in '" LATEX_RESSOURCES_OUTPUT_DIR "'" << std::endl; | |
339 | ✗ | return true; | |
340 | } | ||
341 | ✗ | buildFileName = link; | |
342 | } | ||
343 | ✗ | tmp.setName(buildFileName); | |
344 | } | ||
345 |
1/1✓ Branch 1 taken 8 times.
|
8 | addLatexObj(parent, tmp); |
346 | 8 | return true; | |
347 | 8 | } | |
348 | |||
349 | ///Parse latex percent | ||
350 | /** @param[out] parent : parent PLatexObj | ||
351 | * @param[out] textObj : PLatexObj to deal with text | ||
352 | * @return true on success, false otherwise | ||
353 | */ | ||
354 | 6224 | bool PMarkdownParser::parsePercent(PLatexObj & parent, PLatexObj & textObj){ | |
355 |
4/4✓ Branch 1 taken 6224 times.
✓ Branch 4 taken 6224 times.
✓ Branch 7 taken 6220 times.
✓ Branch 8 taken 4 times.
|
6224 | if(!p_parser->isMatch("%")){return false;} |
356 |
1/1✓ Branch 1 taken 4 times.
|
4 | playTextLatexObj(parent, textObj); |
357 |
1/1✓ Branch 1 taken 4 times.
|
4 | PLatexObj tmp; |
358 |
1/1✓ Branch 1 taken 4 times.
|
4 | tmp.setType(PLatexType::PERCENT); |
359 |
1/1✓ Branch 1 taken 4 times.
|
4 | addLatexObj(parent, tmp); |
360 | 4 | return true; | |
361 | 4 | } | |
362 | |||
363 | ///Parse a new line | ||
364 | /** @param[out] parent : parent PLatexObj | ||
365 | * @param[out] textObj : PLatexObj to deal with text | ||
366 | * @return true on success, false otherwise | ||
367 | */ | ||
368 | 4870 | bool PMarkdownParser::parseNewLine(PLatexObj & parent, PLatexObj & textObj){ | |
369 |
4/4✓ Branch 1 taken 4870 times.
✓ Branch 4 taken 4870 times.
✓ Branch 7 taken 4726 times.
✓ Branch 8 taken 144 times.
|
4870 | if(!p_parser->isMatch("\n\n")){return false;} |
370 |
1/1✓ Branch 1 taken 144 times.
|
144 | playTextLatexObj(parent, textObj); |
371 |
1/1✓ Branch 1 taken 144 times.
|
144 | PLatexObj tmp; |
372 |
1/1✓ Branch 1 taken 144 times.
|
144 | tmp.setType(PLatexType::AUTOSPACEPARAGRAPH); |
373 |
1/1✓ Branch 1 taken 144 times.
|
144 | addLatexObj(parent, tmp); |
374 | 144 | return true; | |
375 | 144 | } | |
376 | |||
377 | ///Parse a new line | ||
378 | /** @param[out] parent : parent PLatexObj | ||
379 | * @param[out] textObj : PLatexObj to deal with text | ||
380 | * @return true on success, false otherwise | ||
381 | */ | ||
382 | 6282 | bool PMarkdownParser::parseComment(PLatexObj & parent, PLatexObj & textObj){ | |
383 |
4/4✓ Branch 1 taken 6282 times.
✓ Branch 4 taken 6282 times.
✓ Branch 7 taken 6278 times.
✓ Branch 8 taken 4 times.
|
6282 | if(!p_parser->isMatch("<!--")){return false;} |
384 |
1/1✓ Branch 1 taken 4 times.
|
4 | playTextLatexObj(parent, textObj); |
385 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
|
4 | PString comment(p_parser->getUntilKeyWithoutPatern("-->")); |
386 |
1/1✓ Branch 1 taken 4 times.
|
4 | PLatexObj tmp; |
387 |
1/1✓ Branch 1 taken 4 times.
|
4 | tmp.setType(PLatexType::COMMENT); |
388 |
1/1✓ Branch 1 taken 4 times.
|
4 | tmp.setName(comment); |
389 |
1/1✓ Branch 1 taken 4 times.
|
4 | addLatexObj(parent, tmp); |
390 | 4 | return true; | |
391 | 4 | } | |
392 | |||
393 | ///Parse an item in the markdown itemize | ||
394 | /** @param[out] vecItemLevel : vector of itemize level | ||
395 | * @return true on success, false otherwise | ||
396 | */ | ||
397 | 52 | bool PMarkdownParser::parseItem(std::vector<std::pair<size_t, PLatexObj> > & vecItemLevel){ | |
398 |
3/4✓ Branch 1 taken 52 times.
✓ Branch 4 taken 52 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 52 times.
|
52 | if(p_parser->isMatchRewind("\n\n")){return false;} |
399 |
2/3✓ Branch 1 taken 52 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 52 times.
|
52 | if(!isItem()){ |
400 | ✗ | return false; | |
401 | } | ||
402 |
1/1✓ Branch 1 taken 52 times.
|
52 | size_t itemLevel(p_parser->getColumn()); |
403 |
1/1✓ Branch 1 taken 52 times.
|
52 | PLatexObj itemObj; |
404 |
1/1✓ Branch 1 taken 52 times.
|
52 | itemObj.setType(PLatexType::ITEM); |
405 | |||
406 |
1/1✓ Branch 1 taken 52 times.
|
52 | PLatexObj tmpText; |
407 |
1/1✓ Branch 1 taken 52 times.
|
52 | tmpText.setType(PLatexType::TEXT); |
408 | |||
409 | //Do some loop to fill the item | ||
410 |
13/18✓ Branch 1 taken 1276 times.
✓ Branch 3 taken 1276 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 1276 times.
✓ Branch 9 taken 1276 times.
✓ Branch 11 taken 1264 times.
✓ Branch 12 taken 12 times.
✓ Branch 14 taken 1264 times.
✓ Branch 16 taken 1224 times.
✓ Branch 17 taken 40 times.
✓ Branch 18 taken 1224 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 1276 times.
✗ Branch 21 not taken.
✓ Branch 23 taken 1224 times.
✓ Branch 24 taken 52 times.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
|
1276 | while(!p_parser->isEndOfFile() && !p_parser->isMatchRewind("\n\n") && !isItem(true) && p_run){ |
411 |
3/3✓ Branch 1 taken 1224 times.
✓ Branch 3 taken 1200 times.
✓ Branch 4 taken 24 times.
|
1224 | if(parseItemLatexObj(itemObj, tmpText)){} |
412 | else{ | ||
413 |
1/1✓ Branch 1 taken 1200 times.
|
1200 | incrementCurrentChar(tmpText); |
414 | } | ||
415 | } | ||
416 |
1/1✓ Branch 1 taken 52 times.
|
52 | playTextLatexObj(itemObj, tmpText); |
417 |
2/2✓ Branch 1 taken 52 times.
✓ Branch 4 taken 52 times.
|
52 | vecItemLevel.push_back(std::pair<size_t, PLatexObj>(itemLevel, itemObj)); |
418 | 52 | return true; | |
419 | 52 | } | |
420 | |||
421 | ///Say if there is no space between the last return and the current char | ||
422 | /** @param rewind : true to test and go back before the parsed token even if it is an item | ||
423 | * @return true if there is no space between the last return and the current char, false otherwise | ||
424 | */ | ||
425 | 6202 | bool PMarkdownParser::isItem(bool rewind){ | |
426 |
1/1✓ Branch 1 taken 6202 times.
|
6202 | size_t currentCol(p_parser->getColumn()); |
427 |
1/1✓ Branch 1 taken 6202 times.
|
6202 | p_parser->pushPosition(); |
428 |
4/4✓ Branch 1 taken 6202 times.
✓ Branch 4 taken 6202 times.
✓ Branch 7 taken 6094 times.
✓ Branch 8 taken 108 times.
|
6202 | if(!p_parser->isMatch("-")){ |
429 |
1/1✓ Branch 1 taken 6094 times.
|
6094 | p_parser->popPosition(); |
430 | 6094 | return false; | |
431 | } | ||
432 |
2/2✓ Branch 1 taken 108 times.
✓ Branch 4 taken 108 times.
|
108 | PString space(" \t"), currentRow(p_parser->getCurrentRow()); |
433 | 108 | size_t i(0lu); | |
434 |
2/2✓ Branch 0 taken 72 times.
✓ Branch 1 taken 104 times.
|
176 | while(i < currentCol){ |
435 |
1/1✓ Branch 1 taken 72 times.
|
72 | char ch = currentRow[i]; |
436 |
3/3✓ Branch 1 taken 72 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 68 times.
|
72 | if(!space.find(ch)){ |
437 |
1/1✓ Branch 1 taken 4 times.
|
4 | p_parser->popPosition(); |
438 | 4 | return false; | |
439 | } | ||
440 | 68 | ++i; | |
441 | } | ||
442 |
2/2✓ Branch 0 taken 52 times.
✓ Branch 1 taken 52 times.
|
104 | if(rewind){ |
443 |
1/1✓ Branch 1 taken 52 times.
|
52 | p_parser->popPosition(); |
444 | } | ||
445 | 104 | return true; | |
446 | 108 | } | |
447 | |||
448 | ///Get the proper parent for the item with the given level | ||
449 | /** @param parent : parent itemize | ||
450 | * @param vecLevel : vector of the parents levels | ||
451 | * @param itemLevel : current level of the item to be added to the parent | ||
452 | * @param listItemType : type of the item list | ||
453 | * @return pointer to the corresponding parent | ||
454 | */ | ||
455 | 68 | PLatexObj * PMarkdownParser::getProperParent(PLatexObj & parent, std::vector<size_t> & vecLevel, size_t itemLevel, PLatexType::PLatexType listItemType){ | |
456 | 68 | PLatexObj * currentParent = &parent; | |
457 |
2/2✓ Branch 1 taken 48 times.
✓ Branch 2 taken 20 times.
|
68 | if(vecLevel.back() >= itemLevel){ //The current parent level is too high |
458 |
5/6✓ Branch 1 taken 16 times.
✓ Branch 2 taken 48 times.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 16 times.
✓ Branch 7 taken 48 times.
|
64 | while(vecLevel.back() > itemLevel && vecLevel.size() > 1lu){ |
459 | 16 | vecLevel.pop_back(); | |
460 | } | ||
461 |
2/2✓ Branch 1 taken 40 times.
✓ Branch 2 taken 8 times.
|
48 | if(vecLevel.size() <= 1lu){ |
462 | 40 | return currentParent; | |
463 | } | ||
464 |
2/2✓ Branch 1 taken 8 times.
✓ Branch 2 taken 8 times.
|
16 | for(size_t i(1lu); i < vecLevel.size(); ++i){ |
465 | 8 | PLatexObj * tmpParent = currentParent; | |
466 |
1/1✓ Branch 1 taken 8 times.
|
8 | PLatexObj & lastItemize = tmpParent->getVecContent().back(); |
467 |
2/3✓ Branch 1 taken 8 times.
✓ Branch 3 taken 8 times.
✗ Branch 4 not taken.
|
8 | if(lastItemize.getType() == listItemType){ |
468 | 8 | currentParent = &lastItemize; | |
469 | }else{ | ||
470 | ✗ | errorAt(); | |
471 | ✗ | std::cerr << "PMarkdownParser::getProperParent : unextected PLatexObj of type " << lastItemize.getType() << std::endl; | |
472 | ✗ | stopParsing(); | |
473 | ✗ | return NULL; | |
474 | } | ||
475 | } | ||
476 | 8 | return currentParent; | |
477 | } | ||
478 | //Only if the level has to increase of one (vecLevel.back() < itemLevel) | ||
479 | //Let's take the last parent we know | ||
480 |
2/2✓ Branch 1 taken 12 times.
✓ Branch 2 taken 20 times.
|
32 | for(size_t i(1lu); i < vecLevel.size(); ++i){ |
481 | 12 | PLatexObj * tmpParent = currentParent; | |
482 |
1/1✓ Branch 1 taken 12 times.
|
12 | PLatexObj & lastItemize = tmpParent->getVecContent().back(); |
483 |
2/3✓ Branch 1 taken 12 times.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
|
12 | if(lastItemize.getType() == listItemType){ |
484 | 12 | currentParent = &lastItemize; | |
485 | }else{ | ||
486 | ✗ | errorAt(); | |
487 | ✗ | std::cerr << "PMarkdownParser::getProperParent : unextected PLatexObj of type " << lastItemize.getType() << std::endl; | |
488 | ✗ | stopParsing(); | |
489 | ✗ | return NULL; | |
490 | } | ||
491 | } | ||
492 |
1/1✓ Branch 1 taken 20 times.
|
20 | PLatexObj newItemize; |
493 |
1/1✓ Branch 1 taken 20 times.
|
20 | newItemize.setType(listItemType); |
494 | |||
495 | 20 | PLatexObj * tmpParent = currentParent; | |
496 |
1/1✓ Branch 1 taken 20 times.
|
20 | addLatexObj(*tmpParent, newItemize); |
497 | |||
498 |
1/1✓ Branch 1 taken 20 times.
|
20 | currentParent = &(tmpParent->getVecContent().back()); |
499 |
1/1✓ Branch 1 taken 20 times.
|
20 | vecLevel.push_back(itemLevel); |
500 | 20 | return currentParent; | |
501 | 20 | } | |
502 | |||
503 | ///Insert the item in the proper itemize | ||
504 | /** @param[out] parent : itemize to be filled | ||
505 | * @param vecItemLevel : vector of initialised items with theirs levels | ||
506 | * @param listItemType : type of the item list | ||
507 | */ | ||
508 | 16 | void PMarkdownParser::insertItemInItemize(PLatexObj & parent, const std::vector<std::pair<size_t, PLatexObj> > & vecItemLevel, PLatexType::PLatexType listItemType){ | |
509 | 16 | std::vector<size_t> parentLevel; | |
510 |
1/1✓ Branch 2 taken 16 times.
|
16 | parentLevel.push_back(vecItemLevel.front().first); |
511 |
2/2✓ Branch 4 taken 68 times.
✓ Branch 5 taken 16 times.
|
84 | for(std::vector<std::pair<size_t, PLatexObj> >::const_iterator it(vecItemLevel.begin()); it != vecItemLevel.end(); ++it){ |
512 | //Get the proper parent | ||
513 |
1/1✓ Branch 2 taken 68 times.
|
68 | PLatexObj * currentParent = getProperParent(parent, parentLevel, it->first, listItemType); |
514 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 68 times.
|
68 | if(currentParent == NULL){return;} |
515 | //Add the current item to it | ||
516 |
1/1✓ Branch 2 taken 68 times.
|
68 | addLatexObj(*currentParent, it->second); |
517 | } | ||
518 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | } |
519 | |||
520 | ///Parse some itemize | ||
521 | /** @param[out] parent : parent PLatexObj | ||
522 | * @param[out] textObj : PLatexObj to deal with text | ||
523 | * @return true on success, false otherwise | ||
524 | */ | ||
525 | 4886 | bool PMarkdownParser::parseItemize(PLatexObj & parent, PLatexObj & textObj){ | |
526 |
3/3✓ Branch 1 taken 4886 times.
✓ Branch 3 taken 4874 times.
✓ Branch 4 taken 12 times.
|
4886 | if(!isItem(true)){return false;} |
527 |
1/1✓ Branch 1 taken 12 times.
|
12 | playTextLatexObj(parent, textObj); |
528 |
1/1✓ Branch 1 taken 12 times.
|
12 | PLatexObj tmp; |
529 |
1/1✓ Branch 1 taken 12 times.
|
12 | tmp.setType(PLatexType::ITEMIZE); |
530 | 12 | std::vector<std::pair<size_t, PLatexObj> > vecItemLevel; | |
531 |
10/15✓ Branch 1 taken 64 times.
✓ Branch 3 taken 64 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 64 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 64 times.
✓ Branch 11 taken 64 times.
✓ Branch 13 taken 52 times.
✓ Branch 14 taken 12 times.
✓ Branch 15 taken 64 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 52 times.
✓ Branch 19 taken 12 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
|
64 | while(!p_parser->isEndOfFile() && p_run && !p_parser->isMatch("\n\n")){ |
532 | //Let's parse the current item | ||
533 |
1/1✓ Branch 1 taken 52 times.
|
52 | parseItem(vecItemLevel); |
534 | } | ||
535 | |||
536 |
1/1✓ Branch 1 taken 12 times.
|
12 | insertItemInItemize(tmp, vecItemLevel, PLatexType::ITEMIZE); |
537 | |||
538 |
1/1✓ Branch 1 taken 12 times.
|
12 | addLatexObj(parent, tmp); |
539 | 12 | return true; | |
540 | 12 | } | |
541 | |||
542 | ///Parse an item in the markdown enumerate | ||
543 | /** @param[out] vecItemLevel : vector of itemize level | ||
544 | * @return true on success, false otherwise | ||
545 | */ | ||
546 | 16 | bool PMarkdownParser::parseEnumerateItem(std::vector<std::pair<size_t, PLatexObj> > & vecItemLevel){ | |
547 |
3/4✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 16 times.
|
16 | if(p_parser->isMatchRewind("\n\n")){return false;} |
548 |
2/3✓ Branch 1 taken 16 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
|
16 | if(!isEnumerateItem()){ |
549 | ✗ | return false; | |
550 | } | ||
551 |
1/1✓ Branch 1 taken 16 times.
|
16 | size_t itemLevel(p_parser->getColumn()); |
552 |
1/1✓ Branch 1 taken 16 times.
|
16 | PLatexObj itemObj; |
553 |
1/1✓ Branch 1 taken 16 times.
|
16 | itemObj.setType(PLatexType::ITEM); |
554 | |||
555 |
1/1✓ Branch 1 taken 16 times.
|
16 | PLatexObj tmpText; |
556 |
1/1✓ Branch 1 taken 16 times.
|
16 | tmpText.setType(PLatexType::TEXT); |
557 | |||
558 | //Do some loop to fill the item | ||
559 |
13/18✓ Branch 1 taken 348 times.
✓ Branch 3 taken 348 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 348 times.
✓ Branch 9 taken 348 times.
✓ Branch 11 taken 344 times.
✓ Branch 12 taken 4 times.
✓ Branch 14 taken 344 times.
✓ Branch 16 taken 332 times.
✓ Branch 17 taken 12 times.
✓ Branch 18 taken 332 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 348 times.
✗ Branch 21 not taken.
✓ Branch 23 taken 332 times.
✓ Branch 24 taken 16 times.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
|
348 | while(!p_parser->isEndOfFile() && !p_parser->isMatchRewind("\n\n") && !isEnumerateItem(true) && p_run){ |
560 |
2/3✓ Branch 1 taken 332 times.
✓ Branch 3 taken 332 times.
✗ Branch 4 not taken.
|
332 | if(parseItemLatexObj(itemObj, tmpText)){} |
561 | else{ | ||
562 |
1/1✓ Branch 1 taken 332 times.
|
332 | incrementCurrentChar(tmpText); |
563 | } | ||
564 | } | ||
565 |
1/1✓ Branch 1 taken 16 times.
|
16 | playTextLatexObj(itemObj, tmpText); |
566 |
2/2✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
|
16 | vecItemLevel.push_back(std::pair<size_t, PLatexObj>(itemLevel, itemObj)); |
567 | 16 | return true; | |
568 | 16 | } | |
569 | |||
570 | ///Say if there is no space between the last return and the current char | ||
571 | /** @param rewind : true to test and go back before the parsed token even if it is an item | ||
572 | * @return true if there is no space between the last return and the current char, false otherwise | ||
573 | */ | ||
574 | 5234 | bool PMarkdownParser::isEnumerateItem(bool rewind){ | |
575 |
1/1✓ Branch 1 taken 5234 times.
|
5234 | p_parser->pushPosition(); |
576 |
1/1✓ Branch 1 taken 5234 times.
|
5234 | size_t currentCol(p_parser->getColumn()); |
577 |
2/2✓ Branch 1 taken 5234 times.
✓ Branch 4 taken 5234 times.
|
5234 | PString listFigure(p_parser->getStrComposedOf("0123456789")); |
578 |
2/2✓ Branch 1 taken 5194 times.
✓ Branch 2 taken 40 times.
|
5234 | if(listFigure == ""){ |
579 |
1/1✓ Branch 1 taken 5194 times.
|
5194 | p_parser->popPosition(); |
580 | 5194 | return false; | |
581 | } | ||
582 |
4/4✓ Branch 1 taken 40 times.
✓ Branch 4 taken 40 times.
✓ Branch 7 taken 4 times.
✓ Branch 8 taken 36 times.
|
40 | if(!p_parser->isMatch(". ")){ |
583 |
1/1✓ Branch 1 taken 4 times.
|
4 | p_parser->popPosition(); |
584 | 4 | return false; | |
585 | } | ||
586 |
2/2✓ Branch 1 taken 36 times.
✓ Branch 4 taken 36 times.
|
36 | PString space(" \t"), currentRow(p_parser->getCurrentRow()); |
587 | 36 | size_t i(0lu); | |
588 |
2/2✓ Branch 0 taken 24 times.
✓ Branch 1 taken 32 times.
|
56 | while(i < currentCol){ |
589 |
1/1✓ Branch 1 taken 24 times.
|
24 | char ch = currentRow[i]; |
590 |
3/3✓ Branch 1 taken 24 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 20 times.
|
24 | if(!space.find(ch)){ |
591 |
1/1✓ Branch 1 taken 4 times.
|
4 | p_parser->popPosition(); |
592 | 4 | return false; | |
593 | } | ||
594 | 20 | ++i; | |
595 | } | ||
596 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 16 times.
|
32 | if(rewind){ |
597 |
1/1✓ Branch 1 taken 16 times.
|
16 | p_parser->popPosition(); |
598 | } | ||
599 | 32 | return true; | |
600 | 5234 | } | |
601 | |||
602 | ///Parse some enumerate | ||
603 | /** @param[out] parent : parent PLatexObj | ||
604 | * @param[out] textObj : PLatexObj to deal with text | ||
605 | * @return true on success, false otherwise | ||
606 | */ | ||
607 | 4874 | bool PMarkdownParser::parseEnumerate(PLatexObj & parent, PLatexObj & textObj){ | |
608 |
3/3✓ Branch 1 taken 4874 times.
✓ Branch 3 taken 4870 times.
✓ Branch 4 taken 4 times.
|
4874 | if(!isEnumerateItem(true)){return false;} |
609 |
1/1✓ Branch 1 taken 4 times.
|
4 | playTextLatexObj(parent, textObj); |
610 |
1/1✓ Branch 1 taken 4 times.
|
4 | PLatexObj tmp; |
611 |
1/1✓ Branch 1 taken 4 times.
|
4 | tmp.setType(PLatexType::ENUMERATE); |
612 | 4 | std::vector<std::pair<size_t, PLatexObj> > vecItemLevel; | |
613 |
10/15✓ Branch 1 taken 20 times.
✓ Branch 3 taken 20 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 20 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 20 times.
✓ Branch 11 taken 20 times.
✓ Branch 13 taken 16 times.
✓ Branch 14 taken 4 times.
✓ Branch 15 taken 20 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 16 times.
✓ Branch 19 taken 4 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
|
20 | while(!p_parser->isEndOfFile() && p_run && !p_parser->isMatch("\n\n")){ |
614 | //Let's parse the current item | ||
615 |
1/1✓ Branch 1 taken 16 times.
|
16 | parseEnumerateItem(vecItemLevel); |
616 | } | ||
617 |
1/1✓ Branch 1 taken 4 times.
|
4 | insertItemInItemize(tmp, vecItemLevel, PLatexType::ENUMERATE); |
618 | |||
619 |
1/1✓ Branch 1 taken 4 times.
|
4 | addLatexObj(parent, tmp); |
620 | 4 | return true; | |
621 | 4 | } | |
622 | |||
623 | ///Parse a vector of latex object | ||
624 | /** @param[out] parent : parent PLatexObj | ||
625 | * @param[out] textObj : PLatexObj to deal with text | ||
626 | * @param beginPatern : starting partern to start the parsing of the vector of PLatexObj (disabled is empty) | ||
627 | * @param endPatern : end patern of the vector of latex obj | ||
628 | */ | ||
629 | 80 | void PMarkdownParser::parseVecLatexObj(PLatexObj & parent, PLatexObj & textObj, const PString & beginPatern, const PString & endPatern){ | |
630 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 80 times.
|
80 | if(beginPatern != ""){ //If we check the begin patern |
631 | ✗ | if(!p_parser->isMatch(beginPatern)){ //And it does not match | |
632 | ✗ | return; //We stop | |
633 | } | ||
634 | } | ||
635 |
6/8✓ Branch 1 taken 1864 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1864 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 1784 times.
✓ Branch 7 taken 80 times.
✓ Branch 8 taken 1784 times.
✓ Branch 9 taken 80 times.
|
1864 | while(!p_parser->isEndOfFile() && p_run && !p_parser->isMatch(endPatern)){ |
636 | 1784 | long unsigned int currentPos = p_parser->getCurrentCharIdx(); | |
637 | |||
638 |
2/2✓ Branch 1 taken 1780 times.
✓ Branch 2 taken 4 times.
|
1784 | if(parseAllLatexObj(parent, textObj)){} |
639 | else{ | ||
640 | 1780 | incrementCurrentChar(textObj); | |
641 | } | ||
642 |
2/6✗ Branch 1 not taken.
✓ Branch 2 taken 1784 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1784 times.
|
1784 | if(currentPos == p_parser->getCurrentCharIdx() && !p_parser->isEndOfFile()){ |
643 | ✗ | std::cerr << "PMarkdownParser::parseVecLatexObj : the parser is stucked at the position :" << std::endl << "\t" << p_parser->getLocation() << std::endl; | |
644 | ✗ | p_run = false; | |
645 | } | ||
646 | } | ||
647 |
1/2✓ Branch 0 taken 80 times.
✗ Branch 1 not taken.
|
80 | if(p_run) playTextLatexObj(parent, textObj); |
648 | } | ||
649 | |||
650 | ///Parse extra environement (terminal, cplusplus, cmake, conseil, attention, ...) | ||
651 | /** @param[out] parent : parent PLatexObj | ||
652 | * @param[out] textObj : PLatexObj to deal with text | ||
653 | * @return true on success, false otherwise | ||
654 | */ | ||
655 | 4386 | bool PMarkdownParser::parseExtraEnvironement(PLatexObj & parent, PLatexObj & textObj){ | |
656 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4386 times.
|
4386 | if(p_vecNameMarkdownExtraEnv.size() == 0lu){return false;} |
657 |
1/1✓ Branch 1 taken 4386 times.
|
4386 | p_parser->pushPosition(); |
658 |
1/1✓ Branch 1 taken 4386 times.
|
4386 | PString matchFunc(p_parser->isMatch(p_vecNameMarkdownExtraEnv)); |
659 |
2/2✓ Branch 1 taken 4366 times.
✓ Branch 2 taken 20 times.
|
4386 | if(matchFunc == ""){ |
660 |
1/1✓ Branch 1 taken 4366 times.
|
4366 | p_parser->popPosition(); |
661 | 4366 | return false; | |
662 | } | ||
663 | |||
664 |
1/1✓ Branch 1 taken 20 times.
|
20 | playTextLatexObj(parent, textObj); |
665 |
1/1✓ Branch 1 taken 20 times.
|
20 | PLatexObj env; |
666 |
1/1✓ Branch 1 taken 20 times.
|
20 | env.setType(PLatexType::ENVIRONEMENT); |
667 |
1/1✓ Branch 1 taken 20 times.
|
20 | PString matchEnv(matchFunc.eraseChar('`')); |
668 |
1/1✓ Branch 1 taken 20 times.
|
20 | env.setName(matchEnv); |
669 | |||
670 |
1/1✓ Branch 1 taken 20 times.
|
20 | PEnvironement & configEnv = p_vecExtraEnv[matchEnv]; |
671 |
2/2✓ Branch 1 taken 20 times.
✓ Branch 4 taken 20 times.
|
20 | env.setBalise(configEnv.getBalise()); |
672 |
1/1✓ Branch 1 taken 20 times.
|
20 | PLatexObj tmpText; |
673 |
1/1✓ Branch 1 taken 20 times.
|
20 | tmpText.setType(PLatexType::TEXT); |
674 | |||
675 |
10/15✓ Branch 1 taken 460 times.
✓ Branch 3 taken 460 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 460 times.
✓ Branch 9 taken 460 times.
✓ Branch 11 taken 440 times.
✓ Branch 12 taken 20 times.
✓ Branch 13 taken 440 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 460 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 440 times.
✓ Branch 19 taken 20 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
|
460 | while(!p_parser->isEndOfFile() && !p_parser->isMatch("```") && p_run){ |
676 |
3/3✓ Branch 1 taken 440 times.
✓ Branch 3 taken 432 times.
✓ Branch 4 taken 8 times.
|
440 | if(parseEnvLatexObj(env, tmpText)){} |
677 | else{ | ||
678 |
1/1✓ Branch 1 taken 432 times.
|
432 | incrementCurrentChar(tmpText); |
679 | } | ||
680 | } | ||
681 |
1/1✓ Branch 1 taken 20 times.
|
20 | playTextLatexObj(env, tmpText); |
682 | |||
683 |
1/1✓ Branch 1 taken 20 times.
|
20 | addLatexObj(parent, env); |
684 | 20 | return true; | |
685 | 4386 | } | |
686 | |||
687 | |||
688 | ///Parse extra environement (terminal, cplusplus, cmake, conseil, attention, ...) | ||
689 | /** @param[out] parent : parent PLatexObj | ||
690 | * @param[out] textObj : PLatexObj to deal with text | ||
691 | * @return true on success, false otherwise | ||
692 | */ | ||
693 | 4366 | bool PMarkdownParser::parseExtraParser(PLatexObj & parent, PLatexObj & textObj){ | |
694 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4366 times.
|
4366 | if(p_vecNameMarkdownExtraParser.size() == 0lu){return false;} |
695 |
1/1✓ Branch 1 taken 4366 times.
|
4366 | p_parser->pushPosition(); |
696 |
1/1✓ Branch 1 taken 4366 times.
|
4366 | PString matchFunc(p_parser->isMatch(p_vecNameMarkdownExtraParser)); |
697 |
2/2✓ Branch 1 taken 4354 times.
✓ Branch 2 taken 12 times.
|
4366 | if(matchFunc == ""){ |
698 |
1/1✓ Branch 1 taken 4354 times.
|
4354 | p_parser->popPosition(); |
699 | 4354 | return false; | |
700 | } | ||
701 | |||
702 |
1/1✓ Branch 1 taken 12 times.
|
12 | playTextLatexObj(parent, textObj); |
703 |
1/1✓ Branch 1 taken 12 times.
|
12 | PLatexObj tmp; |
704 |
1/1✓ Branch 1 taken 12 times.
|
12 | tmp.setType(PLatexType::PARSER); |
705 |
1/1✓ Branch 1 taken 12 times.
|
12 | PString matchEnv(matchFunc.eraseChar('`')); |
706 |
1/1✓ Branch 1 taken 12 times.
|
12 | tmp.setName(matchEnv); |
707 | |||
708 |
1/1✓ Branch 1 taken 12 times.
|
12 | PParserEnv parser(getParserEnv(p_vecExtraParser, matchEnv)); |
709 | |||
710 |
6/6✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
✓ Branch 7 taken 12 times.
✓ Branch 10 taken 12 times.
✓ Branch 13 taken 12 times.
✓ Branch 16 taken 12 times.
|
24 | PString inputFileContent(p_parser->getUntilKeyWithoutPatern("```").eraseFirstLastChar(" \n") + "\n"); |
711 | |||
712 |
2/2✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
|
12 | tmp.setNbline(inputFileContent.count('\n')); |
713 | |||
714 |
1/1✓ Branch 1 taken 12 times.
|
12 | PString envContent(parser_makeHighlighting(inputFileContent, parser)); |
715 |
1/1✓ Branch 1 taken 12 times.
|
12 | tmp.setText(envContent); |
716 |
1/1✓ Branch 1 taken 12 times.
|
12 | tmp.setSubTitle(inputFileContent); |
717 |
1/1✓ Branch 1 taken 12 times.
|
12 | addLatexObj(parent, tmp); |
718 | 12 | return true; | |
719 | 4366 | } | |
720 | |||
721 | ///Parse a work in progress | ||
722 | /** @param[out] parent : parent PLatexObj | ||
723 | * @param[out] textObj : PLatexObj to deal with text | ||
724 | * @return true on success, false otherwise | ||
725 | */ | ||
726 | 4354 | bool PMarkdownParser::parseWip(PLatexObj & parent, PLatexObj & textObj){ | |
727 |
4/4✓ Branch 1 taken 4354 times.
✓ Branch 4 taken 4354 times.
✓ Branch 7 taken 4350 times.
✓ Branch 8 taken 4 times.
|
4354 | if(!p_parser->isMatch("```wip")){return false;} |
728 | |||
729 |
1/1✓ Branch 1 taken 4 times.
|
4 | playTextLatexObj(parent, textObj); |
730 |
1/1✓ Branch 1 taken 4 times.
|
4 | PLatexObj env; |
731 |
1/1✓ Branch 1 taken 4 times.
|
4 | env.setType(PLatexType::WORK_IN_PROGRESS); |
732 | |||
733 |
1/1✓ Branch 1 taken 4 times.
|
4 | PLatexObj tmpText; |
734 |
1/1✓ Branch 1 taken 4 times.
|
4 | tmpText.setType(PLatexType::TEXT); |
735 | |||
736 |
11/15✓ Branch 1 taken 112 times.
✓ Branch 3 taken 108 times.
✓ Branch 4 taken 4 times.
✓ Branch 6 taken 108 times.
✓ Branch 9 taken 108 times.
✓ Branch 11 taken 108 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 108 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 108 times.
✓ Branch 16 taken 4 times.
✓ Branch 18 taken 108 times.
✓ Branch 19 taken 4 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
|
112 | while(!p_parser->isEndOfFile() && !p_parser->isMatch("```") && p_run){ |
737 |
3/3✓ Branch 1 taken 108 times.
✓ Branch 3 taken 100 times.
✓ Branch 4 taken 8 times.
|
108 | if(parseEnvLatexObj(env, tmpText)){} |
738 | else{ | ||
739 |
1/1✓ Branch 1 taken 100 times.
|
100 | incrementCurrentChar(tmpText); |
740 | } | ||
741 | } | ||
742 |
1/1✓ Branch 1 taken 4 times.
|
4 | playTextLatexObj(env, tmpText); |
743 | |||
744 |
1/1✓ Branch 1 taken 4 times.
|
4 | addLatexObj(parent, env); |
745 | 4 | return true; | |
746 | 4 | } | |
747 | |||
748 | |||
749 | |||
750 | |||
751 |