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
use crate::tests::prelude::*;

track_file!("ref/asciidoc-lang/docs/modules/document/pages/multiple-authors.adoc");

non_normative!(
    r#"
= Add Multiple Authors to a Document

The xref:author-line.adoc[author line] is the only way to assign more than one author to a document for display in the byline.
Additionally, only the HTML 5 and Docbook converters can convert documents with multiple authors.

"#
);

#[test]
fn multi_author_syntax() {
    non_normative!(
        r#"
== Multi-author syntax

"#
    );

    verifies!(
        r#"
The information for each author is concluded with a semicolon (`;`).

.Author line structure for multiple authors
[source]
----
= Document Title
firstname middlename lastname <email>; firstname middlename lastname <email>
----

Directly after each author's last name or optional email, enter a semicolon (`;`) followed by a space, and then enter the next author's information.

"#
    );

    let doc = Parser::default().parse("= The Intrepid Chronicles\nKismet R. Lee <kismet@asciidoctor.org>; B. Steppenwolf; Pax Draeke <pax@asciidoctor.org>");

    assert_eq!(
        doc,
        Document {
            header: Header {
                title_source: Some(Span {
                    data: "The Intrepid Chronicles",
                    line: 1,
                    col: 3,
                    offset: 2,
                },),
                title: Some("The Intrepid Chronicles",),
                attributes: &[],
                author_line: Some(AuthorLine {
                    authors: &[
                        Author {
                            name: "Kismet R. Lee",
                            firstname: "Kismet",
                            middlename: Some("R.",),
                            lastname: Some("Lee",),
                            email: Some("kismet@asciidoctor.org",),
                        },
                        Author {
                            name: "B. Steppenwolf",
                            firstname: "B.",
                            middlename: None,
                            lastname: Some("Steppenwolf",),
                            email: None,
                        },
                        Author {
                            name: "Pax Draeke",
                            firstname: "Pax",
                            middlename: None,
                            lastname: Some("Draeke",),
                            email: Some("pax@asciidoctor.org",),
                        },
                    ],
                    source: Span {
                        data: "Kismet R. Lee <kismet@asciidoctor.org>; B. Steppenwolf; Pax Draeke <pax@asciidoctor.org>",
                        line: 2,
                        col: 1,
                        offset: 26,
                    },
                },),
                revision_line: None,
                comments: &[],
                source: Span {
                    data: "= The Intrepid Chronicles\nKismet R. Lee <kismet@asciidoctor.org>; B. Steppenwolf; Pax Draeke <pax@asciidoctor.org>",
                    line: 1,
                    col: 1,
                    offset: 0,
                },
            },
            blocks: &[],
            source: Span {
                data: "= The Intrepid Chronicles\nKismet R. Lee <kismet@asciidoctor.org>; B. Steppenwolf; Pax Draeke <pax@asciidoctor.org>",
                line: 1,
                col: 1,
                offset: 0,
            },
            warnings: &[],
            source_map: SourceMap(&[]),
            catalog: Catalog::default(),
        }
    );
}

#[test]
fn escape_trailing_character_reference() {
    non_normative!(
        r#"
=== Escape a trailing character reference

"#
    );

    verifies!(
        r#"
If an author name segment ends with a character reference (e.g., `\&#174;`), you must escape it from processing.
One way to escape it is to add a trailing attribute reference (e.g., `\{empty}`).
If the character reference appears at the end of the last author name segment, you can use a second semicolon instead.

A better way of escaping the character reference is to replace it with an attribute reference (e.g., `\{reg}`).

Even if the character reference is escaped, the segments of the author name will not be processed.
Instead, the whole name will be assigned to the `author` and `firstname` attributes.
This limitation may be lifted in the future.

"#
    );

    let doc = Parser::default().parse("= Document Title\nAsciiDoc&#174;{empty} WG; Another Author");

    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: "AsciiDoc&#174; WG",
                            firstname: "AsciiDoc&#174;",
                            middlename: None,
                            lastname: Some("WG"),
                            email: None,
                        },
                        Author {
                            name: "Another Author",
                            firstname: "Another",
                            middlename: None,
                            lastname: Some("Author",),
                            email: None,
                        },
                    ],
                    source: Span {
                        data: "AsciiDoc&#174;{empty} WG; Another Author",
                        line: 2,
                        col: 1,
                        offset: 17,
                    },
                },),
                revision_line: None,
                comments: &[],
                source: Span {
                    data: "= Document Title\nAsciiDoc&#174;{empty} WG; Another Author",
                    line: 1,
                    col: 1,
                    offset: 0,
                },
            },
            blocks: &[],
            source: Span {
                data: "= Document Title\nAsciiDoc&#174;{empty} WG; Another Author",
                line: 1,
                col: 1,
                offset: 0,
            },
            warnings: &[],
            source_map: SourceMap(&[]),
            catalog: Catalog::default(),
        }
    );
}

#[test]
fn list_multiple_authors_on_author_line() {
    non_normative!(
        r#"
== List multiple authors on the author line

"#
    );

    verifies!(
        r#"
The author line in <<ex-line-multiple>> lists the information for three authors.
Each author's information is separated by a semicolon (`;`).
Notice that the author _B. Steppenwolf_ doesn't have an email, so the semicolon is placed at the end of their name.

.An author line with three authors and two email addresses
[source#ex-line-multiple]
----
include::example$multiple-authors.adoc[tag=header]
----

The result of <<ex-line-multiple>> is displayed below.

image::author-line-with-multiple-authors.png[Multiple authors and their emails displayed on the byline,role=screenshot]

The information for each author can also be xref:reference-author-attributes.adoc#reference-multiple-authors[referenced in the document] using their respective built-in attribute.

"#
    );

    // Test the exact example from the documentation.
    let doc = Parser::default().parse("= The Intrepid Chronicles\nKismet R. Lee <kismet@asciidoctor.org>; B. Steppenwolf; Pax Draeke <pax@asciidoctor.org>");

    assert_eq!(
        doc,
        Document {
            header: Header {
                title_source: Some(Span {
                    data: "The Intrepid Chronicles",
                    line: 1,
                    col: 3,
                    offset: 2,
                },),
                title: Some("The Intrepid Chronicles",),
                attributes: &[],
                author_line: Some(AuthorLine {
                    authors: &[
                        Author {
                            name: "Kismet R. Lee",
                            firstname: "Kismet",
                            middlename: Some("R.",),
                            lastname: Some("Lee",),
                            email: Some("kismet@asciidoctor.org",),
                        },
                        Author {
                            name: "B. Steppenwolf",
                            firstname: "B.",
                            middlename: None,
                            lastname: Some("Steppenwolf",),
                            email: None,
                        },
                        Author {
                            name: "Pax Draeke",
                            firstname: "Pax",
                            middlename: None,
                            lastname: Some("Draeke",),
                            email: Some("pax@asciidoctor.org",),
                        },
                    ],
                    source: Span {
                        data: "Kismet R. Lee <kismet@asciidoctor.org>; B. Steppenwolf; Pax Draeke <pax@asciidoctor.org>",
                        line: 2,
                        col: 1,
                        offset: 26,
                    },
                },),
                revision_line: None,
                comments: &[],
                source: Span {
                    data: "= The Intrepid Chronicles\nKismet R. Lee <kismet@asciidoctor.org>; B. Steppenwolf; Pax Draeke <pax@asciidoctor.org>",
                    line: 1,
                    col: 1,
                    offset: 0,
                },
            },
            blocks: &[],
            source: Span {
                data: "= The Intrepid Chronicles\nKismet R. Lee <kismet@asciidoctor.org>; B. Steppenwolf; Pax Draeke <pax@asciidoctor.org>",
                line: 1,
                col: 1,
                offset: 0,
            },
            warnings: &[],
            source_map: SourceMap(&[]),
            catalog: Catalog::default(),
        }
    );
}

#[test]
fn preserve_semicolon_in_character_reference_with_trailing_attribute() {
    verifies!(
        r#"
If an author name ends with with a character reference, you can preserve the semicolon in the character reference by adding a trailing attribute reference:

----
AsciiDoc&#174;{empty} WG; Another Author
----

"#
    );

    // Test the exact example from the documentation.
    let doc = Parser::default().parse("= Document Title\nAsciiDoc&#174;{empty} WG; Another Author");

    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: "AsciiDoc&#174; WG",
                            firstname: "AsciiDoc&#174;",
                            middlename: None,
                            lastname: Some("WG"),
                            email: None,
                        },
                        Author {
                            name: "Another Author",
                            firstname: "Another",
                            middlename: None,
                            lastname: Some("Author",),
                            email: None,
                        },
                    ],
                    source: Span {
                        data: "AsciiDoc&#174;{empty} WG; Another Author",
                        line: 2,
                        col: 1,
                        offset: 17,
                    },
                },),
                revision_line: None,
                comments: &[],
                source: Span {
                    data: "= Document Title\nAsciiDoc&#174;{empty} WG; Another Author",
                    line: 1,
                    col: 1,
                    offset: 0,
                },
            },
            blocks: &[],
            source: Span {
                data: "= Document Title\nAsciiDoc&#174;{empty} WG; Another Author",
                line: 1,
                col: 1,
                offset: 0,
            },
            warnings: &[],
            source_map: SourceMap(&[]),
            catalog: Catalog::default(),
        }
    );
}

#[test]
fn move_character_reference_to_attribute() {
    verifies!(
        r#"
Another solution entails moving the character reference to an attribute and inserting it using an attribute reference:

----
:reg: &#174;
AsciiDoc{reg} WG; Another Author
----

Even though the character reference is escaped, the segments of the author name will not be processed.

"#
    );

    // Test the exact example from the documentation.
    let doc =
        Parser::default().parse(":reg: &#174;\n= Document Title\nAsciiDoc{reg} WG; Another Author");

    assert_eq!(
        doc,
        Document {
            header: Header {
                title_source: Some(Span {
                    data: "Document Title",
                    line: 2,
                    col: 3,
                    offset: 15,
                },),
                title: Some("Document Title",),
                attributes: &[Attribute {
                    name: Span {
                        data: "reg",
                        line: 1,
                        col: 2,
                        offset: 1,
                    },
                    value_source: Some(Span {
                        data: "&#174;",
                        line: 1,
                        col: 7,
                        offset: 6,
                    },),
                    value: InterpretedValue::Value("&amp;#174;",),
                    source: Span {
                        data: ":reg: &#174;",
                        line: 1,
                        col: 1,
                        offset: 0,
                    },
                },],
                author_line: Some(AuthorLine {
                    authors: &[
                        Author {
                            name: "AsciiDoc&amp;#174; WG",
                            firstname: "AsciiDoc&amp;#174;",
                            middlename: None,
                            lastname: Some("WG",),
                            email: None,
                        },
                        Author {
                            name: "Another Author",
                            firstname: "Another",
                            middlename: None,
                            lastname: Some("Author",),
                            email: None,
                        },
                    ],
                    source: Span {
                        data: "AsciiDoc{reg} WG; Another Author",
                        line: 3,
                        col: 1,
                        offset: 30,
                    },
                },),
                revision_line: None,
                comments: &[],
                source: Span {
                    data: ":reg: &#174;\n= Document Title\nAsciiDoc{reg} WG; Another Author",
                    line: 1,
                    col: 1,
                    offset: 0,
                },
            },
            blocks: &[],
            source: Span {
                data: ":reg: &#174;\n= Document Title\nAsciiDoc{reg} WG; Another Author",
                line: 1,
                col: 1,
                offset: 0,
            },
            warnings: &[],
            source_map: SourceMap(&[]),
            catalog: Catalog::default(),
        }
    );
}