It would be convenient to be able to specify a js file on the command line which contains handlebars helpers. Much like is included in the typedoc/src/td/output/plugins/MarkedPlugin.ts file on lines 90-95.
Handlebars.registerHelper('markdown', function(arg:any) { return that.parseMarkdown(arg.fn(this), this); });
Handlebars.registerHelper('compact', function(arg:any) { return that.getCompact(arg.fn(this)); });
Handlebars.registerHelper('relativeURL', (url:string) => this.getRelativeUrl(url));
Handlebars.registerHelper('wbr', (str:string) => this.getWordBreaks(str));
Handlebars.registerHelper('ifCond', function(v1, operator, v2, options) { return that.getIfCond(v1, operator, v2, options, this) });
Handlebars.registerHelper('ifSignature', function(obj:any, arg:any) { return obj instanceof models.SignatureReflection ? arg.fn(this) : arg.inverse(this) });
This would allow for further customization of the themes. I would be able to pass in my own helpers.
Hi Mike, nice to hear from you. We have already changed this for the next version of TypeDoc. v0.4 will automatically load all helpers stored in the /helpers/ directory of a theme.
Thanks, Sebastian!
I figured this out.
helpers directory under your desired theme, e.g. defaultTo export one or more helpers in one file you can do:
default/helpers/ifEquals.js
module.exports = {
ifEquals: function ( value1, value2, options ) {
return value1 === value2 ? options.fn(this) : "";
}
}
Unfortunately, this nifty detail is missing in the documentation on the website http://typedoc.org/guides/themes/#custom-themes, leading to confusion in at least two plugin projects:
thepalebluedot/typedoc-md-theme and kimamula/typedoc-markdown-theme
@sclausen True. If anyone wants to take a crack at updating the docs you can submit a PR to TypeStrong/typedoc-site
See #846 for an alternate way of adding helpers in a plugin.
this.application.renderer.theme.resources.deactivate();
this.application.renderer.theme.resources.helpers.addOrigin('custom-helper', `<path-to-my-custom-helper-function>`));
this.application.renderer.theme.resources.activate();
Added pointer in https://github.com/TypeStrong/typedoc-site/pull/23
Resolved by TypeStrong/typedoc-site#23
Most helpful comment
I figured this out.
helpersdirectory under your desired theme, e.g.defaultTo export one or more helpers in one file you can do:
default/helpers/ifEquals.js