jsdoc-to-markdown icon indicating copy to clipboard operation
jsdoc-to-markdown copied to clipboard

@see <namepath> not supported

Open rhys-vdw opened this issue 9 years ago • 3 comments

/**
 * Both of these will link to the bar function.
 * @see {@link bar}
 * @see bar
 */
function foo() {}

docs

Input:

/** @see Class#method */

Output with jsdoc to markdown:

**See:** Class#method

Should be:

**See:** [Class#method](Class+method)

I've been looking through the ddata source trying to work out how to make this change. Not entirely sure if this is a jsdoc-parse issue or a dmd issue. Either way I'm happy to submit a PR.

rhys-vdw avatar Jun 02 '16 10:06 rhys-vdw

Hi, thanks for the report! will look at it this evening.

75lb avatar Jun 02 '16 10:06 75lb

Not sure how formal the spec for @see is, but this is my quick fix in my plugin:

helpers.js

var ddata = require('ddata');

exports.linkifyOrInlineLinks = linkifyOrInlineLinks;

/**
replaces {@link} tags with markdown links in the suppied input text.
if no links are found, then assume this is a valid link target.
*/
function linkifyOrInlineLinks (text, options) {
  if (text) {
    var links = ddata.parseLink(text);
    if (links.length > 0) {
      links.forEach(function (link) {
        var linked = ddata._link(link.url, options)
        if (link.caption === link.url) link.caption = linked.name
        if (linked.url) link.url = linked.url
        text = text.replace(link.original, '[' + link.caption + '](' + link.url + ')')
      })
    } else {
      var linked = ddata._link(text, options)
      text = '[' + linked.name + '](' + linked.url + ')';
    }
  }
  return text
}

see.hbs

{{#if see~}}

{{#if (equal see.length 1)~}}
**See**: {{{linkifyOrInlineLinks see.[0]}}}  
{{else~}}
**See**

{{#each see}}- {{{linkifyOrInlineLinks this}}}
{{/each}}

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

rhys-vdw avatar Jun 02 '16 10:06 rhys-vdw

Apologies for the delay! Yes, you're right - @see does not seem to parse namepaths which is a glaring oversight on my behalf.. I'd gratefully accept a PR but the handlebars templates/helpers are a not particularly inviting to work on, which is my main long-term goal to solve..


Try the jsdoc2md v2 pre-release

75lb avatar Aug 09 '16 22:08 75lb