sphinxcontrib-screenshot 0.1.1__py3-none-any.whl → 0.1.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of sphinxcontrib-screenshot might be problematic. Click here for more details.
- sphinxcontrib/screenshot.py +30 -3
- {sphinxcontrib_screenshot-0.1.1.dist-info → sphinxcontrib_screenshot-0.1.3.dist-info}/METADATA +16 -16
- sphinxcontrib_screenshot-0.1.3.dist-info/RECORD +6 -0
- {sphinxcontrib_screenshot-0.1.1.dist-info → sphinxcontrib_screenshot-0.1.3.dist-info}/WHEEL +1 -1
- sphinxcontrib_screenshot-0.1.1.dist-info/RECORD +0 -6
- {sphinxcontrib_screenshot-0.1.1.dist-info → sphinxcontrib_screenshot-0.1.3.dist-info}/LICENSE +0 -0
- {sphinxcontrib_screenshot-0.1.1.dist-info → sphinxcontrib_screenshot-0.1.3.dist-info}/top_level.txt +0 -0
sphinxcontrib/screenshot.py
CHANGED
|
@@ -32,7 +32,7 @@ Meta = typing.TypedDict('Meta', {
|
|
|
32
32
|
'parallel_write_safe': bool
|
|
33
33
|
})
|
|
34
34
|
|
|
35
|
-
__version__ = '0.1.
|
|
35
|
+
__version__ = '0.1.3'
|
|
36
36
|
|
|
37
37
|
|
|
38
38
|
class ScreenshotDirective(SphinxDirective):
|
|
@@ -72,6 +72,21 @@ class ScreenshotDirective(SphinxDirective):
|
|
|
72
72
|
|
|
73
73
|
document.querySelector('button').click();
|
|
74
74
|
```
|
|
75
|
+
|
|
76
|
+
Use `figclass` option if you want to specify a class name to the image.
|
|
77
|
+
|
|
78
|
+
```rst
|
|
79
|
+
.. screenshot:: http://www.example.com
|
|
80
|
+
:figclass: foo
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
It also generates a PDF file when `pdf` option is given, which might be
|
|
84
|
+
useful when you need scalable image assets.
|
|
85
|
+
|
|
86
|
+
```rst
|
|
87
|
+
.. screenshot:: http://www.example.com
|
|
88
|
+
:pdf:
|
|
89
|
+
```
|
|
75
90
|
"""
|
|
76
91
|
|
|
77
92
|
required_arguments = 1 # URL
|
|
@@ -80,12 +95,14 @@ class ScreenshotDirective(SphinxDirective):
|
|
|
80
95
|
'height': directives.positive_int,
|
|
81
96
|
'width': directives.positive_int,
|
|
82
97
|
'caption': directives.unchanged,
|
|
98
|
+
'figclass': directives.unchanged,
|
|
99
|
+
'pdf': directives.flag,
|
|
83
100
|
}
|
|
84
101
|
pool = ThreadPoolExecutor()
|
|
85
102
|
|
|
86
103
|
@staticmethod
|
|
87
104
|
def take_screenshot(url: str, width: int, height: int, filepath: str,
|
|
88
|
-
init_script: str, interactions: str):
|
|
105
|
+
init_script: str, interactions: str, generate_pdf: bool):
|
|
89
106
|
"""Takes a screenshot with Playwright's Chromium browser.
|
|
90
107
|
|
|
91
108
|
Args:
|
|
@@ -98,6 +115,7 @@ class ScreenshotDirective(SphinxDirective):
|
|
|
98
115
|
https://playwright.dev/python/docs/api/class-page#page-add-init-script
|
|
99
116
|
interactions (str): JavaScript code to run before taking the screenshot
|
|
100
117
|
after the page was loaded.
|
|
118
|
+
generate_pdf (bool): Generate a PDF file along with the screenshot.
|
|
101
119
|
"""
|
|
102
120
|
with sync_playwright() as playwright:
|
|
103
121
|
browser = playwright.chromium.launch()
|
|
@@ -118,6 +136,10 @@ class ScreenshotDirective(SphinxDirective):
|
|
|
118
136
|
raise RuntimeError('Timeout error occured at %s in executing\n%s' %
|
|
119
137
|
(url, interactions))
|
|
120
138
|
page.screenshot(path=filepath)
|
|
139
|
+
if generate_pdf:
|
|
140
|
+
page.emulate_media(media='screen')
|
|
141
|
+
root, ext = os.path.splitext(filepath)
|
|
142
|
+
page.pdf(width=f'{width}px', height=f'{height}px', path=root + '.pdf')
|
|
121
143
|
page.close()
|
|
122
144
|
browser.close()
|
|
123
145
|
|
|
@@ -133,6 +155,8 @@ class ScreenshotDirective(SphinxDirective):
|
|
|
133
155
|
height = self.options.get('height', 960)
|
|
134
156
|
width = self.options.get('width', 1280)
|
|
135
157
|
caption_text = self.options.get('caption', '')
|
|
158
|
+
figclass = self.options.get('figclass', '')
|
|
159
|
+
pdf = 'pdf' in self.options
|
|
136
160
|
interactions = '\n'.join(self.content)
|
|
137
161
|
|
|
138
162
|
if urlparse(url).scheme not in {'http', 'https'}:
|
|
@@ -148,7 +172,7 @@ class ScreenshotDirective(SphinxDirective):
|
|
|
148
172
|
if not os.path.exists(filepath):
|
|
149
173
|
fut = self.pool.submit(ScreenshotDirective.take_screenshot, url, width,
|
|
150
174
|
height, filepath, screenshot_init_script,
|
|
151
|
-
interactions)
|
|
175
|
+
interactions, pdf)
|
|
152
176
|
fut.result()
|
|
153
177
|
|
|
154
178
|
# Create image and figure nodes
|
|
@@ -158,6 +182,9 @@ class ScreenshotDirective(SphinxDirective):
|
|
|
158
182
|
image_node = nodes.image(uri=rel_filepath)
|
|
159
183
|
figure_node = nodes.figure('', image_node)
|
|
160
184
|
|
|
185
|
+
if figclass:
|
|
186
|
+
figure_node['classes'].append(figclass)
|
|
187
|
+
|
|
161
188
|
if caption_text:
|
|
162
189
|
parsed = nodes.Element()
|
|
163
190
|
self.state.nested_parse(
|
{sphinxcontrib_screenshot-0.1.1.dist-info → sphinxcontrib_screenshot-0.1.3.dist-info}/METADATA
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: sphinxcontrib-screenshot
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.3
|
|
4
4
|
Summary: A Shpinx extension to embed webpage screenshots.
|
|
5
5
|
Home-page: https://github.com/tushuhei/sphinxcontrib-screenshot/
|
|
6
6
|
Author: Shuhei Iitsuka
|
|
@@ -18,21 +18,21 @@ License-File: LICENSE
|
|
|
18
18
|
Requires-Dist: playwright
|
|
19
19
|
Requires-Dist: sphinx
|
|
20
20
|
Provides-Extra: dev
|
|
21
|
-
Requires-Dist: beautifulsoup4
|
|
22
|
-
Requires-Dist: build
|
|
23
|
-
Requires-Dist: flake8
|
|
24
|
-
Requires-Dist: isort
|
|
25
|
-
Requires-Dist: mypy
|
|
26
|
-
Requires-Dist: Pillow
|
|
27
|
-
Requires-Dist: pytest
|
|
28
|
-
Requires-Dist: sphinx[test]
|
|
29
|
-
Requires-Dist: toml
|
|
30
|
-
Requires-Dist: twine
|
|
31
|
-
Requires-Dist: types-beautifulsoup4
|
|
32
|
-
Requires-Dist: types-docutils
|
|
33
|
-
Requires-Dist: types-Pillow
|
|
34
|
-
Requires-Dist: types-setuptools
|
|
35
|
-
Requires-Dist: yapf
|
|
21
|
+
Requires-Dist: beautifulsoup4; extra == "dev"
|
|
22
|
+
Requires-Dist: build; extra == "dev"
|
|
23
|
+
Requires-Dist: flake8; extra == "dev"
|
|
24
|
+
Requires-Dist: isort; extra == "dev"
|
|
25
|
+
Requires-Dist: mypy; extra == "dev"
|
|
26
|
+
Requires-Dist: Pillow; extra == "dev"
|
|
27
|
+
Requires-Dist: pytest; extra == "dev"
|
|
28
|
+
Requires-Dist: sphinx[test]; extra == "dev"
|
|
29
|
+
Requires-Dist: toml; extra == "dev"
|
|
30
|
+
Requires-Dist: twine; extra == "dev"
|
|
31
|
+
Requires-Dist: types-beautifulsoup4; extra == "dev"
|
|
32
|
+
Requires-Dist: types-docutils; extra == "dev"
|
|
33
|
+
Requires-Dist: types-Pillow; extra == "dev"
|
|
34
|
+
Requires-Dist: types-setuptools; extra == "dev"
|
|
35
|
+
Requires-Dist: yapf; extra == "dev"
|
|
36
36
|
|
|
37
37
|
# sphinxcontrib-screenshot
|
|
38
38
|
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
sphinxcontrib/screenshot.py,sha256=rTcbf2bx5DiRIGKcA8dL7jbi-GwfrW7-aXU83M5vAlY,6829
|
|
2
|
+
sphinxcontrib_screenshot-0.1.3.dist-info/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
|
3
|
+
sphinxcontrib_screenshot-0.1.3.dist-info/METADATA,sha256=T6kkviJZwZe0ZtYllM4YwhlI9qiKtoTbnI6OAcxlvII,3652
|
|
4
|
+
sphinxcontrib_screenshot-0.1.3.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
|
5
|
+
sphinxcontrib_screenshot-0.1.3.dist-info/top_level.txt,sha256=VJrV3_vaiKQVgVpR0I1iecxoO0drzGu-M0j40PVP2QQ,14
|
|
6
|
+
sphinxcontrib_screenshot-0.1.3.dist-info/RECORD,,
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
sphinxcontrib/screenshot.py,sha256=voSjROC2WAs0K--pf6mtzDxO29CVBfoOe_TcY06vZwg,5985
|
|
2
|
-
sphinxcontrib_screenshot-0.1.1.dist-info/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
|
3
|
-
sphinxcontrib_screenshot-0.1.1.dist-info/METADATA,sha256=1lmWqgT2Ol8tFKD8HP9OpmEwWwQ4IfaHSw_5mfJnN1o,3667
|
|
4
|
-
sphinxcontrib_screenshot-0.1.1.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
5
|
-
sphinxcontrib_screenshot-0.1.1.dist-info/top_level.txt,sha256=VJrV3_vaiKQVgVpR0I1iecxoO0drzGu-M0j40PVP2QQ,14
|
|
6
|
-
sphinxcontrib_screenshot-0.1.1.dist-info/RECORD,,
|
{sphinxcontrib_screenshot-0.1.1.dist-info → sphinxcontrib_screenshot-0.1.3.dist-info}/LICENSE
RENAMED
|
File without changes
|
{sphinxcontrib_screenshot-0.1.1.dist-info → sphinxcontrib_screenshot-0.1.3.dist-info}/top_level.txt
RENAMED
|
File without changes
|