asciidoc-parser 0.19.0

Parser for AsciiDoc format
Documentation
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
499
use crate::{document::RefType, tests::prelude::*};

track_file!("ref/asciidoc-lang/docs/modules/document/pages/compound-author-name.adoc");

non_normative!(
    r#"
= Compound Author Names

When a name consists of multiple parts, such as a compound or composite surname, or a double middle name, the processor needs to be explicitly told which words should be assigned to a specific attribute.

"#
);

#[test]
fn connecting_compound_author_names() {
    non_normative!(
        r#"
== Connecting compound author names

"#
    );

    verifies!(
        r#"
If the parts of an author's name aren't assigned to the correct built-in attributes, they may output the wrong information if they're referenced in the body of the document.
For instance, if the name _Ann Marie Jenson_ was entered on the author line or assigned to the attribute `author`, the processor would assign _Ann_ to `firstname`, _Marie_ to `middlename`, and _Jenson_ to `lastname` based on the location and order of each word.
This assignment would be incorrect because the author's first name is _Ann Marie_.

When part of an author's name consists of more than one word, use an underscore (`+_+`) between the words to connect them.

.Compound name syntax
[source]
----
= Document Title
firstname_firstname lastname; firstname middlename_middlename lastname
----

If the more than three space-separated names (or initials) are entered in the implicit author line, the entire line (including the email portion) will be used as the author's full name and first name.
Thus, it's important to use the underscore separator to ensure there are no more than three space-separated names.

"#
    );

    let mut parser = Parser::default();
    let doc = parser.parse(
        "= Document Title\nfirstname_firstname lastname; firstname middlename_middlename lastname",
    );

    assert_eq!(
        doc,
        Document {
            header: Header {
                title_source: Some(Span {
                    data: "Document Title",
                    line: 1,
                    col: 3,
                    offset: 2,
                },),
                title: Some("Document Title",),
                attributes: &[],
                author_line: Some(AuthorLine {
                    authors: &[
                        Author {
                            name: "firstname firstname lastname",
                            firstname: "firstname firstname",
                            middlename: None,
                            lastname: Some("lastname",),
                            email: None,
                        },
                        Author {
                            name: "firstname middlename middlename lastname",
                            firstname: "firstname",
                            middlename: Some("middlename middlename",),
                            lastname: Some("lastname",),
                            email: None,
                        },
                    ],
                    source: Span {
                        data: "firstname_firstname lastname; firstname middlename_middlename lastname",
                        line: 2,
                        col: 1,
                        offset: 17,
                    },
                },),
                revision_line: None,
                comments: &[],
                source: Span {
                    data: "= Document Title\nfirstname_firstname lastname; firstname middlename_middlename lastname",
                    line: 1,
                    col: 1,
                    offset: 0,
                },
            },
            blocks: &[],
            source: Span {
                data: "= Document Title\nfirstname_firstname lastname; firstname middlename_middlename lastname",
                line: 1,
                col: 1,
                offset: 0,
            },
            warnings: &[],
            source_map: SourceMap(&[]),
            catalog: Catalog::default(),
        }
    );
}

#[test]
fn ex_line_compound() {
    non_normative!(
        r#"
== Compound names in the author line

"#
    );

    verifies!(
        r#"
In <<ex-line-compound>>, the first author has a compound first name and the second author has a compound surname.

.Assign compound names in the author line
[source#ex-line-compound]
----
= Drum and Bass Breakbeats
Ann_Marie Jenson; Tomás López_del_Toro <.> <.>
----
<.> To signal to the processor that _Ann Marie_ is the author's first name (instead of their first and middle names), type an underscore (`+_+`) between each part of the author's first name.
<.> The second author's last name consists of three words.
Type an underscore (`+_+`) between each word of the author's last name.

The result of <<ex-line-compound>> is displayed below.
Notice that the underscores (`+_+`) aren't displayed when the document is rendered.

image::author-line-with-compound-names.png[Compound author names displayed in the byline,role=screenshot]

"#
    );

    let mut parser = Parser::default();
    let doc = parser.parse("= Drum and Bass Breakbeats\nAnn_Marie Jenson; Tomás López_del_Toro");

    assert_eq!(
        doc,
        Document {
            header: Header {
                title_source: Some(Span {
                    data: "Drum and Bass Breakbeats",
                    line: 1,
                    col: 3,
                    offset: 2,
                },),
                title: Some("Drum and Bass Breakbeats",),
                attributes: &[],
                author_line: Some(AuthorLine {
                    authors: &[
                        Author {
                            name: "Ann Marie Jenson",
                            firstname: "Ann Marie",
                            middlename: None,
                            lastname: Some("Jenson",),
                            email: None,
                        },
                        Author {
                            name: "Tomás López del Toro",
                            firstname: "Tomás",
                            middlename: None,
                            lastname: Some("López del Toro",),
                            email: None,
                        },
                    ],
                    source: Span {
                        data: "Ann_Marie Jenson; Tomás López_del_Toro",
                        line: 2,
                        col: 1,
                        offset: 27,
                    },
                },),
                revision_line: None,
                comments: &[],
                source: Span {
                    data: "= Drum and Bass Breakbeats\nAnn_Marie Jenson; Tomás López_del_Toro",
                    line: 1,
                    col: 1,
                    offset: 0,
                },
            },
            blocks: &[],
            source: Span {
                data: "= Drum and Bass Breakbeats\nAnn_Marie Jenson; Tomás López_del_Toro",
                line: 1,
                col: 1,
                offset: 0,
            },
            warnings: &[],
            source_map: SourceMap(&[]),
            catalog: Catalog::default(),
        }
    );
}

#[test]
fn ex_reference_compound() {
    verifies!(
        r#"
The underscore between each word in a compound name ensures that the parts of an author's name are assigned correctly to the corresponding built-in attributes.
If you were to reference the first author's first name or the second author's last name in the document body, as shown in <<ex-reference-compound>>, the correct values would be displayed.

.Reference authors with compound names
[source#ex-reference-compound]
----
= Drum and Bass Breakbeats
Ann_Marie Jenson; Tomás López_del_Toro

The first author's first name is {firstname}.

The second author's last name is {lastname_2}.
----

Like in the byline, the underscores (`+_+`) aren't displayed when the document is rendered.

image::reference-compound-names.png[Compound author names displayed in the document body when referenced,role=screenshot]

"#
    );

    let mut parser = Parser::default();
    let doc = parser.parse(
        "= Drum and Bass Breakbeats\nAnn_Marie Jenson; Tomás López_del_Toro\n\nThe first author's first name is {firstname}.\n\nThe second author's last name is {lastname_2}.",
    );

    assert_eq!(
        doc,
        Document {
            header: Header {
                title_source: Some(Span {
                    data: "Drum and Bass Breakbeats",
                    line: 1,
                    col: 3,
                    offset: 2,
                },),
                title: Some("Drum and Bass Breakbeats",),
                attributes: &[],
                author_line: Some(AuthorLine {
                    authors: &[
                        Author {
                            name: "Ann Marie Jenson",
                            firstname: "Ann Marie",
                            middlename: None,
                            lastname: Some("Jenson",),
                            email: None,
                        },
                        Author {
                            name: "Tomás López del Toro",
                            firstname: "Tomás",
                            middlename: None,
                            lastname: Some("López del Toro",),
                            email: None,
                        },
                    ],
                    source: Span {
                        data: "Ann_Marie Jenson; Tomás López_del_Toro",
                        line: 2,
                        col: 1,
                        offset: 27,
                    },
                },),
                revision_line: None,
                comments: &[],
                source: Span {
                    data: "= Drum and Bass Breakbeats\nAnn_Marie Jenson; Tomás López_del_Toro",
                    line: 1,
                    col: 1,
                    offset: 0,
                },
            },
            blocks: &[
                Block::Simple(SimpleBlock {
                    content: Content {
                        original: Span {
                            data: "The first author's first name is {firstname}.",
                            line: 4,
                            col: 1,
                            offset: 69,
                        },
                        rendered: "The first author&#8217;s first name is Ann Marie.",
                    },
                    source: Span {
                        data: "The first author's first name is {firstname}.",
                        line: 4,
                        col: 1,
                        offset: 69,
                    },
                    style: SimpleBlockStyle::Paragraph,
                    title_source: None,
                    title: None,
                    caption: None,
                    number: None,
                    anchor: None,
                    anchor_reftext: None,
                    attrlist: None,
                },),
                Block::Simple(SimpleBlock {
                    content: Content {
                        original: Span {
                            data: "The second author's last name is {lastname_2}.",
                            line: 6,
                            col: 1,
                            offset: 116,
                        },
                        rendered: "The second author&#8217;s last name is López del Toro.",
                    },
                    source: Span {
                        data: "The second author's last name is {lastname_2}.",
                        line: 6,
                        col: 1,
                        offset: 116,
                    },
                    style: SimpleBlockStyle::Paragraph,
                    title_source: None,
                    title: None,
                    caption: None,
                    number: None,
                    anchor: None,
                    anchor_reftext: None,
                    attrlist: None,
                },),
            ],
            source: Span {
                data: "= Drum and Bass Breakbeats\nAnn_Marie Jenson; Tomás López_del_Toro\n\nThe first author's first name is {firstname}.\n\nThe second author's last name is {lastname_2}.",
                line: 1,
                col: 1,
                offset: 0,
            },
            warnings: &[],
            source_map: SourceMap(&[]),
            catalog: Catalog::default(),
        }
    );
}

#[test]
fn ex_compound() {
    non_normative!(
        r#"
== Compound names in the author attribute

"#
    );

    verifies!(
        r#"
An underscore (`+_+`) should also be placed between each part of a compound name when the author is assigned using the `author` attribute.

.Assign a compound name using the author attribute
[source#ex-compound]
----
= Quantum Networks
:author: Mara_Moss Wirribi <.>

== About {author}

{firstname} lives on the Bellarine Peninsula near Geelong, Australia. <.>
----
<.> Assign the author's name to the `author` attribute.
Enter an underscore (`+_+`) between each part of the author's first name.
This ensures that their full first name is correct when it's automatically assigned to `firstname` by the processor.
<.> The built-in attribute `firstname` is referenced in the document's body.
The author's first name is automatically extracted from the value of `author` and assigned to `firstname`.

The result of <<ex-compound>>, displayed below, shows that the processor assigned the correct words to the built-in attribute `firstname` since the author's full first name, _Mara Moss_, is displayed where `firstname` was referenced.

image::author-attribute-with-compound-name.png[Compound author name displayed in the byline using the author attribute,role=screenshot]
"#
    );

    let mut parser = Parser::default();
    let doc = parser.parse(
        "= Quantum Networks\n:author: Mara_Moss Wirribi\n\n== About {author}\n\n{firstname} lives on the Bellarine Peninsula near Geelong, Australia.",
    );

    assert_eq!(
        doc,
        Document {
            header: Header {
                title_source: Some(Span {
                    data: "Quantum Networks",
                    line: 1,
                    col: 3,
                    offset: 2,
                },),
                title: Some("Quantum Networks",),
                attributes: &[Attribute {
                    name: Span {
                        data: "author",
                        line: 2,
                        col: 2,
                        offset: 20,
                    },
                    value_source: Some(Span {
                        data: "Mara_Moss Wirribi",
                        line: 2,
                        col: 10,
                        offset: 28,
                    },),
                    value: InterpretedValue::Value("Mara_Moss Wirribi",),
                    source: Span {
                        data: ":author: Mara_Moss Wirribi",
                        line: 2,
                        col: 1,
                        offset: 19,
                    },
                },],
                author_line: None,
                revision_line: None,
                comments: &[],
                source: Span {
                    data: "= Quantum Networks\n:author: Mara_Moss Wirribi",
                    line: 1,
                    col: 1,
                    offset: 0,
                },
            },
            blocks: &[Block::Section(SectionBlock {
                level: 1,
                section_title: Content {
                    original: Span {
                        data: "About {author}",
                        line: 4,
                        col: 4,
                        offset: 50,
                    },
                    rendered: "About Mara_Moss Wirribi",
                },
                blocks: &[Block::Simple(SimpleBlock {
                    content: Content {
                        original: Span {
                            data: "{firstname} lives on the Bellarine Peninsula near Geelong, Australia.",
                            line: 6,
                            col: 1,
                            offset: 66,
                        },
                        rendered: "Mara Moss lives on the Bellarine Peninsula near Geelong, Australia.",
                    },
                    source: Span {
                        data: "{firstname} lives on the Bellarine Peninsula near Geelong, Australia.",
                        line: 6,
                        col: 1,
                        offset: 66,
                    },
                    style: SimpleBlockStyle::Paragraph,
                    title_source: None,
                    title: None,
                    caption: None,
                    number: None,
                    anchor: None,
                    anchor_reftext: None,
                    attrlist: None,
                },),],
                source: Span {
                    data: "== About {author}\n\n{firstname} lives on the Bellarine Peninsula near Geelong, Australia.",
                    line: 4,
                    col: 1,
                    offset: 47,
                },
                title_source: None,
                title: None,
                anchor: None,
                anchor_reftext: None,
                attrlist: None,
                section_type: SectionType::Normal,
                section_id: Some("_about_mara_moss_wirribi"),
                caption: None,
                section_number: None,
            },),],
            source: Span {
                data: "= Quantum Networks\n:author: Mara_Moss Wirribi\n\n== About {author}\n\n{firstname} lives on the Bellarine Peninsula near Geelong, Australia.",
                line: 1,
                col: 1,
                offset: 0,
            },
            warnings: &[],
            source_map: SourceMap(&[]),
            catalog: Catalog {
                refs: HashMap::from([(
                    "_about_mara_moss_wirribi",
                    RefEntry {
                        id: "_about_mara_moss_wirribi",
                        reftext: Some("About Mara_Moss Wirribi",),
                        ref_type: RefType::Section,
                    }
                ),]),
                reftext_to_id: HashMap::from([(
                    "About Mara_Moss Wirribi",
                    "_about_mara_moss_wirribi"
                ),]),
            },
        }
    );
}