Skip to content

Commit

Permalink
Update documentation for path support
Browse files Browse the repository at this point in the history
  • Loading branch information
tushuhei committed Jan 16, 2025
1 parent 506b159 commit d9c2e24
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
34 changes: 11 additions & 23 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ Then use the `screenshot` directive in your Sphinx source file.
.. screenshot:: http://www.example.com
The extension also supports the ``file://`` protocol to take screenshots of local files, and root or document relative paths.

.. code-block:: rst
.. screenshot:: file:///path/to/your/file.html
.. screenshot:: /static/example.html
.. screenshot:: ./example.html
Options
#######

Expand Down Expand Up @@ -138,10 +146,6 @@ It also generates a PDF file when :code:`pdf` option is given, which might be us
.. screenshot:: http://www.example.com
:pdf:
.. screenshot:: http://www.example.com
:pdf:


.. _viewport_width:
.. _viewport_height:

Expand All @@ -153,11 +157,11 @@ You can specify the screen size for a particular screenshot with :code:`viewport
.. code-block:: rst
.. screenshot:: http://www.example.com
:viewport-width: 800
:viewport-width: 320
:viewport-height: 600
.. screenshot:: http://www.example.com
:viewport-width: 800
:viewport-width: 320
:viewport-height: 600

Configuration
Expand Down Expand Up @@ -300,27 +304,11 @@ Then you can use a Sphinx substitution with your application name to refer to it
.. screenshot:: |example|/hello
Local http server
#################

`sphinxcontrib-screenshot` supports URLs with the HTTP and HTTPS protocols.
To take screenshots of local files and build the document while running a local server for them, you can use the NPM library `concurrently <https://www.npmjs.com/package/concurrently>`__ in the following way:

.. code-block:: bash
:caption: Build the document
npx --yes concurrently -k --success=first "make html" "python3 -m http.server 3000 --directory=examples"
.. code-block:: bash
:caption: Watch and build the document
npx --yes concurrently -k "make livehtml" "python3 -m http.server 3000 --directory=examples"
Notes
#####

This extension uses `Playwright <https://playwright.dev>`__ to capture a screenshot of the specified website only.
No data is sent to any other external server; the request is limited to the specified website.
No data is sent to any other external server; the request is limited to the website specified in the directive.
Be cautious: avoid including sensitive information (such as authentication data) in the directive content.

Contributing
Expand Down
18 changes: 18 additions & 0 deletions sphinxcontrib/screenshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,24 @@ class ScreenshotDirective(SphinxDirective, Figure):
.. screenshot:: http://www.example.com
:pdf:
```
You can take a screenshot of a local file using a root-relative path.
```rst
.. screenshot:: /static/example.html
```
Or you can use a document-relative path.
```rst
.. screenshot:: ./example.html
```
The `file://` protocol is also supported.
```rst
.. screenshot:: file:///path/to/your/file.html
```
"""

required_arguments = 1 # URL
Expand Down

0 comments on commit d9c2e24

Please sign in to comment.