Skip to content

Create a custom partial

Lloyd Brookes edited this page Oct 27, 2016 · 2 revisions

It's possible to change any part of the output by overriding the built in partials. In this example we will change the default separator. Currently, the default is - (a single dash which renders as a thin line on Github) and the --no-gfm (no github-flavoured markdown) option uses * * *. We will change the default to ---. Below is the typical workflow for finding and editing a partial.

1. Navigate to the template entry point, the main partial:

{{>main-index~}}
{{>all-docs~}}

2. You'll see the output is broken into an index section and the main documentation. Press t on the keyboard to launch the Github file chooser then navigate to all-docs.hbs. Here we see the main docs are generated by iterating over the orphans (top-level globals and modules with no parent) rendering docs for each:

{{#orphans ~}}
{{>docs~}}
{{/orphans~}}

3. Press t on Github again and navigate to docs.hbs. Here we discover the separator is rendered after the header, body and member-index of each identifier's documentation:

{{>header~}}
{{>body}}
{{>member-index~}}
{{>separator~}}
{{>members~}}

4. Navigate to separator.hbs, this is the partial we will edit:

{{#if (option "separators")~}}
{{#if (option "no-gfm")}}

* * *

{{else}}

-

{{/if~}}
{{/if~}}

5. Create a duplicate of the file (e.g. in your project repository). Filenames are significant in handlebars so the filename must be separator.hbs. Now, tweak the custom partial as required:

{{#if (option "separators")~}}
{{#if (option "no-gfm")}}

* * *

{{else}}

---

{{/if~}}
{{/if~}}

6. Launch jsdoc2md supplying the path to the custom partial.

$ jsdoc2md --partial separator.hbs --files lib/*.js
Clone this wiki locally