Anup
Anup

Reputation: 955

Asciidoc table for counter values and text references

I am creating an asciidoc as described below:

Start of document 

* R{counter:recom}: sentence1 
...
* R{counter:recom}: sentence2
...
* R{counter:recom}: sentence3

End

Note: The R{counter:recom} from the asciidoc will be displayed as R1 R2 R3 in the resulting document.

I need to create a table at the start of the document which will refer the counters and text form the doc as described below:

Start of document 

|Ref#|text from the document
|R1|sentence1
|R2|sentence2
|R3|sentence3

throughout the doc: 

* R{counter:recom}: sentence1
...
* R{counter:recom}: sentence2
...
* R{counter:recom}: sentence3

End

Now, there are 2 unknown things here:

  1. How do I refer the counter and sentence part from the asciidoc R1 sentence1 in the table together or separately so that, if I change it in the doc it will be changed in the table?

  2. How do I refer the counter values in the table so that they work as links to the actual counter value R1 in the doc?

Not sure there is a readymade construct to achieve this and I haven't figured out how can I achieve it using an anchor or include statement.

Upvotes: 0

Views: 1571

Answers (2)

ahus1
ahus1

Reputation: 5932

The following is an experiment with attributes. It fulfills the following requirements:

  • if you change the sentence in the attribute, it will be changed in both the table and the doc
  • the table and the doc will contain the same number
  • the table to the item in the document
:ref-a: R{counter:recom}
:sen-a: sentence1

:ref-b: R{counter:recom}
:sen-b: sentence2

:ref-c: R{counter:recom}
:sen-c: sentence3

|===
|Ref#|text from the document
|<<link-a>>|{sen-a}
|<<link-b>>|{sen-b}
|<<link-c>>|{sen-c}
|===

throughout the doc:

* [[link-a,{ref-a}]]{ref-a}: {sen-a}
...
* [[link-b,{ref-b}]]{ref-b}: {sen-b}
...
* [[link-c,{ref-c}]]{ref-c}: {sen-c}
...

rendering this with either

Asciidoctor 2.0.10 [https://asciidoctor.org]
Runtime Environment (jruby 9.2.7.0 (2.5.3) 2019-04-09 8a269e3 Java HotSpot(TM) 64-Bit Server VM 25.161-b12 on 1.8.0_161-b12 +jit [mswin32-x86_64]) (lc:CP850 fs:Windows-1252 in:CP850 ex:CP850)

or

Asciidoctor PDF 1.5.0.beta.1 using Asciidoctor 2.0.10 [https://asciidoctor.org]
Runtime Environment (jruby 9.2.7.0 (2.5.3) 2019-04-09 8a269e3 Java HotSpot(TM) 64-Bit Server VM 25.161-b12 on 1.8.0_161-b12 +jit [mswin32-x86_64]) (lc:CP850 fs:Windows-1252 in:CP850 ex:CP850)

displays

screenshot asciidoctor output

Alternative to putting the sentence in an attribute: assuming that each chapter is described in a separate file, you can use an include statement that only includes the first line of the file for the table using include::filename.txt[lines=1], and later include the full file inside the document. See Include By Line Ranges in the Asciidoctor documentation for details (you can also use tags to specify the contents for the table).

Upvotes: 1

eskwayrd
eskwayrd

Reputation: 4521

What @ahus1 said.

Or, if you can convert your counter lines into section titles, then it's easy:

= Document

[cols="a"]
|===
| <<first>>
| <<second>>
| <<third>>
|===

...

[[first]]
== R{counter:recom}: sentence 1

...

[[second]]
== R{counter:recom}: sentence 2

...

[[third]]
== R{counter:recom}: sentence 3

...


End

Upvotes: 2

Related Questions