-
Hello! Thanks for working on the Typedoc 0.28 compatibility 🎉 I'm working on migrating to the latest version and do wonder how to achieve my current logic (in a less hacky way). I currently have this custom plugin. It feels hacky but it works 😅 In /**
* @param {import('typedoc-plugin-markdown').MarkdownApplication} app
*/
export function load(app) {
app.renderer.on(MarkdownRendererEvent.BEGIN, output => {
// Modify the output object
output.urls = output.urls
// Do not output README.mdx files
?.filter(e => !e.url.endsWith('README.mdx'))
.map(e => {
// Convert URLs (by default camelCase) to kebab-case
const kebabUrl = toKebabCase(e.url);
e.url = kebabUrl;
e.model.url = kebabUrl;
/**
* For the `@clerk/shared` package it outputs the hooks as for example: shared/react/hooks/use-clerk/functions/use-clerk.mdx.
* It also places the interfaces as shared/react/hooks/use-organization/interfaces/use-organization-return.mdx
* Group all those .mdx files under shared/react/hooks
*/
if (e.url.includes('shared/react/hooks')) {
e.url = e.url.replace(/\/[^/]+\/(functions|interfaces)\//, '/');
e.model.url = e.url;
}
return e;
});
});
app.renderer.on(MarkdownPageEvent.END, output => {
const fileName = output.url.split('/').pop();
const linkReplacements = getRelativeLinkReplacements();
for (const { pattern, replace } of linkReplacements) {
if (output.contents) {
output.contents = output.contents.replace(pattern, replace);
}
}
if (fileName) {
if (FILES_WITHOUT_HEADINGS.includes(fileName)) {
if (output.contents) {
// Remove any headings from the file, irrespective of the level
output.contents = output.contents.replace(/^#+\s.+/gm, '');
}
}
}
});
} My thinking is that I can extend the router defined in https://github.com/typedoc2md/typedoc-plugin-markdown/blob/main/packages/typedoc-plugin-markdown/src/router/routers/member-router.ts to override the Similar to how I can currently extend the Anyways, my ask would be: Can you add the routers to the public API or do you not want to? If not, suggestions what I should do instead? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
Hello, You are absolutely on the right lines. Rather than changing the output urls in the event, you should now create a custom router in the method you have described:
Only thing is as you mention I haven't exported the custom routers publicly so this example will not yet work. I will move this to the top of the TODO list. I also plan to support all the TypeDoc default core routers (which only require small tweak to get working). |
Beta Was this translation helpful? Give feedback.
-
Routers exposed in [email protected]. Here is a pointless example:
|
Beta Was this translation helpful? Give feedback.
-
This is so much nicer with the router class 👍 // @ts-check
import { MemberRouter } from "typedoc-plugin-markdown"
/**
* @param {string} str
*/
function toKebabCase(str) {
return str.replace(/((?<=[a-z\d])[A-Z]|(?<=[A-Z\d])[A-Z](?=[a-z]))/g, '-$1').toLowerCase();
}
/**
* @param {import('typedoc-plugin-markdown').MarkdownApplication} app
*/
export function load(app) {
app.renderer.defineRouter('clerk-router', ClerkRouter)
}
/**
* Our custom router that changes the file output
* @extends MemberRouter
*/
class ClerkRouter extends MemberRouter {
/**
* @param {import('typedoc').ProjectReflection} project
*/
buildPages(project) {
const pages = super.buildPages(project)
const modifiedPages = pages
// Do not output README files
.filter(page => !page.url.toLocaleLowerCase().endsWith('readme.mdx'))
return modifiedPages
}
/**
* @param {import('typedoc').Reflection} reflection
*/
getIdealBaseName(reflection) {
const original = super.getIdealBaseName(reflection)
// Convert URLs (by default camelCase) to kebab-case
const kebabCase = toKebabCase(original)
return kebabCase
}
} |
Beta Was this translation helpful? Give feedback.
Routers exposed in [email protected].
Here is a pointless example: