sphinxcontrib-screenshot 0.1.2__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.

@@ -32,7 +32,7 @@ Meta = typing.TypedDict('Meta', {
32
32
  'parallel_write_safe': bool
33
33
  })
34
34
 
35
- __version__ = '0.1.2'
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
@@ -81,12 +96,13 @@ class ScreenshotDirective(SphinxDirective):
81
96
  'width': directives.positive_int,
82
97
  'caption': directives.unchanged,
83
98
  'figclass': directives.unchanged,
99
+ 'pdf': directives.flag,
84
100
  }
85
101
  pool = ThreadPoolExecutor()
86
102
 
87
103
  @staticmethod
88
104
  def take_screenshot(url: str, width: int, height: int, filepath: str,
89
- init_script: str, interactions: str):
105
+ init_script: str, interactions: str, generate_pdf: bool):
90
106
  """Takes a screenshot with Playwright's Chromium browser.
91
107
 
92
108
  Args:
@@ -99,6 +115,7 @@ class ScreenshotDirective(SphinxDirective):
99
115
  https://playwright.dev/python/docs/api/class-page#page-add-init-script
100
116
  interactions (str): JavaScript code to run before taking the screenshot
101
117
  after the page was loaded.
118
+ generate_pdf (bool): Generate a PDF file along with the screenshot.
102
119
  """
103
120
  with sync_playwright() as playwright:
104
121
  browser = playwright.chromium.launch()
@@ -119,6 +136,10 @@ class ScreenshotDirective(SphinxDirective):
119
136
  raise RuntimeError('Timeout error occured at %s in executing\n%s' %
120
137
  (url, interactions))
121
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')
122
143
  page.close()
123
144
  browser.close()
124
145
 
@@ -135,6 +156,7 @@ class ScreenshotDirective(SphinxDirective):
135
156
  width = self.options.get('width', 1280)
136
157
  caption_text = self.options.get('caption', '')
137
158
  figclass = self.options.get('figclass', '')
159
+ pdf = 'pdf' in self.options
138
160
  interactions = '\n'.join(self.content)
139
161
 
140
162
  if urlparse(url).scheme not in {'http', 'https'}:
@@ -150,7 +172,7 @@ class ScreenshotDirective(SphinxDirective):
150
172
  if not os.path.exists(filepath):
151
173
  fut = self.pool.submit(ScreenshotDirective.take_screenshot, url, width,
152
174
  height, filepath, screenshot_init_script,
153
- interactions)
175
+ interactions, pdf)
154
176
  fut.result()
155
177
 
156
178
  # Create image and figure nodes
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sphinxcontrib-screenshot
3
- Version: 0.1.2
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 ; 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'
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,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.2.0)
2
+ Generator: setuptools (75.6.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,6 +0,0 @@
1
- sphinxcontrib/screenshot.py,sha256=Ri86PkBZ4EMYCj1BgKT9ZfQbEh6dVJRFr2n_E5cf9Ko,6137
2
- sphinxcontrib_screenshot-0.1.2.dist-info/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
3
- sphinxcontrib_screenshot-0.1.2.dist-info/METADATA,sha256=lF-Qzmb4dvtCHvVzeqhvmfIdc4IUa7Sk-EVez6L4Dp8,3667
4
- sphinxcontrib_screenshot-0.1.2.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
5
- sphinxcontrib_screenshot-0.1.2.dist-info/top_level.txt,sha256=VJrV3_vaiKQVgVpR0I1iecxoO0drzGu-M0j40PVP2QQ,14
6
- sphinxcontrib_screenshot-0.1.2.dist-info/RECORD,,