Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn about links with template expressions #191

Merged
merged 2 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/source/syntax/links.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ I link to the [Inline link](#inline-link) heading above.
I link to the [Notes](tables.md#notes) heading on the [Tables](tables.md) page.
```

## Cross Links

Cross links are links that point to a different docset.

```markdown
[Cross link](kibana://cross-link.md)
```

The syntax is `<scheme>://<path>`, where <scheme> is the repository name and <path> is the path to the file.

## Heading anchors

Headings will automatically create anchor links in the resulting html.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ public override bool Match(InlineProcessor processor, ref StringSlice slice)
return match;
}

if (url.Contains("{{") || url.Contains("}}"))
{
processor.EmitWarning(line, column, length, "The url contains a template expression. Please do not use template expressions in links. See https://github.com/elastic/docs-builder/issues/182 for further information.");
return match;
}

var uri = Uri.TryCreate(url, UriKind.Absolute, out var u) ? u : null;

if (IsCrossLink(uri))
Expand Down
22 changes: 22 additions & 0 deletions tests/Elastic.Markdown.Tests/Inline/InlineLinkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,25 @@ public void EmitsCrossLink()
Collector.CrossLinks.Should().Contain("kibana://index.md");
}
}

public class LinksWithInterpolationWarning(ITestOutputHelper output) : LinkTestBase(output,
"""
[global search field]({{kibana-ref}}/introduction.html#kibana-navigation-search)
"""
)
{
[Fact]
public void GeneratesHtml() =>
// language=html
Html.Should().Contain(
"""<p><a href="%7B%7Bkibana-ref%7D%7D/introduction.html#kibana-navigation-search">global search field</a></p>"""
);

[Fact]
public void HasWarnings()
{
Collector.Diagnostics.Should().HaveCount(1);
Collector.Diagnostics.First().Severity.Should().Be(Diagnostics.Severity.Warning);
Collector.Diagnostics.First().Message.Should().Contain("The url contains a template expression. Please do not use template expressions in links. See https://github.com/elastic/docs-builder/issues/182 for further information.");
}
}
Loading