|
2 | 2 | // Elasticsearch B.V licenses this file to you under the Apache 2.0 License. |
3 | 3 | // See the LICENSE file in the project root for more information |
4 | 4 |
|
| 5 | +using System.IO.Abstractions.TestingHelpers; |
5 | 6 | using Elastic.Markdown.Myst.InlineParsers; |
6 | 7 | using FluentAssertions; |
| 8 | +using JetBrains.Annotations; |
7 | 9 | using Markdig.Syntax; |
| 10 | +using Markdig.Syntax.Inlines; |
8 | 11 | using Xunit.Abstractions; |
9 | 12 |
|
10 | 13 | namespace Elastic.Markdown.Tests.Inline; |
@@ -135,3 +138,74 @@ public void GeneratesAttributesInHtml() => |
135 | 138 | """.TrimEnd() |
136 | 139 | ); |
137 | 140 | } |
| 141 | + |
| 142 | + |
| 143 | +public abstract class InlineAnchorLinkTestBase(ITestOutputHelper output, [LanguageInjection("markdown")] string content) |
| 144 | + : InlineTest<LinkInline>(output, |
| 145 | +$""" |
| 146 | +## Hello world |
| 147 | +
|
| 148 | +A paragraph |
| 149 | +
|
| 150 | +{content} |
| 151 | +
|
| 152 | +$$$same-page-anchor$$$ |
| 153 | +
|
| 154 | +""") |
| 155 | +{ |
| 156 | + protected override void AddToFileSystem(MockFileSystem fileSystem) |
| 157 | + { |
| 158 | + // language=markdown |
| 159 | + var inclusion = |
| 160 | +""" |
| 161 | +# Special Requirements |
| 162 | +
|
| 163 | +## Sub Requirements |
| 164 | +
|
| 165 | +To follow this tutorial you will need to install the following components: |
| 166 | +
|
| 167 | +## New Requirements [#new-reqs] |
| 168 | +
|
| 169 | +These are new requirements |
| 170 | +
|
| 171 | +With a custom anchor that exists temporarily. $$$custom-anchor$$$ |
| 172 | +"""; |
| 173 | + fileSystem.AddFile(@"docs/testing/req.md", inclusion); |
| 174 | + fileSystem.AddFile(@"docs/_static/img/observability.png", new MockFileData("")); |
| 175 | + } |
| 176 | + |
| 177 | +} |
| 178 | + |
| 179 | +public class InlineAnchorCanBeLinkedToo(ITestOutputHelper output) : InlineAnchorLinkTestBase(output, |
| 180 | +""" |
| 181 | +[Hello](#same-page-anchor) |
| 182 | +""" |
| 183 | +) |
| 184 | +{ |
| 185 | + [Fact] |
| 186 | + public void GeneratesHtml() => |
| 187 | + // language=html |
| 188 | + Html.Should().Contain( |
| 189 | + """<p><a href="#same-page-anchor">Hello</a></p>""" |
| 190 | + ); |
| 191 | + |
| 192 | + [Fact] |
| 193 | + public void HasNoErrors() => Collector.Diagnostics.Should().HaveCount(0); |
| 194 | +} |
| 195 | + |
| 196 | +public class ExternalPageInlineAnchorCanBeLinkedToo(ITestOutputHelper output) : InlineAnchorLinkTestBase(output, |
| 197 | +""" |
| 198 | +[Sub Requirements](testing/req.md#custom-anchor) |
| 199 | +""" |
| 200 | +) |
| 201 | +{ |
| 202 | + [Fact] |
| 203 | + public void GeneratesHtml() => |
| 204 | + // language=html |
| 205 | + Html.Should().Contain( |
| 206 | + """<p><a href="testing/req.html#custom-anchor">Sub Requirements</a></p>""" |
| 207 | + ); |
| 208 | + |
| 209 | + [Fact] |
| 210 | + public void HasNoErrors() => Collector.Diagnostics.Should().HaveCount(0); |
| 211 | +} |
0 commit comments