mkdocstrings icon indicating copy to clipboard operation
mkdocstrings copied to clipboard

Add ability to link to source code on GitHub

Open dhirschfeld opened this issue 3 years ago • 5 comments

Similar to the sphinx.ext.linkcode extension:

  • https://www.sphinx-doc.org/en/master/usage/extensions/linkcode.html

dhirschfeld avatar Jul 06 '21 01:07 dhirschfeld

This is already implemented on master in https://github.com/mkdocstrings/mkdocstrings/pull/287 Thanks for signaling the need for it

oprypin avatar Jul 06 '21 05:07 oprypin

Great! It didn't click for me that #287 would allow for this. Cheers, and sorry for the noise!

dhirschfeld avatar Jul 06 '21 07:07 dhirschfeld

Wait, sorry-- I think I misunderstood your request. I pointed to an ability to link to a documentation website, which would only hopefully have a link to the source code. But actually mkdocstrings-Python has no ability to link to the source code, only to embed it. It would be possible to implement similarly to what I did in mkdocstrings-Crystal: Usage example: https://github.com/athena-framework/website/blob/befd26027e7e0465a13a5a0e1377fc18ae3092a6/mkdocs.yml#L55 Code: https://github.com/mkdocstrings/crystal/blob/b724d9d16b9a762821e58449ed0248fb7bee1042/mkdocstrings/handlers/crystal/collector.py#L106 But the links would probably need to know about Git commit hashes and such, but mkdocstrings so far has not entered the territory of understanding SCM systems

oprypin avatar Jul 06 '21 08:07 oprypin

It would be possible to implement similarly to what I did in mkdocstrings-Crystal

I think that looks like what I'm after - hyperlinks to actual files on GitHub. For me, it's got a lot more value than just the source as every line has the associated commit message and PR reference (blame) which IMHO is a fundamental part of the documentation of source code.

But the links would probably need to know about Git commit hashes and such

You'd hopefully be able to get that using either __version__, pkg_resources or importlib.metadata

dhirschfeld avatar Jul 06 '21 10:07 dhirschfeld

Well summarized by @oprypin:

the links would probably need to know about Git commit hashes and such, but mkdocstrings so far has not entered the territory of understanding SCM systems

Not sure we want to enter such a territory. However I believe this could be achieved with a combo of extra plugins and template overriding. mkdocstrings-sourcelink might interest you.

pawamoy avatar Jul 22 '21 16:07 pawamoy