starlight_help/src/content/docs/add-a-custom-linkifier.mdx
import FlattenedSteps from "../../components/FlattenedSteps.astro"; import NavigationSteps from "../../components/NavigationSteps.astro"; import ZulipTip from "../../components/ZulipTip.astro"; import AdminOnly from "../include/_AdminOnly.mdx";
import EditIcon from "~icons/zulip-icon/edit"; import ExternalLinkIcon from "~icons/zulip-icon/external-link"; import TrashIcon from "~icons/zulip-icon/trash";
<AdminOnly />Linkifiers make it easy to refer to issues or tickets in third
party issue trackers, like GitHub, Salesforce, Zendesk, and others.
For instance, you can add a linkifier that automatically turns #2468
into a link to https://github.com/zulip/zulip/issues/2468.
You can configure linkifiers to work in reverse as well: when you paste a URL
that matches the linkifier into the compose box, Zulip will automatically
convert it to linked text (e.g., https://github.com/zulip/zulip/issues/2468
becomes #2468).
If a linkifier pattern (e.g., #2468) appears in the name of a topic, Zulip adds
an open (<ExternalLinkIcon />) button to the right of the topic in the
message recipient bar that links to the appropriate URL.
If you have any trouble creating the linkifiers you want, please contact Zulip support with details on what you're trying to do.
All linkifiers automatically turn text matching the specified pattern into links. You can also configure pasted links matching the URL template to automatically convert to linked text.
<FlattenedSteps> <NavigationSteps target="settings/linkifier-settings" />Linkifiers are processed in order, and will not apply to text that is already linkified. You can therefore choose which linkifiers to prioritize when more than one linkifier applies. The same priority order applies for converting URLs to shortened links. See the overlapping patterns section for examples.
<FlattenedSteps> <NavigationSteps target="settings/linkifier-settings" />The following examples cover the most common types of linkifiers, with a focus on linkifiers for issues or tickets.
This is a pattern that turns a # followed by a number into a link. It is often
used to link to issues or tickets in third party issue trackers, like GitHub,
Salesforce, Zendesk, and others.
#2468#(?P<id>[0-9]+)https://github.com/zulip/zulip/issues/{id}#{id}https://github.com/zulip/zulip/issues/2468To set up linkifiers for issues or tickets in multiple projects,
consider extending the #2468 format with project-specific
variants. For example, the Zulip development community
uses
#M2468 for an issue in the repository for the Zulip mobile app,
#D2468 and issue in the desktop app repository, etc.
#F245#F(?P<id>[0-9]+)https://github.com/zulip/zulip-flutter/issues/{id}#F{id}https://github.com/zulip/zulip-flutter/issues/245For organizations that commonly link to multiple GitHub repositories, this
linkfier pattern turns org/repo#ID into an issue or pull request link.
zulip/zulip#2468(?P<org>[a-zA-Z0-9_-]+)/(?P<repo>[a-zA-Z0-9_-]+)#(?P<id>[0-9]+)https://github.com/{org}/{repo}/issues/{id}{org}/{repo}#{id}https://github.com/zulip/zulip/issues/2468The following pattern linkfies a string of hexadecimal digits between 7 and 40 characters long, such as a Git commit ID.
abdc123(?P<id>[0-9a-f]{7,40})https://github.com/zulip/zulip/commit/{id}{id}https://github.com/zulip/zulip/commit/abcd123Linkifiers are a flexible system that can be used to construct rules for a wide variety of situations. Linkifier patterns are regular expressions, using the re2 regular expression engine.
Linkifiers use RFC 6570 compliant
URL templates to describe how links should be generated. These templates support
several expression types. The default expression type ({var}) will URL-encode
special characters like / and &; this behavior is desired for the vast
majority of linkifiers. Fancier URL template expression types can allow you to
get the exact behavior you want in corner cases like optional URL query
parameters. For example:
{+var} when you want URL delimiter characters to not be URL-encoded.{?var} and {&var} for variables in URL query parameters.{#var} when generating # fragments in URLs.The URL template specification has brief examples and detailed examples explaining the precise behavior of URL templates.
This example pattern is a shorthand for linking to pages on Zulip's ReadTheDocs site.
RTD/overview/changelog.htmlRTD/(?P<article>[a-zA-Z0-9_/.#-]+)https://zulip.readthedocs.io/en/latest/{+article}RTD/{article}https://zulip.readthedocs.io/en/latest/overview/changelog.htmlThis example pattern allows linking to Google searches.
google:(?P<q>\w+)?https://google.com/search{?q}google:foo or google:https://google.com/search?q=foo or https://google.com/searchThis example shows how specific linkifiers can be combined with more general ones to offer succinct linked text for the most commonly referenced links. For example, if you could have:
zulip/zulip GitHub repository, so that #123
links to an issue or pull request in that repository.You would set that up with:
#123#(?P<id>[0-9]+)https://github.com/zulip/zulip/pull/{id}#{id}org/repo#123(?P<org>[a-zA-Z0-9_-]+)/(?P<repo>[a-zA-Z0-9_-]+)#(?P<id>[0-9]+)https://github.com/{org}/{repo}/pull/{id}{org}/{repo}#{id}With the specific linkifier ordered first, when both linkifiers match, the specific linkifier will take precedence:
#123https://github.com/zulip/zulip/pull/123https://github.com/zulip/zulip/pull/123 auto-converts to: #123When only the general linkifier matches:
django/django#123https://github.com/django/django/pull/123https://github.com/django/django/pull/123 auto-converts to: django/django#123