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

chore: drop Docfx.MarkdigEngine.Validators #8971

Merged
merged 1 commit into from
Jul 17, 2023
Merged

chore: drop Docfx.MarkdigEngine.Validators #8971

merged 1 commit into from
Jul 17, 2023

Conversation

yufeih
Copy link
Contributor

@yufeih yufeih commented Jul 16, 2023

The IMarkdownObjectValidator was originally designed as an extension mechanism for adding custom markdown validation rules for MSLearn. MSLearn never really used that interface for custom markdown validation and this interface didn't gain much traction in the community.

To add custom markdown validation rules, or custom markdown extensions, use the standard markdig extensions interface, where it exposed the markdown AST at various stages.

@yufeih yufeih added the breaking-change Makes the pull request appear in "Breaking Changes" section of the next release note label Jul 16, 2023
@codecov
Copy link

codecov bot commented Jul 16, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: -0.09 ⚠️

Comparison is base (7ab1ad6) 76.93% compared to head (f74d3eb) 76.85%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8971      +/-   ##
==========================================
- Coverage   76.93%   76.85%   -0.09%     
==========================================
  Files         605      601       -4     
  Lines       25054    24968      -86     
==========================================
- Hits        19275    19188      -87     
- Misses       5779     5780       +1     
Impacted Files Coverage Δ
src/Docfx.Build.Engine/DocumentBuilder.cs 79.19% <ø> (-0.24%) ⬇️
src/Docfx.Plugins/MarkdownTagValidationRule.cs 100.00% <ø> (+14.28%) ⬆️
src/Docfx.MarkdigEngine/MarkdigMarkdownService.cs 87.23% <100.00%> (-0.14%) ⬇️
src/Docfx.MarkdigEngine/MarkdigServiceProvider.cs 100.00% <100.00%> (ø)
...rkdigEngine/Validation/MarkdownValidatorBuilder.cs 89.58% <100.00%> (-0.42%) ⬇️
src/Docfx.MarkdigEngine/Validation/TagValidator.cs 96.29% <100.00%> (+0.64%) ⬆️

... and 4 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@filzrev
Copy link
Contributor

filzrev commented Jul 16, 2023

To add custom markdown validation rules, or custom markdown extensions, use the standard markdig extensions interface, where it exposed the markdown AST at various stages.

For custom Markdown validation rules.
Docfx seems supporting custom validation by placing md.style file to docs root or template directory's md.styles folder.

private static void LoadValidatorConfig(string baseDir, string templateDir, MarkdownValidatorBuilder builder)
{
if (string.IsNullOrEmpty(baseDir))
{
return;
}
if (templateDir != null)
{
var configFolder = Path.Combine(templateDir, MarkdownStyleDefinition.MarkdownStyleDefinitionFolderName);
if (Directory.Exists(configFolder))
{
LoadValidatorDefinition(configFolder, builder);
}
}
var configFile = Path.Combine(baseDir, MarkdownStyleConfig.MarkdownStyleFileName);
if (EnvironmentContext.FileAbstractLayer.Exists(configFile))
{
var config = JsonUtility.Deserialize<MarkdownStyleConfig>(configFile);
builder.AddValidators(config.Rules);
builder.AddTagValidators(config.TagRules);
builder.AddSettings(config.Settings);
}
builder.EnsureDefaultValidator();
}

sample of md.style usage in tests

File.WriteAllText(MarkdownStyleConfig.MarkdownStyleFileName, @"{
settings : [
{ category: ""div"", disable: true},
{ category: ""p"", id: ""p-3"", disable: true}
],
}");
CreateFile(
MarkdownStyleDefinition.MarkdownStyleDefinitionFolderName + "/p" + MarkdownStyleDefinition.MarkdownStyleDefinitionFilePostfix,
@"{
tagRules : {
""p-1"": {
tagNames: [""p""],
behavior: ""Warning"",
messageFormatter: ""Tag {0} is not valid."",
openingTagOnly: true
},
""p-2"": {
tagNames: [""p""],
behavior: ""Warning"",
messageFormatter: ""Tag {0} is not valid."",
openingTagOnly: false,
disable: true
},
""p-3"": {
tagNames: [""p""],
behavior: ""Warning"",
messageFormatter: ""Tag {0} is not valid."",
openingTagOnly: false,
}
}
}
", _templateFolder);
CreateFile(
MarkdownStyleDefinition.MarkdownStyleDefinitionFolderName + "/div" + MarkdownStyleDefinition.MarkdownStyleDefinitionFilePostfix,
@"{
tagRules : {
""div-1"": {
tagNames: [""div""],
behavior: ""Warning"",
messageFormatter: ""Tag {0} is not valid."",
openingTagOnly: true
}
}

This features is not documented. and It seems not be used by any public repository and custom templates.
Is this feature support is continued?
(or is it better to use some standard tools like markdownlint?)

@yufeih
Copy link
Contributor Author

yufeih commented Jul 16, 2023

You are right, the md.style file was introduced a long time ago and wasn't documented. It does seem to have low usage and I agree that standard tools like markdown lint is a better alternative. We could drop it as a separate PR.

@yufeih yufeih merged commit a3c8409 into main Jul 17, 2023
7 checks passed
@yufeih yufeih deleted the nomdv branch July 17, 2023 02:05
p-kostov pushed a commit to ErpNetDocs/docfx that referenced this pull request Jun 28, 2024
Co-authored-by: Yufei Huang <yufeih@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Makes the pull request appear in "Breaking Changes" section of the next release note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants