Typedoc: Custom theme with theme.js file

Created on 17 Jun 2016  Â·  3Comments  Â·  Source: TypeStrong/typedoc

I would like to create a custom theme that generates a single README.md file containing the entire public API for a project – suitable for small or mid-sized project on GitHub, for example. To do that, I would need to modify not just the Handlebars templates, but the theme.js file. This is apparently possible according to the documentation, but the part of the code that allows this to happen is commented out. Is there a reason for this? Or am I missing something?

If I'm not totally confused about this, I think there are three ways in which creating a custom theme.js file could be made easier:

  1. Rather than evaluating theme.js, it should be imported with a require() call. The creator of the theme could then import the relevant classes (e.g. DefaultTheme, Renderer) from a single module. This would also make it possible to extend any theme – not just the default theme – which would resolve issue #36.
  2. The TypeDoc API – along with its type declarations – should be exposed. It is already documented, so exposing it should be the easy part. This should make it possible to create a theme.ts file.
  3. The themes guide in the documentation should be updated with a detailed example of creating a new theme with a theme.js or theme.ts file.

To illustrate, a theme.ts file might look like this:

// A single module exports the entire public API
import {DefaultTheme, AssetsPlugin, PageEvent} from 'typedoc/api';

// export = ... should also work for compatibility with module.exports in plain JS
export default class ReadmeTheme extends DefaultTheme {

  constructor(renderer, basePath) {
    super(renderer, basePath);

    // Remove components with the constructor to guard against typos and naming conflicts
    renderer.removeComponent(AssetsPlugin);

    this.listenTo(renderer, PageEvent.BEGIN, this.onRendererBeginPage);
  }

  // ...
}

These changes would likely be time-consuming, but I think they would make TypeDoc much more powerful. I would be happy to help with this in whatever way I can. I could even do a pull request, but I would certainly like some input first.

Thank you for this fantastic project.

Most helpful comment

:+1: I'd like to see typedoc have an out-of-box markdown output support.

All 3 comments

:+1: I'd like to see typedoc have an out-of-box markdown output support.

typedoc-md-theme no longer exists it seems

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jumpinjackie picture jumpinjackie  Â·  4Comments

Bibliofile picture Bibliofile  Â·  3Comments

nidsharm picture nidsharm  Â·  3Comments

KevinEady picture KevinEady  Â·  3Comments

unsafecode picture unsafecode  Â·  4Comments