Skip to content

Commit 4317b06

Browse files
authored
Remove 'format' flag and most markdown dependencies. (#3594)
* Remove the format flag in options. * Remove most of the reliance of the format flag.
1 parent ed34275 commit 4317b06

18 files changed

+39
-136
lines changed

lib/src/dartdoc.dart

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import 'package:dartdoc/src/failure.dart';
1212
import 'package:dartdoc/src/generator/empty_generator.dart';
1313
import 'package:dartdoc/src/generator/generator.dart';
1414
import 'package:dartdoc/src/generator/html_generator.dart';
15-
import 'package:dartdoc/src/generator/markdown_generator.dart';
1615
import 'package:dartdoc/src/logging.dart';
1716
import 'package:dartdoc/src/model/model.dart';
1817
import 'package:dartdoc/src/package_meta.dart';
@@ -173,15 +172,10 @@ class Dartdoc {
173172
maxFileCount: context.maxFileCount,
174173
maxTotalSize: context.maxTotalSize,
175174
);
176-
var generator = await switch (context.format) {
177-
'html' => initHtmlGenerator(context, writer: writer),
178-
'md' => initMarkdownGenerator(context, writer: writer),
179-
_ => throw DartdocFailure('Unsupported output format: ${context.format}')
180-
};
181175
return Dartdoc._(
182176
context,
183177
outputDir,
184-
generator,
178+
await initHtmlGenerator(context, writer: writer),
185179
packageBuilder,
186180
);
187181
}

lib/src/dartdoc_options.dart

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,9 +1330,6 @@ class DartdocOptionContext extends DartdocOptionContextBase
13301330

13311331
bool get showStats => optionSet['showStats'].valueAt(context);
13321332

1333-
/// Output format, e.g. 'html', 'md'
1334-
String get format => optionSet['format'].valueAt(context);
1335-
13361333
// TODO(jdkoren): temporary while we confirm href base behavior doesn't break
13371334
// important clients
13381335
bool get useBaseHref => optionSet['useBaseHref'].valueAt(context);
@@ -1712,10 +1709,6 @@ List<DartdocOption> createDartdocOptions(
17121709
hide: true),
17131710
DartdocOptionArgOnly<bool>('showStats', false, resourceProvider,
17141711
help: 'Show statistics useful for debugging.', hide: true),
1715-
DartdocOptionArgOnly<String>('format', 'html', resourceProvider,
1716-
help: 'The format of documentation to generate: `md` for markdown, '
1717-
'`html` for html.',
1718-
hide: false),
17191712
DartdocOptionArgOnly<String>('maxFileCount', '0', resourceProvider,
17201713
help:
17211714
'The maximum number of files dartdoc is allowed to create (0 for no limit).',

lib/src/generator/file_structure.dart

Lines changed: 16 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:dartdoc/src/comment_references/parser.dart';
6-
import 'package:dartdoc/src/failure.dart';
76
import 'package:meta/meta.dart';
87

98
import '../model/model.dart';
109

11-
const _validFormats = {'html', 'md'};
12-
1310
/// This class defines an interface to allow [ModelElement]s and [Generator]s
1411
/// to get information about the desired on-disk representation of a single
1512
/// [ModelElement]. None of these getters should be considered valid unless
@@ -19,52 +16,39 @@ const _validFormats = {'html', 'md'};
1916
/// together.
2017
abstract class FileStructure {
2118
factory FileStructure.fromDocumentable(Documentable documentable) {
22-
/// This assumes all remote packages are HTML.
23-
/// Add configurability for remote formats in dartdoc_options if changing
24-
/// that becomes desireable.
25-
var format = documentable.config.format;
26-
if (documentable.package.documentedWhere == DocumentLocation.remote) {
27-
format = 'html';
28-
}
29-
if (!_validFormats.contains(format)) {
30-
throw DartdocFailure('Internal error: unrecognized format: $format');
31-
}
3219
return switch (documentable) {
3320
LibraryContainer() =>
3421
// [LibraryContainer]s are not ModelElements, but have documentation.
35-
FileStructure._fromLibraryContainer(documentable, format),
22+
FileStructure._fromLibraryContainer(documentable),
3623
ModelElement() =>
3724
// This should be the common case.
38-
FileStructure._fromModelElement(documentable, format),
25+
FileStructure._fromModelElement(documentable),
3926
_ => throw UnimplementedError(
4027
'Tried to build a FileStructure for an unknown subtype of Documentable: ${documentable.runtimeType}')
4128
};
4229
}
4330

4431
factory FileStructure._fromLibraryContainer(
4532
LibraryContainer libraryContainer,
46-
String format,
4733
) =>
4834
switch (libraryContainer) {
49-
Category() => FileStructureImpl(format, libraryContainer.name, 'topic'),
50-
Package() => FileStructureImpl(format, 'index', null),
35+
Category() => FileStructureImpl(libraryContainer.name, 'topic'),
36+
Package() => FileStructureImpl('index', null),
5137
_ => throw UnimplementedError(
5238
'Unrecognized LibraryContainer subtype: ${libraryContainer.runtimeType}')
5339
};
5440

55-
factory FileStructure._fromModelElement(
56-
ModelElement modelElement, String format) {
41+
factory FileStructure._fromModelElement(ModelElement modelElement) {
5742
return switch (modelElement) {
58-
Library() => FileStructureImpl(format, modelElement.dirName, 'library'),
59-
Mixin() => FileStructureImpl(format, modelElement.name, 'mixin'),
60-
Class() => FileStructureImpl(format, modelElement.name, 'class'),
61-
ExtensionType() =>
62-
FileStructureImpl(format, modelElement.name, 'extension-type'),
63-
Operator() => FileStructureImpl(format,
43+
Library() => FileStructureImpl(modelElement.dirName, 'library'),
44+
Mixin() => FileStructureImpl(modelElement.name, 'mixin'),
45+
Class() => FileStructureImpl(modelElement.name, 'class'),
46+
ExtensionType() => FileStructureImpl(modelElement.name, 'extension-type'),
47+
Operator() => FileStructureImpl(
6448
'operator_${operatorNames[modelElement.referenceName]}', null),
6549
GetterSetterCombo() => FileStructureImpl(
66-
format, modelElement.name, modelElement.isConst ? 'constant' : null),
67-
_ => FileStructureImpl(format, modelElement.name, null)
50+
modelElement.name, modelElement.isConst ? 'constant' : null),
51+
_ => FileStructureImpl(modelElement.name, null)
6852
};
6953
}
7054

@@ -82,22 +66,16 @@ abstract class FileStructure {
8266

8367
/// The file name for an independent file. Only valid if [hasIndependentFile]
8468
/// is `true`. May contain platform-local path separators. Includes
85-
/// the [fileType] and the [modelElement.enclosingElement]'s [dirName].
69+
/// the file type and the [modelElement.enclosingElement]'s [dirName].
8670
String get fileName;
8771

8872
/// The directory name that should contain any elements enclosed by
8973
/// [modelElement].
9074
String get dirName;
91-
92-
/// A type (generally "html" or "md") to be appended to the file name.
93-
String get fileType;
9475
}
9576

9677
@visibleForTesting
9778
class FileStructureImpl implements FileStructure {
98-
@override
99-
final String fileType;
100-
10179
/// This is a name for the underlying [Documentable] that is free of
10280
/// characters that can not appear in a path (URI, Unix, or Windows).
10381
String pathSafeName;
@@ -111,7 +89,7 @@ class FileStructureImpl implements FileStructure {
11189
// always having a disambiguating string.
11290
final String? kindAddition;
11391

114-
FileStructureImpl(this.fileType, this.pathSafeName, this.kindAddition);
92+
FileStructureImpl(this.pathSafeName, this.kindAddition);
11593

11694
@override
11795

@@ -120,9 +98,9 @@ class FileStructureImpl implements FileStructure {
12098
/// some will not. See [FileStructure._fromModelElement].
12199
String get fileName {
122100
if (kindAddition != null) {
123-
return '$pathSafeName-$kindAddition.$fileType';
101+
return '$pathSafeName-$kindAddition.html';
124102
}
125-
return '$pathSafeName.$fileType';
103+
return '$pathSafeName.html';
126104
}
127105

128106
@override

lib/src/generator/templates.dart

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,23 +118,17 @@ abstract class Templates {
118118
static Future<Templates> fromContext(DartdocGeneratorOptionContext context,
119119
{bool forceRuntimeTemplates = false}) async {
120120
var templatesDir = context.templatesDir;
121-
var format = context.format;
122-
123121
if (templatesDir != null) {
124122
return RuntimeTemplates._create(
125-
context.resourceProvider.getFolder(templatesDir), format,
123+
context.resourceProvider.getFolder(templatesDir),
126124
resourceProvider: context.resourceProvider);
127125
} else if (forceRuntimeTemplates) {
128126
var directory = await context.resourceProvider
129-
.getResourceFolder('package:dartdoc/templates/$format');
130-
return RuntimeTemplates._create(directory, format,
127+
.getResourceFolder('package:dartdoc/templates/html');
128+
return RuntimeTemplates._create(directory,
131129
resourceProvider: context.resourceProvider);
132-
} else if (format == 'html') {
133-
return HtmlAotTemplates();
134-
} else if (format == 'md') {
135-
return MarkdownAotTemplates();
136130
} else {
137-
throw ArgumentError.value(format, 'format');
131+
return HtmlAotTemplates();
138132
}
139133
}
140134
}
@@ -393,17 +387,17 @@ class RuntimeTemplates implements Templates {
393387
final Template _typedefTemplate;
394388

395389
/// Creates a [Templates] from a custom set of template files, found in [dir].
396-
static Future<Templates> _create(Folder dir, String format,
390+
static Future<Templates> _create(Folder dir,
397391
{required ResourceProvider resourceProvider}) async {
398392
Future<Template> loadTemplate(String templatePath) {
399-
var templateFile = dir.getChildAssumingFile('$templatePath.$format');
393+
var templateFile = dir.getChildAssumingFile('$templatePath.html');
400394
if (!templateFile.exists) {
401395
throw DartdocFailure(
402-
'Missing required template file: $templatePath.$format');
396+
'Missing required template file: $templatePath.html');
403397
}
404398
return Template.parse(templateFile,
405399
partialResolver: (String partialName) async =>
406-
dir.getChildAssumingFile('_$partialName.$format'));
400+
dir.getChildAssumingFile('_$partialName.html'));
407401
}
408402

409403
var indexTemplate = await loadTemplate('index');

lib/src/generator/templates.runtime_renderers.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16375,7 +16375,6 @@ const _invisibleGetters = {
1637516375
'exclude',
1637616376
'excludeFooterVersion',
1637716377
'flutterRoot',
16378-
'format',
1637916378
'hashCode',
1638016379
'include',
1638116380
'includeExternal',
@@ -16626,7 +16625,6 @@ const _invisibleGetters = {
1662616625
'FileStructure': {
1662716626
'dirName',
1662816627
'fileName',
16629-
'fileType',
1663016628
'hasIndependentFile',
1663116629
'hashCode',
1663216630
'href',

lib/src/model/class.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ class Class extends InheritingContainer
2424
];
2525

2626
@override
27-
String get sidebarPath =>
28-
'${library.dirName}/$name-class-sidebar.${fileStructure.fileType}';
27+
String get sidebarPath => '${library.dirName}/$name-class-sidebar.html';
2928

3029
@override
3130
late final List<InheritingContainer> inheritanceChain = [

lib/src/model/enum.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ class Enum extends InheritingContainer
3535
];
3636

3737
@override
38-
String get sidebarPath =>
39-
'${library.dirName}/$name-enum-sidebar.${fileStructure.fileType}';
38+
String get sidebarPath => '${library.dirName}/$name-enum-sidebar.html';
4039

4140
@override
4241
Kind get kind => Kind.enum_;

lib/src/model/extension.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ class Extension extends Container implements EnclosedElement {
9797
String get filePath => '${library.dirName}/${fileStructure.fileName}';
9898

9999
@override
100-
String get sidebarPath =>
101-
'${library.dirName}/$name-extension-sidebar.${fileStructure.fileType}';
100+
String get sidebarPath => '${library.dirName}/$name-extension-sidebar.html';
102101

103102
Map<String, CommentReferable>? _referenceChildren;
104103
@override

lib/src/model/extension_type.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class ExtensionType extends InheritingContainer
7171

7272
@override
7373
String get sidebarPath =>
74-
'${library.dirName}/$name-extension-type-sidebar.${fileStructure.fileType}';
74+
'${library.dirName}/$name-extension-type-sidebar.html';
7575

7676
Map<String, CommentReferable>? _referenceChildren;
7777
@override

lib/src/model/field.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,7 @@ class Field extends ModelElement
141141
}
142142

143143
@override
144-
String get fileName =>
145-
'${isConst ? '$name-constant' : name}.${fileStructure.fileType}';
144+
String get fileName => '${isConst ? '$name-constant' : name}.html';
146145

147146
@override
148147
String get aboveSidebarPath => enclosingElement.sidebarPath;

0 commit comments

Comments
 (0)