diff --git a/packages/typedoc-plugin-markdown/src/index.ts b/packages/typedoc-plugin-markdown/src/index.ts index 5fbd1e81a..8ffc73d5e 100644 --- a/packages/typedoc-plugin-markdown/src/index.ts +++ b/packages/typedoc-plugin-markdown/src/index.ts @@ -1,11 +1,16 @@ -import * as fs from 'fs'; import * as path from 'path'; -import { Application, Converter, ParameterType, Renderer } from 'typedoc'; +import { Application, ParameterType } from 'typedoc'; +import { CustomOptionsReader } from './options-reader'; import MarkdownTheme from './theme'; export function load(app: Application) { + addDeclarations(app); + loadTheme(app); +} + +function addDeclarations(app: Application) { app.options.addDeclaration({ help: '[Markdown Plugin] Do not render page title.', name: 'hidePageTitle', @@ -21,23 +26,20 @@ export function load(app: Application) { }); app.options.addDeclaration({ - help: - '[Markdown Plugin] Specifies the base path that all links to be served from. If omitted all urls will be relative.', + help: '[Markdown Plugin] Specifies the base path that all links to be served from. If omitted all urls will be relative.', name: 'publicPath', type: ParameterType.String, }); app.options.addDeclaration({ - help: - '[Markdown Plugin] Use HTML named anchors as fragment identifiers for engines that do not automatically assign header ids. Should be set for Bitbucket Server docs.', + help: '[Markdown Plugin] Use HTML named anchors as fragment identifiers for engines that do not automatically assign header ids. Should be set for Bitbucket Server docs.', name: 'namedAnchors', type: ParameterType.Boolean, defaultValue: false, }); app.options.addDeclaration({ - help: - '[Markdown Plugin] Output all reflections into seperate output files.', + help: '[Markdown Plugin] Output all reflections into seperate output files.', name: 'allReflectionsHaveOwnDocument', type: ParameterType.Boolean, defaultValue: false, @@ -69,37 +71,35 @@ export function load(app: Application) { name: 'indexTitle', type: ParameterType.String, }); +} - app.converter.on(Converter.EVENT_BEGIN, () => { - Renderer.getDefaultTheme = () => path.join(__dirname, 'resources'); - }); - - app.converter.on(Converter.EVENT_RESOLVE_BEGIN, () => { - const themeName = app.options.getValue('theme'); - - const themeDir = path.join(__dirname); - - if (![themeDir, 'default', 'markdown'].includes(themeName)) { - // For custom themes check that the theme is a markdown theme - // If it is return and pass through to renderer - const themeFileName = path.resolve(path.join(themeName, 'theme.js')); - if (fs.existsSync(themeFileName) && isMarkdownTheme(themeFileName)) { - return; - } +function loadTheme(app: Application) { + const themeRef = app.options.getValue('theme'); + const themeDir = path.join(__dirname); + const basePath = themeDir + '/resources'; + + if ([themeDir, 'default', 'markdown'].includes(themeRef)) { + app.renderer.theme = new MarkdownTheme(app.renderer, basePath); + } else { + const CustomTheme = getCustomTheme( + path.resolve(path.join(themeRef, 'theme.js')), + ); + if (CustomTheme !== null) { + app.options.addReader(new CustomOptionsReader()); + app.renderer.theme = new CustomTheme(app.renderer, basePath); + } else { app.logger.warn( - `[typedoc-plugin-markdown] '${themeName}' is not a recognised markdown theme. If an html theme is required, please disable this plugin.`, + `[typedoc-plugin-markdown] '${themeRef}' is not a recognised markdown theme.`, ); } - - app.options.setValue('theme', themeDir); - }); + } } -function isMarkdownTheme(themeFileName: string) { +function getCustomTheme(themeFile: string) { try { - const ThemeClass = require(themeFileName).default; - return ThemeClass.prototype instanceof MarkdownTheme; + const ThemeClass = require(themeFile).default; + return ThemeClass.prototype instanceof MarkdownTheme ? ThemeClass : null; } catch (e) { - return false; + return null; } } diff --git a/packages/typedoc-plugin-markdown/src/options-reader.ts b/packages/typedoc-plugin-markdown/src/options-reader.ts new file mode 100644 index 000000000..22a3349e1 --- /dev/null +++ b/packages/typedoc-plugin-markdown/src/options-reader.ts @@ -0,0 +1,29 @@ +import * as path from 'path'; + +import { Options, OptionsReader } from 'typedoc'; +import { Logger } from 'typedoc/dist/lib/utils'; + +export class CustomOptionsReader implements OptionsReader { + priority = 900; + + name = 'custom-options'; + + read(container: Options, logger: Logger) { + const options = this.getOptionsFile( + path.resolve(path.join(container.getValue('theme'), 'options.js')), + ); + if (options) { + Object.entries(options).forEach(([key, value]) => { + container.setValue(key, value); + }); + } + } + + getOptionsFile(optionsFile: string) { + try { + return require(optionsFile).default; + } catch (e) { + return null; + } + } +} diff --git a/packages/typedoc-plugin-markdown/src/theme.ts b/packages/typedoc-plugin-markdown/src/theme.ts index cc585f08b..af998fff3 100644 --- a/packages/typedoc-plugin-markdown/src/theme.ts +++ b/packages/typedoc-plugin-markdown/src/theme.ts @@ -38,7 +38,7 @@ export default class MarkdownTheme extends Theme { @BindOption('filenameSeparator') filenameSeparator!: string; @BindOption('entryDocument') - entryDocument!: string; + entryDocument: string; // creates an isolated Handlebars environment to store context aware helpers static HANDLEBARS = Handlebars.create(); @@ -237,12 +237,8 @@ export default class MarkdownTheme extends Theme { const navigationItem = new NavigationItem(title, url); navigationItem.isLabel = isLabel; navigationItem.children = children; - const { - reflection, - parent, - cssClasses, - ...filteredNavigationItem - } = navigationItem; + const { reflection, parent, cssClasses, ...filteredNavigationItem } = + navigationItem; return filteredNavigationItem as NavigationItem; }; const navigation = createNavigationItem(project.name, undefined, false); diff --git a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/comments.spec.ts.snap b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/comments.spec.ts.snap index f39e617dd..22bf6863d 100644 --- a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/comments.spec.ts.snap +++ b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/comments.spec.ts.snap @@ -11,7 +11,7 @@ You can write HTML tags directly in comments `; exports[`Comments: should build @link references' 1`] = ` -"See [\`CommentClass\`](commentclass.md) and [CommentClass's comment property](commentclass.md#comment). +"See [\`CommentClass\`](CommentClass.md) and [CommentClass's comment property](CommentClass.md#comment). Also, check out [Google](https://www.google.com) and [GitHub](https://github.com). @@ -61,7 +61,7 @@ Another tag description exports[`Comments: should convert symbols brackets to symbol links' 1`] = ` "Additionally you can link to other classes, members or functions using double square brackets. -- Link to an external reflection: [CommentClass](commentclass.md) +- Link to an external reflection: [CommentClass](CommentClass.md) - Link to an internal reflection: [commentsInReturn](../modules.md#commentsinreturn) - Link to an undefined reflection: [[VOID]] " diff --git a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/generics.spec.ts.snap b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/generics.spec.ts.snap index 4d593cd30..9df046031 100644 --- a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/generics.spec.ts.snap +++ b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/generics.spec.ts.snap @@ -46,7 +46,7 @@ exports[`Generics: should compile function with complex type params' 1`] = ` | Name | Type | Description | | :------ | :------ | :------ | -| \`A\` | extends [\`ClassWithTypeParams\`](classwithtypeparams.md)<\`string\`, \`number\`, \`A\`\\\\> | Comment for type \`A\` | +| \`A\` | extends [\`ClassWithTypeParams\`](ClassWithTypeParams.md)<\`string\`, \`number\`, \`A\`\\\\> | Comment for type \`A\` | | \`B\` | \`string\` \\\\| \`boolean\` | Comment for type \`B\` | | \`C\` | \`string\` | - | diff --git a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/hierarchy.spec.ts.snap b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/hierarchy.spec.ts.snap index f42e153c7..94a58ec06 100644 --- a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/hierarchy.spec.ts.snap +++ b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/hierarchy.spec.ts.snap @@ -1,19 +1,19 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Hierarchy: should compile nested type hierarchy 1`] = ` -"- [\`ParentClass\`](parentclass.md) +"- [\`ParentClass\`](ParentClass.md) ↳ **\`ChildClassA\`** - ↳↳ [\`GrandChildClassA\`](grandchildclassa.md) + ↳↳ [\`GrandChildClassA\`](GrandChildClassA.md) " `; exports[`Hierarchy: should compile type hierarchy 1`] = ` "- **\`ParentClass\`** - ↳ [\`ChildClassA\`](childclassa.md) + ↳ [\`ChildClassA\`](ChildClassA.md) - ↳ [\`ChildClassB\`](childclassb.md) + ↳ [\`ChildClassB\`](ChildClassB.md) " `; diff --git a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/options.spec.ts.snap b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/options.spec.ts.snap index ff3fe1ef5..8357a8118 100644 --- a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/options.spec.ts.snap +++ b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/options.spec.ts.snap @@ -1,5 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Options: (defaults) should compile relativeURL helper 1`] = `"breadcrumbs.md"`; +exports[`Options: (defaults) should compile relativeURL helper 1`] = `"Breadcrumbs.md"`; -exports[`Options: (with plugin options) should compile relativeURL helper with public path 1`] = `"test-public-pathclasses/breadcrumbs.md"`; +exports[`Options: (with plugin options) should compile relativeURL helper with public path 1`] = `"test-public-pathclasses/Breadcrumbs.md"`; diff --git a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/reflections.spec.ts.snap b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/reflections.spec.ts.snap index d566db6d9..af06245a8 100644 --- a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/reflections.spec.ts.snap +++ b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/reflections.spec.ts.snap @@ -12,7 +12,14 @@ exports[`Reflections: (header) should compile template with breadcrumbs and with exports[`Reflections: (template) should compile Enum 1`] = ` "# Enumeration: EnumReflection -[helper: toc] +## Table of contents + +### Enumeration members + +- [Down](../enums/EnumReflection.md#down) +- [Left](../enums/EnumReflection.md#left) +- [Right](../enums/EnumReflection.md#right) +- [Up](../enums/EnumReflection.md#up) [partial: members] " @@ -27,8 +34,6 @@ exports[`Reflections: (template) should compile a callable reflection 1`] = ` [partial: member.signature] -[helper: toc] - [partial: members] " `; @@ -42,8 +47,6 @@ exports[`Reflections: (template) should compile an indexable reflection 1`] = ` [partial: comment] -[helper: toc] - [partial: members] " `; @@ -53,9 +56,13 @@ exports[`Reflections: (template) should compile implemented class 1`] = ` ## Implements -- [\`ReflectionClass\`](../classes/reflectionclass.md) +- [\`ReflectionClass\`](../classes/ReflectionClass.md) -[helper: toc] +## Table of contents + +### Constructors + +- [constructor](../classes/ImplementedClass.md#constructor) [partial: members] " @@ -64,7 +71,14 @@ exports[`Reflections: (template) should compile implemented class 1`] = ` exports[`Reflections: (template) should compile module with breadcrumbs and project title 1`] = ` "# Enumeration: EnumReflection -[helper: toc] +## Table of contents + +### Enumeration members + +- [Down](../enums/EnumReflection.md#down) +- [Left](../enums/EnumReflection.md#left) +- [Right](../enums/EnumReflection.md#right) +- [Up](../enums/EnumReflection.md#up) [partial: members] " diff --git a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/signatures.spec.ts.snap b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/signatures.spec.ts.snap index 254970184..fe90bf38f 100644 --- a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/signatures.spec.ts.snap +++ b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/signatures.spec.ts.snap @@ -84,7 +84,7 @@ Some nested params. | \`params.nestedObj\` | \`Object\` | A nested object. | | \`params.nestedObj.name\` | \`string\` | - | | \`params.nestedObj.obj\` | \`Object\` | - | -| \`params.nestedObj.obj.name\` | () => \`void\` | - | +| \`params.nestedObj.obj.name\` | | - | | \`params.nestedObj.value\` | \`number\` | - | | \`params.parent?\` | \`number\` | - | | \`context\` | \`any\` | The context of the method call. | diff --git a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/sources.spec.ts.snap b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/sources.spec.ts.snap index e08f307a9..64c5e57a2 100644 --- a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/sources.spec.ts.snap +++ b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/sources.spec.ts.snap @@ -3,7 +3,7 @@ exports[`Sources: should display implementation of sources' 1`] = ` "#### Implementation of -[SomeInterface](someinterface.md).[prop](someinterface.md#prop) +[SomeInterface](SomeInterface.md).[prop](SomeInterface.md#prop) #### Defined in @@ -14,7 +14,7 @@ sources.ts:6 exports[`Sources: should display inherited sources' 1`] = ` "#### Inherited from -[SomeClass](../classes/someclass.md).[prop](../classes/someclass.md#prop) +[SomeClass](../classes/SomeClass.md).[prop](../classes/SomeClass.md#prop) #### Defined in @@ -25,7 +25,7 @@ sources.ts:2 exports[`Sources: should display overide sources' 1`] = ` "#### Overrides -[SomeClass](../classes/someclass.md).[prop](../classes/someclass.md#prop) +[SomeClass](../classes/SomeClass.md).[prop](../classes/SomeClass.md#prop) #### Defined in diff --git a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/theme.spec.ts.snap b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/theme.spec.ts.snap index 4c0b8cf77..19db57283 100644 --- a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/theme.spec.ts.snap +++ b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/theme.spec.ts.snap @@ -5,28 +5,28 @@ Array [ "modules.md", "index.md", "modules/breadcrumbs.md", - "classes/breadcrumbs.breadcrumbs-1.md", - "classes/breadcrumbs.breadcrumbs-1.md#constructor", - "classes/breadcrumbs.breadcrumbs-1.md#somemethod", + "classes/breadcrumbs.Breadcrumbs.md", + "classes/breadcrumbs.Breadcrumbs.md#constructor", + "classes/breadcrumbs.Breadcrumbs.md#somemethod", "modules/theme.md", "modules/theme.md#declarationitema", "modules/theme.md#declarationitemb", "modules/theme.md#functionitema", "modules/theme.md#functionitemb", - "modules/theme.namespacea.md", - "classes/theme.namespacea.somenestedclass.md", - "classes/theme.namespacea.somenestedclass.md#constructor", - "modules/theme.namespaceb.md", - "enums/theme.enumitema.md", - "enums/theme.enumitemb.md", - "classes/theme.classitema.md", - "classes/theme.classitema.md#constructor", - "classes/theme.classitemb.md", - "classes/theme.classitemb.md#constructor", - "interfaces/theme.interfaceitema.md", - "interfaces/theme.interfaceitema.md#prop", - "interfaces/theme.interfaceitemb.md", - "interfaces/theme.interfaceitemb.md#prop", + "modules/theme.namespaceA.md", + "classes/theme.namespaceA.SomeNestedClass.md", + "classes/theme.namespaceA.SomeNestedClass.md#constructor", + "modules/theme.namespaceB.md", + "enums/theme.enumItemA.md", + "enums/theme.enumItemB.md", + "classes/theme.ClassItemA.md", + "classes/theme.ClassItemA.md#constructor", + "classes/theme.ClassItemB.md", + "classes/theme.ClassItemB.md#constructor", + "interfaces/theme.InterfaceItemA.md", + "interfaces/theme.InterfaceItemA.md#prop", + "interfaces/theme.InterfaceItemB.md", + "interfaces/theme.InterfaceItemB.md#prop", ] `; @@ -35,28 +35,28 @@ Array [ "modules.md", "README.md", "modules/breadcrumbs.md", - "classes/breadcrumbs-breadcrumbs-1.md", - "classes/breadcrumbs-breadcrumbs-1.md#constructor", - "classes/breadcrumbs-breadcrumbs-1.md#somemethod", + "classes/breadcrumbs-Breadcrumbs.md", + "classes/breadcrumbs-Breadcrumbs.md#constructor", + "classes/breadcrumbs-Breadcrumbs.md#somemethod", "modules/theme.md", "modules/theme.md#declarationitema", "modules/theme.md#declarationitemb", "modules/theme.md#functionitema", "modules/theme.md#functionitemb", - "modules/theme-namespacea.md", - "classes/theme-namespacea-somenestedclass.md", - "classes/theme-namespacea-somenestedclass.md#constructor", - "modules/theme-namespaceb.md", - "enums/theme-enumitema.md", - "enums/theme-enumitemb.md", - "classes/theme-classitema.md", - "classes/theme-classitema.md#constructor", - "classes/theme-classitemb.md", - "classes/theme-classitemb.md#constructor", - "interfaces/theme-interfaceitema.md", - "interfaces/theme-interfaceitema.md#prop", - "interfaces/theme-interfaceitemb.md", - "interfaces/theme-interfaceitemb.md#prop", + "modules/theme-namespaceA.md", + "classes/theme-namespaceA-SomeNestedClass.md", + "classes/theme-namespaceA-SomeNestedClass.md#constructor", + "modules/theme-namespaceB.md", + "enums/theme-enumItemA.md", + "enums/theme-enumItemB.md", + "classes/theme-ClassItemA.md", + "classes/theme-ClassItemA.md#constructor", + "classes/theme-ClassItemB.md", + "classes/theme-ClassItemB.md#constructor", + "interfaces/theme-InterfaceItemA.md", + "interfaces/theme-InterfaceItemA.md#prop", + "interfaces/theme-InterfaceItemB.md", + "interfaces/theme-InterfaceItemB.md#prop", ] `; @@ -193,13 +193,13 @@ exports[`Theme: (getNavigation) should getNavigation' 1`] = ` \\"children\\": [ { \\"title\\": \\"namespaceA\\", - \\"url\\": \\"modules/namespacea.md\\", + \\"url\\": \\"modules/namespaceA.md\\", \\"isLabel\\": true, \\"children\\": [] }, { \\"title\\": \\"namespaceB\\", - \\"url\\": \\"modules/namespaceb.md\\", + \\"url\\": \\"modules/namespaceB.md\\", \\"isLabel\\": true, \\"children\\": [] } @@ -212,13 +212,13 @@ exports[`Theme: (getNavigation) should getNavigation' 1`] = ` \\"children\\": [ { \\"title\\": \\"enumItemA\\", - \\"url\\": \\"enums/enumitema.md\\", + \\"url\\": \\"enums/enumItemA.md\\", \\"isLabel\\": true, \\"children\\": [] }, { \\"title\\": \\"enumItemB\\", - \\"url\\": \\"enums/enumitemb.md\\", + \\"url\\": \\"enums/enumItemB.md\\", \\"isLabel\\": true, \\"children\\": [] } @@ -231,19 +231,19 @@ exports[`Theme: (getNavigation) should getNavigation' 1`] = ` \\"children\\": [ { \\"title\\": \\"ClassItemA\\", - \\"url\\": \\"classes/classitema.md\\", + \\"url\\": \\"classes/ClassItemA.md\\", \\"isLabel\\": true, \\"children\\": [] }, { \\"title\\": \\"ClassItemB\\", - \\"url\\": \\"classes/classitemb.md\\", + \\"url\\": \\"classes/ClassItemB.md\\", \\"isLabel\\": true, \\"children\\": [] }, { \\"title\\": \\"namespaceA.SomeNestedClass\\", - \\"url\\": \\"classes/namespacea.somenestedclass.md\\", + \\"url\\": \\"classes/namespaceA.SomeNestedClass.md\\", \\"isLabel\\": true, \\"children\\": [] } @@ -256,13 +256,13 @@ exports[`Theme: (getNavigation) should getNavigation' 1`] = ` \\"children\\": [ { \\"title\\": \\"InterfaceItemA\\", - \\"url\\": \\"interfaces/interfaceitema.md\\", + \\"url\\": \\"interfaces/InterfaceItemA.md\\", \\"isLabel\\": true, \\"children\\": [] }, { \\"title\\": \\"InterfaceItemB\\", - \\"url\\": \\"interfaces/interfaceitemb.md\\", + \\"url\\": \\"interfaces/InterfaceItemB.md\\", \\"isLabel\\": true, \\"children\\": [] } @@ -277,28 +277,28 @@ Array [ "modules.md", "README.md", "modules/breadcrumbs.md", - "classes/breadcrumbs.breadcrumbs-1.md", - "classes/breadcrumbs.breadcrumbs-1.md#constructor", - "classes/breadcrumbs.breadcrumbs-1.md#somemethod", + "classes/breadcrumbs.Breadcrumbs.md", + "classes/breadcrumbs.Breadcrumbs.md#constructor", + "classes/breadcrumbs.Breadcrumbs.md#somemethod", "modules/theme.md", - "modules/theme.namespacea.md", - "classes/theme.namespacea.somenestedclass.md", - "classes/theme.namespacea.somenestedclass.md#constructor", - "modules/theme.namespaceb.md", - "enums/theme.enumitema.md", - "enums/theme.enumitemb.md", - "classes/theme.classitema.md", - "classes/theme.classitema.md#constructor", - "classes/theme.classitemb.md", - "classes/theme.classitemb.md#constructor", - "interfaces/theme.interfaceitema.md", - "interfaces/theme.interfaceitema.md#prop", - "interfaces/theme.interfaceitemb.md", - "interfaces/theme.interfaceitemb.md#prop", - "variables/theme.declarationitema.md", - "variables/theme.declarationitemb.md", - "functions/theme.functionitema.md", - "functions/theme.functionitemb.md", + "modules/theme.namespaceA.md", + "classes/theme.namespaceA.SomeNestedClass.md", + "classes/theme.namespaceA.SomeNestedClass.md#constructor", + "modules/theme.namespaceB.md", + "enums/theme.enumItemA.md", + "enums/theme.enumItemB.md", + "classes/theme.ClassItemA.md", + "classes/theme.ClassItemA.md#constructor", + "classes/theme.ClassItemB.md", + "classes/theme.ClassItemB.md#constructor", + "interfaces/theme.InterfaceItemA.md", + "interfaces/theme.InterfaceItemA.md#prop", + "interfaces/theme.InterfaceItemB.md", + "interfaces/theme.InterfaceItemB.md#prop", + "variables/theme.declarationItemA.md", + "variables/theme.declarationItemB.md", + "functions/theme.functionItemA.md", + "functions/theme.functionItemB.md", ] `; @@ -306,28 +306,28 @@ exports[`Theme: (getUrls) should getUrls with readme 'none' 1`] = ` Array [ "README.md", "modules/breadcrumbs.md", - "classes/breadcrumbs.breadcrumbs-1.md", - "classes/breadcrumbs.breadcrumbs-1.md#constructor", - "classes/breadcrumbs.breadcrumbs-1.md#somemethod", + "classes/breadcrumbs.Breadcrumbs.md", + "classes/breadcrumbs.Breadcrumbs.md#constructor", + "classes/breadcrumbs.Breadcrumbs.md#somemethod", "modules/theme.md", "modules/theme.md#declarationitema", "modules/theme.md#declarationitemb", "modules/theme.md#functionitema", "modules/theme.md#functionitemb", - "modules/theme.namespacea.md", - "classes/theme.namespacea.somenestedclass.md", - "classes/theme.namespacea.somenestedclass.md#constructor", - "modules/theme.namespaceb.md", - "enums/theme.enumitema.md", - "enums/theme.enumitemb.md", - "classes/theme.classitema.md", - "classes/theme.classitema.md#constructor", - "classes/theme.classitemb.md", - "classes/theme.classitemb.md#constructor", - "interfaces/theme.interfaceitema.md", - "interfaces/theme.interfaceitema.md#prop", - "interfaces/theme.interfaceitemb.md", - "interfaces/theme.interfaceitemb.md#prop", + "modules/theme.namespaceA.md", + "classes/theme.namespaceA.SomeNestedClass.md", + "classes/theme.namespaceA.SomeNestedClass.md#constructor", + "modules/theme.namespaceB.md", + "enums/theme.enumItemA.md", + "enums/theme.enumItemB.md", + "classes/theme.ClassItemA.md", + "classes/theme.ClassItemA.md#constructor", + "classes/theme.ClassItemB.md", + "classes/theme.ClassItemB.md#constructor", + "interfaces/theme.InterfaceItemA.md", + "interfaces/theme.InterfaceItemA.md#prop", + "interfaces/theme.InterfaceItemB.md", + "interfaces/theme.InterfaceItemB.md#prop", ] `; @@ -336,27 +336,27 @@ Array [ "modules.md", "README.md", "modules/breadcrumbs.md", - "classes/breadcrumbs.breadcrumbs-1.md", - "classes/breadcrumbs.breadcrumbs-1.md#constructor", - "classes/breadcrumbs.breadcrumbs-1.md#somemethod", + "classes/breadcrumbs.Breadcrumbs.md", + "classes/breadcrumbs.Breadcrumbs.md#constructor", + "classes/breadcrumbs.Breadcrumbs.md#somemethod", "modules/theme.md", "modules/theme.md#declarationitema", "modules/theme.md#declarationitemb", "modules/theme.md#functionitema", "modules/theme.md#functionitemb", - "modules/theme.namespacea.md", - "classes/theme.namespacea.somenestedclass.md", - "classes/theme.namespacea.somenestedclass.md#constructor", - "modules/theme.namespaceb.md", - "enums/theme.enumitema.md", - "enums/theme.enumitemb.md", - "classes/theme.classitema.md", - "classes/theme.classitema.md#constructor", - "classes/theme.classitemb.md", - "classes/theme.classitemb.md#constructor", - "interfaces/theme.interfaceitema.md", - "interfaces/theme.interfaceitema.md#prop", - "interfaces/theme.interfaceitemb.md", - "interfaces/theme.interfaceitemb.md#prop", + "modules/theme.namespaceA.md", + "classes/theme.namespaceA.SomeNestedClass.md", + "classes/theme.namespaceA.SomeNestedClass.md#constructor", + "modules/theme.namespaceB.md", + "enums/theme.enumItemA.md", + "enums/theme.enumItemB.md", + "classes/theme.ClassItemA.md", + "classes/theme.ClassItemA.md#constructor", + "classes/theme.ClassItemB.md", + "classes/theme.ClassItemB.md#constructor", + "interfaces/theme.InterfaceItemA.md", + "interfaces/theme.InterfaceItemA.md#prop", + "interfaces/theme.InterfaceItemB.md", + "interfaces/theme.InterfaceItemB.md#prop", ] `; diff --git a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/toc.spec.ts.snap b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/toc.spec.ts.snap index a07445ba8..feb7a2364 100644 --- a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/toc.spec.ts.snap +++ b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/toc.spec.ts.snap @@ -5,11 +5,11 @@ exports[`TOC: (default) should display toc for class' 1`] = ` ### Constructors -- [constructor](breadcrumbs.md#constructor) +- [constructor](Breadcrumbs.md#constructor) ### Methods -- [someMethod](breadcrumbs.md#somemethod) +- [someMethod](Breadcrumbs.md#somemethod) " `; @@ -18,10 +18,10 @@ exports[`TOC: (default) should display toc for module' 1`] = ` ### Constructors -- [constructor](breadcrumbs.md#constructor) +- [constructor](Breadcrumbs.md#constructor) ### Methods -- [someMethod](breadcrumbs.md#somemethod) +- [someMethod](Breadcrumbs.md#somemethod) " `; diff --git a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/types.spec.ts.snap b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/types.spec.ts.snap index 715eb9f6b..077389b3a 100644 --- a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/types.spec.ts.snap +++ b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/types.spec.ts.snap @@ -5,7 +5,7 @@ exports[`Types: should compile 'array' type' 1`] = ` " `; -exports[`Types: should compile 'intersection' type' 1`] = `"[\`IntersectionClassA\`](intersectionclassa.md) & [\`IntersectionClassB\`](intersectionclassb.md)"`; +exports[`Types: should compile 'intersection' type' 1`] = `"[\`IntersectionClassA\`](IntersectionClassA.md) & [\`IntersectionClassB\`](IntersectionClassB.md)"`; exports[`Types: should compile 'stringLiteral' type' 1`] = ` "\`\`\\"blue\\"\`\` diff --git a/packages/typedoc-plugin-markdown/test/specs/breadcrumbs.spec.ts b/packages/typedoc-plugin-markdown/test/specs/breadcrumbs.spec.ts index 7bccb466e..581bca4ba 100644 --- a/packages/typedoc-plugin-markdown/test/specs/breadcrumbs.spec.ts +++ b/packages/typedoc-plugin-markdown/test/specs/breadcrumbs.spec.ts @@ -4,16 +4,13 @@ import { Reflection } from 'typedoc'; import { TestApp } from '../test-app'; describe(`Breadcrumbs:`, () => { - let testApp: TestApp; let moduleReflection: Reflection; let classReflection: Reflection; - beforeAll(() => { - testApp = new TestApp(['breadcrumbs.ts']); - }); - describe(`(with readme)`, () => { + let testApp: TestApp; beforeAll(async () => { + testApp = new TestApp(['breadcrumbs.ts']); await testApp.bootstrap(); moduleReflection = testApp.project.children[0]; classReflection = testApp.project.findReflectionByName('Breadcrumbs'); @@ -59,7 +56,9 @@ describe(`Breadcrumbs:`, () => { }); }); describe(`(without readme)`, () => { + let testApp: TestApp; beforeAll(async () => { + testApp = new TestApp(['breadcrumbs.ts']); await testApp.bootstrap({ readme: 'none' }); moduleReflection = testApp.project.children[0]; classReflection = testApp.project.findReflectionByName('Breadcrumbs'); diff --git a/packages/typedoc-plugin-markdown/test/specs/generics.spec.ts b/packages/typedoc-plugin-markdown/test/specs/generics.spec.ts index 49def848a..aca20c594 100644 --- a/packages/typedoc-plugin-markdown/test/specs/generics.spec.ts +++ b/packages/typedoc-plugin-markdown/test/specs/generics.spec.ts @@ -10,12 +10,12 @@ describe(`Generics:`, () => { let reflectionTemplate: Handlebars.TemplateDelegate; beforeAll(() => { - testApp = new TestApp(['generics.ts']); partial = TestApp.getPartial('member.signature'); declarationPartial = TestApp.getPartial('member.declaration'); }); beforeEach(async () => { + testApp = new TestApp(['generics.ts']); await testApp.bootstrap(); TestApp.stubPartials([ 'comment', diff --git a/packages/typedoc-plugin-markdown/test/specs/options.spec.ts b/packages/typedoc-plugin-markdown/test/specs/options.spec.ts index b61f733aa..b15b9181b 100644 --- a/packages/typedoc-plugin-markdown/test/specs/options.spec.ts +++ b/packages/typedoc-plugin-markdown/test/specs/options.spec.ts @@ -3,14 +3,10 @@ import * as Handlebars from 'handlebars'; import { TestApp } from '../test-app'; describe(`Options:`, () => { - let testApp: TestApp; - - beforeAll(() => { - testApp = new TestApp(['breadcrumbs.ts']); - }); - describe(`(defaults)`, () => { + let testApp: TestApp; beforeAll(async () => { + testApp = new TestApp(['breadcrumbs.ts']); await testApp.bootstrap({}); }); @@ -39,7 +35,9 @@ describe(`Options:`, () => { }); describe(`(with plugin options)`, () => { + let testApp: TestApp; beforeAll(async () => { + testApp = new TestApp(['breadcrumbs.ts']); await testApp.bootstrap({ publicPath: 'test-public-path', namedAnchors: true, diff --git a/packages/typedoc-plugin-markdown/test/specs/plugin.spec.ts b/packages/typedoc-plugin-markdown/test/specs/plugin.spec.ts index 3967e494f..daa913066 100644 --- a/packages/typedoc-plugin-markdown/test/specs/plugin.spec.ts +++ b/packages/typedoc-plugin-markdown/test/specs/plugin.spec.ts @@ -5,14 +5,13 @@ import MarkdownTheme from 'typedoc-plugin-markdown/dist/theme'; import { TestApp } from '../test-app'; describe(`Plugin:`, () => { - let testApp: TestApp; const defaultMarkdownThemePath = path.resolve(__dirname, '..', '..', 'dist'); - beforeAll(() => { - testApp = new TestApp(['theme.ts']); - }); - describe(`(load theme)`, () => { + let testApp: TestApp; + beforeEach(() => { + testApp = new TestApp(['theme.ts']); + }); afterEach(() => { testApp.app.renderer.theme = undefined; testApp.app.renderer.removeComponent('theme'); @@ -21,7 +20,6 @@ describe(`Plugin:`, () => { test(`should load markdown theme by default`, async () => { await testApp.bootstrap(); expect(testApp.theme instanceof MarkdownTheme).toBeTruthy(); - expect(testApp.theme.basePath).toEqual(defaultMarkdownThemePath); }); test(`should load custom markdown theme by path'`, async () => { @@ -35,13 +33,11 @@ describe(`Plugin:`, () => { theme: customThemePath, }); expect(testApp.theme instanceof MarkdownTheme).toBeTruthy(); - expect(testApp.theme.basePath).toEqual(customThemePath); }); - test(`should load markdown theme with unrecognised theme'`, async () => { + test(`should not load markdown theme with unrecognised theme'`, async () => { await testApp.bootstrap({ theme: 'minimal' }); - expect(testApp.theme instanceof MarkdownTheme).toBeTruthy(); - expect(testApp.theme.basePath).toEqual(defaultMarkdownThemePath); + expect(testApp.theme instanceof MarkdownTheme).toBeFalsy(); }); }); }); diff --git a/packages/typedoc-plugin-markdown/test/specs/reflections.spec.ts b/packages/typedoc-plugin-markdown/test/specs/reflections.spec.ts index cce431f27..7aa45a18b 100644 --- a/packages/typedoc-plugin-markdown/test/specs/reflections.spec.ts +++ b/packages/typedoc-plugin-markdown/test/specs/reflections.spec.ts @@ -3,15 +3,12 @@ import * as Handlebars from 'handlebars'; import { TestApp } from '../test-app'; describe(`Reflections:`, () => { - let testApp: TestApp; let reflectionTemplate: Handlebars.TemplateDelegate; - beforeAll(() => { - testApp = new TestApp(['reflections.ts']); - }); - describe(`(header)`, () => { + let testApp: TestApp; beforeEach(async () => { + testApp = new TestApp(['reflections.ts']); await testApp.bootstrap({ hideBreadcrumbs: false, hidePageTitle: true, @@ -31,7 +28,9 @@ describe(`Reflections:`, () => { }); describe(`(template)`, () => { + let testApp: TestApp; beforeEach(async () => { + testApp = new TestApp(['reflections.ts']); await testApp.bootstrap({ hideBreadcrumbs: true, hidePageTitle: false, diff --git a/packages/typedoc-plugin-markdown/test/specs/theme.spec.ts b/packages/typedoc-plugin-markdown/test/specs/theme.spec.ts index 2fff40276..8a9be31f9 100644 --- a/packages/typedoc-plugin-markdown/test/specs/theme.spec.ts +++ b/packages/typedoc-plugin-markdown/test/specs/theme.spec.ts @@ -3,18 +3,16 @@ import * as fs from 'fs'; import { TestApp } from '../test-app'; describe(`Theme:`, () => { - let testApp: TestApp; - describe(`(getNavigation)`, () => { test(`should getNavigation'`, async () => { - testApp = new TestApp(['theme.ts']); + const testApp = new TestApp(['theme.ts']); await testApp.bootstrap(); const navigation = testApp.theme.getNavigation(testApp.project); expect(JSON.stringify(navigation, null, 1)).toMatchSnapshot(); }); test(`should getNavigation for exports'`, async () => { - testApp = new TestApp(['theme.ts']); + const testApp = new TestApp(['theme.ts']); await testApp.bootstrap(); const navigation = testApp.theme .getNavigation(testApp.project) @@ -23,7 +21,7 @@ describe(`Theme:`, () => { }); test(`should getNavigation for exports with readme=none'`, async () => { - testApp = new TestApp(['theme.ts']); + const testApp = new TestApp(['theme.ts']); await testApp.bootstrap({ readme: 'none' }); const navigation = testApp.theme .getNavigation(testApp.project) @@ -32,7 +30,7 @@ describe(`Theme:`, () => { }); test(`should getNavigation for modules'`, async () => { - testApp = new TestApp(['breadcrumbs.ts', 'theme.ts']); + const testApp = new TestApp(['breadcrumbs.ts', 'theme.ts']); await testApp.bootstrap(); const navigation = testApp.theme .getNavigation(testApp.project) @@ -41,7 +39,7 @@ describe(`Theme:`, () => { }); test(`should getNavigation for modules with readme=none'`, async () => { - testApp = new TestApp(['breadcrumbs.ts', 'theme.ts']); + const testApp = new TestApp(['breadcrumbs.ts', 'theme.ts']); await testApp.bootstrap({ readme: 'none' }); const navigation = testApp.theme .getNavigation(testApp.project) @@ -51,22 +49,23 @@ describe(`Theme:`, () => { }); describe(`(getUrls)`, () => { - beforeAll(() => { - testApp = new TestApp(['breadcrumbs.ts', 'theme.ts']); - }); + beforeAll(() => {}); test(`should getUrls'`, async () => { + const testApp = new TestApp(['breadcrumbs.ts', 'theme.ts']); await testApp.bootstrap(); const urlMappings = testApp.theme.getUrls(testApp.project); expect(TestApp.getExpectedUrls(urlMappings)).toMatchSnapshot(); }); test(`should getUrls with 'allReflectionsHaveOwnDocument' set`, async () => { + const testApp = new TestApp(['breadcrumbs.ts', 'theme.ts']); await testApp.bootstrap({ allReflectionsHaveOwnDocument: true }); const urlMappings = testApp.theme.getUrls(testApp.project); expect(TestApp.getExpectedUrls(urlMappings)).toMatchSnapshot(); }); test(`should getUrls with readme 'none'`, async () => { + const testApp = new TestApp(['breadcrumbs.ts', 'theme.ts']); await testApp.bootstrap({ readme: 'none' }); const urlMappings = testApp.theme.getUrls(testApp.project); expect(TestApp.getExpectedUrls(urlMappings)).toMatchSnapshot(); @@ -74,10 +73,8 @@ describe(`Theme:`, () => { }); describe(`(filenameSeparator)`, () => { - beforeAll(() => { - testApp = new TestApp(['breadcrumbs.ts', 'theme.ts']); - }); test(`should getUrls with custom separator'`, async () => { + const testApp = new TestApp(['breadcrumbs.ts', 'theme.ts']); await testApp.bootstrap({ filenameSeparator: '-' }); const urlMappings = testApp.theme.getUrls(testApp.project); expect(TestApp.getExpectedUrls(urlMappings)).toMatchSnapshot(); @@ -86,6 +83,7 @@ describe(`Theme:`, () => { describe(`(entryDocument)`, () => { test(`should getUrls with custom entryDocument'`, async () => { + const testApp = new TestApp(['breadcrumbs.ts', 'theme.ts']); await testApp.bootstrap({ entryDocument: 'index.md' }); const urlMappings = testApp.theme.getUrls(testApp.project); expect(TestApp.getExpectedUrls(urlMappings)).toMatchSnapshot(); @@ -93,6 +91,7 @@ describe(`Theme:`, () => { }); describe(`(isOutputDirectory)`, () => { + let testApp: TestApp; beforeAll(() => { testApp = new TestApp(['breadcrumbs.ts', 'theme.ts']); }); diff --git a/packages/typedoc-plugin-markdown/test/specs/toc.spec.ts b/packages/typedoc-plugin-markdown/test/specs/toc.spec.ts index 5a3511b64..a688ec05d 100644 --- a/packages/typedoc-plugin-markdown/test/specs/toc.spec.ts +++ b/packages/typedoc-plugin-markdown/test/specs/toc.spec.ts @@ -4,16 +4,13 @@ import { Reflection } from 'typedoc'; import { TestApp } from '../test-app'; describe(`TOC:`, () => { - let testApp: TestApp; let moduleReflection: Reflection; let classReflection: Reflection; - beforeAll(() => { - testApp = new TestApp(['breadcrumbs.ts']); - }); - describe(`(default)`, () => { + let testApp: TestApp; beforeAll(async () => { + testApp = new TestApp(['breadcrumbs.ts']); await testApp.bootstrap(); moduleReflection = testApp.project.children[0]; classReflection = testApp.project.findReflectionByName('Breadcrumbs'); @@ -32,7 +29,9 @@ describe(`TOC:`, () => { }); }); describe(`(hideInPageToc)`, () => { + let testApp: TestApp; beforeAll(async () => { + testApp = new TestApp(['breadcrumbs.ts']); await testApp.bootstrap({ hideInPageTOC: true }); moduleReflection = testApp.project.children[0]; classReflection = testApp.project.findReflectionByName('Breadcrumbs'); diff --git a/packages/typedoc-plugin-markdown/test/test-app.ts b/packages/typedoc-plugin-markdown/test/test-app.ts index 5bf73eca0..55e662dd0 100644 --- a/packages/typedoc-plugin-markdown/test/test-app.ts +++ b/packages/typedoc-plugin-markdown/test/test-app.ts @@ -5,7 +5,6 @@ import * as Handlebars from 'handlebars'; import * as tmp from 'tmp'; import { Application, - ArgumentsReader, DeclarationReflection, ProjectReflection, Renderer, @@ -14,6 +13,7 @@ import { UrlMapping, } from 'typedoc'; +import { load } from '../src/index'; import MarkdownTheme from '../src/theme'; tmp.setGracefulCleanup(); @@ -108,17 +108,15 @@ export class TestApp { path.join(__dirname, './stubs/src/' + inputFile), ) : ['./test/stubs/src']; - this.app.options.addReader(new ArgumentsReader(0)); + load(this.app); this.app.options.addReader(new TypeDocReader()); this.app.options.addReader(new TSConfigReader()); - this.app.options.addReader(new ArgumentsReader(300)); } async bootstrap(options: any = {}) { this.app.bootstrap({ logger: 'none', entryPoints: this.entryPoints, - plugin: [path.join(__dirname, '../dist/index')], tsconfig: path.join(__dirname, 'stubs', 'tsconfig.json'), ...options, });