Skip to content

Commit 097f2b8

Browse files
committed
Documentation improvements
1 parent d05cf47 commit 097f2b8

File tree

7 files changed

+70
-17
lines changed

7 files changed

+70
-17
lines changed

README.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@ human-readable size or throughput. It is localized to:
4242

4343
[https://python-humanize.readthedocs.io](https://python-humanize.readthedocs.io)
4444

45+
<!-- usage-start -->
46+
4547
## Usage
4648

4749
### Integer humanization
4850

49-
```pycon
51+
```python
5052
>>> import humanize
5153
>>> humanize.intcomma(12345)
5254
'12,345'
@@ -62,7 +64,7 @@ human-readable size or throughput. It is localized to:
6264

6365
### Date & time humanization
6466

65-
```pycon
67+
```python
6668
>>> import humanize
6769
>>> import datetime as dt
6870
>>> humanize.naturalday(dt.datetime.now())
@@ -83,7 +85,7 @@ human-readable size or throughput. It is localized to:
8385

8486
### Precise time delta
8587

86-
```pycon
88+
```python
8789
>>> import humanize
8890
>>> import datetime as dt
8991
>>> delta = dt.timedelta(seconds=3633, days=2, microseconds=123000)
@@ -99,13 +101,13 @@ human-readable size or throughput. It is localized to:
99101

100102
If seconds are too large, set `minimum_unit` to milliseconds or microseconds:
101103

102-
```pycon
104+
```python
103105
>>> import humanize
104106
>>> import datetime as dt
105107
>>> humanize.naturaldelta(dt.timedelta(seconds=2))
106108
'2 seconds'
107109
```
108-
```pycon
110+
```python
109111
>>> delta = dt.timedelta(milliseconds=4)
110112
>>> humanize.naturaldelta(delta)
111113
'a moment'
@@ -114,7 +116,7 @@ If seconds are too large, set `minimum_unit` to milliseconds or microseconds:
114116
>>> humanize.naturaldelta(delta, minimum_unit="microseconds")
115117
'4 milliseconds'
116118
```
117-
```pycon
119+
```python
118120
>>> humanize.naturaltime(delta)
119121
'now'
120122
>>> humanize.naturaltime(delta, minimum_unit="milliseconds")
@@ -125,7 +127,7 @@ If seconds are too large, set `minimum_unit` to milliseconds or microseconds:
125127

126128
### File size humanization
127129

128-
```pycon
130+
```python
129131
>>> import humanize
130132
>>> humanize.naturalsize(1_000_000)
131133
'1.0 MB'
@@ -137,7 +139,7 @@ If seconds are too large, set `minimum_unit` to milliseconds or microseconds:
137139

138140
### Human-readable floating point numbers
139141

140-
```pycon
142+
```python
141143
>>> import humanize
142144
>>> humanize.fractional(1/3)
143145
'1/3'
@@ -153,7 +155,7 @@ If seconds are too large, set `minimum_unit` to milliseconds or microseconds:
153155

154156
### Scientific notation
155157

156-
```pycon
158+
```python
157159
>>> import humanize
158160
>>> humanize.scientific(0.3)
159161
'3.00 x 10⁻¹'
@@ -173,7 +175,7 @@ If seconds are too large, set `minimum_unit` to milliseconds or microseconds:
173175

174176
How to change locale at runtime:
175177

176-
```pycon
178+
```python
177179
>>> import humanize
178180
>>> import datetime as dt
179181
>>> humanize.naturaltime(dt.timedelta(seconds=3))
@@ -189,7 +191,7 @@ How to change locale at runtime:
189191
You can pass additional parameter `path` to `activate` to specify a path to search
190192
locales in.
191193

192-
```pycon
194+
```python
193195
>>> import humanize
194196
>>> humanize.i18n.activate("xx_XX")
195197
<...>
@@ -198,6 +200,8 @@ FileNotFoundError: [Errno 2] No translation file found for domain: 'humanize'
198200
<gettext.GNUTranslations instance ...>
199201
```
200202

203+
<!-- usage-end -->
204+
201205
How to add new phrases to existing locale files:
202206

203207
```console

docs/css/code_select.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* Don't allow to select >>> in ```pycon``` code blocks */
2+
.highlight .gp, .highlight .go { /* Generic.Prompt, Generic.Output */
3+
user-select: none;
4+
}
5+
6+
/* >>> selection in ```python``` code blocks is handled with Javascript */
7+
.no-user-select {
8+
user-select: none;
9+
}

docs/index.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,9 @@ Welcome to the humanize API reference.
77
* [Filesize](filesize)
88
* [I18n](i18n)
99

10-
For usage examples see
11-
[README.md](https://github.com/jmoiron/humanize/blob/master/README.md).
10+
{%
11+
include-markdown "../README.md"
12+
start="<!-- usage-start -->"
13+
end="<!-- usage-end -->"
14+
comments=false
15+
%}

docs/js/code_select.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Disable user selection for '>>>' nodes inside code blocks.
3+
*/
4+
function disablePyConsolePromptsUserSelection() {
5+
const spans = document.getElementsByClassName('o');
6+
for (let i=0; i<spans.length; i++) {
7+
const span = spans[i];
8+
if (span.innerText === '>>>') {
9+
// if the next is a text node with a space as content
10+
// move the space to the span so it will not be selectable
11+
if (span.nextSibling.data === ' ') {
12+
span.innerText = '>>> '
13+
span.nextSibling.data = ''
14+
}
15+
span.classList.add('no-user-select');
16+
}
17+
}
18+
}
19+
20+
document.addEventListener("DOMContentLoaded", function() {
21+
disablePyConsolePromptsUserSelection();
22+
})

docs/requirements.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
mkdocs>=1.1
22
mkdocs-material
3-
mkdocstrings
3+
mkdocstrings[python-legacy]>=0.18
4+
mkdocs-include-markdown-plugin
5+
pygments
6+
pymdown-extensions

mkdocs.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ site_name: humanize
22
site_url: https://python-humanize.readthedocs.io
33
repo_url: https://github.com/jmoiron/humanize
44
theme:
5-
name: "material"
5+
name: material
66

77
nav:
88
- Home: index.md
@@ -16,3 +16,14 @@ plugins:
1616
- mkdocstrings:
1717
watch:
1818
- src/humanize
19+
- include-markdown
20+
21+
markdown_extensions:
22+
- pymdownx.highlight:
23+
use_pygments: true
24+
- pymdownx.superfences
25+
26+
extra_css:
27+
- css/code_select.css
28+
extra_javascript:
29+
- js/code_select.js

src/humanize/number.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,9 @@ def clamp(value, format="{:}", floor=None, ceil=None, floor_token="<", ceil_toke
421421
floor (int, float): Smallest value before clamping.
422422
ceil (int, float): Largest value before clamping.
423423
floor_token (str): If value is smaller than floor, token will be prepended
424-
to output.
424+
to output.
425425
ceil_token (str): If value is larger than ceil, token will be prepended
426-
to output.
426+
to output.
427427
428428
Returns:
429429
str: Formatted number. The output is clamped between the indicated floor and

0 commit comments

Comments
 (0)