Skip to content

Conversation

@theletterf
Copy link
Contributor

This follows up from a conversation in #2532 to add automatic link rendering from HTTPs URLs.

Files created:

  • The autolink parser that detects bare https:// URLs
  • 50 unit tests covering all requirements

Files modified:

  • Added .UseAutoLinks() to the pipeline
  • Added documentation for the autolinks feature

Features implemented:

  • Valid https:// URLs are automatically converted to clickable links
  • Autolinks open in a new tab (target="_blank")
  • External link indicator is displayed (via existing CSS for target="_blank" links)
  • URLs containing elastic.co/docs emit a hint suggesting crosslinks/relative links
  • Autolinks are NOT rendered in code blocks or inline code spans
  • Trailing punctuation (., ,, ;, etc.) is correctly excluded from URLs
  • Balanced parentheses in URLs (like Wikipedia links) are handled correctly
  • Works correctly with LLM and plaintext renderers (no changes needed)

—-

LLM usage disclosure: I've used Claude Opus 4.5 in Cursor.

@theletterf
Copy link
Contributor Author

@elastic/docs-tech-leads This adds autolinks!

Copy link
Member

@Mpdreamz Mpdreamz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MarkDig supports .UseAutoLinks() natively, is there a reason we don't use it? (https only?)

@theletterf
Copy link
Contributor Author

@Mpdreamz I think so. Do we want to support also plain HTTP (unencrypted)?

@theletterf
Copy link
Contributor Author

@Mpdreamz After checking with Claude: there are several reasons we implemented a custom parser instead of using Markdig's .UseAutoLinks():

  • Markdig's autolinks supports http://, https://, www., and email addresses. We specifically wanted only https:// URLs.
  • We need to emit hints for elastic.co/docs URLs during parsing. Markdig's native extension doesn't have hooks for this.
  • Markdig's autolinks creates AutolinkInline objects, which would need a separate renderer. Our implementation creates standard LinkInline objects that automatically work with the existing HtmxLinkInlineRenderer, getting target="_blank" and external link indicators for free.

If the requirements were simpler (all URL schemes, no diagnostics), we could have used:
.UseAutoLinks(new AutoLinkOptions { OpenInNewWindow = true }), but then we'd still need to custom renderer for AutolinkInline?

@github-actions
Copy link

github-actions bot commented Jan 23, 2026

🔍 Preview links for changed docs

[Fact]
public void GeneratesHtml() =>
Html.Should().Contain(
"""<a href="https://www.elastic.co/docs/deploy-manage" target="_blank" rel="noopener noreferrer">https://www.elastic.co/docs/deploy-manage</a>"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Internal links need to have hx-* attributes, especially the hx-select-oob attribute.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Autolinks are always assumed to be external, that's why they don't get the hx- attrib?

@theletterf theletterf marked this pull request as draft January 23, 2026 11:45
@theletterf
Copy link
Contributor Author

Temporarily moving this to draft as we assess the situation regarding bare URLs in our docs (see Slack message).


#### Hint for elastic.co/docs URLs

Autolinks pointing to `elastic.co/docs` trigger a hint during build, suggesting you replace them with a [cross-repository link](#cross-repository-links) or relative link for better maintainability.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we exempt /docs/api ? we might want to add an exlusion for .zip given we want to expose llms.zip and elasticsearch-data.zip soon.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would you suggest proceeding here? We could add a filtering system (potentially fragile, hard to maintain, etc.), launch Autolinks anyway despite some broken URLs and let teams fix this, or hold / cancel. See thread in Slack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants