1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
/*!
This submodule contains useful functions and other constructs that don't
sensibly belong to any specific entity in the program.
Copyright © 2020 Santtu Söderholm
*/
use BufRead;
use ;
// =======================
// Text handling utilities
// =======================
/// Returns a `Vec<String>` from a given `&str`,
/// split at new lines `\n` or `\r\n`.
/// Read the lines of a given file into a buffer.
/// Normalizes the given `&str` according to the reStructuredText specification.
/// In this context, normalization means converting any contiguous whitespace into
/// a single ASCII space character and converting letters to their lower-case variants.
///
/// ### Note
/// This might return something nonsensical, as converting a single multi-scalar grapheme
/// into lower-case will return the multiple constituent "characters" as their lower-case variants.
/// A whitespace-aware function for stripping indentation
/// from `String`s. Returns `Ok(String)` if successful.
/// If non-whitespace characters are encountered before
/// the notified `amount` has been stripped, an `Err(message)`
/// is returned instead.
// ============
// Type aliases
// ============
/// A type alias for an integer used as a node identifier.
pub type NodeId = u32;
/// A type alias for different kinds of enumerators such as list or foonote ordinals in integer format.
pub type EnumAsInt = u32;
/// A type alias for question points.
pub type QuizPoints = u32;
/// A type alias for the number type used in the `Length` enum.
pub type LengthNum = f64;
// ==========================
// Enumerators and converters
// ==========================
/// An enumeration fo the different A+ questionnaire types. This is used the differentiate
/// between questionnaire hint output formats, among other things.
/// A section can be underlined, or over- and underlined with a certain character.
/// Enumerated list item labels can either end with a period `.` or a right parenthesis `)`.
/// A third option is to enclose them in matching parentheses `(` and `)`.
/// List enumerator labels can be Arabic numerals, lower- or upper-case alphet `a--z` or `A--Z`,
/// or lower- or upper-case Roman numerals between `1--4999`.
/// There are 4 different kinds of footnote markers:
/// 1. Manually numbered: `.. [1]` , `.. [2]`, ...
/// 2. automatically numbered: .. [#]
/// 3. automatically nubered with a simple reference name: .. [#simple_ref-name]
/// 4. Automatically generated symbolic markers: .. [*]
/// A hyperlink target may be one of 3 types:
///
/// 1. internal,
/// 2. external or
/// 3. indirect
///
/// **Internal** hyperlink targets have empty link blocks. They provide an end point allowing
/// a hyperlink to connect one place to another within a document.
/// An internal hyperlink target points to the element following the target.
///
/// **External** hyperlink targets have an absolute or relative URI or email address in their link blocks.
/// An external hyperlink's URI may begin on the same line as the explicit markup start and target name, or it may begin in an indented text block immediately following, with no intervening blank lines.
/// If there are multiple lines in the link block, they are concatenated.
/// Any unescaped whitespace is removed.
///
/// **Indirect** hyperlink targets have a hyperlink reference in their link blocks.
/// Just as with hyperlink references anywhere else in a document,
/// if a phrase-reference is used in the link block it must be enclosed in backquotes.
/// As with external hyperlink targets, the link block of an indirect hyperlink target may
/// begin on the same line as the explicit markup start or the next line.
/// It may also be split over multiple lines, in which case the lines are
/// joined with whitespace before being normalized.
/// An enumeration of the different types of references that a reference node might contain.
/// There are 3 types of interpreted inline text, such as math:
/// 1. where the given role precedes the interpreted content and
/// 2. where the interpreted content precedes the given role.
/// 3. where the type is not specified and the default role is used.
/// An enumeration of how lengths can be interpreted.
/// This includes precentages of current context and absolute length
/// Units of length recognized by reStructuredText.
/// An enumeration of different horizontal alignment options.
/// An enumeration of different horizontal alignment options:
/// `Left`, `Middle` or `Right`.
/// An enumeration of different backlinking alternatives for a table of contents node.
/// Instructs the doctree to generate links from section headers back to the table of
/// contents entries, the table of contents itself, or generate no backlinks.
/// An enumeration of the (deprecated) "align" attribute alternatives
/// recognized by the HTML `<img>` tag.
///
/// Enumerated the types of tree traversals that one of the `DocTree` walk methods might perform.
use crateDocTree;
use crateState;
/// An enumeration of the different ways a (nested) parsing session might terminate.
/// The return type of the `Parser::parse` method. Generally, finishing conditions
/// that are not outright failures will enclose the document tree fed to the parser
/// when it was initialized.
///
/// There are 6 possible statuses for A+ exercises:
///
/// * ready: Visible exercise listed in table of contents.
/// * unlisted (default): Unlisted in table of contents, otherwise same as ready.
/// * hidden: Hidden from non course staff.
/// * enrollment: Questions for students when they enroll to a course.
/// * enrollment_ext: Same as enrollment but for external students.
/// * maintenance: Hides the exercise description and prevents submissions.
///
/// An enumeration of the different tokenizers offered by the A+ Radar tokenizer.
///
/// See [the docs](https://github.com/Aalto-LeTech/radar/tree/master/tokenizer#tokenizers) for more details.
///
/// The variant "both" forces the element to a new line, "left" ("right") allows
/// no floating elements on the left (right)
///
/// Use "file" for file inputs, "clickable" for clickable inputs, and
/// "dropdown" for dropdown. For dropdowns, the available options should
/// be listed after the type indicating "dropdown" in this
/// format: "dropdown:option1,option2,option3"
///
/// Default type is text; for image (png) outputs use "image"
///
/// An enumeration of the different writer output formats.
/// Currently stdout and files are supported.
// ===========
// Constants
// ===========
/// The standard Docutils system uses these symbols as footnote marks
/// when a FootnoteKind::AutoSymbol is detected.
/// They are, from first to last:
///
/// 1. asterisk/star (`*`)
/// 2. dagger (`†`|`U+02020`)
/// 3. double dagger (`‡`|`U+02021`)
/// 4. section mark (`§`|`U+000A7`)
/// 5. pilcrow or paragraph mark (`¶`|`U+000B6`)
/// 6. number sign (`#`)
/// 7. spade suit (`♠`|`U+02660`)
/// 8. heart suit (`♥`|`U+02665`)
/// 9. diamond suit (`♦`|`U+02666`)
/// 10. club suit (`♣`|`U+02663`)
///
/// As the next autosymbol is detected the next unused item
/// from this list will be used as the footnote label character.
/// If `n` is the number of times this list has been iterated over
/// and `s` the current autosymbol, then the actual label
/// of the footnote is `s^(n+1)`. For example, if a document has
/// `12` automatically symboled footnotes and a new one is constructed,
/// then its label will be `‡‡ = ‡² = ‡¹⁺¹`.
pub const FOOTNOTE_SYMBOLS: = ;
///
/// These are the characters that can be used in underlining section titles,
/// marking the lines of literal text blocks and creating transitions.
pub const SECTION_AND_QUOTING_CHARS: = ;