Skip to content

Commit cb68662

Browse files
authored
DOCS: Update docs for MyST (#160)
1 parent 99ed0ba commit cb68662

File tree

5 files changed

+510
-513
lines changed

5 files changed

+510
-513
lines changed

docs/contribute/index.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
2+
# Contribute
3+
4+
If you'd like to develop or make contributions for sphinx-copybutton, fork
5+
the repository here:
6+
7+
<https://github.com/ExecutableBookProject/sphinx-copybutton>
8+
9+
pull to your computer and install locally with `pip`:
10+
11+
```
12+
pip install -e /path/to/sphinx_copybutton
13+
```
14+
15+
**Pull requests** and **Issues** are absolutely welcome!
16+
17+
The package is tested for three things (see `.github/workflows/integration.yml`):
18+
19+
## code style
20+
21+
To adhere to this code style install the package with [pre-commit](https://pre-commit.com/):
22+
23+
```console
24+
$ pip install .[code_style]
25+
```
26+
27+
Then you can run:
28+
29+
```console
30+
$ pre-commit run --all
31+
```
32+
33+
Or setup pre-commit to run on code commits:
34+
35+
```console
36+
$ pre-commit install
37+
```
38+
39+
## JavaScript unit testing
40+
41+
Install the test dependencies with [npm](https://www.npmjs.com/):
42+
43+
```console
44+
$ npm install ci
45+
```
46+
47+
Then run the tests:
48+
49+
```console
50+
$ npm test
51+
```
52+
53+
:::{note}
54+
NodeJS >= 12 is required
55+
:::
56+
57+
## Documentation builds
58+
59+
Install the package:
60+
61+
```console
62+
$ pip install .
63+
```
64+
65+
Then run the docs build:
66+
67+
```console
68+
$ cd doc
69+
$ make html
70+
```

docs/index.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Sphinx-copybutton
2+
3+
```{image} https://readthedocs.org/projects/sphinx-copybutton/badge/?version=latest
4+
:alt: Documentation
5+
:target: https://sphinx-copybutton.readthedocs.io/en/latest/?badge=latest
6+
```
7+
8+
```{image} https://img.shields.io/pypi/v/sphinx-copybutton.svg
9+
:alt: PyPi page
10+
:target: https://pypi.org/project/sphinx_copybutton
11+
```
12+
13+
```{image} https://img.shields.io/conda/vn/conda-forge/sphinx-copybutton.svg
14+
:alt: Conda Version
15+
:target: https://anaconda.org/conda-forge/sphinx-copybutton
16+
```
17+
18+
Sphinx-copybutton does one thing: add a little "copy" button to the right
19+
of your code blocks. That's it! It is a lightweight wrapper around the
20+
excellent (and also lightweight) Javascript library
21+
[ClipboardJS](https://clipboardjs.com/).
22+
23+
**Here's an example**
24+
25+
% This is stored in this issue: https://github.com/executablebooks/sphinx-copybutton/issues/157
26+
27+
```{image} https://user-images.githubusercontent.com/1839645/150200219-73663c59-08fd-4185-b157-62f3769c02ac.gif
28+
:alt: Copy Button Demo
29+
:width: 500px
30+
```
31+
32+
And here's a code block, note the copy button to the right!
33+
34+
```bash
35+
copy me!
36+
```
37+
38+
If the code block overlaps to the right of the text area, you can just click
39+
the button to get the whole thing.
40+
41+
```bash
42+
123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789
43+
```
44+
45+
You can configure `sphinx-copybutton` to detect *input prompts* in code
46+
cells, and then both remove these prompts before copying, as well as skip
47+
lines that *don't* start with prompts (in case they are output lines).
48+
49+
For example, this site has been configured to strip Python prompts (">>> ").
50+
Try copy-pasting the code block below.
51+
52+
```python
53+
>>> a = 2
54+
>>> print(a)
55+
2
56+
57+
>>> b = 'wow'
58+
>>> print(b)
59+
wow
60+
```
61+
62+
## Install
63+
64+
:::{note}
65+
`sphinx-copybutton` only works on Python >= 3.6
66+
:::
67+
68+
You can install `sphinx-copybutton` with `pip`:
69+
70+
```bash
71+
pip install sphinx-copybutton
72+
```
73+
74+
Or with `conda` via `conda-forge`:
75+
76+
```bash
77+
conda install -c conda-forge sphinx-copybutton
78+
```
79+
80+
[Here's a link to the sphinx-copybutton GitHub repository](https://github.com/ExecutableBookProject/sphinx-copybutton).
81+
82+
## Use
83+
84+
In your `conf.py` configuration file, add `sphinx_copybutton` to your
85+
extensions list. E.g.:
86+
87+
```python
88+
extensions = [
89+
...
90+
'sphinx_copybutton'
91+
...
92+
]
93+
```
94+
95+
When you build your site, your code blocks should now have little copy buttons
96+
to their right. Clicking the button will copy the code inside!
97+
98+
See [](use.md) for more information about how to use `sphinx-copybutton`.
99+
100+
```{toctree}
101+
:maxdepth: 2
102+
use
103+
contribute/index
104+
reference/example
105+
```
106+
107+
## Inspiration
108+
109+
The UI and design elements of `sphinx-copybutton` are heavily inspired by [GitHub's design choices](https://primer.style).
110+
The icon we use is from [Tabler's icons set](https://tablericons.com/).

0 commit comments

Comments
 (0)