Skip to content

Commit 5276583

Browse files
authored
Allow mailto scheme in inline links (#464)
1 parent 513f300 commit 5276583

File tree

5 files changed

+58
-2
lines changed

5 files changed

+58
-2
lines changed

src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,10 @@ private bool ValidateBasicUrl(InlineProcessor processor, string? url, int line,
138138

139139
private bool ValidateExternalUri(InlineProcessor processor, Uri? uri, ParserContext context, int line, int column, int length)
140140
{
141-
if (uri == null || !uri.Scheme.StartsWith("http"))
141+
if (uri == null)
142+
return false;
143+
144+
if (!uri.Scheme.StartsWith("http") && !uri.Scheme.StartsWith("mailto"))
142145
return false;
143146

144147
var baseDomain = uri.Host == "localhost" ? "localhost" : string.Join('.', uri.Host.Split('.')[^2..]);

tests/authoring/Framework/ErrorCollectorAssertions.fs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ module DiagnosticsCollectorAssertions =
2929
|> List.ofArray
3030
let message = errorDiagnostics.FirstOrDefault().Message
3131
test <@ message.Contains(expected) @>
32+
33+
let hasNoWarnings (actual: Lazy<GeneratorResults>) =
34+
let actual = actual.Value
35+
let warnings = actual.Context.Collector.Warnings
36+
test <@ warnings = 0 @>
3237

3338
[<DebuggerStepThrough>]
3439
let hasWarning (expected: string) (actual: Lazy<GeneratorResults>) =

tests/authoring/Framework/Setup.fs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,3 @@ type Setup =
120120
task { return! Setup.Generator [Index m] }
121121
|> Async.AwaitTask |> Async.RunSynchronously
122122
)
123-
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
module ``inline elements``.``links``
6+
7+
open Xunit
8+
open authoring
9+
10+
type ``inline link with mailto`` () =
11+
12+
static let markdown = Setup.Markdown """
13+
[email me](mailto:[email protected])
14+
"""
15+
16+
[<Fact>]
17+
let ``validate HTML`` () =
18+
markdown |> convertsToHtml """
19+
<p>
20+
<a href="mailto:[email protected]">email me</a>
21+
</p>
22+
"""
23+
24+
[<Fact>]
25+
let ``has no errors`` () = markdown |> hasNoErrors
26+
27+
[<Fact>]
28+
let ``has no warning`` () = markdown |> hasNoWarnings
29+
30+
type ``inline link with mailto not allowed external host`` () =
31+
32+
static let markdown = Setup.Markdown """
33+
[email me](mailto:[email protected])
34+
"""
35+
36+
[<Fact>]
37+
let ``validate HTML`` () =
38+
markdown |> convertsToHtml """
39+
<p>
40+
<a href="mailto:[email protected]">email me</a>
41+
</p>
42+
"""
43+
44+
[<Fact>]
45+
let ``has no errors`` () = markdown |> hasNoErrors
46+
47+
[<Fact>]
48+
let ``has warning`` () = markdown |> hasWarning "External URI 'mailto:[email protected]' is not allowed."

tests/authoring/authoring.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
</ItemGroup>
4848

4949
<ItemGroup>
50+
<Compile Include="Inline\InlineLinks.fs" />
5051
<Compile Include="Container\DefinitionLists.fs"/>
5152
<Compile Include="Generator\LinkReferenceFile.fs"/>
5253
</ItemGroup>

0 commit comments

Comments
 (0)