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

grubert--- via Docutils-checkins <[email protected]>
Newsgroups gmane.text.docutils.cvs
Message-ID <[email protected]>
Revision: 9597
          http://sourceforge.net/p/docutils/code/9597
Author:   grubert
Date:     2024-03-26 15:08:54 +0000 (Tue, 26 Mar 2024)
Log Message:
-----------
manpage: render references in writer not in man/mandoc/...

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

Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt	2024-03-26 12:03:42 UTC (rev 9596)
+++ trunk/docutils/HISTORY.txt	2024-03-26 15:08:54 UTC (rev 9597)
@@ -175,7 +175,8 @@
 
   - Skip footer to avoid the link to document source in the manpage.
   - Add multiple definition list term support, see feature #60.
-  - Use ``.UR`` and ``.UE`` macros for reference markup.
+  - Render reference, refid and refuri.
+    Use of ``.UR`` and ``.UE`` macros for reference markup is too brittle.
   - Add preprocessor hinting tbl first line, see bug #477.
   - Change tbl-Tables using box option, see bug #475.
   - Apply literal block patch #205. Use ``.EE`` and ``.EX`` macros.

Modified: trunk/docutils/docutils/writers/manpage.py
===================================================================
--- trunk/docutils/docutils/writers/manpage.py	2024-03-26 12:03:42 UTC (rev 9596)
+++ trunk/docutils/docutils/writers/manpage.py	2024-03-26 15:08:54 UTC (rev 9597)
@@ -1002,15 +1002,25 @@
 
     def visit_reference(self, node):
         """E.g. link or email address."""
-        self.ensure_eol()
-        self.body.append(".UR ")
+        # .UR and .UE macros in roff use OSC8 escape sequences
+        # which are not supported everywhere yet
+        # therefore make the markup ourself
         if 'refuri' in node:
-            if not node['refuri'].endswith(node.astext()):
-                self.body.append("%s\n" % node['refuri'])
+            # if content has the "email" do not output "mailto:email"
+            if node['refuri'].endswith(node.astext()):
+                self.body.append(" <")
+        elif 'refid' in node:
+            self.body.append(" <")
 
     def depart_reference(self, node):
-        self.ensure_eol()
-        self.body.append(".UE\n")
+        if 'refuri' in node:
+            # if content has the "email" do not output "mailto:email"
+            if node['refuri'].endswith(node.astext()):
+                self.body.append("> ")
+            else:
+                self.body.append(" <%s>\n" % node['refuri'])
+        elif 'refid' in node:
+            self.body.append("> ")
 
     def visit_revision(self, node):
         self.visit_docinfo_item(node, 'revision')

Modified: trunk/docutils/test/test_writers/test_manpage.py
===================================================================
--- trunk/docutils/test/test_writers/test_manpage.py	2024-03-26 12:03:42 UTC (rev 9596)
+++ trunk/docutils/test/test_writers/test_manpage.py	2024-03-26 15:08:54 UTC (rev 9597)
@@ -194,10 +194,7 @@
 .UNINDENT
 .SH OTHER SECTION
 .sp
-link to 
-.UR http://docutils.sourceforge.io
-.UE
-
+link to  <http://docutils.sourceforge.io> 
 .sp
 With mixed case.
 .sp

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.