jsdoc2md / jsdoc-to-markdown

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

Link to source file #267

Closed Anthony-Gaudino closed 2 months ago

Anthony-Gaudino commented 2 years ago

Is it possible to add a link in the generated Markdown pointing to the source file?

My idea is to make it easy for who is looking at the documentation to open the source and see the code.

It would be even better if we could have a link for each function, class, etc. and when the user clicks on this link he will be directed to that specific class, function...

We use GitLab and it's easy to have a link to a file and line, for example: https://domain/repository/-/blob/master/source/code.js#L19 would be line 19 of code.js.

75lb commented 2 years ago

You'd need to customise the output - did you check the wiki?

75lb commented 2 months ago

if you use jsdoc2md --json to inspect the templateData for your code, you'll see something like this:

  {
    "id": "GlobalChildClass#methodOne",
    "longname": "GlobalChildClass#methodOne",
    "name": "methodOne",
    "kind": "function",
    "scope": "instance",
    "inherits": "GlobalClass#methodOne",
    "inherited": true,
    "overrides": "GlobalClass#methodOne",
    "description": "parent method one",
    "memberof": "GlobalChildClass",
    "meta": {
      "lineno": 25,
      "filename": "0-src.js",
      "path": "/Users/lloyd/Documents/jsdoc2md/testbed/build/jsdoc2md/dmd-options/partial"
    },
    "order": 10
  },

You would need to create a custom helper which returns a GitLab link derived from meta.lineno, meta.filename etc.. Then create a modified partial containing your desired link text (which calls the new helper).. Then you run jsdoc2md --partial <your-locally modified-partial-file> --helper <your-local-helper-module> to generate the output..

Let me know if you need any more help..