ndoc icon indicating copy to clipboard operation
ndoc copied to clipboard

Add support for JS global objects documentation linking

Open ixti opened this issue 13 years ago • 10 comments

It should recognize global objects in the returned values
/**
 *  Foo.bar(a) -> Array
 **/

The above, should replace Array with link to Array documentation.

It should recognize global objects in the arguments definition
/**
 *  Foo.bar(a) -> Array
 *  - a (RegExp): Some description
 **/

The above should replace RegExp with link to RegExp documentation

It should recognize global objects in links
/**
 *  Foo.baz -> String
 *
 *  Serialized representation of self as [[Object]].
 **/

The above should replace [[Object]] with link to Object documentation

By default links to global objects should point MDN. But there should be an option to provide custom URL for global objects documentation (e.g. node.js documentation page).

ixti avatar Jun 28 '12 23:06 ixti

What do you think about references to Node.js classes?

Sannis avatar Jul 09 '12 18:07 Sannis

I think it should be MDN by default. Here's some extra points that should be considered:

  • allow provide "custom" link format, e.g. http://mydocs.com/js/{name}.html
  • allow provide a way to link format for own "well-known" object, e.g. I want [[Mincer]] to point mincer's documentation.
  • have built-in presets of well known names

I propose to have argument named well-known with ability to specify it multiple time. Format of value should be: <alias>|<names>=<link_fmt>.

  • <alias>: A simple identifier of built-in presets, e.g. @mdn, @node.
  • names: Comma separated list of names, e.g. Object,Array,...
  • link_fmt: Link format for given list of names, e.g. https://mydocs.net/js/{name}.html

According to above:

  • --well-known @mdn equals --well-known Object,Array,...=https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/{name}
  • --well-known @node equals --well-known Buffer,path,...=http://nodejs.org/api/{name:downcase}.html

So it should allow us specify multiple well-known names: --well-known @mdn --well-known @node. Notice that we need to implement filters for variables interpolations (at least downcase and capitalize).

ixti avatar Jul 09 '12 20:07 ixti

Format of value should be: [[<names>=]<link_fmt>].

'=' is bad IMO: --well-known=Object,Array=http://whetever.com/jsdocs/{name}.html breaks my brain.

Sannis avatar Jul 09 '12 20:07 Sannis

Sorry - I have updated my proposal. I might agree about =. Probably we can use @ symbol:

--well-known @mdn
--well-known Buffer,path@http://nodejs.org/api/{name:downcase}.html

ixti avatar Jul 09 '12 21:07 ixti

I have idea about some usage of : or ;, but you have a better catch.

Sannis avatar Jul 09 '12 21:07 Sannis

I thought about :, but it's quiet ugly Buffer,path:http://.... And ; will force to either escape it or take argument into quotes.

ixti avatar Jul 09 '12 21:07 ixti

Why not just use file with simple words mapping?

--references mapping.txt

File content:

Array http://...
Object http://...
Buffer http://

We can attach some default files, or user can use custom one.

Also, that can be added in .ndocrc (1 line per link), since argparse supports appendeable params.

puzrin avatar Jul 20 '12 13:07 puzrin

I like the idea of reference maps.

ixti avatar Jul 20 '12 13:07 ixti

+1 from me too.

Sannis avatar Jul 20 '12 15:07 Sannis

I have done this in my fork already: https://github.com/gjtorikian/panino-docs/blob/master/additionalObjs.json

I am in the process of updating Panino to the ndoc 2.0 rewrite. I can come back here and paste the relevant code changes if interested. It's just a few updates to the link() function.

gjtorikian avatar Aug 14 '12 18:08 gjtorikian