On Tuesday, March 24, 2015 at 3:53:24 PM UTC-7, Lex Trotman wrote:
>
> On 25 March 2015 at 09:20, Ken McGlothlen <[email protected] 
> <javascript:>> wrote: 
> The easiest way of using the toolchains (at least ones others have 
> used) is to use the a2x script that is part of the asciidoc 
> distribution http://asciidoc.github.io/asciidoc/a2x.1.html 
>

No XSLT examples? Foo. Okay, I guess I'll just have to wait to get my books 
out of storage.

Just a hint, don't forget a way of escaping the substitution, 
> otherwise you won't be able to have any text that might happen to 
> match a cross reference inside a listing or other literal location 
> where you would want it passed through unchanged.  Unless you parse 
> the asciidoc file enough to detect those locations yourself.


The short version is that the asciidoc.conf file has to add some HTML 
comments to the [sectx] output. For example:

[sect2]
<div class="sect2{style? {style}}{role? {role}}">
<h3{id? id="{id}"}>{numbered?{sectnum}{nbsp}}{title}</h3>
<!-- sectxref id="{id}" sectnum="{sectnum}" title="{title}"
     caption="{sect2-caption}"
     lnkfmt="{sect2-caption}\{nbsp}%sectnom% {title}" -->
|
</div>


These "sectxref" comments are picked up by the cross-referencing program 
from the HTML output, and indexed by id. Note that {sect2-caption} and the 
like are given values like "Chapter", "Section", "Subsection", and so on.

Let's assume that somewhere in the asciidoc file, the following appears:

[[some-id]]
=== The title


In the HTML document, this would therefore show up as

<!-- sectxref id="some-id" sectnum="3.6." title="The title"
     caption="Subsection"
     lnkfmt="Subsection{nbsp}%sectnom% The title" -->


This is the information that gets absorbed by the cross-referencing 
program; 'sectnom' is just sectnum without the trailing period.

The cross-referencing program then backs up the asciidoc file, and looks 
for anchors that match the following schemes:

[[some-id]]

If there is a sectxref for this id, this anchor is replaced with

[[some-id,pass:[<!-- divxref -->]Subsection{nbsp}3.6 The title]]


[[some-id,pass:[<!-- divxref -->]Subsection{nbsp}3.6 The title]]

The existence of a sectxref is checked (if not, a warning appears); if so, 
it is assumed that this is managed by the cross-referencer, and the label 
text is replaced with whatever the new value is:

[[some-id,pass:[<!-- divxref -->]Subsection{nbsp}3.7 The title]]


[[some-id,%sectcaption%{nbsp}%sectnom% (%title%)]]

If there is a sectref for this id, *and* certain strings appear (%id%, 
%sectcaption%, %sectnum%, %sectnom%, or %title%), this is assumed to be 
newly managed, and this is replaced with

[[some-id,pass:[<!-- divxref format="%sectcaption%{nbsp}%sectnom% 
(%title%)" -->]Subsection{nbsp}3.6 (The title)]]


[[some-id,pass:[<!-- divxref format="%sectcaption%{nbsp}%sectnom% 
(%title%)" -->]Subsection{nbsp}3.6 (The title)]]

The label is managed by the cross-referencer, and is rewritten 
appropriately:

[[some-id,pass:[<!-- divxref format="%sectcaption%{nbsp}%sectnom% 
(%title%)" -->]Subsection{nbsp}3.7 (The title)]]

 

[[some-id,plain old label]]

This is passed through without any management, though you can still get 
"plain old label" when you link to it; that's considered the default link 
text.


Then the links are examined:

<<some-id>>

If some-id has a label or default label, this is replaced with the 
appropriate value:

<<some-id,pass:[<-- xref -->]Subsection{nbsp}3.6 The title>>


<<some-id,pass:[<-- xref -->]Subsection{nbsp}3.6 The title>>

This is assumed to be managed by the cross-referencer, and the label is 
rewritten appropriately.

<<some-id,pass:[<-- xref -->]Subsection{nbsp}3.7 The title>>


<<some-id,%sectcaption%{nbsp}%sectnom% (%title%)>>

Same deal as with anchors; this gets rewritten to

<<some-id,pass:[<-- xref format="%sectcaption%{nbsp}%sectnom% (%title%)" 
-->]Subsection{nbsp}3.6 (The title)>>


<<some-id,pass:[<-- xref format="%sectcaption%{nbsp}%sectnom% (%title%)" 
-->]Subsection{nbsp}3.6 (The title)>>

Same deal as with anchors; this gets rewritten to

<<some-id,pass:[<-- xref format="%sectcaption%{nbsp}%sectnom% (%title%)" 
-->]Subsection{nbsp}3.6 (The title)>>


<<some-id,some other text>>

As long as "some other text" does not contain any %string% elements or a <-- 
xref --> thing, it's just passed through unmodified.


If you can spot any holes in that, let me know.

—Ken


-- 
You received this message because you are subscribed to the Google Groups 
"asciidoc" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/asciidoc.
For more options, visit https://groups.google.com/d/optout.

Reply via email to