-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(remark): refactor remark-toc implementation
- Loading branch information
Showing
18 changed files
with
155 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
// THIS FILE IS AUTO GENERATED FROM THE OPTIONS CONFIG. DO NOT EDIT DIRECTLY. | ||
import { ManuallyValidatedOption } from 'typedoc'; | ||
import { RemarkPlugin } from './types/options.js'; | ||
declare module 'typedoc' { | ||
export interface TypeDocOptionMap { | ||
defaultRemarkPlugins: { gfm: boolean; frontmatter: boolean; mdx: boolean }; | ||
remarkPlugins: ManuallyValidatedOption<Partial<any>>; | ||
remarkPlugins: ManuallyValidatedOption<RemarkPlugin[]>; | ||
remarkStringifyOptions: ManuallyValidatedOption<Record<string, any>>; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
packages/typedoc-plugin-remark/src/helpers/get-default-plugins.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,4 @@ | |
* @module | ||
*/ | ||
|
||
export * as helpers from '../helpers/add-toc.js'; | ||
export * as declarations from './declarations.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { Heading } from 'mdast'; | ||
import { DeclarationReflection, Options, ReflectionKind } from 'typedoc'; | ||
import { Node } from 'unist'; | ||
import { visit } from 'unist-util-visit'; | ||
|
||
/** | ||
* This plugin is used internally to add a toc heading as required to be present in the page when using the remark-toc plugin. | ||
*/ | ||
export default function (options: any) { | ||
const { reflection, typedocOptions, tocOptions } = options; | ||
|
||
return (tree: Node) => { | ||
// If the current page is already an index page, do nothing. | ||
if (isIndexPage(reflection, typedocOptions)) { | ||
return tree; | ||
} | ||
visit( | ||
tree, | ||
'heading', | ||
(node: Heading, index, parent: { children: Node[] }) => { | ||
if (node.depth === 2) { | ||
const newHeading: Heading = { | ||
type: 'heading', | ||
depth: 2, | ||
children: [ | ||
{ | ||
type: 'text', | ||
value: tocOptions?.heading || 'Contents', | ||
}, | ||
], | ||
}; | ||
parent?.children.splice(index, 0, newHeading); | ||
return false; | ||
} | ||
}, | ||
); | ||
}; | ||
} | ||
|
||
/** | ||
* Determine if the current page is already an index page. | ||
* - Reflection is a project and all children are modules. | ||
* - Reflection is a module and outputFileStrategy is equal to "members". | ||
*/ | ||
function isIndexPage( | ||
reflection: DeclarationReflection, | ||
typedocOptions: Options, | ||
) { | ||
if ( | ||
reflection.kind === ReflectionKind.Project && | ||
reflection.children?.every((child) => child.kind === ReflectionKind.Module) | ||
) { | ||
return true; | ||
} | ||
if ( | ||
[ReflectionKind.Project, ReflectionKind.Module].includes(reflection.kind) && | ||
typedocOptions?.getValue('outputFileStrategy') === 'members' | ||
) { | ||
return true; | ||
} | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* @module | ||
*/ | ||
|
||
export const someVariable = true; | ||
|
||
export const someFunction = (a: string, b: number) => { | ||
return true; | ||
}; | ||
|
||
export class Class { | ||
a: string; | ||
b: number; | ||
} | ||
|
||
export type SimpleTypeAlias = string | boolean; | ||
|
||
export type TypeAliasWithTypeDeclaration = { | ||
a: string; | ||
b: number; | ||
}; | ||
|
||
export interface Interface { | ||
a: string; | ||
b: number; | ||
} | ||
|
||
export enum Enum { | ||
A, | ||
B, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.