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

milde--- via Docutils-checkins <[email protected]> Thu, 16 Jan 2025 09:50:06 +0000
Newsgroups gmane.text.docutils.cvs
Message-ID <[email protected]>
Revision: 10006
          http://sourceforge.net/p/docutils/code/10006
Author:   milde
Date:     2025-01-16 09:50:06 +0000 (Thu, 16 Jan 2025)
Log Message:
-----------
Clean up and update TODO list.

Code modernization: check for and fix remaining cases from PEP 290

Doctree validation is implemented in 0.22.

Bug 241 is fixed long ago.

The proposed "--include FILE" command line option is
obsoleted by the upcoming changes to the command line interface.

Modified Paths:
--------------
    trunk/docutils/docs/dev/todo.rst
    trunk/docutils/docutils/utils/__init__.py
    trunk/docutils/docutils/writers/latex2e/__init__.py

Modified: trunk/docutils/docs/dev/todo.rst
===================================================================
--- trunk/docutils/docs/dev/todo.rst	2024-12-18 22:03:27 UTC (rev 10005)
+++ trunk/docutils/docs/dev/todo.rst	2025-01-16 09:50:06 UTC (rev 10006)
@@ -121,18 +121,6 @@
 Miscellaneous
 -------------
 
-Code cleanup and modernization:
-  Use flake8_? See also the configuration in `<../../tox.ini>`__.
-
-  Check and solve issue from  :PEP:`290` - Code Migration and Modernization.
-  (Covers issues up to Python 2.4, is there an equivalent for more recent
-  modernizations?)
-
-  Ensure `backwards compatibility`_!
-
-  .. _flake8: https://pypi.org/project/flake8/
-  .. _backwards compatibility: policies.html#backwards-compatibility-policy
-
 * Improve handling on Windows:
 
   - Get graphical installer.
@@ -239,8 +227,6 @@
     translations.
 
 
-* Add validation?  See http://pytrex.sourceforge.net, RELAX NG, pyRXP.
-
 * In ``docutils.readers.get_reader_class`` (& ``parsers`` &
   ``writers`` too), should we be importing "standalone" or
   "docutils.readers.standalone"?  (This would avoid importing
@@ -258,18 +244,6 @@
   Do we need it at all?  Or rather let the writers just ignore some
   nodes (like we already do for "class" values)?
 
-  The current implementation of the framework also leads to bug
-  `bug #241`__ "doctree-based publishing != publish_string".
-  The "components.Filter" transform is run by publish_doctree(). When
-  filtering based on the output format, it should be run by
-  publish_from_doctree() instead because only then the writer is
-  known.
-
-  So we need to either remove or fix the framework.
-
-  __ https://sourceforge.net/p/docutils/bugs/241/
-
-
 * Think about _`large documents` made up of multiple subdocument
   files.  Issues: continuity (`persistent sequences`_ above),
   cross-references (`name-to-id mapping file`_ above and `targets in
@@ -419,11 +393,6 @@
 
 * Rationalize Writer settings (HTML/LaTeX/PEP) -- share settings.
 
-* Add an "--include file" command-line option (config setting too?),
-  equivalent to ".. include:: file" as the first line of the doc text?
-  Especially useful for character entity sets, text transform specs,
-  boilerplate, etc.
-
 * Support "include" as embedded inline-compatible directive in substitution
   definitions, e.g. ::
 
@@ -603,7 +572,10 @@
 ``\label{<refname}`` command, ``\ref{<refname>}`` inserts the
 corresponding number.
 
-No such mechanism exists in HTML.
+No such mechanism exists in HTML/CSS (there is "target-counter" for paged
+media but this is not supported by browsers as of 2024).
+Cf. https://stackoverflow.com/questions/16453488/ and
+https://stackoverflow.com/questions/9463523/.
 
 * We need _`persistent sequences`, similar to chapter and footnote
   numbers. See `OpenOffice.org XML`_ "fields".

Modified: trunk/docutils/docutils/utils/__init__.py
===================================================================
--- trunk/docutils/docutils/utils/__init__.py	2024-12-18 22:03:27 UTC (rev 10005)
+++ trunk/docutils/docutils/utils/__init__.py	2025-01-16 09:50:06 UTC (rev 10006)
@@ -409,37 +409,34 @@
     """
     attlist = []
     while line:
-        equals = line.find('=')
-        if equals == -1:
+        equals_index = line.find('=')
+        if equals_index == -1:
             raise NameValueError('missing "="')
-        attname = line[:equals].strip()
-        if equals == 0 or not attname:
-            raise NameValueError(
-                  'missing attribute name before "="')
-        line = line[equals+1:].lstrip()
+        attname = line[:equals_index].strip()
+        if equals_index == 0 or not attname:
+            raise NameValueError('missing attribute name before "="')
+        line = line[equals_index+1:].lstrip()
         if not line:
-            raise NameValueError(
-                  'missing value after "%s="' % attname)
+            raise NameValueError(f'missing value after "{attname}="')
         if line[0] in '\'"':
-            endquote = line.find(line[0], 1)
-            if endquote == -1:
+            endquote_index = line.find(line[0], 1)
+            if endquote_index == -1:
                 raise NameValueError(
-                      'attribute "%s" missing end quote (%s)'
-                      % (attname, line[0]))
-            if len(line) > endquote + 1 and line[endquote + 1].strip():
-                raise NameValueError(
-                      'attribute "%s" end quote (%s) not followed by '
-                      'whitespace' % (attname, line[0]))
-            data = line[1:endquote]
-            line = line[endquote+1:].lstrip()
+                      f'attribute "{attname}" missing end quote ({line[0]})')
+            if (len(line) > endquote_index + 1
+                and line[endquote_index + 1].strip()):
+                raise NameValueError(f'attribute "{attname}" end quote '
+                                     f'({line[0]}) not followed by whitespace')
+            data = line[1:endquote_index]
+            line = line[endquote_index+1:].lstrip()
         else:
-            space = line.find(' ')
-            if space == -1:
+            space_index = line.find(' ')
+            if space_index == -1:
                 data = line
                 line = ''
             else:
-                data = line[:space]
-                line = line[space+1:].lstrip()
+                data = line[:space_index]
+                line = line[space_index+1:].lstrip()
         attlist.append((attname.lower(), data))
     return attlist
 
@@ -664,13 +661,13 @@
     parts = []
     start = 0
     while True:
-        found = text.find('\\', start)
-        if found == -1:
+        bs_index = text.find('\\', start)
+        if bs_index == -1:
             parts.append(text[start:])
             return ''.join(parts)
-        parts.extend((text[start:found],
-                      '\x00' + text[found + 1:found + 2]))
-        start = found + 2  # skip character after escape
+        parts.extend((text[start:bs_index],
+                      '\x00' + text[bs_index + 1:bs_index + 2]))
+        start = bs_index + 2  # skip character after escape
 
 
 def split_escaped_whitespace(text: str) -> list[str]:

Modified: trunk/docutils/docutils/writers/latex2e/__init__.py
===================================================================
--- trunk/docutils/docutils/writers/latex2e/__init__.py	2024-12-18 22:03:27 UTC (rev 10005)
+++ trunk/docutils/docutils/writers/latex2e/__init__.py	2025-01-16 09:50:06 UTC (rev 10006)
@@ -1355,9 +1355,9 @@
                     self.requirements['_textquotedbl'] = (
                         r'\DeclareTextSymbolDefault{\textquotedbl}{T1}')
         # page layout with typearea (if there are relevant document options)
-        if (settings.documentclass.find('scr') == -1
-            and (self.documentoptions.find('DIV') != -1
-                 or self.documentoptions.find('BCOR') != -1)):
+        if (not settings.documentclass.startswith('scr')
+            and ('DIV' in self.documentoptions
+                 or 'BCOR' in self.documentoptions)):
             self.requirements['typearea'] = r'\usepackage{typearea}'
 
         # Stylesheets
@@ -2831,7 +2831,7 @@
         if 'refuri' in node:
             href = str(node['refuri']).translate(special_chars)
             # problematic chars double caret and unbalanced braces:
-            if href.find('^^') != -1 or self.has_unbalanced_braces(href):
+            if '^^' in href or self.has_unbalanced_braces(href):
                 self.error(
                     f'External link "{href}" not supported by LaTeX.\n'
                     ' (Must not contain "^^" or unbalanced braces.)')
@@ -3027,8 +3027,7 @@
         if (self.active_table._latex_type == 'longtable'
             and isinstance(node.parent, nodes.section)
             and node.parent.index(node) == 1
-            and self.d_class.section(
-                   self.section_level).find('paragraph') != -1):
+            and 'paragraph' in self.d_class.section(self.section_level)):
             self.out.append('\\leavevmode')
         self.active_table.open()
         self.active_table.set_table_style(node, self.settings)

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



_______________________________________________
Docutils-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/docutils-checkins