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
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
use crate::tests::prelude::*;
track_file!("ref/asciidoc-lang/docs/modules/tables/pages/add-cells-and-rows.adoc");
non_normative!(
r#"
= Add Cells and Rows to a Table
//let's add a tip or xref to something about the "default" cell separator and data format and the alternatives that's not too invasive to the flow
"#
);
#[test]
fn table_cells() {
non_normative!(
r#"
== Table cells
"#
);
verifies!(
r#"
[[cell-separator]]Each new cell in a table is declared with a cell separator.
The default [.term]*cell separator* is a vertical bar (`|`).
All of the content entered after a cell separator is included in that cell until the processor encounters a space followed by another vertical bar (`|`) or a new line that begins with a `|`.
.Creating table cells with the default cell separator
[source#ex-separator]
----
[cols="3,2,3"]
|===
|This content is placed in the first cell of column 1
|This line starts with a vertical bar so this content is placed in a new cell in column 2 |When the processor encounters a whitespace followed by a vertical bar it ends the previous cell and starts a new cell
|===
----
When the processor encounters another `|`, it creates a new cell in the next consecutive column.
Once the processor reaches the xref:add-columns.adoc[last column assigned to the table], the next cell it encounters is placed in a new row.
Taking into account any xref:span-cells.adoc[spans], which are applied via a <<specifiers,cell specifier>>, each row consists of the same number of cells.
"#
);
// A space (or tab) followed by a `|`, or a `|` at the start of a line, ends
// the previous cell and begins a new one. The three cells declared here flow
// into a single row because the table has three columns.
let doc = Parser::default().parse(
"[cols=\"3,2,3\"]\n|===\n|This content is placed in the first cell of column 1\n|This line starts with a vertical bar so this content is placed in a new cell in column 2 |When the processor encounters a whitespace followed by a vertical bar it ends the previous cell and starts a new cell\n|===",
);
assert_eq!(
doc,
Document {
header: Header {
title_source: None,
title: None,
attributes: &[],
author_line: None,
revision_line: None,
comments: &[],
source: Span {
data: "",
line: 1,
col: 1,
offset: 0,
},
},
blocks: &[Block::Table(TableBlock {
columns: &[
TableColumn {
width: 3,
h_align: HorizontalAlignment::Left,
v_align: VerticalAlignment::Top,
style: ColumnStyle::Default,
},
TableColumn {
width: 2,
h_align: HorizontalAlignment::Left,
v_align: VerticalAlignment::Top,
style: ColumnStyle::Default,
},
TableColumn {
width: 3,
h_align: HorizontalAlignment::Left,
v_align: VerticalAlignment::Top,
style: ColumnStyle::Default,
},
],
header_row: None,
body_rows: &[TableRow {
cells: &[
TableCell {
content: TableCellContent::Simple(Content {
original: Span {
data: "This content is placed in the first cell of column 1",
line: 3,
col: 2,
offset: 21,
},
rendered: "This content is placed in the first cell of column 1",
}),
},
TableCell {
content: TableCellContent::Simple(Content {
original: Span {
data: "This line starts with a vertical bar so this content is placed in a new cell in column 2",
line: 4,
col: 2,
offset: 75,
},
rendered: "This line starts with a vertical bar so this content is placed in a new cell in column 2",
}),
},
TableCell {
content: TableCellContent::Simple(Content {
original: Span {
data: "When the processor encounters a whitespace followed by a vertical bar it ends the previous cell and starts a new cell",
line: 4,
col: 92,
offset: 165,
},
rendered: "When the processor encounters a whitespace followed by a vertical bar it ends the previous cell and starts a new cell",
}),
},
],
}],
footer_row: None,
source: Span {
data: "[cols=\"3,2,3\"]\n|===\n|This content is placed in the first cell of column 1\n|This line starts with a vertical bar so this content is placed in a new cell in column 2 |When the processor encounters a whitespace followed by a vertical bar it ends the previous cell and starts a new cell\n|===",
line: 1,
col: 1,
offset: 0,
},
title_source: None,
title: None,
caption: None,
number: None,
anchor: None,
anchor_reftext: None,
attrlist: Some(Attrlist {
attributes: &[ElementAttribute {
name: Some("cols"),
shorthand_items: &[],
value: "3,2,3",
}],
anchor: None,
source: Span {
data: "cols=\"3,2,3\"",
line: 1,
col: 2,
offset: 1,
},
}),
})],
source: Span {
data: "[cols=\"3,2,3\"]\n|===\n|This content is placed in the first cell of column 1\n|This line starts with a vertical bar so this content is placed in a new cell in column 2 |When the processor encounters a whitespace followed by a vertical bar it ends the previous cell and starts a new cell\n|===",
line: 1,
col: 1,
offset: 0,
},
warnings: &[],
source_map: SourceMap(&[]),
catalog: Catalog::default(),
}
);
// Cell specifiers introduce per-cell spans, duplication, alignment, and
// style operators, each specified in detail on a dedicated page (span-cells,
// duplicate-cells, align-by-cell, format-cell-content). The span,
// duplication, alignment, and style operators (and the override behavior)
// are all implemented and verified here.
verifies!(
r#"
[#specifiers]
=== Cell specifiers and operators
A [.term]*cell specifier* is a positional attribute placed directly in front of a cell separator that represents the position and style properties assigned to a cell's content.
In the example below, a horizontal alignment operator and style operator have been assigned to the first cell's specifier.
.Using cell specifiers
[source#ex-specifier]
----
[cols="2*"]
|===
>s|This cell's specifier indicates that this cell's content is right-aligned and bold.
|The cell specifier on this cell hasn't been set explicitly, so the default properties are applied.
|===
----
AsciiDoc provides operators to control the following cell properties:
* xref:span-cells.adoc[span]
* xref:duplicate-cells.adoc[duplication]
* xref:align-by-cell.adoc#horizontal-operators[horizontal alignment]
* xref:align-by-cell.adoc#vertical-operators[vertical alignment]
* xref:format-cell-content.adoc[content style]
A cell specifier only applies to the cell it's placed on, not to all of the cells in the same row.
Also, the operator in a cell specifier will override the operator in a xref:add-columns.adoc#col-specifier[column specifier] if they belong to the same property.
"#
);
// Expansion of `ex-specifier`. The first cell's specifier (`>s`) makes its
// content right-aligned and bold; the second cell has no specifier, so the
// default properties (left-aligned, default style) apply. This also shows
// that a cell specifier applies only to the cell it's placed on, not to the
// whole row.
let table = specifier_table(
"[cols=\"2*\"]\n|===\n>s|This cell's specifier indicates that this cell's content is right-aligned and bold.\n|The cell specifier on this cell hasn't been set explicitly, so the default properties are applied.\n|===",
);
let row = &table.body_rows()[0];
assert_eq!(row.cells()[0].h_align(), HorizontalAlignment::Right);
assert_eq!(row.cells()[0].style(), ColumnStyle::Strong);
assert_eq!(row.cells()[1].h_align(), HorizontalAlignment::Left);
assert_eq!(row.cells()[1].style(), ColumnStyle::Default);
// A cell specifier operator overrides the column specifier operator for the
// same property: the column is centered and monospace (`^m`), but the cell's
// own `>` and `s` operators win, while a property the cell leaves unset (here
// vertical alignment) still falls back to the column.
let table = specifier_table("[cols=\"^.^m\"]\n|===\n>s|overridden\n|===");
let cell = &table.body_rows()[0].cells()[0];
assert_eq!(cell.h_align(), HorizontalAlignment::Right);
assert_eq!(cell.style(), ColumnStyle::Strong);
assert_eq!(cell.v_align(), VerticalAlignment::Middle);
}
/// Parse `source` as a single block and return the [`TableBlock`] it produced.
///
/// [`TableBlock`]: crate::blocks::TableBlock
fn specifier_table(source: &str) -> crate::blocks::TableBlock<'_> {
let mut parser = Parser::default();
let mi = crate::blocks::Block::parse(crate::Span::new(source), &mut parser)
.unwrap_if_no_warnings()
.unwrap();
match mi.item {
crate::blocks::Block::Table(table) => table,
other => panic!("expected a table block, got {other:?}"),
}
}
#[test]
fn create_a_table_cell() {
non_normative!(
r#"
== Create a table cell
In this section, we'll set up a table and add two rows of cells to it.
First, let's create two cells in <<ex-cells>> and see how they get arranged into a row.
"#
);
verifies!(
r#"
.Add two cells to a table
[source#ex-cells]
----
[cols="1,1"] <.>
|===
|This cell is in column 1, row 1 <.>
|This cell is in column 2, row 1 <.>
|===
----
<.> The table has two columns because two column specifiers are assigned to the `cols` attribute.
<.> The processor places this cell in the first column and row of the table because the vertical bar (`|`) at the beginning of this cell is the first cell separator the processor encounters after the opening table delimiter (`|===`).
<.> This is the second `|` the processor encounters, so this cell is placed in the second column of the first row.
Though the two cells in <<ex-cells>> were entered on separate lines, the processor places them in the same row.
.Result of <<ex-cells>>
[cols="1,1"]
|===
|This cell is in column 1, row 1
|This cell is in column 2, row 1
|===
Since the number of columns in <<ex-cells>> is set to two by the `cols` attribute, and there are two cells entered in the table, the first row is complete.
Now, let's add two more cells to the table.
"#
);
// Two cells entered on separate lines flow into a single row because the
// table has two columns.
let doc = Parser::default().parse(
"[cols=\"1,1\"]\n|===\n|This cell is in column 1, row 1\n|This cell is in column 2, row 1\n|===",
);
assert_eq!(
doc,
Document {
header: Header {
title_source: None,
title: None,
attributes: &[],
author_line: None,
revision_line: None,
comments: &[],
source: Span {
data: "",
line: 1,
col: 1,
offset: 0,
},
},
blocks: &[Block::Table(TableBlock {
columns: &[
TableColumn {
width: 1,
h_align: HorizontalAlignment::Left,
v_align: VerticalAlignment::Top,
style: ColumnStyle::Default,
},
TableColumn {
width: 1,
h_align: HorizontalAlignment::Left,
v_align: VerticalAlignment::Top,
style: ColumnStyle::Default,
},
],
header_row: None,
body_rows: &[TableRow {
cells: &[
TableCell {
content: TableCellContent::Simple(Content {
original: Span {
data: "This cell is in column 1, row 1",
line: 3,
col: 2,
offset: 19,
},
rendered: "This cell is in column 1, row 1",
}),
},
TableCell {
content: TableCellContent::Simple(Content {
original: Span {
data: "This cell is in column 2, row 1",
line: 4,
col: 2,
offset: 52,
},
rendered: "This cell is in column 2, row 1",
}),
},
],
}],
footer_row: None,
source: Span {
data: "[cols=\"1,1\"]\n|===\n|This cell is in column 1, row 1\n|This cell is in column 2, row 1\n|===",
line: 1,
col: 1,
offset: 0,
},
title_source: None,
title: None,
caption: None,
number: None,
anchor: None,
anchor_reftext: None,
attrlist: Some(Attrlist {
attributes: &[ElementAttribute {
name: Some("cols"),
shorthand_items: &[],
value: "1,1",
}],
anchor: None,
source: Span {
data: "cols=\"1,1\"",
line: 1,
col: 2,
offset: 1,
},
}),
})],
source: Span {
data: "[cols=\"1,1\"]\n|===\n|This cell is in column 1, row 1\n|This cell is in column 2, row 1\n|===",
line: 1,
col: 1,
offset: 0,
},
warnings: &[],
source_map: SourceMap(&[]),
catalog: Catalog::default(),
}
);
verifies!(
r#"
.Add two more cells to a table
[source#ex-more-cells]
----
[cols="1,1"]
|===
|This cell is in column 1, row 1
|This cell is in column 2, row 1
<.>
|This cell is in column 1, row 2 <.>
| This cell is in column 2, row 2 <.>
|===
----
<.> Separate rows by one or more empty lines.
<.> The processor places this cell on the second row because the table has two columns and this is the third cell separator (`|`) it encounters.
<.> Any leading or trailing spaces around the cell content is stripped by the processor.
The table from <<ex-more-cells>> now has four cells arranged into two consecutive rows.
.Result of <<ex-more-cells>>
[cols="1,1"]
|===
|This cell is in column 1, row 1
|This cell is in column 2, row 1
|This cell is in column 1, row 2
| This cell is in column 2, row 2
|===
The cells in a row can be entered on the same line or consecutive lines because the row a cell in placed on is determined by the number of columns in a table and the order in which the processor encounters the cell's separator (`|`).
"#
);
// Four cells flow into two rows of two. Rows are separated by one or more
// empty lines, and leading/trailing whitespace around cell content is
// stripped (the second cell of the second row is indented four spaces).
let doc = Parser::default().parse(
"[cols=\"1,1\"]\n|===\n|This cell is in column 1, row 1\n|This cell is in column 2, row 1\n\n|This cell is in column 1, row 2\n| This cell is in column 2, row 2\n|===",
);
assert_eq!(
doc,
Document {
header: Header {
title_source: None,
title: None,
attributes: &[],
author_line: None,
revision_line: None,
comments: &[],
source: Span {
data: "",
line: 1,
col: 1,
offset: 0,
},
},
blocks: &[Block::Table(TableBlock {
columns: &[
TableColumn {
width: 1,
h_align: HorizontalAlignment::Left,
v_align: VerticalAlignment::Top,
style: ColumnStyle::Default,
},
TableColumn {
width: 1,
h_align: HorizontalAlignment::Left,
v_align: VerticalAlignment::Top,
style: ColumnStyle::Default,
},
],
header_row: None,
body_rows: &[
TableRow {
cells: &[
TableCell {
content: TableCellContent::Simple(Content {
original: Span {
data: "This cell is in column 1, row 1",
line: 3,
col: 2,
offset: 19,
},
rendered: "This cell is in column 1, row 1",
}),
},
TableCell {
content: TableCellContent::Simple(Content {
original: Span {
data: "This cell is in column 2, row 1",
line: 4,
col: 2,
offset: 52,
},
rendered: "This cell is in column 2, row 1",
}),
},
],
},
TableRow {
cells: &[
TableCell {
content: TableCellContent::Simple(Content {
original: Span {
data: "This cell is in column 1, row 2",
line: 6,
col: 2,
offset: 86,
},
rendered: "This cell is in column 1, row 2",
}),
},
TableCell {
content: TableCellContent::Simple(Content {
original: Span {
data: "This cell is in column 2, row 2",
line: 7,
col: 6,
offset: 123,
},
rendered: "This cell is in column 2, row 2",
}),
},
],
},
],
footer_row: None,
source: Span {
data: "[cols=\"1,1\"]\n|===\n|This cell is in column 1, row 1\n|This cell is in column 2, row 1\n\n|This cell is in column 1, row 2\n| This cell is in column 2, row 2\n|===",
line: 1,
col: 1,
offset: 0,
},
title_source: None,
title: None,
caption: None,
number: None,
anchor: None,
anchor_reftext: None,
attrlist: Some(Attrlist {
attributes: &[ElementAttribute {
name: Some("cols"),
shorthand_items: &[],
value: "1,1",
}],
anchor: None,
source: Span {
data: "cols=\"1,1\"",
line: 1,
col: 2,
offset: 1,
},
}),
})],
source: Span {
data: "[cols=\"1,1\"]\n|===\n|This cell is in column 1, row 1\n|This cell is in column 2, row 1\n\n|This cell is in column 1, row 2\n| This cell is in column 2, row 2\n|===",
line: 1,
col: 1,
offset: 0,
},
warnings: &[],
source_map: SourceMap(&[]),
catalog: Catalog::default(),
}
);
}
#[test]
fn enter_a_rows_cells_on_a_single_line() {
non_normative!(
r#"
[#same]
== Enter a row's cells on a single line
"#
);
verifies!(
r#"
You can enter a row's cells on a single line.
//This method is how the number or columns in a table are implicitly assigned and implicitly assign the `header` option to the table's first row.
When entering cells on a single line, *at least one space must be entered between the last character of the previous cell's content and the cell separator (`|`) of the next cell*.
.Cells entered on the same line
[source#ex-single-line]
----
|===
|Column 1 |Column 2 |Column 3 <.> <.>
|Cell in column 1, row 2 |Cell in column 2, row 2 |Cell in column 3, row 2 <.>
|Cell in column 1, row 3 <.>
|Cell in column 2, row 3 |Cell in column 3, row 3
|===
----
<.> Since `cols` is not set, the first row in this table must have the cells entered on a single line in order to implicitly assign three columns to the table.
<.> The first row is entered on the line directly after the opening table delimiter (`|===`) and followed by an empty line.
This automatically assigns the `header` option to it.
<.> When multiple cells are entered on a single line, enter at least one space between the last character of the previous cell's content and the cell separator (`|`) of the next cell.
<.> A row's cells can be entered on a combination of lines as long as the lines are consecutive.
The table created in <<ex-single-line>> contains three columns and three rows.
.Result of <<ex-single-line>>
|===
|Column 1 |Column 2 |Column 3
|Cell in column 1, row 2 |Cell in column 2, row 2 |Cell in column 3, row 2
|Cell in column 1, row 3
|Cell in column 2, row 3 |Cell in column 3, row 3
|===
Any leading and trailing spaces around the cell content are stripped and don't affect the table's layout when rendered.
"#
);
// `cols` is not set, so the three cells on the first line implicitly assign
// three columns. That first line, followed by an empty line, is treated as
// the header row. The remaining cells flow into two body rows, whether
// entered on a single line or across consecutive lines.
let doc = Parser::default().parse(
"|===\n|Column 1 |Column 2 |Column 3\n\n|Cell in column 1, row 2 |Cell in column 2, row 2 |Cell in column 3, row 2\n\n|Cell in column 1, row 3\n|Cell in column 2, row 3 |Cell in column 3, row 3\n|===",
);
assert_eq!(
doc,
Document {
header: Header {
title_source: None,
title: None,
attributes: &[],
author_line: None,
revision_line: None,
comments: &[],
source: Span {
data: "",
line: 1,
col: 1,
offset: 0,
},
},
blocks: &[Block::Table(TableBlock {
columns: &[
TableColumn {
width: 1,
h_align: HorizontalAlignment::Left,
v_align: VerticalAlignment::Top,
style: ColumnStyle::Default,
},
TableColumn {
width: 1,
h_align: HorizontalAlignment::Left,
v_align: VerticalAlignment::Top,
style: ColumnStyle::Default,
},
TableColumn {
width: 1,
h_align: HorizontalAlignment::Left,
v_align: VerticalAlignment::Top,
style: ColumnStyle::Default,
},
],
header_row: Some(TableRow {
cells: &[
TableCell {
content: TableCellContent::Simple(Content {
original: Span {
data: "Column 1",
line: 2,
col: 2,
offset: 6,
},
rendered: "Column 1",
}),
},
TableCell {
content: TableCellContent::Simple(Content {
original: Span {
data: "Column 2",
line: 2,
col: 12,
offset: 16,
},
rendered: "Column 2",
}),
},
TableCell {
content: TableCellContent::Simple(Content {
original: Span {
data: "Column 3",
line: 2,
col: 22,
offset: 26,
},
rendered: "Column 3",
}),
},
],
}),
body_rows: &[
TableRow {
cells: &[
TableCell {
content: TableCellContent::Simple(Content {
original: Span {
data: "Cell in column 1, row 2",
line: 4,
col: 2,
offset: 37,
},
rendered: "Cell in column 1, row 2",
}),
},
TableCell {
content: TableCellContent::Simple(Content {
original: Span {
data: "Cell in column 2, row 2",
line: 4,
col: 27,
offset: 62,
},
rendered: "Cell in column 2, row 2",
}),
},
TableCell {
content: TableCellContent::Simple(Content {
original: Span {
data: "Cell in column 3, row 2",
line: 4,
col: 52,
offset: 87,
},
rendered: "Cell in column 3, row 2",
}),
},
],
},
TableRow {
cells: &[
TableCell {
content: TableCellContent::Simple(Content {
original: Span {
data: "Cell in column 1, row 3",
line: 6,
col: 2,
offset: 113,
},
rendered: "Cell in column 1, row 3",
}),
},
TableCell {
content: TableCellContent::Simple(Content {
original: Span {
data: "Cell in column 2, row 3",
line: 7,
col: 2,
offset: 138,
},
rendered: "Cell in column 2, row 3",
}),
},
TableCell {
content: TableCellContent::Simple(Content {
original: Span {
data: "Cell in column 3, row 3",
line: 7,
col: 27,
offset: 163,
},
rendered: "Cell in column 3, row 3",
}),
},
],
},
],
footer_row: None,
source: Span {
data: "|===\n|Column 1 |Column 2 |Column 3\n\n|Cell in column 1, row 2 |Cell in column 2, row 2 |Cell in column 3, row 2\n\n|Cell in column 1, row 3\n|Cell in column 2, row 3 |Cell in column 3, row 3\n|===",
line: 1,
col: 1,
offset: 0,
},
title_source: None,
title: None,
caption: None,
number: None,
anchor: None,
anchor_reftext: None,
attrlist: None,
})],
source: Span {
data: "|===\n|Column 1 |Column 2 |Column 3\n\n|Cell in column 1, row 2 |Cell in column 2, row 2 |Cell in column 3, row 2\n\n|Cell in column 1, row 3\n|Cell in column 2, row 3 |Cell in column 3, row 3\n|===",
line: 1,
col: 1,
offset: 0,
},
warnings: &[],
source_map: SourceMap(&[]),
catalog: Catalog::default(),
}
);
}
#[test]
fn enter_a_rows_cells_on_consecutive_lines() {
non_normative!(
r#"
[#consecutive]
== Enter a row's cells on consecutive lines
The cells in a row can be entered on consecutive, individual lines.
When using this method, remember to either xref:add-columns.adoc[set the cols attribute] or xref:add-columns.adoc#implicit-cols[enter the first row's cells on a single line].
"#
);
verifies!(
r#"
.Cells on consecutive, individual lines
[source#ex-consecutive-lines]
----
include::example$row.adoc[tag=indv]
----
The `cols` attribute in <<ex-consecutive-lines>> is assigned a xref:add-columns.adoc#column-multiplier[multiplier] of `+3*+`, indicating that this table has three columns.
.Result of <<ex-consecutive-lines>>
include::example$row.adoc[tag=indv]
Entering cells on consecutive lines can improve the readability (and debugging) of your raw AsciiDoc content when you're applying <<specifiers,specifiers to the cells>>, using xref:format-cell-content.adoc#a-operator[AsciiDoc block elements in the cells], or entering a lot of content into the cells.
"#
);
// The example pulls in `example$row.adoc[tag=indv]`, whose expanded content
// is asserted here directly. The `cols="3*"` multiplier sets three columns,
// and the cells (entered on consecutive, individual lines) flow into two
// body rows. The first row is not a header because the line after the
// opening delimiter is immediately followed by another cell, not a blank.
let doc = Parser::default().parse(
"[cols=\"3*\"]\n|===\n|Cell in column 1, row 1\n|Cell in column 2, row 1\n|Cell in column 3, row 1\n\n|Cell in column 1, row 2\n|Cell in column 2, row 2\n|Cell in column 3, row 2\n|===",
);
assert_eq!(
doc,
Document {
header: Header {
title_source: None,
title: None,
attributes: &[],
author_line: None,
revision_line: None,
comments: &[],
source: Span {
data: "",
line: 1,
col: 1,
offset: 0,
},
},
blocks: &[Block::Table(TableBlock {
columns: &[
TableColumn {
width: 1,
h_align: HorizontalAlignment::Left,
v_align: VerticalAlignment::Top,
style: ColumnStyle::Default,
},
TableColumn {
width: 1,
h_align: HorizontalAlignment::Left,
v_align: VerticalAlignment::Top,
style: ColumnStyle::Default,
},
TableColumn {
width: 1,
h_align: HorizontalAlignment::Left,
v_align: VerticalAlignment::Top,
style: ColumnStyle::Default,
},
],
header_row: None,
body_rows: &[
TableRow {
cells: &[
TableCell {
content: TableCellContent::Simple(Content {
original: Span {
data: "Cell in column 1, row 1",
line: 3,
col: 2,
offset: 18,
},
rendered: "Cell in column 1, row 1",
}),
},
TableCell {
content: TableCellContent::Simple(Content {
original: Span {
data: "Cell in column 2, row 1",
line: 4,
col: 2,
offset: 43,
},
rendered: "Cell in column 2, row 1",
}),
},
TableCell {
content: TableCellContent::Simple(Content {
original: Span {
data: "Cell in column 3, row 1",
line: 5,
col: 2,
offset: 68,
},
rendered: "Cell in column 3, row 1",
}),
},
],
},
TableRow {
cells: &[
TableCell {
content: TableCellContent::Simple(Content {
original: Span {
data: "Cell in column 1, row 2",
line: 7,
col: 2,
offset: 94,
},
rendered: "Cell in column 1, row 2",
}),
},
TableCell {
content: TableCellContent::Simple(Content {
original: Span {
data: "Cell in column 2, row 2",
line: 8,
col: 2,
offset: 119,
},
rendered: "Cell in column 2, row 2",
}),
},
TableCell {
content: TableCellContent::Simple(Content {
original: Span {
data: "Cell in column 3, row 2",
line: 9,
col: 2,
offset: 144,
},
rendered: "Cell in column 3, row 2",
}),
},
],
},
],
footer_row: None,
source: Span {
data: "[cols=\"3*\"]\n|===\n|Cell in column 1, row 1\n|Cell in column 2, row 1\n|Cell in column 3, row 1\n\n|Cell in column 1, row 2\n|Cell in column 2, row 2\n|Cell in column 3, row 2\n|===",
line: 1,
col: 1,
offset: 0,
},
title_source: None,
title: None,
caption: None,
number: None,
anchor: None,
anchor_reftext: None,
attrlist: Some(Attrlist {
attributes: &[ElementAttribute {
name: Some("cols"),
shorthand_items: &[],
value: "3*",
}],
anchor: None,
source: Span {
data: "cols=\"3*\"",
line: 1,
col: 2,
offset: 1,
},
}),
})],
source: Span {
data: "[cols=\"3*\"]\n|===\n|Cell in column 1, row 1\n|Cell in column 2, row 1\n|Cell in column 3, row 1\n\n|Cell in column 1, row 2\n|Cell in column 2, row 2\n|Cell in column 3, row 2\n|===",
line: 1,
col: 1,
offset: 0,
},
warnings: &[],
source_map: SourceMap(&[]),
catalog: Catalog::default(),
}
);
}