-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
322 additions
and
227 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
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
84 changes: 84 additions & 0 deletions
84
packages/typedoc-plugin-markdown/src/partials/member.inheritance.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { | ||
ArrayType, | ||
DeclarationReflection, | ||
ReferenceType, | ||
SignatureReflection, | ||
} from 'typedoc'; | ||
import { backTicks, heading, link } from '../support/els'; | ||
import { MarkdownThemeRenderContext } from '../theme-render-context'; | ||
|
||
import { escapeChars } from '../support/utils'; | ||
|
||
export function inheritance( | ||
context: MarkdownThemeRenderContext, | ||
reflection: DeclarationReflection | SignatureReflection, | ||
headingLevel: number, | ||
) { | ||
const md: string[] = []; | ||
|
||
if (reflection.implementationOf) { | ||
md.push(heading(headingLevel, 'Implementation of')); | ||
md.push(typeAndParent(context, reflection.implementationOf)); | ||
} | ||
|
||
if (reflection.inheritedFrom) { | ||
md.push(heading(headingLevel, 'Inherited from')); | ||
md.push(typeAndParent(context, reflection.inheritedFrom)); | ||
} | ||
|
||
if (reflection.overwrites) { | ||
md.push(heading(headingLevel, 'Overrides')); | ||
md.push(typeAndParent(context, reflection.overwrites)); | ||
} | ||
|
||
return md.join('\n\n'); | ||
} | ||
|
||
const typeAndParent = ( | ||
context: MarkdownThemeRenderContext, | ||
props: ArrayType | ReferenceType, | ||
) => { | ||
const getUrl = (name: string, url: string) => | ||
link(backTicks(name), context.relativeURL(url)); | ||
|
||
if (props) { | ||
if ('elementType' in props) { | ||
return typeAndParent(context, props.elementType as any) + '[]'; | ||
} else { | ||
if (props.reflection) { | ||
const md: string[] = []; | ||
if (props.reflection instanceof SignatureReflection) { | ||
if (props.reflection.parent?.parent?.url) { | ||
md.push( | ||
getUrl( | ||
props.reflection.parent.parent.name, | ||
props.reflection.parent.parent.url, | ||
), | ||
); | ||
if (props.reflection.parent.url) { | ||
md.push( | ||
getUrl( | ||
props.reflection.parent.name, | ||
props.reflection.parent.url, | ||
), | ||
); | ||
} | ||
} | ||
} else { | ||
if (props.reflection.parent?.url) { | ||
md.push( | ||
getUrl(props.reflection.parent.name, props.reflection.parent.url), | ||
); | ||
if (props.reflection.url) { | ||
md.push(getUrl(props.reflection.name, props.reflection.url)); | ||
} | ||
} | ||
} | ||
return md.length > 0 ? md.join('.') : props.name; | ||
} else { | ||
return escapeChars(props.toString()); | ||
} | ||
} | ||
} | ||
return 'void'; | ||
}; |
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
99 changes: 12 additions & 87 deletions
99
packages/typedoc-plugin-markdown/src/partials/member.sources.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,97 +1,22 @@ | ||
import { | ||
ArrayType, | ||
DeclarationReflection, | ||
ReferenceType, | ||
SignatureReflection, | ||
} from 'typedoc'; | ||
import { heading, link } from '../support/els'; | ||
import { DeclarationReflection, SignatureReflection } from 'typedoc'; | ||
import { link } from '../support/els'; | ||
import { MarkdownThemeRenderContext } from '../theme-render-context'; | ||
|
||
import { escapeChars } from '../support/utils'; | ||
|
||
export function sources( | ||
context: MarkdownThemeRenderContext, | ||
reflection: DeclarationReflection | SignatureReflection, | ||
headingLevel: number, | ||
) { | ||
const md: string[] = []; | ||
|
||
if (reflection.implementationOf) { | ||
md.push(heading(headingLevel, 'Implementation of')); | ||
md.push(typeAndParent(context, reflection.implementationOf)); | ||
} | ||
|
||
if (reflection.inheritedFrom) { | ||
md.push(heading(headingLevel, 'Inherited from')); | ||
md.push(typeAndParent(context, reflection.inheritedFrom)); | ||
} | ||
|
||
if (reflection.overwrites) { | ||
md.push(heading(headingLevel, 'Overrides')); | ||
md.push(typeAndParent(context, reflection.overwrites)); | ||
} | ||
|
||
if (reflection.sources) { | ||
const definedInMd = [heading(headingLevel, 'Defined in')]; | ||
|
||
reflection.sources.forEach((source) => { | ||
if (source.url) { | ||
definedInMd.push( | ||
link(`${escapeChars(source.fileName)}:${source.line}`, source.url), | ||
); | ||
} else { | ||
definedInMd.push(`${escapeChars(source.fileName)}:${source.line}`); | ||
} | ||
}); | ||
md.push(definedInMd.join('\n')); | ||
} | ||
return md.join('\n\n'); | ||
} | ||
|
||
const typeAndParent = ( | ||
context: MarkdownThemeRenderContext, | ||
props: ArrayType | ReferenceType, | ||
) => { | ||
const getUrl = (name: string, url: string) => | ||
`[${name}](${context.relativeURL(url)})`; | ||
if (props) { | ||
if ('elementType' in props) { | ||
return typeAndParent(context, props.elementType as any) + '[]'; | ||
const md = ['Defined in:']; | ||
reflection.sources?.forEach((source) => { | ||
if (source.url) { | ||
md.push( | ||
link(`${escapeChars(source.fileName)}:${source.line}`, source.url), | ||
); | ||
} else { | ||
if (props.reflection) { | ||
const md: string[] = []; | ||
if (props.reflection instanceof SignatureReflection) { | ||
if (props.reflection.parent?.parent?.url) { | ||
md.push( | ||
getUrl( | ||
props.reflection.parent.parent.name, | ||
props.reflection.parent.parent.url, | ||
), | ||
); | ||
if (props.reflection.parent.url) { | ||
md.push( | ||
getUrl( | ||
props.reflection.parent.name, | ||
props.reflection.parent.url, | ||
), | ||
); | ||
} | ||
} | ||
} else { | ||
if (props.reflection.parent?.url) { | ||
md.push( | ||
getUrl(props.reflection.parent.name, props.reflection.parent.url), | ||
); | ||
if (props.reflection.url) { | ||
md.push(getUrl(props.reflection.name, props.reflection.url)); | ||
} | ||
} | ||
} | ||
return md.length > 0 ? md.join('.') : props.name; | ||
} else { | ||
return escapeChars(props.toString()); | ||
} | ||
md.push(`${escapeChars(source.fileName)}:${source.line}`); | ||
} | ||
} | ||
return 'void'; | ||
}; | ||
}); | ||
return md.join(' '); | ||
} |
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.