Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
reakaleek committed Feb 6, 2025
1 parent c313647 commit 2f3b26c
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,14 @@ private static void UpdateLinkUrl(LinkInline link, string url, ParserContext con
{
var newUrl = url;
var urlPathPrefix = context.Build.UrlPathPrefix ?? string.Empty;
if (url.EndsWith(".md"))
newUrl = Path.ChangeExtension(newUrl, ".html");

if (!url.StartsWith('/'))
if (!url.StartsWith('/') && !string.IsNullOrEmpty(url))
{
newUrl = GetRootRelativePath(context, file);
}

if (url.EndsWith(".md"))
newUrl = Path.ChangeExtension(newUrl, ".html");

if (!string.IsNullOrWhiteSpace(urlPathPrefix))
newUrl = $"{urlPathPrefix.TrimEnd('/')}{newUrl}";
Expand Down
10 changes: 5 additions & 5 deletions tests/Elastic.Markdown.Tests/Inline/AnchorLinkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ [Sub Requirements](testing/req.md#sub-requirements)
public void GeneratesHtml() =>
// language=html
Html.Should().Contain(
"""<p><a href="testing/req.html#sub-requirements">Sub Requirements</a></p>"""
"""<p><a href="/testing/req.html#sub-requirements">Sub Requirements</a></p>"""
);

[Fact]
Expand All @@ -94,7 +94,7 @@ [Sub Requirements](testing/req.md#new-reqs)
public void GeneratesHtml() =>
// language=html
Html.Should().Contain(
"""<p><a href="testing/req.html#new-reqs">Sub Requirements</a></p>"""
"""<p><a href="/testing/req.html#new-reqs">Sub Requirements</a></p>"""
);

[Fact]
Expand All @@ -111,7 +111,7 @@ public class ExternalPageAnchorAutoTitleTests(ITestOutputHelper output) : Anchor
public void GeneratesHtml() =>
// language=html
Html.Should().Contain(
"""<p><a href="testing/req.html#sub-requirements">Special Requirements &gt; Sub Requirements</a></p>"""
"""<p><a href="/testing/req.html#sub-requirements">Special Requirements &gt; Sub Requirements</a></p>"""
);

[Fact]
Expand Down Expand Up @@ -147,7 +147,7 @@ [Sub Requirements](testing/req.md#sub-requirements2)
public void GeneratesHtml() =>
// language=html
Html.Should().Contain(
"""<p><a href="testing/req.html#sub-requirements2">Sub Requirements</a></p>"""
"""<p><a href="/testing/req.html#sub-requirements2">Sub Requirements</a></p>"""
);

[Fact]
Expand All @@ -166,7 +166,7 @@ [Heading inside dropdown](testing/req.md#heading-inside-dropdown)
public void GeneratesHtml() =>
// language=html
Html.Should().Contain(
"""<a href="/testing/req#heading-inside-dropdown">Heading inside dropdown</a>"""
"""<a href="/testing/req.html#heading-inside-dropdown">Heading inside dropdown</a>"""
);
[Fact]
public void HasError() => Collector.Diagnostics.Should().HaveCount(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ [Sub Requirements](testing/req.md#hint_ref)
public void GeneratesHtml() =>
// language=html
Html.Should().Contain(
"""<p><a href="testing/req.html#hint_ref">Sub Requirements</a></p>"""
"""<p><a href="/testing/req.html#hint_ref">Sub Requirements</a></p>"""
);

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion tests/Elastic.Markdown.Tests/Inline/InlineAnchorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ [Sub Requirements](testing/req.md#custom-anchor)
public void GeneratesHtml() =>
// language=html
Html.Should().Contain(
"""<p><a href="testing/req.html#custom-anchor">Sub Requirements</a></p>"""
"""<p><a href="/testing/req.html#custom-anchor">Sub Requirements</a></p>"""
);

[Fact]
Expand Down
6 changes: 3 additions & 3 deletions tests/Elastic.Markdown.Tests/Inline/InlineLinkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class LinkToPageTests(ITestOutputHelper output) : LinkTestBase(output,
public void GeneratesHtml() =>
// language=html
Html.Should().Contain(
"""<p><a href="/testing/req">Requirements</a></p>"""
"""<p><a href="/testing/req.html">Requirements</a></p>"""
);

[Fact]
Expand All @@ -81,7 +81,7 @@ public class InsertPageTitleTests(ITestOutputHelper output) : LinkTestBase(outpu
public void GeneratesHtml() =>
// language=html
Html.Should().Contain(
"""<p><a href="/testing/req">Special Requirements</a></p>"""
"""<p><a href="/testing/req.html">Special Requirements</a></p>"""
);

[Fact]
Expand All @@ -106,7 +106,7 @@ public class LinkReferenceTest(ITestOutputHelper output) : LinkTestBase(output,
public void GeneratesHtml() =>
// language=html
Html.Should().Contain(
"""<p><a href="/testing/req">test</a></p>"""
"""<p><a href="/testing/req.html">test</a></p>"""
);

[Fact]
Expand Down
10 changes: 5 additions & 5 deletions tests/authoring/Inline/InlineImages.fs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type ``relative path to image`` () =
[<Fact>]
let ``validate HTML: preserves relative path`` () =
markdown |> convertsToHtml """
<p><img src="_static/img/observability.png" alt="Elasticsearch" /></p>
<p><img src="/_static/img/observability.png" alt="Elasticsearch" /></p>
"""

type ``supplying a tittle`` () =
Expand All @@ -37,7 +37,7 @@ type ``supplying a tittle`` () =
[<Fact>]
let ``validate HTML: includes title`` () =
markdown |> convertsToHtml """
<p><img src="_static/img/observability.png" alt="Elasticsearch" title="Hello world" /></p>
<p><img src="/_static/img/observability.png" alt="Elasticsearch" title="Hello world" /></p>
"""

type ``supplying a tittle with width and height`` () =
Expand All @@ -48,7 +48,7 @@ type ``supplying a tittle with width and height`` () =
[<Fact>]
let ``validate HTML: does not include width and height in title`` () =
markdown |> convertsToHtml """
<p><img src="obs.png" width="250px" height="400px" alt="o" title="Title"/></p>
<p><img src="/obs.png" width="250px" height="400px" alt="o" title="Title"/></p>
"""

type ``supplying a tittle with width and height in percentage`` () =
Expand All @@ -59,7 +59,7 @@ type ``supplying a tittle with width and height in percentage`` () =
[<Fact>]
let ``validate HTML: does not include width and height in title`` () =
markdown |> convertsToHtml """
<p><img src="obs.png" width="50%" height="40%" alt="o" title="Title"/></p>
<p><img src="/obs.png" width="50%" height="40%" alt="o" title="Title"/></p>
"""
type ``supplying a tittle with width only`` () =
static let markdown = Setup.Markdown """
Expand All @@ -69,5 +69,5 @@ type ``supplying a tittle with width only`` () =
[<Fact>]
let ``validate HTML: sets height to width if not supplied`` () =
markdown |> convertsToHtml """
<p><img src="obs.png" width="30%" height="30%" alt="o" title="Title"/></p>
<p><img src="/obs.png" width="30%" height="30%" alt="o" title="Title"/></p>
"""

0 comments on commit 2f3b26c

Please sign in to comment.