From: Wojciech Jarosz Date: Mon, 30 Aug 2021 16:30:13 +0000 (-0400) Subject: documentation/doxygen: support img alt properties. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=2d1f0bceb9a98a093019b5a5439b7d130af21900;p=blog.git documentation/doxygen: support img alt properties. Co-authored-by: Vladimír Vondruš --- diff --git a/documentation/doxygen.py b/documentation/doxygen.py index 4ce662d0..2a5568a2 100755 --- a/documentation/doxygen.py +++ b/documentation/doxygen.py @@ -1092,14 +1092,19 @@ def parse_desc_internal(state: State, element: ET.Element, immediate_parent: ET. elif 'height' in i.attrib: sizespec = ' style="height: {};"'.format(i.attrib['height']) + # The alt text can apparently be specified only with the HTML + # tag, not with @image. It's also present only since + # 1.9.1(?). + alt = i.attrib.get('alt', 'Image') + caption = i.text if caption: - out.parsed += '
Image
{}
'.format( + out.parsed += '
{}
{}
'.format( ' ' + add_css_class if add_css_class else '', - name, sizespec, html.escape(caption)) + name, alt, sizespec, html.escape(caption)) else: - out.parsed += 'Image'.format( - ' ' + add_css_class if add_css_class else '', name, sizespec) + out.parsed += '{}'.format( + ' ' + add_css_class if add_css_class else '', name, alt, sizespec) elif i.tag in ['dot', 'dotfile']: assert element.tag in ['para', '{http://mcss.mosra.cz/doxygen/}div'] diff --git a/documentation/test_doxygen/contents_image/index-1820.html b/documentation/test_doxygen/contents_image/index-1820.html new file mode 100644 index 00000000..52b00053 --- /dev/null +++ b/documentation/test_doxygen/contents_image/index-1820.html @@ -0,0 +1,31 @@ + + + + + My Project + + + + + +
+
+
+
+
+

+ My Project +

+

Image:

Image

Figure:

Image
Caption

Explicit width:

Image

Explicit height and a caption:

Image
This is 64 pixels high.

Alt text. Can be only specified with the HTML tag, not with @image.

Image +
+
+
+
+ + diff --git a/documentation/test_doxygen/contents_image/index.html b/documentation/test_doxygen/contents_image/index.html index 953e8cb2..186614b9 100644 --- a/documentation/test_doxygen/contents_image/index.html +++ b/documentation/test_doxygen/contents_image/index.html @@ -22,7 +22,7 @@

My Project

-

Image:

Image

Figure:

Image
Caption

Explicit width:

Image

Explicit height and a caption:

Image
This is 64 pixels high.
+

Image:

Image

Figure:

Image
Caption

Explicit width:

Image

Explicit height and a caption:

Image
This is 64 pixels high.

Alt text. Can be only specified with the HTML tag, not with @image.

This is an alt text. diff --git a/documentation/test_doxygen/contents_image/input.dox b/documentation/test_doxygen/contents_image/input.dox index 3ab8fd96..7d7a3005 100644 --- a/documentation/test_doxygen/contents_image/input.dox +++ b/documentation/test_doxygen/contents_image/input.dox @@ -16,6 +16,10 @@ Explicit height and a caption: @image html tiny.png "This is 64 pixels high." height=64px +Alt text. Can be only specified with the HTML tag, not with `@image`. + +This is an alt text. + */ /** @page warnings Images that produce warnings diff --git a/documentation/test_doxygen/test_contents.py b/documentation/test_doxygen/test_contents.py index 77031105..e88d0968 100644 --- a/documentation/test_doxygen/test_contents.py +++ b/documentation/test_doxygen/test_contents.py @@ -126,7 +126,14 @@ class CodeLanguage(IntegrationTestCase): class Image(IntegrationTestCase): def test(self): self.run_doxygen(wildcard='indexpage.xml') - self.assertEqual(*self.actual_expected_contents('index.html')) + + # Versions before 1.9.1(?) don't have the alt attribute preserved for + # + if parse_version(doxygen_version()) >= parse_version("1.9.1"): + self.assertEqual(*self.actual_expected_contents('index.html')) + else: + self.assertEqual(*self.actual_expected_contents('index.html', 'index-1820.html')) + self.assertTrue(os.path.exists(os.path.join(self.path, 'html', 'tiny.png'))) def test_warnings(self):