From 926014ce1232440feb8bbd4cb5df3b400ab55902 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 14 Jan 2025 14:40:41 +0100 Subject: [PATCH 1/2] Warn about links with template expressions --- docs/source/syntax/links.md | 10 +++++++++ .../DiagnosticLinkInlineParser.cs | 6 +++++ .../Inline/InlineLinkTests.cs | 22 +++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/docs/source/syntax/links.md b/docs/source/syntax/links.md index 527a03017..4381acd62 100644 --- a/docs/source/syntax/links.md +++ b/docs/source/syntax/links.md @@ -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 `://`, where is the repository name and is the path to the file. + ## Heading anchors Headings will automatically create anchor links in the resulting html. diff --git a/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs b/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs index 021c4ddbe..a31e12ef3 100644 --- a/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs +++ b/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs @@ -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)) diff --git a/tests/Elastic.Markdown.Tests/Inline/InlineLinkTests.cs b/tests/Elastic.Markdown.Tests/Inline/InlineLinkTests.cs index d52b49260..a4ff9f539 100644 --- a/tests/Elastic.Markdown.Tests/Inline/InlineLinkTests.cs +++ b/tests/Elastic.Markdown.Tests/Inline/InlineLinkTests.cs @@ -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( + """

global search field

""" + ); + + [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."); + } +} From a63a7ffa1a3b557bb706ed895ef034e1bda57c89 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 14 Jan 2025 14:42:49 +0100 Subject: [PATCH 2/2] format --- .../Myst/InlineParsers/DiagnosticLinkInlineParser.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs b/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs index a31e12ef3..69fed5b07 100644 --- a/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs +++ b/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs @@ -64,7 +64,7 @@ public override bool Match(InlineProcessor processor, ref StringSlice slice) 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."); + 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; }