Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
46268af
feat: add markdig extension override with default settings
filzrev Mar 11, 2024
5f1442c
build(deps): bump the xunit group with 1 update (#9778)
dependabot[bot] Mar 12, 2024
0a86a0f
fix: Broken examples problems when using inheritdoc tag (#9754)
filzrev Mar 12, 2024
174f052
build(deps): bump PdfPig from 0.1.9-alpha-20240307-ac027 to 0.1.9-alp…
dependabot[bot] Mar 12, 2024
5038d8e
build(deps-dev): bump the typescript-eslint group in /templates with …
dependabot[bot] Mar 12, 2024
3e06043
build(deps): bump the xunit group with 1 update (#9785)
dependabot[bot] Mar 13, 2024
d19f0de
chore: Disable parallel tests for target frameworks that introduced a…
filzrev Mar 14, 2024
fecd104
fix: NullReferenceException occurred when both include and exclude ar…
filzrev Mar 14, 2024
73f7a71
feat: publish nightly pre-release packages (#9788)
yufeih Mar 14, 2024
fb8e408
build(deps-dev): bump esbuild-sass-plugin from 3.1.0 to 3.2.0 in /tem…
dependabot[bot] Mar 14, 2024
be16f69
build(deps): bump paulhatch/semantic-version from 5.3.0 to 5.4.0 (#9789)
dependabot[bot] Mar 14, 2024
347e350
build(deps-dev): bump esbuild from 0.20.1 to 0.20.2 in /templates (#9…
dependabot[bot] Mar 15, 2024
0010c66
build(deps-dev): bump follow-redirects from 1.15.4 to 1.15.6 in /temp…
dependabot[bot] Mar 15, 2024
214d72f
build(deps): bump Markdig from 0.35.0 to 0.36.2 (#9794)
dependabot[bot] Mar 15, 2024
2866d45
build(deps): bump the xunit group with 1 update (#9799)
dependabot[bot] Mar 18, 2024
bd8c1a4
build(deps): bump JsonSchema.Net from 6.0.4 to 6.0.5 (#9801)
dependabot[bot] Mar 19, 2024
20790fd
build(deps-dev): bump the typescript-eslint group in /templates with …
dependabot[bot] Mar 19, 2024
130c45c
chore: Add detailed error message for specific exceptions (#9746)
filzrev Mar 20, 2024
431d692
chore: update pdfpig nuget package version (#9803)
filzrev Mar 21, 2024
8a7a95a
build(deps-dev): bump typescript from 5.4.2 to 5.4.3 in /templates (#…
dependabot[bot] Mar 21, 2024
2c0d733
chore: Change JsonSchema EvaluationOptions instance to shared object …
filzrev Mar 21, 2024
14df1ea
fix: Invalid documentation on type parameter #9755 (#9806)
soniyadotp Mar 21, 2024
2012329
Update markdown documentation regarding MarkDig extension (#9810)
tbolon Mar 25, 2024
fe240c7
build(deps): bump PdfPig from 0.1.9-alpha-20240318-69e2b to 0.1.9-alp…
dependabot[bot] Mar 25, 2024
bd87bd2
build(deps): bump JsonSchema.Net from 6.0.5 to 6.0.6 (#9814)
dependabot[bot] Mar 25, 2024
e301880
build(deps): bump katex from 0.16.9 to 0.16.10 in /templates (#9816)
dependabot[bot] Mar 25, 2024
d8e4aa6
build(deps-dev): bump the typescript-eslint group in /templates with …
dependabot[bot] Mar 26, 2024
3542b48
build(deps): bump JsonSchema.Net from 6.0.6 to 6.0.7 (#9818)
dependabot[bot] Mar 26, 2024
b3ec103
chore: Update `docfx.json` config reference document (#9813)
filzrev Mar 27, 2024
7126223
chore: Correct `docfx template` page title (#9812)
peitschie Mar 27, 2024
a6c4c83
feat: add markdig extension override with default settings
filzrev Mar 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docs/reference/docfx-json-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,28 @@ Sets the max parallelism. Setting 0 (default) is the same as setting to the coun

Sets the parameters for the markdown engine, value is a JSON object.

For example. It can enable additional markdig extensions with following settings.

```json
{
"build": {
"markdownEngineProperties": {
"markdigExtensions": [
"advanced"
]
}
}
}
```

List of available built-in markdig extensions are available at [this URL](https://github.com/xoofx/markdig/blob/fcb56fb03701cc1a07a52769908579adb8927ee2/src/Markdig/MarkdownExtensions.cs#L537-L650).

It can't remove existing markdig extensions added by docfx.
But It can reset settings to markdig default when specifing following extension names.
- `AutoIdentifiers`
- `EmphasisExtras`
- `Emojis`

### `sitemap`

Specifies the options for generating [sitemap.xml](https://www.sitemaps.org/protocol.html) file:
Expand Down
28 changes: 27 additions & 1 deletion src/Docfx.MarkdigEngine.Extensions/MarkdownExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Markdig;
using Markdig.Extensions.AutoIdentifiers;
using Markdig.Extensions.CustomContainers;
using Markdig.Extensions.Emoji;
using Markdig.Extensions.EmphasisExtras;
using Markdig.Parsers;

Expand All @@ -17,7 +18,7 @@ public static MarkdownPipelineBuilder UseDocfxExtensions(
{
return pipeline
.UseMathematics()
.UseEmphasisExtras()
.UseEmphasisExtras(EmphasisExtraOptions.Strikethrough)
.UseAutoIdentifiers(AutoIdentifierOptions.GitHub)
.UseMediaLinks()
.UsePipeTables()
Expand Down Expand Up @@ -56,9 +57,34 @@ public static MarkdownPipelineBuilder UseOptionalExtensions(
return pipeline;
}

ReplaceExistingExtensions();

pipeline.Configure(string.Join("+", optionalExtensions));

return pipeline;

// Some markdig extensions are added by UseDocfxExtensions with non-default settings.
// This methods replace these extensions with default settings.
void ReplaceExistingExtensions()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These feel like configuration of existing extensions, it might be more future proof if we configure it such as:

markdigExtensions: [
    'other-extensions'
    { emoji: { enableSmileys: true }],
    { autoidentifier: 'default' }
]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added commented features to override extension properties by PR #9820.

Example configs

markdigExtensions: [
    "FootNotes",
    { "Emojis": { "options": {  "enableSmileys": true } },
    { "AutoIdentifiers": { "options": 'default '} },
    { "MediaLinks": { "options": { "width": 800, "height": 400 }} 
]

Note: I've added options key. Because it might required to support additional property
when implementing remove markdig extensions that are enabled by default feature.(Discussed at #7833)

{
// AutoIdentifierExtension
if (optionalExtensions.Contains("autoidentifiers", StringComparer.OrdinalIgnoreCase))
{
pipeline.Extensions.Replace<AutoIdentifierExtension>(new AutoIdentifierExtension(AutoIdentifierOptions.Default));
}

// EmphasisExtraExtension
if (optionalExtensions.Contains("emphasisextras", StringComparer.OrdinalIgnoreCase))
{
pipeline.Extensions.Replace<EmphasisExtraExtension>(new EmphasisExtraExtension(EmphasisExtraOptions.Default));
}

// EmojiExtension
if (optionalExtensions.Contains("emojis", StringComparer.OrdinalIgnoreCase))
{
pipeline.Extensions.Replace<EmojiExtension>(new EmojiExtension(EmojiMapping.DefaultEmojisAndSmileysMapping));
}
}
}

private static MarkdownPipelineBuilder RemoveUnusedExtensions(this MarkdownPipelineBuilder pipeline)
Expand Down
16 changes: 16 additions & 0 deletions test/Docfx.MarkdigEngine.Extensions.Tests/EmojiTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,20 @@ public void EmojiTestGeneral()

TestUtility.VerifyMarkup(content, expected);
}

[Fact]
public void EmojiTestWithSmileys()
{
var content = @":)";

// By default Docfx use `UseEmojiAndSmiley(enableSmileys:false)` setting.
{
var expected = @"<p>:)</p>";
TestUtility.VerifyMarkup(content, expected);
}
{
var expected = @"<p>😃</p>";
TestUtility.VerifyMarkup(content, expected, optionalExtensions: ["Emojis"]);
}
}
}
69 changes: 69 additions & 0 deletions test/Docfx.MarkdigEngine.Extensions.Tests/EmphasisExtraTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Xunit;

namespace Docfx.MarkdigEngine.Tests;

public class EmphasisExtraTest
{
[Fact]
public void EmphasisExtraTest_Strikethrough()
{
var content = @"The following text ~~is deleted~~";
var expected = @"<p>The following text <del>is deleted</del></p>";

// `Strikethrough` is enabled by default.
TestUtility.VerifyMarkup(content, expected);
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 = $"<p>{content}</p>";
TestUtility.VerifyMarkup(content, expected);
}
{
var expected = @"<p>H<sub>2</sub>O is a liquid. 2<sup>10</sup> is 1024</p>";
TestUtility.VerifyMarkup(content, expected, optionalExtensions: ["EmphasisExtras"]);
}
}

[Fact]
public void EmphasisExtraTest_Inserted()
{
var content = @"++Inserted text++";

// `Inserted` is disabled by default.
{
var expected = $"<p>{content}</p>";
TestUtility.VerifyMarkup(content, expected);
}
{
var expected = @"<p><ins>Inserted text</ins></p>";
TestUtility.VerifyMarkup(content, expected, optionalExtensions: ["EmphasisExtras"]);
}
}

[Fact]
public void EmphasisExtraTest_Marked()
{
var content = @"==Marked text==";

// `Marked` is disabled by default.
{
var expected = $"<p>{content}</p>";
TestUtility.VerifyMarkup(content, expected);
}
{
var expected = @"<p><mark>Marked text</mark></p>";
TestUtility.VerifyMarkup(content, expected, optionalExtensions: ["EmphasisExtras"]);
}

}
}