Skip to content

Commit

Permalink
Merge pull request #855 from Paldari/fix/854-uml-captions
Browse files Browse the repository at this point in the history
Issue #854 Fix image (uml) captions with emphasis
  • Loading branch information
jdknight authored Nov 18, 2023
2 parents 01a3b74 + 5d1604c commit ad152f7
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 3 deletions.
2 changes: 1 addition & 1 deletion sphinxcontrib/confluencebuilder/storage/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1865,7 +1865,7 @@ def _visit_image(self, node, opts):
self.body.append(self._start_tag(node, 'ac:caption'))
next_sibling._skip_caption = True
for child in next_sibling.children:
child.walk(self)
child.walkabout(self)
self.body.append(self._end_tag(node))

self.body.append(self._end_ac_image(node))
Expand Down
31 changes: 29 additions & 2 deletions tests/lib/testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def test_storage_example(self):
super().__init__(*args, **kwargs)

self.builder = DEFAULT_BUILDER
self.target_editor = None

@classmethod
def setUpClass(cls):
Expand All @@ -60,7 +61,9 @@ def build(self, *args, **kwargs):

new_kwargs = dict(kwargs)
new_kwargs.setdefault('builder', self.builder)
new_kwargs.setdefault('config', self.config)
new_kwargs.setdefault('config', self.config.clone())
if self.target_editor:
new_kwargs['config']['confluence_editor'] = self.target_editor

return build_sphinx(*args, **new_kwargs)

Expand All @@ -75,7 +78,9 @@ def prepare(self, *args, **kwargs):

new_kwargs = dict(kwargs)
new_kwargs.setdefault('builder', self.builder)
new_kwargs.setdefault('config', self.config)
new_kwargs.setdefault('config', self.config.clone())
if self.target_editor:
new_kwargs['config']['confluence_editor'] = self.target_editor

return prepare_sphinx(*args, **new_kwargs)

Expand All @@ -100,3 +105,25 @@ def _wrapper(self, *args, **kwargs):
return func(self, *args, **kwargs)
return _wrapper
return _decorator


def setup_editor(editor):
"""
prepare a confluence unit test for a specific editor configuration
A utility "decorator" to help setup editor options for a unit test. This
avoids the need to explicitly configure an editor directly in the
configuration for a unit test testing against a dataset.
Args:
editor: the editor to use
"""

def _decorator(func):
@wraps(func)
def _wrapper(self, *args, **kwargs):
self.target_editor = editor

return func(self, *args, **kwargs)
return _wrapper
return _decorator
12 changes: 12 additions & 0 deletions tests/unit-tests/datasets/rst/figure-caption/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.. https://docutils.sourceforge.io/docs/ref/rst/directives.html#figure
figure
------

.. figure with caption
.. figure:: ../../../assets/image03.png

**caption** with *markup*

legend
58 changes: 58 additions & 0 deletions tests/unit-tests/test_rst_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from tests.lib.parse import parse
from tests.lib.testcase import ConfluenceTestCase
from tests.lib.testcase import setup_builder
from tests.lib.testcase import setup_editor
import os


Expand Down Expand Up @@ -166,3 +167,60 @@ def test_storage_rst_figure_defaults(self):
self.assertIsNotNone(next_tag)
self.assertTrue(next_tag.has_attr('style'))
self.assertTrue('clear: both' in next_tag['style'])

@setup_builder('confluence')
def test_storage_rst_figure_caption_default(self):
dataset = os.path.join(self.datasets, 'rst', 'figure-caption')
out_dir = self.build(dataset)

with parse('index', out_dir) as data:
figures = data.find_all('p', recursive=False)
self.assertEqual(len(figures), 1)

# ##########################################################
# single figure with caption
# ##########################################################
figure = figures.pop(0)

image = figure.find('ac:image', recursive=False)
self.assertIsNotNone(image)

caption = figure.find('p', recursive=False)
self.assertIsNotNone(caption)

markup1 = caption.find('strong', recursive=False)
self.assertIsNotNone(markup1)
self.assertIsNotNone(markup1.text, 'caption')

markup2 = caption.find('em', recursive=False)
self.assertIsNotNone(markup2)
self.assertIsNotNone(markup2.text, 'markup')

@setup_builder('confluence')
@setup_editor('v2')
def test_storage_rst_figure_caption_v2(self):
dataset = os.path.join(self.datasets, 'rst', 'figure-caption')
out_dir = self.build(dataset)

with parse('index', out_dir) as data:
figures = data.find_all('p', recursive=False)
self.assertEqual(len(figures), 1)

# ##########################################################
# single figure with caption
# ##########################################################
figure = figures.pop(0)

image = figure.find('ac:image', recursive=False)
self.assertIsNotNone(image)

caption = image.find('ac:caption', recursive=False)
self.assertIsNotNone(caption)

markup1 = caption.find('strong', recursive=False)
self.assertIsNotNone(markup1)
self.assertIsNotNone(markup1.text, 'caption')

markup2 = caption.find('em', recursive=False)
self.assertIsNotNone(markup2)
self.assertIsNotNone(markup2.text, 'markup')

0 comments on commit ad152f7

Please sign in to comment.