diff --git a/sphinxcontrib/screenshot.py b/sphinxcontrib/screenshot.py index 7c1a85c..e687bf0 100644 --- a/sphinxcontrib/screenshot.py +++ b/sphinxcontrib/screenshot.py @@ -80,6 +80,7 @@ class ScreenshotDirective(SphinxDirective): 'height': directives.positive_int, 'width': directives.positive_int, 'caption': directives.unchanged, + 'figclass': directives.unchanged, } pool = ThreadPoolExecutor() @@ -133,6 +134,7 @@ def run(self) -> typing.List[nodes.Node]: height = self.options.get('height', 960) width = self.options.get('width', 1280) caption_text = self.options.get('caption', '') + figclass = self.options.get('figclass', '') interactions = '\n'.join(self.content) if urlparse(url).scheme not in {'http', 'https'}: @@ -158,6 +160,9 @@ def run(self) -> typing.List[nodes.Node]: image_node = nodes.image(uri=rel_filepath) figure_node = nodes.figure('', image_node) + if figclass: + figure_node['classes'].append(figclass) + if caption_text: parsed = nodes.Element() self.state.nested_parse( diff --git a/tests/test-root/index.rst b/tests/test-root/index.rst index cb282ac..af6f02f 100644 --- a/tests/test-root/index.rst +++ b/tests/test-root/index.rst @@ -14,3 +14,8 @@ :caption: Changing the background. document.body.style.background = 'red'; + +.. screenshot:: http://www.example.com + :width: 480 + :height: 320 + :figclass: round diff --git a/tests/test_it.py b/tests/test_it.py index 467a984..d9fb4f7 100644 --- a/tests/test_it.py +++ b/tests/test_it.py @@ -29,7 +29,7 @@ def test_default(app: SphinxTestApp, status: StringIO, # Every screenshot directive should become an image. imgs = soup.find_all('img') - assert len(list(imgs)) == 3 + assert len(list(imgs)) == 4 # The image size should be set as specified. img_obj = Image.open(app.outdir / imgs[0]['src']) @@ -44,7 +44,7 @@ def test_default(app: SphinxTestApp, status: StringIO, # The images should be different after the specified user interaction. img_before_interaction = Image.open(app.outdir / imgs[0]['src']) - img_after_interaction = Image.open(app.outdir / imgs[-1]['src']) + img_after_interaction = Image.open(app.outdir / imgs[2]['src']) assert list(img_before_interaction.getdata()) != list( img_after_interaction.getdata()) @@ -52,3 +52,6 @@ def test_default(app: SphinxTestApp, status: StringIO, img_with_caption_a = imgs[0] img_with_caption_b = imgs[1] assert img_with_caption_a['src'] == img_with_caption_b['src'] + + # The figure node should have the class name specified. + assert 'round' in soup.find_all('figure')[-1]['class']