SF.net SVN: docutils:[9776] trunk

grubert--- via Docutils-checkins <[email protected]>
Newsgroups gmane.text.docutils.cvs
Message-ID <[email protected]>
Revision: 9776
          http://sourceforge.net/p/docutils/code/9776
Author:   grubert
Date:     2024-07-22 09:48:35 +0000 (Mon, 22 Jul 2024)
Log Message:
-----------
move non printing breakpoint insertion function into manpage writer

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

Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt	2024-07-19 11:57:06 UTC (rev 9775)
+++ trunk/docutils/HISTORY.txt	2024-07-22 09:48:35 UTC (rev 9776)
@@ -143,6 +143,7 @@
   - Feature-request #105 more informative document comments.
     docutils version in header
   - Stop converting text to full capitals (bug #481).
+  - Add module function insert_URI_breakpoints.
 
 * docutils/writers/null.py
 

Modified: trunk/docutils/docutils/writers/manpage.py
===================================================================
--- trunk/docutils/docutils/writers/manpage.py	2024-07-19 11:57:06 UTC (rev 9775)
+++ trunk/docutils/docutils/writers/manpage.py	2024-07-22 09:48:35 UTC (rev 9776)
@@ -89,7 +89,24 @@
 ..
 """
 
+# see groff_man_style recommends aplying non-printing break points
+# in long URIs.
+NONPRINTING_BREAKPOINT = r'\:'
 
+# after a slash series of
+# after?before at sign
+# after question marks
+# after question ampersands
+# after question number signs
+# (?=.) avoids matching the of string
+# TODO before each dot or a series of
+NONBREAKING_INSERT_RE = re.compile(r'([/@?&#]+)(?=.)')
+
+def insert_URI_breakpoints(s):
+    # TODO only for long URIs ?
+    return NONBREAKING_INSERT_RE.sub( r'\1'+NONPRINTING_BREAKPOINT, s)
+
+
 class Writer(writers.Writer):
     """
     manpage writer class

Modified: trunk/docutils/test/test_writers/test_manpage.py
===================================================================
--- trunk/docutils/test/test_writers/test_manpage.py	2024-07-19 11:57:06 UTC (rev 9775)
+++ trunk/docutils/test/test_writers/test_manpage.py	2024-07-22 09:48:35 UTC (rev 9776)
@@ -17,8 +17,27 @@
     sys.path.insert(0, str(Path(__file__).resolve().parents[2]))
 
 from docutils.core import publish_string
+from docutils.writers.manpage import insert_URI_breakpoints
 
+URI_tests = (
+        ("///abc.de", r"///\:abc.de"),
+        ("/abc.de/", r"/\:abc.de/"),
+        ("http://abc.de", r"http://\:abc.de"),
+        ("http://abc.de/fg", r"http://\:abc.de/\:fg"),
+        ("http://abc.de/fg?q=abc", r"http://\:abc.de/\:fg?\:q=abc"),
+        ("http://abc.de/fg/?q=abc", r"http://\:abc.de/\:fg/?\:q=abc"),
+        ("http://abc.de/fg/?q=abc&me#", r"http://\:abc.de/\:fg/?\:q=abc&\:me#"),
+        ("[email protected]", r"me@\:home.here"),
+        )
 
+class URIBreakpointsTestCase(unittest.TestCase):
+
+    def test_insert(self):
+        for t in URI_tests:
+            got = insert_URI_breakpoints(t[0])
+            self.assertEqual(t[1], got)
+
+
 class WriterPublishTestCase(unittest.TestCase):
 
     maxDiff = None

Modified: trunk/sandbox/manpage-writer/ref-breakpoints.py
===================================================================
--- trunk/sandbox/manpage-writer/ref-breakpoints.py	2024-07-19 11:57:06 UTC (rev 9775)
+++ trunk/sandbox/manpage-writer/ref-breakpoints.py	2024-07-22 09:48:35 UTC (rev 9776)
@@ -1,3 +1,6 @@
+# MOVED to writers.manpage and test.writers.manpage
+# LEFT for reference.
+
 # see groff_man_style on
 
 #  Hyperlink macros
@@ -32,6 +35,8 @@
 #      vers.
 #      
 
+from docutils.writers.manpage import insert_URI_breakpoints
+
 tests = (
         ("///abc.de", r"///\:abc.de"),
         ("/abc.de/", r"/\:abc.de/"),
@@ -43,27 +48,20 @@
         ("[email protected]", r"me@\:home.here"),
         )
 
-import re
-
-BREAKPOINT = r'\:'
-
-# after series of slash
+# after a slash series of
 # after?before at sign
 # after question marks
 # after question ampersands
 # after question number signs
 # (?=.) avoids matching the of string
-MATCH = re.compile(r'([/@?&#]+)(?=.)')
+# TODO before each dot or a series of
 
-def insert_breakpoints(s):
-    return MATCH.sub( r'\1'+BREAKPOINT, s)
-
 err = 0
 cnt = 0
 
 for t in tests:
     cnt += 1
-    got = insert_breakpoints(t[0])
+    got = insert_URI_breakpoints(t[0])
     if t[1] != got:
         print( "FAIL {0} got {1} expected {2}".format(t[0], got, t[1]) )
         err += 1

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.