https://discuss.asciidoctor.org/Links-to-relative-files-by-an-anchor-tp354p471.html
Alex,
Several variations of this requirement have been raised recently and it's definitely something important to address. I believe the core functionality you need is captured by issue #417 (
https://github.com/asciidoctor/asciidoctor/issues/417). After an explanation, I'll present your example using the change I've proposed in the attached pull request.
The feature that appears to be missing from the AsciiDoc syntax is a means of creating an inter-document cross-reference. Until now, we've been viewing these as links. However, it's incorrect to encode them as links since the references could end up in the same document if both the source and destination get included in a master document. If there are written as cross-references, then Asciidoctor can intelligently wire them together appropriately since it has visibility into the full context of the document.
The proposed change enhances the existing xref macro from a simple id reference with an optional label:
<<id,label>>
to a compound reference that encodes the source document and id.
In fact, the AsciiDoc extension is optional.
<<doc#id,label>>
If the reference target is included in the same document as the reference source, the document (e.g., doc) is dropped. Thus, that reference may produce either one of these HTML elements:
<a href="#id">label</a>
or
<a href="doc.html#id">label</a>
Notice the .html is automatically added, since Asciidoctor knows what type of output it is producing.
Here's your example:
prs.ad= Product Requirement Specifications
...
== Physical System Requirements
[cols="1,3"]
.Physical Requirements
|===
|PRS -1 [[PRS-1]]
|system should .....
|PRS-2 [[PRS-2]]
|system should ...
|===
= Software Requirement Specifications
...
== Persistence
* In order to meet <<prs#PRS-1>>, we are going to use MongoDB.
If the document is rendered together as a book, the link in the last sentence would be represented as:
<a href="#PRS-1">[PRS-1]</a>
If the documents are rendered separately, the link would be represented as:
<a href="prs.html#PRS-1">[prs#PRS-1]</a>
(you can provide an explicit label if you don't like the one that is auto-generated). Feedback welcome as well.
NOTE: We're assuming (for now) that reference ids are globally unique within a document set.
-Dan