";
- TestUtility.VerifyMarkup(source, expected, optionalExtensions: new List
- {
- "tasklists"
- });
+ TestUtility.VerifyMarkup(source, expected, optionalExtensions:
+ [
+ "tasklists",
+ ]);
}
[Fact]
@@ -68,11 +68,11 @@ Term 1
";
- TestUtility.VerifyMarkup(source, expected, optionalExtensions: new List
- {
+ TestUtility.VerifyMarkup(source, expected, optionalExtensions:
+ [
"tasklists",
- "definitionlists"
- });
+ "definitionlists",
+ ]);
}
[Fact]
diff --git a/test/Docfx.MarkdigEngine.Extensions.Tests/MarkdigBuiltinExtensionTests/AutoIdentifierTest.cs b/test/Docfx.MarkdigEngine.Extensions.Tests/MarkdigBuiltinExtensionTests/AutoIdentifierTest.cs
new file mode 100644
index 00000000000..31501ad3a44
--- /dev/null
+++ b/test/Docfx.MarkdigEngine.Extensions.Tests/MarkdigBuiltinExtensionTests/AutoIdentifierTest.cs
@@ -0,0 +1,70 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System.Text.Json.Nodes;
+using Markdig.Extensions.AutoIdentifiers;
+using Xunit;
+
+namespace Docfx.MarkdigEngine.Tests;
+
+///
+/// Unit tests for markdig .
+///
+///
+[Trait("Related", "MarkdigExtension")]
+public class AutoIdentifierTest
+{
+ [Fact]
+ public void AutoIdentifierTest_DocfxDefault()
+ {
+ // docfx use `AutoIdentifierOptions.GitHub` as default options.
+ var content = @"# This - is a &@! heading _ with . and ! -";
+ var expected = @"
This - is a &@! heading _ with . and ! -
";
+
+ TestUtility.VerifyMarkup(content, expected);
+ TestUtility.VerifyMarkup(content, expected, optionalExtensions: [
+ new("AutoIdentifiers", new JsonObject
+ {
+ ["options"] = "GitHub",
+ })
+ ]);
+ }
+
+ [Fact]
+ public void AutoIdentifierTest_MarkdigDefault()
+ {
+ var content = @"# This - is a &@! heading _ with . and ! -";
+ var expected = @"
This - is a &@! heading _ with . and ! -
";
+
+ // Default option is used when
+ TestUtility.VerifyMarkup(content, expected, optionalExtensions: ["AutoIdentifiers"]);
+
+ TestUtility.VerifyMarkup(content, expected, optionalExtensions: [
+ new("AutoIdentifiers", new JsonObject
+ {
+ ["options"] = "Default",
+ })
+ ]);
+
+ TestUtility.VerifyMarkup(content, expected, optionalExtensions: [
+ new("AutoIdentifiers", new JsonObject
+ {
+ ["options"] = "AutoLink, AllowOnlyAscii", // Same as Default option.
+ })
+ ]);
+ }
+
+ [Fact]
+ public void AutoIdentifierTest_None()
+ {
+ var content = @"# This - is a &@! heading _ with . and ! -";
+ var expected = @"
This - is a &@! heading _ with . and ! -
";
+
+ TestUtility.VerifyMarkup(content, expected, optionalExtensions: [
+ new("AutoIdentifiers", new JsonObject
+ {
+ ["options"] = "None",
+ })
+ ]);
+ }
+}
diff --git a/test/Docfx.MarkdigEngine.Extensions.Tests/MarkdigBuiltinExtensionTests/AutoLinkTest.cs b/test/Docfx.MarkdigEngine.Extensions.Tests/MarkdigBuiltinExtensionTests/AutoLinkTest.cs
new file mode 100644
index 00000000000..0af18b2a842
--- /dev/null
+++ b/test/Docfx.MarkdigEngine.Extensions.Tests/MarkdigBuiltinExtensionTests/AutoLinkTest.cs
@@ -0,0 +1,50 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System.Text.Json;
+using System.Text.Json.Nodes;
+using Docfx.MarkdigEngine.Extensions;
+using Markdig.Extensions.AutoLinks;
+using Xunit;
+
+namespace Docfx.MarkdigEngine.Tests;
+
+///
+/// Unit tests for markdig .
+///
+///
+[Trait("Related", "MarkdigExtension")]
+public class AutoLinkTest
+{
+ [Fact]
+ public void AutoLinkTest_DocfxDefault()
+ {
+ // docfx use `AutoIdentifierOptions.GitHub` as default options.
+ var content = "This is not a nhttp://www.google.com URL but this is (https://www.google.com)";
+ var expected = "
";
+
+ TestUtility.VerifyMarkup(content, expected, optionalExtensions: [
+ new("AutoLinks", new JsonObject
+ {
+ ["options"] = JsonSerializer.SerializeToNode(options, MarkdigExtensionSettingConverter.DefaultSerializerOptions),
+ })
+ ]);
+ }
+}
diff --git a/test/Docfx.MarkdigEngine.Extensions.Tests/MarkdigBuiltinExtensionTests/EmojiTest.cs b/test/Docfx.MarkdigEngine.Extensions.Tests/MarkdigBuiltinExtensionTests/EmojiTest.cs
new file mode 100644
index 00000000000..722028c7895
--- /dev/null
+++ b/test/Docfx.MarkdigEngine.Extensions.Tests/MarkdigBuiltinExtensionTests/EmojiTest.cs
@@ -0,0 +1,64 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System.Text.Json.Nodes;
+using Markdig.Extensions.Emoji;
+using Xunit;
+
+namespace Docfx.MarkdigEngine.Tests;
+
+///
+/// Unit tests for markdig .
+///
+///
+[Trait("Related", "MarkdigExtension")]
+public class EmojiTest
+{
+ [Fact]
+ public void EmojiTest_DocfxDefault()
+ {
+ var content = @"**content :** :smile:";
+ var expected = @"
content : 😄
";
+
+ // By default. `UseEmojiAndSmiley(enableSmileys: false)` option used.
+ TestUtility.VerifyMarkup(content, expected);
+ }
+
+ [Fact]
+ public void EmojiTest_MarkdigDefault()
+ {
+ var content = @":)";
+ var expected = @"
😃
";
+
+ // `UseEmojiAndSmiley(enableSmileys: true)` option is used when enable `Emojis` extension by name.
+ TestUtility.VerifyMarkup(content, expected, optionalExtensions: ["Emojis"]);
+ }
+
+ [Fact]
+ public void EmojiTest_Smileys_Enabled()
+ {
+ var content = @":)";
+ var expected = @"
";
+
+ TestUtility.VerifyMarkup(content, expected, optionalExtensions: [
+ new("Emojis", new JsonObject
+ {
+ ["options"] = false,
+ }),
+ ]);
+ }
+}
diff --git a/test/Docfx.MarkdigEngine.Extensions.Tests/MarkdigBuiltinExtensionTests/EmphasisExtraTest.cs b/test/Docfx.MarkdigEngine.Extensions.Tests/MarkdigBuiltinExtensionTests/EmphasisExtraTest.cs
new file mode 100644
index 00000000000..60a28684fd5
--- /dev/null
+++ b/test/Docfx.MarkdigEngine.Extensions.Tests/MarkdigBuiltinExtensionTests/EmphasisExtraTest.cs
@@ -0,0 +1,114 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System.Text.Json.Nodes;
+using Markdig.Extensions.EmphasisExtras;
+using Xunit;
+
+namespace Docfx.MarkdigEngine.Tests;
+
+///
+/// Unit tests for markdig .
+///
+///
+[Trait("Related", "MarkdigExtension")]
+public class EmphasisExtraTest
+{
+ [Fact]
+ public void EmphasisExtraTest_DocfxDefault()
+ {
+ var content = @"The following text ~~is deleted~~";
+ var expected = @"
The following text is deleted
";
+
+ // `Strikethrough` is enabled by default.
+ TestUtility.VerifyMarkup(content, expected);
+ }
+
+ [Fact]
+ public void EmphasisExtraTest_ResetToMarkdigDefault()
+ {
+ var content =
+ """
+ The following text ~~is deleted~~
+ H~2~O is a liquid. 2^10^ is 1024
+ ++Inserted text++
+ ==Marked text==
+ """;
+
+ var expected =
+ """
+
+ The following text is deleted
+ H2O is a liquid. 210 is 1024
+ Inserted text
+ Marked text
+
+ """;
+
+ // `EmphasisExtraOptions.Default` option is used
+ TestUtility.VerifyMarkup(content, expected, optionalExtensions: ["EmphasisExtras"]);
+ }
+
+ [Fact]
+ public void EmphasisExtraTest_SuperscriptAndSubscript()
+ {
+ var content = @"H~2~O is a liquid. 2^10^ is 1024";
+
+ // `Superscript` and `Subscript` are disabled by default.
+ {
+ var expected = $"
{content}
";
+ TestUtility.VerifyMarkup(content, expected);
+ }
+ // `Superscript` and `Subscript` is enabled when using default options or option is explicitly specified.
+ {
+ var expected = @"
H2O is a liquid. 210 is 1024
";
+ TestUtility.VerifyMarkup(content, expected, optionalExtensions: [
+ new("EmphasisExtras", new JsonObject
+ {
+ ["options"] = "Superscript, Subscript",
+ })]);
+ }
+ }
+
+ [Fact]
+ public void EmphasisExtraTest_Inserted()
+ {
+ var content = @"++Inserted text++";
+
+ // `Inserted` is disabled by default.
+ {
+ var expected = $"
{content}
";
+ TestUtility.VerifyMarkup(content, expected);
+ }
+ // `Inserted` is enabled when using default options or option is explicitly specified.
+ {
+ var expected = @"
Inserted text
";
+ TestUtility.VerifyMarkup(content, expected, optionalExtensions: [
+ new("EmphasisExtras", new JsonObject
+ {
+ ["options"] = "Inserted",
+ })]);
+ }
+ }
+
+ [Fact]
+ public void EmphasisExtraTest_Marked()
+ {
+ var content = @"==Marked text==";
+
+ // `Marked` is disabled by default.
+ {
+ var expected = $"
{content}
";
+ TestUtility.VerifyMarkup(content, expected);
+ }
+ // `Marked` is enabled when using default options or option is explicitly specified.
+ {
+ var expected = @"
Marked text
";
+ TestUtility.VerifyMarkup(content, expected, optionalExtensions: [
+ new("EmphasisExtras", new JsonObject
+ {
+ ["options"] = "Marked",
+ })]);
+ }
+ }
+}
diff --git a/test/Docfx.MarkdigEngine.Extensions.Tests/MarkdigBuiltinExtensionTests/MediaLinksTest.cs b/test/Docfx.MarkdigEngine.Extensions.Tests/MarkdigBuiltinExtensionTests/MediaLinksTest.cs
new file mode 100644
index 00000000000..5e2a66c84d1
--- /dev/null
+++ b/test/Docfx.MarkdigEngine.Extensions.Tests/MarkdigBuiltinExtensionTests/MediaLinksTest.cs
@@ -0,0 +1,53 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System.Text.Json;
+using System.Text.Json.Nodes;
+using Docfx.MarkdigEngine.Extensions;
+using Markdig.Extensions.MediaLinks;
+using Xunit;
+
+namespace Docfx.MarkdigEngine.Tests;
+
+///
+/// Unit tests for markdig .
+///
+///
+[Trait("Related", "MarkdigExtension")]
+public class MediaLinksTest
+{
+ [Fact]
+ public void MediaLinksTest_Default()
+ {
+ var content = "![static mp4](https://example.com/video.mp4)";
+
+ var expected = """""";
+
+ TestUtility.VerifyMarkup(content, expected);
+ TestUtility.VerifyMarkup(content, expected, optionalExtensions: ["MediaLinks"]);
+ }
+
+ [Fact]
+ public void MediaLinksTest_Custom()
+ {
+ // `ExtensionToMimeType` and `Hosts` property override is not supported.
+ // Because it getter-only property. and it can't deserialize property value);
+ var options = new MediaOptions
+ {
+ Height = "100", // Default: 500
+ Width = "100", // Default: 281
+ AddControlsProperty = false, // Default: true
+ Class = "custom-class", // Default: ""
+ };
+
+ var content = "![static mp4](https://example.com/video.mp4)";
+ var expected = $"""""";
+
+ TestUtility.VerifyMarkup(content, expected, optionalExtensions: [
+ new("MediaLinks", new JsonObject
+ {
+ ["options"] = JsonSerializer.SerializeToNode(options, MarkdigExtensionSettingConverter.DefaultSerializerOptions),
+ })
+ ]);
+ }
+}
diff --git a/test/Docfx.MarkdigEngine.Extensions.Tests/MarkdigBuiltinExtensionTests/PipeTableTest.cs b/test/Docfx.MarkdigEngine.Extensions.Tests/MarkdigBuiltinExtensionTests/PipeTableTest.cs
new file mode 100644
index 00000000000..6752955efd0
--- /dev/null
+++ b/test/Docfx.MarkdigEngine.Extensions.Tests/MarkdigBuiltinExtensionTests/PipeTableTest.cs
@@ -0,0 +1,95 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System.Text.Json;
+using System.Text.Json.Nodes;
+using Docfx.MarkdigEngine.Extensions;
+using Markdig.Extensions.Tables;
+using Xunit;
+
+namespace Docfx.MarkdigEngine.Tests;
+
+///
+/// Unit tests for markdig .
+///
+///
+[Trait("Related", "MarkdigExtension")]
+public class PipeTableTest
+{
+ [Fact]
+ public void PipeTableTest_Default()
+ {
+ var content =
+ """
+ a | b
+ -- | -
+ 0 | 1 | 2
+ """;
+
+ var expected =
+ """
+
+ """;
+
+ TestUtility.VerifyMarkup(content, expected, optionalExtensions: ["gfm-pipetables"]);
+ TestUtility.VerifyMarkup(content, expected, optionalExtensions: [
+ new ("PipeTables", new JsonObject
+ {
+ ["options"] = JsonSerializer.SerializeToNode(options, MarkdigExtensionSettingConverter.DefaultSerializerOptions),
+ })
+ ]);
+ }
+}
diff --git a/test/Docfx.MarkdigEngine.Extensions.Tests/MarkdigBuiltinExtensionTests/SmartyPantsTest.cs b/test/Docfx.MarkdigEngine.Extensions.Tests/MarkdigBuiltinExtensionTests/SmartyPantsTest.cs
new file mode 100644
index 00000000000..0f637be3954
--- /dev/null
+++ b/test/Docfx.MarkdigEngine.Extensions.Tests/MarkdigBuiltinExtensionTests/SmartyPantsTest.cs
@@ -0,0 +1,61 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System.Text.Json;
+using System.Text.Json.Nodes;
+using System.Text.Json.Serialization;
+using Docfx.MarkdigEngine.Extensions;
+using Markdig.Extensions.SmartyPants;
+using Xunit;
+
+namespace Docfx.MarkdigEngine.Tests;
+
+
+///
+/// Unit tests for markdig .
+///
+///
+[Trait("Related", "MarkdigExtension")]
+public class SmartyPantsTest
+{
+ ///
+ /// SmartyPants extension is not enabled by docfx default.
+ ///
+ [Fact]
+ public void SmartyPantsTest_DocfxDefault()
+ {
+ string content = "This is a \"text 'with\" a another text'";
+ string expected = "
This is a "text 'with" a another text'
";
+
+ TestUtility.VerifyMarkup(content, expected);
+ }
+
+ [Fact]
+ public void SmartyPantsTest_Default()
+ {
+ string content = "This is a \"text 'with\" a another text'";
+ string expected = "
This is a “text 'with” a another text'
";
+
+ TestUtility.VerifyMarkup(content, expected, optionalExtensions: ["SmartyPants"]);
+ }
+
+ // Currently custom mapping is not works as expected.
+ // Because SmartyPantOptions.Mapping is defined as setter-only property. It's not deserialized by default.
+ [Fact(Skip = "Currently custom mapping is not supported.")]
+ public void SmartyPantsTest_Custom()
+ {
+ var options = new SmartyPantOptions();
+ options.Mapping[SmartyPantType.LeftQuote] = "<<";
+ options.Mapping[SmartyPantType.RightQuote] = ">>";
+
+ string content = "This is a 'text with' a another text'";
+ string expected = "
This is a <> a another text'
";
+
+ TestUtility.VerifyMarkup(content, expected, optionalExtensions: [
+ new("SmartyPants", new JsonObject
+ {
+ ["options"] = JsonSerializer.SerializeToNode(options, MarkdigExtensionSettingConverter.DefaultSerializerOptions),
+ })
+ ]);
+ }
+}
diff --git a/test/Docfx.MarkdigEngine.Extensions.Tests/TestUtility.cs b/test/Docfx.MarkdigEngine.Extensions.Tests/TestUtility.cs
index d0129598fd5..293bc15f0d6 100644
--- a/test/Docfx.MarkdigEngine.Extensions.Tests/TestUtility.cs
+++ b/test/Docfx.MarkdigEngine.Extensions.Tests/TestUtility.cs
@@ -19,14 +19,14 @@ public static void VerifyMarkup(
string filePath = "test.md",
Dictionary tokens = null,
Dictionary files = null,
- IEnumerable optionalExtensions = null,
+ MarkdigExtensionSetting[] optionalExtensions = null,
Dictionary notes = null,
PlantUmlOptions plantUml = null)
{
errors ??= Array.Empty();
tokens ??= new Dictionary();
files ??= new Dictionary();
- optionalExtensions ??= new List();
+ optionalExtensions ??= [];
var actualErrors = new List();
var actualDependencies = new HashSet();
diff --git a/test/docfx.Tests/Api.verified.cs b/test/docfx.Tests/Api.verified.cs
index 0933d8366bb..10a3ec16426 100644
--- a/test/docfx.Tests/Api.verified.cs
+++ b/test/docfx.Tests/Api.verified.cs
@@ -3284,7 +3284,7 @@ public MarkdownServiceProperties() { }
public string[] FallbackFolders { get; set; }
[Newtonsoft.Json.JsonProperty("markdigExtensions")]
[System.Text.Json.Serialization.JsonPropertyName("markdigExtensions")]
- public string[] MarkdigExtensions { get; set; }
+ public Docfx.MarkdigEngine.Extensions.MarkdigExtensionSetting[] MarkdigExtensions { get; set; }
[Newtonsoft.Json.JsonProperty("plantUml")]
[System.Text.Json.Serialization.JsonPropertyName("plantUml")]
public Docfx.MarkdigEngine.Extensions.PlantUmlOptions PlantUml { get; set; }
@@ -3564,6 +3564,17 @@ public LineNumberExtension(System.Func