pdoc icon indicating copy to clipboard operation
pdoc copied to clipboard

Strip docstring from source code examples

Open derek-adair opened this issue 5 years ago • 3 comments

It would be very nice to be able to just look at the source code w/o all the comments.

Live Example

If you expand play you can see that the documentation text is quite long and does not need to be there. image

It'd also be cool to remove any other config/text that is predictable.

derek-adair avatar May 01 '20 22:05 derek-adair

I understood you'd like to collapse the repeated docstring in the item's source code view.

Pdoc only outputs raw <pre><code>, leaving further markup to Highlight.js: https://github.com/pdoc3/pdoc/blob/004204320773cb98a8f0cd5fa82e8095f517e488/pdoc/templates/html.mako#L427-L430

You can remove the strings if you issue:

Array.from(document.querySelectorAll(
    '.source code.python .hljs-class + .hljs-string, \
     .source code.python .hljs-function + .hljs-string'
)).forEach(el => el.parentNode.removeChild(el))

I guess something similar could be issued to wrap in <details>. I'd be interested in a small working snippet if you find it. :+1:

kernc avatar May 02 '20 00:05 kernc

I was thinking something in the python code. There is no reason to have the docstring in the code source link.

derek-adair avatar May 02 '20 00:05 derek-adair

oh i misunderstood. I'll have to dig in and submit a PR i guess.

derek-adair avatar May 02 '20 00:05 derek-adair