chiark / gitweb /
documentation/doxygen: support img alt properties.
authorWojciech Jarosz <wkjarosz@users.noreply.github.com>
Mon, 30 Aug 2021 16:30:13 +0000 (12:30 -0400)
committerVladimír Vondruš <mosra@centrum.cz>
Sun, 15 Sep 2024 14:28:41 +0000 (16:28 +0200)
Co-authored-by: Vladimír Vondruš <mosra@centrum.cz>
documentation/doxygen.py
documentation/test_doxygen/contents_image/index-1820.html [new file with mode: 0644]
documentation/test_doxygen/contents_image/index.html
documentation/test_doxygen/contents_image/input.dox
documentation/test_doxygen/test_contents.py

index 4ce662d053024c506539b6bc96568b5e767f29a4..2a5568a2f028d153264db5d74560298bb9f73899 100755 (executable)
@@ -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
+                # <img> 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 += '<figure class="m-figure{}"><img src="{}" alt="Image"{} /><figcaption>{}</figcaption></figure>'.format(
+                    out.parsed += '<figure class="m-figure{}"><img src="{}" alt="{}"{} /><figcaption>{}</figcaption></figure>'.format(
                         ' ' + add_css_class if add_css_class else '',
-                        name, sizespec, html.escape(caption))
+                        name, alt, sizespec, html.escape(caption))
                 else:
-                    out.parsed += '<img class="m-image{}" src="{}" alt="Image"{} />'.format(
-                        ' ' + add_css_class if add_css_class else '', name, sizespec)
+                    out.parsed += '<img class="m-image{}" src="{}" alt="{}"{} />'.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 (file)
index 0000000..52b0005
--- /dev/null
@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+  <meta charset="UTF-8" />
+  <title>My Project</title>
+  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,400i,600,600i%7CSource+Code+Pro:400,400i,600" />
+  <link rel="stylesheet" href="m-dark+documentation.compiled.css" />
+  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+</head>
+<body>
+<header><nav id="navigation">
+  <div class="m-container">
+    <div class="m-row">
+      <a href="index.html" id="m-navbar-brand" class="m-col-t-8 m-col-m-none m-left-m">My Project</a>
+    </div>
+  </div>
+</nav></header>
+<main><article>
+  <div class="m-container m-container-inflatable">
+    <div class="m-row">
+      <div class="m-col-l-10 m-push-l-1">
+        <h1>
+          My Project
+        </h1>
+<p>Image:</p><img class="m-image" src="tiny.png" alt="Image" /><p>Figure:</p><figure class="m-figure"><img src="tiny.png" alt="Image" /><figcaption>Caption</figcaption></figure><p>Explicit width:</p><img class="m-image" src="tiny.png" alt="Image" style="width: 128px;" /><p>Explicit height and a caption:</p><figure class="m-figure"><img src="tiny.png" alt="Image" style="height: 64px;" /><figcaption>This is 64 pixels high.</figcaption></figure><p>Alt text. Can be only specified with the HTML tag, not with <code>@image</code>.</p><img class="m-image" src="tiny.png" alt="Image" />
+      </div>
+    </div>
+  </div>
+</article></main>
+</body>
+</html>
index 953e8cb2b4c6cdf38ca0a7c68bdcee7bf7b80458..186614b975b46885d3854cb7bb54d3ee1fa6ff43 100644 (file)
@@ -22,7 +22,7 @@
         <h1>
           My Project
         </h1>
-<p>Image:</p><img class="m-image" src="tiny.png" alt="Image" /><p>Figure:</p><figure class="m-figure"><img src="tiny.png" alt="Image" /><figcaption>Caption</figcaption></figure><p>Explicit width:</p><img class="m-image" src="tiny.png" alt="Image" style="width: 128px;" /><p>Explicit height and a caption:</p><figure class="m-figure"><img src="tiny.png" alt="Image" style="height: 64px;" /><figcaption>This is 64 pixels high.</figcaption></figure>
+<p>Image:</p><img class="m-image" src="tiny.png" alt="Image" /><p>Figure:</p><figure class="m-figure"><img src="tiny.png" alt="Image" /><figcaption>Caption</figcaption></figure><p>Explicit width:</p><img class="m-image" src="tiny.png" alt="Image" style="width: 128px;" /><p>Explicit height and a caption:</p><figure class="m-figure"><img src="tiny.png" alt="Image" style="height: 64px;" /><figcaption>This is 64 pixels high.</figcaption></figure><p>Alt text. Can be only specified with the HTML tag, not with <code>@image</code>.</p><img class="m-image" src="tiny.png" alt="This is an alt text." />
       </div>
     </div>
   </div>
index 3ab8fd969ac48f59728a202c2e0471f5e8f31f7f..7d7a300596af5646c8fd7dac273474962eacd276 100644 (file)
@@ -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`.
+
+<img src="tiny.png" alt="This is an alt text." />
+
 */
 
 /** @page warnings Images that produce warnings
index 77031105f1c6ffb6daf6256f85bf25d6e4977148..e88d09682cf4c52e82c0543061a4104eba17ec60 100644 (file)
@@ -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
+        # <img>
+        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):