jsdoc2md / jsdoc-to-markdown

Generate markdown documentation from jsdoc-annotated javascript
MIT License
1.69k stars 152 forks source link

[feature request] Support optional instantiate parent name prefix #293

Closed augusttty closed 2 months ago

augusttty commented 1 year ago

By default, the instance method of a class output with a instantiate parent class name prefix on every method. When the className getting longer, or the methods getting too many , it seems unnecessary to give every "local" method a prefix. I expected to omit the parent name, and I do tried the partial and the helper, but none of theme can achieve without a sideEffect(the signature is shared).And I have to change the dmd the source code to achieve that.Can jsdoc2md add a configuration to achieve this? For example:

=>source:


/**
 * Chat Service
 */
class ChatService {
  constructor(){}

  /**
   * send a message to a person
   */
  send() {}

  /**
   * receiving message
   */
  receive() {}
}

=>default jsdoc2md output:

ChatService

Chat Service

Kind: global class

chatService.send()

send a message to a person

Kind: instance method of ChatService

chatService.receive()

receiving message

Kind: instance method of ChatService

=>expected output:

//...

send()

send a message to a person

Kind: instance method of ChatService

receive()

receiving message

Kind: instance method of ChatService

75lb commented 2 months ago

I was able to achieve something like what you're looking for by modifying the built-in {{>sig-name}} partial, which looks like this:

{{#if virtual}}*{{/if}}{{#with (parentObject)}}{{#if virtual}}*{{/if~}}{{/with~}}
{{#if name}}{{#sig~}}
{{{@depOpen}~}}
{{{@codeOpen}~}}
{{#if @prefix}}{{@prefix}} {{/if~}}
{{@parent~}}
{{@accessSymbol}}{{#if (isEvent)}}"{{{name}}}"{{else}}{{{escape name}}}{{/if~}}
{{#if @methodSign}}{{#if (isEvent)}} {{@methodSign}}{{else}}{{@methodSign}}{{/if}}{{/if~}}
{{{@codeClose}~}}
{{#if @returnSymbol}} {{@returnSymbol}}{{/if~}}
{{#if @returnTypes}} {{>linked-type-list types=@returnTypes delimiter=" \| " }}{{/if~}}
{{#if @suffix}} {{@suffix}}{{/if~}}
{{{@depClose}~}}
{{~/sig}}{{/if~}}
{{#if virtual}}*{{/if}}{{#with (parentObject)}}{{#if virtual}}*{{/if~}}{{/with~}}

Try this:

  1. Copy the above into a new file
  2. remove line 6 ({{@parent~}})
  3. Save the file as sig-name.hbs
  4. Run jsdoc2md with your modified partial: jsdoc2md --partial sig-name.hbs --files *.js

Hopefully that helps.. Let me know if not.

75lb commented 2 months ago

But if you're still getting undesired side-effects (due to the fact {{>sig-name}} is used in multiple places, you might need to make your edit context-aware.. e.g. only strip the parent on class members: (replace line 6 of the above with this)

{{#if (isClassMember)}}{{else}}{{@parent~}}{{/if~}}