RE: About Links.
The following example shows four different methods to create a link to a target passage named Next.
Some text with a [[markup-based link->Next]]
Some text with a (link: "macro-based link")[(go-to: "Next")] in it.
Some text with a [named hook]<thehook| in it.
(click: ?thehook)[(go-to: "Next")]
Some text with an unique phrase in it.
(click: "unique phrase")[(go-to: "Next")]
The following describes the effort the Harlowe engine needs to go through to product the clickable link. For the sake of simplicity the following information is not 100% correct technically.
Harlowe generally starts at the top of a passage's content and processes/executes each 'line' of TwineScript as it's read, then adds the HTML elements required for that TwineScript to a temporary HTML structure and once all of the passage content has been processed any delay effects (like click macros) are resolved before the final temporary structure is rendered as part of the existing page.
A. The markup based link example.
The markup is processed as it is encounter within the passage contents and produces HTML elements like the following:
Some text with a
<tw-expression type="macro" name="link-goto">
<tw-link tabindex="0" passage-name="Next" data-raw="">markup-based link</tw-link>
</tw-expression>
in it.
B. The (link:) macro based link example.
The macro is processed as it is encounter within the passage contents and produces HTML elements like the following:
Some text with a
<tw-expression type="macro" name="link"></tw-expression>
<tw-hook>
<tw-link tabindex="0" data-raw="">macro-based link</tw-link>
</tw-hook>
in it.
C. The (click:) macro with named hook link example.
The TwineScript related to this example is processed in a number of steps and basically produces the following HTML for each one:
1. After the text and named hook is processed but before the (click:) macro is processed.
Some text with a
<tw-hook name="thehook">named hook</tw-hook>
in it.
<tw-expression type="macro" name="click" class="false"></tw-expression>
<tw-hook></tw-hook>
2. After the (click:) macro is processed but before the whole of temporary structure is scanned to locate the related name hook so that the related click handler can be attached.
Some text with a
<tw-hook name="thehook">named hook</tw-hook>
in it.
<tw-expression type="macro" name="click" class="false"></tw-expression>
<tw-hook></tw-hook>
3. After the scanning of the whole structure and the attaching of the click handler.
Some text with a
<tw-enchantment class="link enchantment-link" tabindex="0">
<tw-hook name="thehook">named hook</tw-hook>
</tw-enchantment>
in it.
<tw-expression type="macro" name="click" class="false"></tw-expression>
<tw-hook></tw-hook>
... you will notice that a tw-enchantment element has been inserted into the structure and that this element wraps the tw-hook element from step 2.
D. The (click:) macro with an unique phrase link example.
The TwineScript related to this example is processed in a number of steps and basically produces the following HTML for each one:
1. After the text is processed but before the (click:) macro is processed.
Some text with an unique phrase in it.
2. After the (click:) macro is processed but before the whole of temporary structure is scanned to locate the unique phrase so that the related click handler can be attached.
Some text with an unque phrase in it.
<tw-expression type="macro" name="click" class="false"></tw-expression>
<tw-hook></tw-hook>
3. After the scanning of the whole structure and the attaching of the click handler.
Some text with an
<tw-enchantment class="link enchantment-link" tabindex="0">unque phrase</tw-enchantment>
in it.
<tw-expression type="macro" name="click" class="false"></tw-expression>
<tw-hook></tw-hook>
... you will notice that a tw-enchantment element has been inserted into the structure and that this element wraps the tw-hook element from step 2.
In the case of a (click:) based macro link the scanning of the whole structure for the relevant item needs to be done for each and every (click:) macro within the Passage content, this means the the whole of the structure can be scanned multiple times.
This is why it is generally better to use either markup-based links or (link:) macro based links whenever possible.
NOTE: There are situations (related to post-render structure changes) which can cause the scanning required by the attaching of click handlers to be done again, which in turn can interfere with the end-users ability to interact with the page.