88using System . Text ;
99using System . Threading ;
1010using System . Threading . Tasks ;
11+ using DotMarkdown ;
1112using Microsoft . CodeAnalysis ;
1213using Roslynator . Documentation ;
1314using Roslynator . Documentation . Markdown ;
@@ -26,9 +27,14 @@ public GenerateDocCommand(
2627 NamespaceDocumentationParts ignoredNamespaceParts ,
2728 TypeDocumentationParts ignoredTypeParts ,
2829 MemberDocumentationParts ignoredMemberParts ,
30+ CommonDocumentationParts ignoredCommonParts ,
2931 OmitMemberParts omitMemberParts ,
3032 IncludeContainingNamespaceFilter includeContainingNamespaceFilter ,
3133 Visibility visibility ,
34+ DocumentationHost documentationHost ,
35+ FilesLayout filesLayout ,
36+ bool groupByCommonNamespace ,
37+ InheritanceStyle inheritanceStyle ,
3238 in ProjectFilter projectFilter ) : base ( projectFilter )
3339 {
3440 Options = options ;
@@ -37,9 +43,14 @@ public GenerateDocCommand(
3743 IgnoredNamespaceParts = ignoredNamespaceParts ;
3844 IgnoredTypeParts = ignoredTypeParts ;
3945 IgnoredMemberParts = ignoredMemberParts ;
46+ IgnoredCommonParts = ignoredCommonParts ;
4047 OmitMemberParts = omitMemberParts ;
4148 IncludeContainingNamespaceFilter = includeContainingNamespaceFilter ;
4249 Visibility = visibility ;
50+ DocumentationHost = documentationHost ;
51+ FilesLayout = filesLayout ;
52+ GroupByCommonNamespace = groupByCommonNamespace ;
53+ InheritanceStyle = inheritanceStyle ;
4354 }
4455
4556 public GenerateDocCommandLineOptions Options { get ; }
@@ -54,17 +65,28 @@ public GenerateDocCommand(
5465
5566 public MemberDocumentationParts IgnoredMemberParts { get ; }
5667
68+ public CommonDocumentationParts IgnoredCommonParts { get ; }
69+
5770 public OmitMemberParts OmitMemberParts { get ; }
5871
5972 public IncludeContainingNamespaceFilter IncludeContainingNamespaceFilter { get ; }
6073
6174 public Visibility Visibility { get ; }
6275
76+ public DocumentationHost DocumentationHost { get ; }
77+
78+ public FilesLayout FilesLayout { get ; }
79+
80+ public bool GroupByCommonNamespace { get ; }
81+
82+ public InheritanceStyle InheritanceStyle { get ; }
83+
6384 public override async Task < CommandResult > ExecuteAsync ( ProjectOrSolution projectOrSolution , CancellationToken cancellationToken = default )
6485 {
6586 AssemblyResolver . Register ( ) ;
6687
6788 var documentationOptions = new DocumentationOptions (
89+ rootFileHeading : Options . Heading ,
6890 ignoredNames : Options . IgnoredNames ,
6991 preferredCultureName : Options . PreferredCulture ,
7092 maxDerivedTypes : Options . MaxDerivedTypes ,
@@ -82,26 +104,90 @@ public override async Task<CommandResult> ExecuteAsync(ProjectOrSolution project
82104 includeInheritedAttributes : ! Options . OmitInheritedAttributes ,
83105 omitIEnumerable : ! Options . IncludeIEnumerable ,
84106 depth : Depth ,
85- inheritanceStyle : Options . InheritanceStyle ,
107+ inheritanceStyle : InheritanceStyle ,
86108 ignoredRootParts : IgnoredRootParts ,
87109 ignoredNamespaceParts : IgnoredNamespaceParts ,
88110 ignoredTypeParts : IgnoredTypeParts ,
89111 ignoredMemberParts : IgnoredMemberParts ,
112+ ignoredCommonParts : IgnoredCommonParts ,
90113 includeContainingNamespaceFilter : IncludeContainingNamespaceFilter ,
114+ filesLayout : FilesLayout ,
91115 scrollToContent : Options . ScrollToContent ) ;
92116
93117 ImmutableArray < Compilation > compilations = await GetCompilationsAsync ( projectOrSolution , cancellationToken ) ;
94118
95119 var documentationModel = new DocumentationModel ( compilations , DocumentationFilterOptions . Instance , Options . AdditionalXmlDocumentation ) ;
96- #if DEBUG
97- SourceReferenceProvider sourceReferenceProvider = ( Options . SourceReferences . Any ( ) )
98- ? SourceReferenceProvider . Load ( Options . SourceReferences )
99- : null ;
100120
101- var generator = new MarkdownDocumentationGenerator ( documentationModel , WellKnownUrlProviders . GitHub , documentationOptions , sourceReferenceProvider ) ;
102- #else
103- var generator = new MarkdownDocumentationGenerator ( documentationModel , WellKnownUrlProviders . GitHub , documentationOptions ) ;
121+ List < INamespaceSymbol > commonNamespaces = null ;
122+
123+ if ( GroupByCommonNamespace )
124+ {
125+ commonNamespaces = DocumentationUtility . FindCommonNamespaces (
126+ documentationModel . Types . Concat ( documentationModel . GetExtendedExternalTypes ( ) ) ) ;
127+ }
128+
129+ UrlSegmentProvider urlSegmentProvider = new DefaultUrlSegmentProvider ( FilesLayout , commonNamespaces ) ;
130+
131+ var externalProviders = new MicrosoftDocsUrlProvider [ ] { MicrosoftDocsUrlProvider . Instance } ;
132+
133+ DocumentationUrlProvider GetUrlProvider ( )
134+ {
135+ switch ( DocumentationHost )
136+ {
137+ case DocumentationHost . GitHub :
138+ return new GitHubDocumentationUrlProvider ( urlSegmentProvider , externalProviders ) ;
139+ case DocumentationHost . Docusaurus :
140+ return new DocusaurusDocumentationUrlProvider ( urlSegmentProvider , externalProviders ) ;
141+ default :
142+ throw new InvalidOperationException ( $ "Unknown value '{ DocumentationHost } '.") ;
143+ }
144+ }
145+
146+ MarkdownWriterSettings GetMarkdownWriterSettings ( )
147+ {
148+ switch ( DocumentationHost )
149+ {
150+ case DocumentationHost . GitHub :
151+ return MarkdownWriterSettings . Default ;
152+ case DocumentationHost . Docusaurus :
153+ return new MarkdownWriterSettings ( new MarkdownFormat ( angleBracketEscapeStyle : AngleBracketEscapeStyle . EntityRef ) ) ;
154+ default :
155+ throw new InvalidOperationException ( $ "Unknown value '{ DocumentationHost } '.") ;
156+ }
157+ }
158+
159+ MarkdownWriterSettings markdownWriterSettings = GetMarkdownWriterSettings ( ) ;
160+
161+ DocumentationWriter CreateDocumentationWriter ( DocumentationContext context )
162+ {
163+ MarkdownWriter writer = MarkdownWriter . Create ( new StringBuilder ( ) , markdownWriterSettings ) ;
164+
165+ switch ( DocumentationHost )
166+ {
167+ case DocumentationHost . GitHub :
168+ return new MarkdownDocumentationWriter ( context , writer ) ;
169+ case DocumentationHost . Docusaurus :
170+ return new DocusaurusDocumentationWriter ( context , writer ) ;
171+ default :
172+ throw new InvalidOperationException ( $ "Unknown value '{ DocumentationHost } '.") ;
173+ }
174+ }
175+
176+ SourceReferenceProvider sourceReferenceProvider = null ;
177+ #if DEBUG
178+ if ( Options . SourceReferences . Any ( ) )
179+ sourceReferenceProvider = SourceReferenceProvider . Load ( Options . SourceReferences ) ;
104180#endif
181+ var context = new DocumentationContext (
182+ documentationModel ,
183+ GetUrlProvider ( ) ,
184+ documentationOptions ,
185+ c => CreateDocumentationWriter ( c ) ,
186+ sourceReferenceProvider : sourceReferenceProvider ,
187+ commonNamespaces : commonNamespaces ) ;
188+
189+ var generator = new DocumentationGenerator ( context ) ;
190+
105191 string directoryPath = Options . Output ;
106192
107193 if ( ! Options . NoDelete
0 commit comments