noi-techpark / odh-docs

Open Data Hub (http://opendatahub.com/) Documentation
http://opendatahub.readthedocs.io/en/latest/index.html
4 stars 4 forks source link

Add facility to copy code snippets from the documentation #184

Closed stefanodavid closed 3 years ago

stefanodavid commented 3 years ago

Developers often need to quickly copy&paste snippets, therefore we need to implement such a facility. Luckily, guys at ExecutableBooks have developed an extension exactly for this purpose, called sphinx-copybutton which we will implement.

We will also clean code snippets so they are ready to use, i.e., we will:

stefanodavid commented 3 years ago

With the configuration that I added now, in bash snippets only the actual command is copied, even if there is some output shown. I also set the prompt to either ~$ or ~#, depending if the command should be run as user or superuser.

If no prompt is specified, the whole snippet is copied: this applies to all json, java, and other codes snippets.

Bash commands spanning multiple lines (i.e., with lines ending with \) have also been written without prompt: in this case only the first line would be copied, therefore as a workaround (until I don't find a better or proper way to do so!) I removed the prompt.

Addendum: I did not add html to the code blocks containing URLs, or to other short snippets that are not intended to be copied, because this would take quite a lot of time and would have little added value.