Skip to content

Commit

Permalink
Merge branch 'main' into IncludeReferencesInAssemblyDepResolve
Browse files Browse the repository at this point in the history
  • Loading branch information
yufeih authored Feb 18, 2025
2 parents 2ca5913 + f99ba39 commit 3bcde95
Show file tree
Hide file tree
Showing 18 changed files with 1,802 additions and 850 deletions.
26 changes: 16 additions & 10 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="HtmlAgilityPack" Version="1.11.71" />
<PackageVersion Include="ICSharpCode.Decompiler" Version="8.2.0.7535" />
<PackageVersion Include="Jint" Version="4.1.0" />
<PackageVersion Include="JsonSchema.Net" Version="7.2.3" />
<PackageVersion Include="Markdig" Version="0.38.0" />
<PackageVersion Include="Microsoft.Playwright" Version="1.49.0" />
<PackageVersion Include="HtmlAgilityPack" Version="1.11.72" />
<PackageVersion Include="ICSharpCode.Decompiler" Version="9.0.0.7889" />
<PackageVersion Include="Jint" Version="4.2.0" />
<PackageVersion Include="JsonSchema.Net" Version="7.3.3" />
<PackageVersion Include="Markdig" Version="0.40.0" />
<PackageVersion Include="Microsoft.Playwright" Version="1.50.0" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="OneOf" Version="3.0.271" />
<PackageVersion Include="OneOf.SourceGenerator" Version="3.0.271" />
Expand All @@ -18,13 +18,19 @@
<PackageVersion Include="Spectre.Console" Version="0.49.1" />
<PackageVersion Include="Spectre.Console.Cli" Version="0.49.1" />
<PackageVersion Include="Stubble.Core" Version="1.10.8" />
<PackageVersion Include="System.Collections.Immutable" Version="9.0.0" />
<PackageVersion Include="System.Composition" Version="9.0.0" />
<PackageVersion Include="System.Formats.Asn1" Version="9.0.0" />
<PackageVersion Include="System.Text.Json" Version="9.0.0" />
<PackageVersion Include="System.Collections.Immutable" Version="9.0.2" />
<PackageVersion Include="System.Composition" Version="9.0.2" />
<PackageVersion Include="System.Formats.Asn1" Version="9.0.2" />
<PackageVersion Include="System.Text.Json" Version="9.0.2" />
<PackageVersion Include="YamlDotNet" Version="15.3.0" />
</ItemGroup>

<!-- .slnx solution format is supported Microsoft.Build 17.13.9 or later. -->
<ItemGroup>
<PackageVersion Include="Microsoft.Build" Version="[17.11.4]" Condition="'$(TargetFramework)' == 'net8.0'"/>
<PackageVersion Include="Microsoft.Build" Version="17.13.9" Condition="'$(TargetFramework)' != 'net8.0'"/>
</ItemGroup>

<ItemGroup>
<PackageVersion Include="Microsoft.CodeAnalysis" Version="4.12.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="4.12.0" />
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ If you want to use prerelease version, you can install package with following st
2. Login to GitHub with additional scope request

```pwsh
gh auth login --scopes "read:packages" --host github.com
gh auth login --scopes "read:packages" --hostname github.com
```
3. Follow the instructions and complete the login steps.
Expand Down
7 changes: 5 additions & 2 deletions src/Docfx.Build/HtmlTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@

namespace Docfx.Build;

struct HtmlTemplate
partial struct HtmlTemplate
{
[GeneratedRegex("(\\s+[a-zA-Z0-9_-]+)=([\"']){(\\d)}[\"']")]
private static partial Regex AttributePlaceholderRegex();

private string? _html;

public override string ToString() => _html ?? "";
Expand All @@ -18,7 +21,7 @@ struct HtmlTemplate

public static HtmlTemplate Html(FormattableString template)
{
var format = Regex.Replace(template.Format, "(\\s+[a-zA-Z0-9_-]+)=([\"']){(\\d)}[\"']", RenderAttribute);
var format = AttributePlaceholderRegex().Replace(template.Format, RenderAttribute);
var html = string.Format(format, Array.ConvertAll(template.GetArguments(), Render));
return new() { _html = html };

Expand Down
3 changes: 1 addition & 2 deletions src/Docfx.Build/ResourceFileReaders/ResourceFileReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ bool filter(string s)
{
if (selector != null)
{
var regex = new Regex(selector, RegexOptions.IgnoreCase);
return regex.IsMatch(s);
return Regex.IsMatch(s, selector, RegexOptions.IgnoreCase);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ internal partial class MustacheTemplateRenderer : ITemplateRenderer
{
public const string Extension = ".tmpl";

[GeneratedRegex(@"{{\s*!\s*include\s*\(:?(:?['""]?)\s*(?<file>(.+?))\1\s*\)\s*}}", RegexOptions.IgnoreCase | RegexOptions.Compiled, "en-AU")]
private static partial Regex IncludeRegex();

[GeneratedRegex(@"{{\s*!\s*master\s*\(:?(:?['""]?)\s*(?<file>(.+?))\1\s*\)\s*}}\s*\n?", RegexOptions.IgnoreCase | RegexOptions.Compiled, "en-AU")]
private static partial Regex MasterPageRegex();

[GeneratedRegex(@"{{\s*!\s*body\s*}}\s*\n?", RegexOptions.IgnoreCase | RegexOptions.Compiled, "en-AU")]
// Following regex are not supported by GeneratedRegexAttribute. (Because it contains case-insensitive backreferences)
// When using GeneratedRegexAttribute. following message are shown as information leve.
// SYSLIB1044: The regex generator couldn't generate a complete source implementation for the specified regular expression due to an internal limitation. See the explanation in the generated source for more details.
// And Regex instance is created with following remarks comments.
// A custom Regex-derived type could not be generated because the expression contains case-insensitive backreferences which are not supported by the source generator.
#pragma warning disable SYSLIB1045
private static readonly Regex IncludeRegex = new(@"{{\s*!\s*include\s*\(:?(:?['""]?)\s*(?<file>(.+?))\1\s*\)\s*}}", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex MasterPageRegex = new(@"{{\s*!\s*master\s*\(:?(:?['""]?)\s*(?<file>(.+?))\1\s*\)\s*}}\s*\n?", RegexOptions.Compiled | RegexOptions.IgnoreCase);
#pragma warning restore SYSLIB1045

[GeneratedRegex(@"{{\s*!\s*body\s*}}\s*\n?", RegexOptions.IgnoreCase)]
private static partial Regex MasterPageBodyRegex();

private readonly ResourceFileReader _reader;
Expand All @@ -42,7 +47,7 @@ public MustacheTemplateRenderer(ResourceFileReader reader, ResourceInfo info, st
})
.Build();

var processedTemplate = ParseTemplateHelper.ExpandMasterPage(reader, info, MasterPageRegex(), MasterPageBodyRegex());
var processedTemplate = ParseTemplateHelper.ExpandMasterPage(reader, info, MasterPageRegex, MasterPageBodyRegex());

_template = processedTemplate;

Expand All @@ -68,7 +73,7 @@ public string Render(object model)
/// <param name="template"></param>
private IEnumerable<string> ExtractDependencyResourceNames(string template)
{
foreach (Match match in IncludeRegex().Matches(template))
foreach (Match match in IncludeRegex.Matches(template))
{
var filePath = match.Groups["file"].Value;
foreach (var name in ParseTemplateHelper.GetResourceName(filePath, Path, _reader))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,9 @@ public static IEnumerable<string> GetResourceName(string file, string templateNa
{
file = regexPatternMatch.Groups[1].Value;
var resourceKey = GetRelativeResourceKey(templateName, file);
var regex = new Regex(resourceKey, RegexOptions.IgnoreCase);
foreach (var name in reader.Names)
{
if (regex.IsMatch(name))
if (Regex.IsMatch(name, resourceKey, RegexOptions.IgnoreCase))
{
yield return name;
}
Expand Down
1 change: 1 addition & 0 deletions src/Docfx.Dotnet/Docfx.Dotnet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<PackageReference Include="OneOf" />
<PackageReference Include="OneOf.SourceGenerator" PrivateAssets="All" />
<PackageReference Include="Markdig" />
<PackageReference Include="Microsoft.Build" />
<PackageReference Include="Microsoft.CodeAnalysis" />
<PackageReference Include="Microsoft.CodeAnalysis.Common" />
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic" />
Expand Down
6 changes: 5 additions & 1 deletion src/Docfx.Dotnet/DotnetApiCatalog.ApiPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ namespace Docfx.Dotnet;

partial class DotnetApiCatalog
{
// Regex to match any character other than a word character(alphabet/numeric/underscore)
[GeneratedRegex(@"\W")]
private static partial Regex NonWordCharRegex();

private static void CreatePages(Action<string, string, ApiPage> output, List<(IAssemblySymbol symbol, Compilation compilation)> assemblies, ExtractMetadataConfig config, DotnetApiOptions options)
{
Directory.CreateDirectory(config.OutputFolder);
Expand Down Expand Up @@ -122,7 +126,7 @@ void Heading(int level, string title, string? id = null)
void Api(int level, string title, ISymbol symbol, Compilation compilation)
{
var uid = VisitorHelper.GetId(symbol);
var id = Regex.Replace(uid, @"\W", "_");
var id = NonWordCharRegex().Replace(uid, "_");
var commentId = VisitorHelper.GetCommentId(symbol);
var source = config.DisableGitFeatures ? null : VisitorHelper.GetSourceDetail(symbol, compilation);
var git = source?.Remote is null ? null
Expand Down
8 changes: 8 additions & 0 deletions src/Docfx.Dotnet/FileInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ private static FileType GetFileType(string filePath)
case ".sln":
case ".slnf":
return FileType.Solution;

case ".slnx":
#if NET9_0_OR_GREATER
return FileType.Solution;
#else
return FileType.NotSupported;
#endif

case ".csproj":
case ".vbproj":
return FileType.Project;
Expand Down
2 changes: 1 addition & 1 deletion src/Docfx.Dotnet/Filters/ConfigFilterRuleItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public string UidRegex
}
set
{
_uidRegex = new Regex(value);
_uidRegex = new Regex(value, RegexOptions.Compiled);
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/Docfx.Dotnet/Parsers/XmlComment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ internal partial class XmlComment
[GeneratedRegex(@"^\s*<!--\s*</(.*)>\s*-->$")]
private static partial Regex XmlEndRegionRegex();

[GeneratedRegex(@"^(\s*)&gt;", RegexOptions.Multiline)]
private static partial Regex BlockQuoteRegex();

private readonly XmlCommentParserContext _context;

public string Summary { get; private set; }
Expand Down Expand Up @@ -603,7 +606,7 @@ static string HandleBlockQuote(string xml)
{
// > is encoded to &gt; in XML. When interpreted as markdown, > is as blockquote
// Decode standalone &gt; to > to enable the block quote markdown syntax
return Regex.Replace(xml, @"^(\s*)&gt;", "$1>", RegexOptions.Multiline);
return BlockQuoteRegex().Replace(xml, "$1>");
}

static void MarkdownXmlDecode(MarkdownObject node)
Expand Down
8 changes: 6 additions & 2 deletions src/Docfx.Dotnet/SymbolUrlResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ enum SymbolUrlKind

internal static partial class SymbolUrlResolver
{
// Regex to match any character other than a word character(alphabet/numeric/underscore)
[GeneratedRegex(@"\W")]
private static partial Regex NonWordCharRegex();

public static string? GetSymbolUrl(ISymbol symbol, Compilation compilation, MemberLayout memberLayout, SymbolUrlKind urlKind, HashSet<IAssemblySymbol> allAssemblies, SymbolFilter filter)
{
// Reduce symbol into generic definitions
Expand Down Expand Up @@ -53,8 +57,8 @@ internal static partial class SymbolUrlResolver
"!" => null,
"N" or "T" => $"{VisitorHelper.PathFriendlyId(uid)}{ext}",
"M" or "F" or "P" or "E" => memberLayout is MemberLayout.SeparatePages && !symbol.IsEnumMember()
? $"{VisitorHelper.PathFriendlyId(VisitorHelper.GetOverloadId(symbol))}{ext}#{Regex.Replace(uid, @"\W", "_")}"
: $"{VisitorHelper.PathFriendlyId(VisitorHelper.GetId(symbol.ContainingType))}{ext}#{Regex.Replace(uid, @"\W", "_")}",
? $"{VisitorHelper.PathFriendlyId(VisitorHelper.GetOverloadId(symbol))}{ext}#{NonWordCharRegex().Replace(uid, "_")}"
: $"{VisitorHelper.PathFriendlyId(VisitorHelper.GetId(symbol.ContainingType))}{ext}#{NonWordCharRegex().Replace(uid, "_")}",
_ => throw new NotSupportedException($"Unknown comment ID format '{type}'"),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Docfx.MarkdigEngine.Extensions;

public partial class CodeSnippetExtractor
{
[GeneratedRegex(@"^[\w\.-]+$", RegexOptions.IgnoreCase, "en-AU")]
[GeneratedRegex(@"^[\w\.-]+$", RegexOptions.IgnoreCase)]
private static partial Regex TagnameFormat();

private readonly string StartLineTemplate;
Expand Down
Loading

0 comments on commit 3bcde95

Please sign in to comment.