|
| 1 | +// Licensed to Elasticsearch B.V under one or more agreements. |
| 2 | +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. |
| 3 | +// See the LICENSE file in the project root for more information |
| 4 | + |
| 5 | +using Elastic.Markdown.Myst.InlineParsers; |
| 6 | +using FluentAssertions; |
| 7 | +using Markdig.Syntax; |
| 8 | +using Xunit.Abstractions; |
| 9 | + |
| 10 | +namespace Elastic.Markdown.Tests.Inline; |
| 11 | + |
| 12 | +public class InlineAnchorTests(ITestOutputHelper output) : LeafTest<InlineAnchor>(output, |
| 13 | + """ |
| 14 | + this is regular text and this $$$is-an-inline-anchor$$$ and this continues to be regular text |
| 15 | + """ |
| 16 | +) |
| 17 | +{ |
| 18 | + [Fact] |
| 19 | + public void ParsesBlock() |
| 20 | + { |
| 21 | + Block.Should().NotBeNull(); |
| 22 | + Block!.Anchor.Should().Be("is-an-inline-anchor"); |
| 23 | + } |
| 24 | + |
| 25 | + [Fact] |
| 26 | + public void GeneratesAttributesInHtml() => |
| 27 | + // language=html |
| 28 | + Html.Should().Contain( |
| 29 | + """<p>this is regular text and this <a id="is-an-inline-anchor"></a> and this continues to be regular text</p>""" |
| 30 | + ); |
| 31 | +} |
| 32 | + |
| 33 | +public class InlineAnchorAtStartTests(ITestOutputHelper output) : LeafTest<InlineAnchor>(output, |
| 34 | + """ |
| 35 | + $$$is-an-inline-anchor$$$ and this continues to be regular text |
| 36 | + """ |
| 37 | +) |
| 38 | +{ |
| 39 | + [Fact] |
| 40 | + public void ParsesBlock() |
| 41 | + { |
| 42 | + Block.Should().NotBeNull(); |
| 43 | + Block!.Anchor.Should().Be("is-an-inline-anchor"); |
| 44 | + } |
| 45 | + |
| 46 | + [Fact] |
| 47 | + public void GeneratesAttributesInHtml() => |
| 48 | + // language=html |
| 49 | + Html.Should().Be( |
| 50 | + """<p><a id="is-an-inline-anchor"></a> and this continues to be regular text</p>""" |
| 51 | + ); |
| 52 | +} |
| 53 | + |
| 54 | +public class InlineAnchorAtEndTests(ITestOutputHelper output) : LeafTest<InlineAnchor>(output, |
| 55 | + """ |
| 56 | + this is regular text and this $$$is-an-inline-anchor$$$ |
| 57 | + """ |
| 58 | +) |
| 59 | +{ |
| 60 | + [Fact] |
| 61 | + public void ParsesBlock() |
| 62 | + { |
| 63 | + Block.Should().NotBeNull(); |
| 64 | + Block!.Anchor.Should().Be("is-an-inline-anchor"); |
| 65 | + } |
| 66 | + |
| 67 | + [Fact] |
| 68 | + public void GeneratesAttributesInHtml() => |
| 69 | + // language=html |
| 70 | + Html.Should().Contain( |
| 71 | + """<p>this is regular text and this <a id="is-an-inline-anchor"></a></p>""" |
| 72 | + ); |
| 73 | +} |
| 74 | + |
| 75 | +public class BadStartInlineAnchorTests(ITestOutputHelper output) : BlockTest<ParagraphBlock>(output, |
| 76 | + """ |
| 77 | + this is regular text and this $$is-an-inline-anchor$$$ |
| 78 | + """ |
| 79 | +) |
| 80 | +{ |
| 81 | + [Fact] |
| 82 | + public void GeneratesAttributesInHtml() => |
| 83 | + // language=html |
| 84 | + Html.Should().Contain( |
| 85 | + """<p>this is regular text and this $$is-an-inline-anchor$$$</p>""" |
| 86 | + ); |
| 87 | +} |
| 88 | + |
| 89 | +public class BadEndInlineAnchorTests(ITestOutputHelper output) : BlockTest<ParagraphBlock>(output, |
| 90 | + """ |
| 91 | + this is regular text and this $$$is-an-inline-anchor$$ |
| 92 | + """ |
| 93 | +) |
| 94 | +{ |
| 95 | + [Fact] |
| 96 | + public void GeneratesAttributesInHtml() => |
| 97 | + // language=html |
| 98 | + Html.Should().Contain( |
| 99 | + """<p>this is regular text and this $$$is-an-inline-anchor$$</p>""" |
| 100 | + ); |
| 101 | +} |
| 102 | + |
| 103 | +public class InlineAnchorInHeading(ITestOutputHelper output) : BlockTest<HeadingBlock>(output, |
| 104 | + """ |
| 105 | + ## Hello world $$$my-anchor$$$ |
| 106 | + """ |
| 107 | +) |
| 108 | +{ |
| 109 | + [Fact] |
| 110 | + public void GeneratesAttributesInHtml() => |
| 111 | + // language=html |
| 112 | + Html.Should().Be( |
| 113 | + """ |
| 114 | + <section id="hello-world"><h2>Hello world <a id="my-anchor"></a><a class="headerlink" href="#hello-world" title="Link to this heading">¶</a> |
| 115 | + </h2> |
| 116 | + </section> |
| 117 | + """.TrimEnd() |
| 118 | + ); |
| 119 | +} |
| 120 | + |
| 121 | +public class ExplicitSlugInHeader(ITestOutputHelper output) : BlockTest<HeadingBlock>(output, |
| 122 | + """ |
| 123 | + ## Hello world [#my-anchor] |
| 124 | + """ |
| 125 | +) |
| 126 | +{ |
| 127 | + [Fact] |
| 128 | + public void GeneratesAttributesInHtml() => |
| 129 | + // language=html |
| 130 | + Html.Should().Be( |
| 131 | + """ |
| 132 | + <section id="my-anchor"><h2>Hello world <a class="headerlink" href="#my-anchor" title="Link to this heading">¶</a> |
| 133 | + </h2> |
| 134 | + </section> |
| 135 | + """.TrimEnd() |
| 136 | + ); |
| 137 | +} |
0 commit comments