Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add feature to reset markdig extension settings that are added by default #9780

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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)
soniyaprasad77 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
30 changes: 30 additions & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: nightly
on:
schedule:
- cron: '0 0 * * *'

jobs:
publish-github-packages:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- id: version
uses: paulhatch/[email protected]
with:
version_format: ${major}.${minor}.${patch}-preview.${increment}

- uses: ./.github/actions/build

- name: dotnet pack
run: dotnet pack -c Release /p:Version=${{ steps.version.outputs.version }} -o drop/nuget

- name: dotnet nuget push
run: |
dotnet nuget push drop/nuget/*.nupkg --api-key "${{ secrets.GITHUB_TOKEN }}" --skip-duplicate --source https://nuget.pkg.github.com/dotnet/index.json

8 changes: 4 additions & 4 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<PackageVersion Include="ICSharpCode.Decompiler" Version="8.2.0.7535" />
<PackageVersion Include="IgnoresAccessChecksToGenerator" Version="0.7.0" />
<PackageVersion Include="Jint" Version="3.0.1" />
<PackageVersion Include="JsonSchema.Net" Version="6.0.4" />
<PackageVersion Include="Markdig" Version="0.35.0" />
<PackageVersion Include="JsonSchema.Net" Version="6.0.7" />
<PackageVersion Include="Markdig" Version="0.36.2" />
<PackageVersion Include="Microsoft.CodeAnalysis" Version="4.9.2" />
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="4.9.2" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.9.2" />
Expand All @@ -23,7 +23,7 @@
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="OneOf" Version="3.0.263" />
<PackageVersion Include="OneOf.SourceGenerator" Version="3.0.263" />
<PackageVersion Include="PdfPig" Version="0.1.9-alpha-20240307-ac027" />
<PackageVersion Include="PdfPig" Version="0.1.9-alpha-20240324-e7896" />
<PackageVersion Include="PlantUml.Net" Version="1.4.80" />
<PackageVersion Include="Spectre.Console" Version="0.48.0" />
<PackageVersion Include="Spectre.Console.Cli" Version="0.48.0" />
Expand All @@ -37,7 +37,7 @@
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageVersion Include="PublicApiGenerator" Version="11.1.0" />
<PackageVersion Include="Verify.DiffPlex" Version="2.3.0" />
<PackageVersion Include="Verify.Xunit" Version="23.3.0" />
<PackageVersion Include="Verify.Xunit" Version="23.5.2" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.7" />
<PackageVersion Include="xunit" Version="2.7.0" />
</ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ Docfx is planned to continue as a community-driven project. We hope to produce f

For more information, refer to [Getting Started](http://dotnet.github.io/docfx/tutorial/docfx_getting_started.html).

> [!TIP]
> Docfx publishes nightly builds to [GitHub Packages](https://github.com/orgs/dotnet/packages), this allows you to stay up-to-date with the latest developments in Docfx.

## Contributing

Use [Discussions](https://github.com/dotnet/docfx/discussions) for questions and general discussions.
Expand Down
2 changes: 2 additions & 0 deletions docs/docs/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ Alternatively, set the `build.markdownEngineProperties.markdigExtensions` proper
}
```

The known extension names are listed in [MardownExtensions.Configure](https://github.com/xoofx/markdig/blob/master/src/Markdig/MarkdownExtensions.cs) method in the MarkDig project.

> [!Note]
> The custom configuration of extensions via the `build.markdownEngineProperties.markdigExtensions` property is not supported.

Expand Down
2 changes: 1 addition & 1 deletion docs/reference/docfx-cli-reference/docfx-template.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# docfx build
# docfx template

## Name

Expand Down
58 changes: 54 additions & 4 deletions docs/reference/docfx-json-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ The `docfx.json` file indicates that the directory is the root of a docfx projec
}
```

## Global properties
## Global properties

### `rules`
## `rules`

Overrides default log message severity level. Key is the log code, supported values are `verbose`, `info`, `suggestion`, `warning`, `error`:

Expand Down Expand Up @@ -148,6 +148,7 @@ Templates are used to transform YAML files generated by `docfx` to human-readabl
}
}
```

```json
{
"build": {
Expand All @@ -166,7 +167,6 @@ The themes applied to the documentation. Theme is used to customize the styles g

Theme is to provide general styles for all the generated pages. Files inside a theme will be generally copied to the output folder. A typical usage is, after YAML files are transformed to HTML pages, well-designed CSS style files in a Theme can then overwrite the default styles defined in template, e.g. `main.css`.


### `xref`

Specifies the urls of xrefmap used by content files. Currently, it supports following scheme: http, https, file.
Expand Down Expand Up @@ -199,6 +199,45 @@ 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`

### `customLinkResolver`

Set the name of the `ICustomHrefGenerator` derived class.

### `groups`

Specifies the output folder of specified group name.

```json
"groups": {
"v1": {
"dest": "output_dir_v1"
}
}
```

### `sitemap`

Specifies the options for generating [sitemap.xml](https://www.sitemaps.org/protocol.html) file:
Expand Down Expand Up @@ -320,6 +359,12 @@ Specifies the output folder of the generated metadata files relative to `docfx.j

If set to true, DocFX would not render triple-slash-comments in source code as markdown.

### `references`

Specify additinal assembly reference files.
This settings is used when generating metadata from DLLs or source files.
Solution or project file-based metadata generation does not use this property.

### `filter`

Specifies the filter configuration file, please go to [How to filter out unwanted apis attributes](../tutorial/howto_filter_out_unwanted_apis_attributes.md) for more details.
Expand All @@ -332,6 +377,10 @@ Disables the default filter configuration file.

Disables generation of view source links.

### `codeSourceBasePath`

Specify the base directory that is used to resolve code source (e.g. `<code source="Example.cs">`).

### `properties`

Specifies an optional set of MSBuild properties used when interpreting project files. These are the same properties that are passed to msbuild via the `/property:name=value` command line argument.
Expand All @@ -347,6 +396,7 @@ Specifies an optional set of MSBuild properties used when interpreting project f
]
}
```

> [!Note]
> Make sure to specify `"TargetFramework": <one of the frameworks>` in your docfx.json when the project is targeting for multiple platforms.

Expand All @@ -372,7 +422,7 @@ Specifies how member pages are organized:

When enabled, continues documentation generation in case of compilation errors.

### `EnumSortOrder`
### `enumSortOrder`

Specifies how enum members are sorted:

Expand Down
5 changes: 2 additions & 3 deletions src/Docfx.App/Config/BuildJsonConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,13 @@ internal class BuildJsonConfig
public string CustomLinkResolver { get; set; }

/// <summary>
/// Define groups.
/// Specifies the output folder of specified group name.
/// </summary>
/// <example>
/// <code>
/// groups:{
/// "v1": {
/// "dest": "v1",
/// "extraMetadata01": {}
/// "dest": "output_dir_v1"
/// }
/// }
/// </code>
Expand Down
5 changes: 4 additions & 1 deletion src/Docfx.App/PdfBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ await Parallel.ForEachAsync(pages, async (item, _) =>
if (outline.pdfTocPage)
{
var href = $"/_pdftoc{outlineUrl.AbsolutePath}";
yield return (new(outlineUrl, href), new() { href = href, pdfPrintBackground = outline.pdfPrintBackground });
yield return (new(outlineUrl, href), new() { href = href, pdfPrintBackground = outline.pdfPrintBackground });
}

if (!string.IsNullOrEmpty(outline.href))
Expand Down Expand Up @@ -325,6 +325,9 @@ async Task MergePdf()
// Refresh TOC page numbers
updatePageNumbers(pageNumbers);
bytes = await printPdf(outline, url);

if (bytes == null)
continue;
}

using var document = PdfDocument.Open(bytes);
Expand Down
12 changes: 7 additions & 5 deletions src/Docfx.Build.SchemaDriven/Validators/SchemaValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ public class SchemaValidator
{
private readonly JsonSchema _schema;

private static readonly EvaluationOptions DefaultOptions = new EvaluationOptions
{
ValidateAgainstMetaSchema = false,
OutputFormat = OutputFormat.List,
};

static SchemaValidator()
{
SchemaRegistry.Global.Register(new("http://dotnet.github.io/docfx/schemas/v1.0/schema.json#"), MetaSchemas.Draft7);
Expand All @@ -25,11 +31,7 @@ public SchemaValidator(string json)
public void Validate(object obj)
{
var json = JsonSerializer.Serialize(obj);
var result = _schema.Evaluate(JsonDocument.Parse(json), new EvaluationOptions
{
ValidateAgainstMetaSchema = false,
OutputFormat = OutputFormat.List,
});
var result = _schema.Evaluate(JsonDocument.Parse(json), DefaultOptions);

if (result.IsValid)
return;
Expand Down
6 changes: 5 additions & 1 deletion src/Docfx.Build/HostServiceCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ public virtual (FileModel model, bool valid) Load(
{
if (e is not DocumentException)
{
var message = e is ArgumentException or NullReferenceException
? e.ToString()
: e.Message;

Logger.LogError(
$"Unable to load file '{file.File}' via processor '{processor.Name}': {e.Message}",
$"Unable to load file '{file.File}' via processor '{processor.Name}': {message}",
code: ErrorCodes.Build.InvalidInputFile);
}
return (null, false);
Expand Down
5 changes: 4 additions & 1 deletion src/Docfx.Dotnet/Filters/ConfigFilterRuleItemUnion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ public ConfigFilterRuleItem Rule
}

// If kind is not specified for exclude. Set `ExtendedSymbolKind.Type` as default kind.
Exclude.Kind ??= ExtendedSymbolKind.Type | ExtendedSymbolKind.Member;
if (Exclude != null)
{
Exclude.Kind ??= ExtendedSymbolKind.Type | ExtendedSymbolKind.Member;
}

return Exclude;
}
Expand Down
9 changes: 5 additions & 4 deletions src/Docfx.Dotnet/MetadataJsonConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,11 @@ internal class MetadataJsonItemConfig
[JsonPropertyName("shouldSkipMarkup")]
public bool? ShouldSkipMarkup { get; set; }

[JsonProperty("raw")]
[JsonPropertyName("raw")]
public bool? Raw { get; set; }

/// <summary>
/// Specify additinal assembly reference files.
/// This settings is used when generating metadata from DLLs or source files.
/// Solution or project file-based metadata generation does not use this property.
/// </summary>
[JsonProperty("references")]
[JsonPropertyName("references")]
public FileMapping References { get; set; }
Expand Down
4 changes: 4 additions & 0 deletions src/Docfx.Dotnet/Parsers/XmlComment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ public static XmlComment Parse(string xml, XmlCommentParserContext context = nul
}
try
{
// Format xml with indentation.
// It's needed to fix issue (https://github.com/dotnet/docfx/issues/9736)
xml = XElement.Parse(xml).ToString(SaveOptions.None);

return new XmlComment(xml, context ?? new());
}
catch (XmlException)
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
5 changes: 5 additions & 0 deletions templates/common/ManagedReference.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,9 @@ function handleItem(vm, gitContribute, gitUrlPattern) {

return array;
}
if(vm.syntax.typeParameters) {
vm.syntax.typeParameters.forEach(item => {
item.description = item.description || "";
});
}
}
Loading