Expand description
This module defines the href feature (Href), which provides three commands
that insert a link to an address outside the document:
| written | links to | shows |
|---|---|---|
\href{https://example.com}{Click here} | https://example.com | Click here |
\url{https://example.com/} | https://example.com/ | example.com |
\email{someone@example.com} | mailto:someone@example.com | someone@example.com |
The first argument of each command is the address, as the author wrote it. The
target of a link is the address to which the link points: for \email, the
address preceded by mailto:, and for \href and \url, the address itself
(HrefCommand::prefix). A link written with \href shows its second argument.
A link written with \url or \email shows the display of its target, that is,
the target without a leading http://, https:// or mailto:, and without
trailing /, # and ? characters (display).
The three commands can be written only in text mode. The feature has no configuration. The language guide describes the commands for authors (hyperlinks).
§The address
The address argument is read as raw text up to the matching }
(ArgStdKind::Verbatim). Every character before this brace is part of the
address, including %, #, \, ~ and nested braces. For instance,
\url{https://example.com/a%20b#top} links to https://example.com/a%20b#top.
In the template of a user definition, a placeholder in an address is replaced by
the corresponding argument of the call, and a literal # is written ##, as
everywhere in a template. For instance, if the template of \doi is
\href{https://doi.org/#1}{#1}, the call \doi{10.1000/xyz} links to
https://doi.org/10.1000/xyz. The argument of the call must be plain text.
Otherwise, the error AddressNotCharacters is reported and no link is made.
The feature does not validate or normalize addresses. A backend can refuse an
address when it writes a link. For instance, the HTML backend refuses an address
whose scheme is not allowed by the render option
HtmlAllowedUrlSchemes.
The HTML backend then writes the link without an href attribute, and reports
the error flm.html.refused-address.
§The element and the lowering rules
The three commands share one element type, LINK_ELEMENT (flm.href.link).
Each command has its own element value, whose data is an HrefCommand.
The feature registers two lowering rules for this element type:
- The default rule
RULE(LinkRule) is used on every backend exceptlatex-recomposed. It lowers a link to aflm.pres.linknode of kindLINK_KIND(url), which points to the target of the link. The node contains the text argument of\href, or the display of the target for\urland\email. - The rule
latex::LATEX_RULEis used on thelatex-recomposedbackend. It writes each link as a call of a LaTeX hook, that is, a macro that is defined in the style file and that a user can redefine:\flmHref{address}{text},\flmUrl{address}or\flmEmail{address}. The hooks\flmUrland\flmEmailcompute the display in LaTeX, with the same result asdisplay. See the modulelatex.
Each backend writes a flm.pres.link node in its own format. For instance, the
HTML backend writes an <a> element whose href attribute is the target
(hyperlinks in HTML). The text
backend writes what the link shows, followed by the target between angle
brackets, as in Click here <https://example.com>. By default, the text
backend omits the target after a link written with \url or \email, since such
a link already shows its address. The render options
link_addresses
and
link_addresses_when_shown
change this behavior. The text backend recognizes such a link by the field
LinkPayload::shows_target, which the default rule sets for \url and \email.
Modules§
- latex
- The hyperlinks on the
latex-recomposedbackend: each command of thehreffeature written back as a LaTeX hook, a macro that the recomposed LaTeX writes and the style file defines with a plain default, which a user redefines in the document’s preamble (latex::preamble; see the LaTeX hooks).
Structs§
- Address
NotCharacters - The error that is reported when the address of
\href,\urlor\emailis not plain text (flm.href.address-not-characters). - Href
- The
hreffeature, which provides the commands\href,\urland\emailfor links to addresses outside the document. See the module documentation. - Link
Rule - The implementation of the default lowering rule
RULEof\href,\urland\email.
Enums§
- Href
Command - The command with which a link is written:
\href,\urlor\email.
Constants§
- ADDRESS_
ARG - The name of the address argument,
address. - ADDRESS_
ARG_ ROLE - The name of the argument role
flm.href.address, which marks an argument that contains the address of a link. The address argumentADDRESS_ARGof\href,\urland\emailhas this role (ArgDef::role). - DISPLAY_
PREFIXES - The prefixes that
displayremoves from the start of a link target:http://,https://andmailto:. At most one prefix is removed. - DISPLAY_
TRAILING - The characters that
displayremoves from the end of a link target:/,#and?. All of these characters at the end of the target are removed, in any number and in any order. - FEATURE
- The feature’s registered name,
href. - LINK_
ELEMENT - The name of the element type of
\href,\urland\email,flm.href.link. Each of the three commands has its own element value of this type, whose data is anHrefCommand. - LINK_
KIND - The link kind of the links that the default rule
RULEbuilds,url(LinkPayload::kind). This kind marks a link to an address outside the document. The HTML backend writes it as the attributedata-flm-kind="url". - RULE
- The name of the default lowering rule of
LINK_ELEMENT,flm.href.link.lower.default. The rule is implemented byLinkRule, and is used on every backend exceptlatex-recomposed. On thelatex-recomposedbackend, the rulelatex::LATEX_RULEis used instead. - TEXT_
ARG - The name of the text argument of
\href,text.