SF.net SVN: docutils:[9960 ] trunk/docutils

grubert--- via Docutils-checkins <[email protected]>
Newsgroups gmane.text.docutils.cvs
Message-ID <[email protected]>
Revision: 9960
          http://sourceforge.net/p/docutils/code/9960
Author:   grubert
Date:     2024-10-21 20:48:53 +0000 (Mon, 21 Oct 2024)
Log Message:
-----------
manpage image handling redo

Modified Paths:
--------------
    trunk/docutils/docutils/writers/manpage.py
    trunk/docutils/test/test_writers/test_manpage.py

Modified: trunk/docutils/docutils/writers/manpage.py
===================================================================
--- trunk/docutils/docutils/writers/manpage.py	2024-10-21 19:26:26 UTC (rev 9959)
+++ trunk/docutils/docutils/writers/manpage.py	2024-10-21 20:48:53 UTC (rev 9960)
@@ -822,14 +822,20 @@
         self.body.append('\n')
 
     def visit_image(self, node):
-        self.document.reporter.warning('"image" not supported',
+        msg = '"image" not supported by "manpage" writer.'
+        if 'alt' in node.attributes:
+            self.document.reporter.info(msg,
+                                        base_node=node)
+            self.body.append('.sp\n    %s\n' % (
+                    node.attributes['alt']))
+        elif 'uri' in node.attributes:
+            self.body.append('.sp\n    image: %s\n' % (
+                    node.attributes['uri']))
+            self.document.reporter.warning(
+                    f'''{msg}
+Please provide an "alt" attribute with textual replacement.''',
                                        base_node=node)
-        text = []
-        if 'alt' in node.attributes:
-            text.append(node.attributes['alt'])
-        if 'uri' in node.attributes:
-            text.append(node.attributes['uri'])
-        self.body.append('[image: %s]\n' % ('/'.join(text)))
+        # else 0 arguments to image not allowed
         raise nodes.SkipNode
 
     def visit_important(self, node) -> None:

Modified: trunk/docutils/test/test_writers/test_manpage.py
===================================================================
--- trunk/docutils/test/test_writers/test_manpage.py	2024-10-21 19:26:26 UTC (rev 9959)
+++ trunk/docutils/test/test_writers/test_manpage.py	2024-10-21 20:48:53 UTC (rev 9960)
@@ -89,7 +89,7 @@
                     warnings.seek(0)
                     self.assertEqual(
                             case_warning,
-                            warnings.readline())
+                            warnings.readlines())
 
 
 
@@ -587,7 +587,7 @@
 # test defintion
 # [ input, expect, expected_warning ]
 totest_system_msgs ={}
-# TODO check we get an INFO not a WARNING
+# check we get an INFO not a WARNING
 totest_system_msgs['image'] = [
         ["""\
 text
@@ -601,29 +601,18 @@
 .SH Name
  \\- \n\
 text
-[image: an image of something/gibsnich.png]
 .sp
+    an image of something
+.sp
 more text
 .\\" End of generated man page.
 """,
-"""\
-<string>:3: (WARNING/2) "image" not supported
-"""],
-# TODO make alt text a quote like
-#
-# text
-#
-#    an image of something
-#
-# more text
-]
+[]
+# TODO check INFO text
+# INFO not in warning_stream    #<string>:3: (INFO/1) "image" not supported\"""
+],
 
-# TODO check we get a WARNING
-#
-#   (WARNING/2) "image" not supported by "manpage" writer.
-#   Please provide an "alt" attribute with textual replacement.
-#
-totest_system_msgs['image-without-alt'] = [
+# check we get a WARNING if no alt text
         ["""text
 
 .. image:: gibsnich.png
@@ -634,16 +623,16 @@
 .SH Name
  \\- \n\
 text
-[image: gibsnich.png]
 .sp
+    image: gibsnich.png
+.sp
 more text
 .\\" End of generated man page.
 """,
-"""\
-<string>:3: (WARNING/2) "image" not supported
-"""],
-# TODO there should be nothing of the image in the manpage, might be decorative
+[ '<string>:3: (WARNING/2) "image" not supported by "manpage" writer.\n',
+'Please provide an "alt" attribute with textual replacement.\n']
 ]
+]
 
 
 if __name__ == '__main__':

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.