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

milde--- via Docutils-checkins <[email protected]> Thu, 20 Feb 2025 10:07:20 +0000
Newsgroups gmane.text.docutils.cvs
Message-ID <[email protected]>
Revision: 10011
          http://sourceforge.net/p/docutils/code/10011
Author:   milde
Date:     2025-02-20 10:07:20 +0000 (Thu, 20 Feb 2025)
Log Message:
-----------
Fixes for metadata in LaTeX and ODT.

Just like the HTML writer, LaTeX and ODT writers now use
the `<document>` element's "title" attribute (the "metadata title",
https://docutils.sourceforge.io/docs/ref/doctree.html#title-1)
instead of its `<title>` element in the document metadata.

LaTeX writer:
Encode special characters in the content of the "meta" directive.
Fix "hyperef" keys for "creator" and "producer".

TODO:
Filter nodes with additional fields ("lang", "http-equiv", ...)?
They are HTML-specific and may override equally named keys.
Only if name already present?

Modified Paths:
--------------
    trunk/docutils/HISTORY.rst
    trunk/docutils/docutils/writers/latex2e/__init__.py
    trunk/docutils/docutils/writers/odf_odt/__init__.py

Modified: trunk/docutils/HISTORY.rst
===================================================================
--- trunk/docutils/HISTORY.rst	2025-02-19 21:25:17 UTC (rev 10010)
+++ trunk/docutils/HISTORY.rst	2025-02-20 10:07:20 UTC (rev 10011)
@@ -180,6 +180,8 @@
   - Support SVG image inclusion with the "svg" LaTeX package (see the
     `stylesheet`__ configuration setting).
   - Add "template" to the parts returned by `Writer.assemble_parts()`.
+  - Use <document> "title" attribute in pdfinfo.
+  - Encode <meta> element content in pdfinfo.
 
   .. _reference-label: docs/user/config.html#reference-label
   __ docs/user/config.html#stylesheet-latex-writers
@@ -214,6 +216,7 @@
   - Fix conversion of image width in "%" if the height is specified.
   - Adjust fallback DPI value (currently not used) to match CSS units.
   - Fix errors with ``*.xml`` style files (bug #494).
+  - Use <document> "title" attribute in document metadata.
 
 * pyproject.toml
 

Modified: trunk/docutils/docutils/writers/latex2e/__init__.py
===================================================================
--- trunk/docutils/docutils/writers/latex2e/__init__.py	2025-02-19 21:25:17 UTC (rev 10010)
+++ trunk/docutils/docutils/writers/latex2e/__init__.py	2025-02-20 10:07:20 UTC (rev 10011)
@@ -1303,7 +1303,7 @@
         self.author_stack = []
         self.date = []
 
-        # PDF properties: pdftitle, pdfauthor
+        # PDF properties:
         self.pdfauthor = []
         self.pdfinfo = []
         if settings.language_code != 'en':
@@ -2003,6 +2003,9 @@
             self.requirements['babel'] = self.babel()
         # * PDF properties
         self.pdfsetup.append(PreambleCmds.linking % self.hyperref_options)
+        if self.document.get('title', ''):
+            self.pdfinfo.insert(0, '  pdftitle={%s},' %
+                                self.encode(self.document.get('title', '')))
         if self.pdfauthor:
             authors = self.author_separator.join(self.pdfauthor)
             self.pdfinfo.append('  pdfauthor={%s}' % authors)
@@ -2646,18 +2649,20 @@
         self.duclass_close(node)
 
     def visit_meta(self, node) -> None:
-        name = node.attributes.get('name')
-        content = node.attributes.get('content')
-        if not name or not content:
-            return
-        if name in ('author', 'creator', 'keywords', 'subject', 'title'):
+        if 'name' not in node or 'content' not in node:
+            raise nodes.SkipNode  # HTML specific or empty metadata
+        # TODO: Filter nodes with additional fields ("lang", "http-equiv", …)?
+        #       They are HTML-specific and may override equally named keys.
+        #       Only if name already present?  See also ODT writer.
+        name = node['name']
+        content = self.encode(node['content'])
+        if name in ('author', 'keywords', 'producer', 'subject', 'title'):
             # fields with dedicated hyperref options:
             self.pdfinfo.append('  pdf%s={%s},'%(name, content))
-        elif name == 'producer':
-            self.pdfinfo.append('  addtopdfproducer={%s},'%content)
+        elif name == 'creator':
+            self.pdfinfo.append('  addtopdfcreator={%s},'%content)
         else:
             # generic interface (case sensitive!)
-            # TODO: filter irrelevant nodes ("http-equiv", ...)?
             self.pdfinfo.append('  pdfinfo={%s={%s}},'%(name, content))
 
     def depart_meta(self, node) -> None:
@@ -3144,8 +3149,6 @@
         if isinstance(node.parent, nodes.document):
             self.push_output_collector(self.title)
             self.context.append('')
-            self.pdfinfo.append('  pdftitle={%s},' %
-                                self.encode(node.astext()))
         # Topic titles (topic, admonition, sidebar)
         elif (isinstance(node.parent, nodes.topic)
               or isinstance(node.parent, nodes.admonition)

Modified: trunk/docutils/docutils/writers/odf_odt/__init__.py
===================================================================
--- trunk/docutils/docutils/writers/odf_odt/__init__.py	2025-02-19 21:25:17 UTC (rev 10010)
+++ trunk/docutils/docutils/writers/odf_odt/__init__.py	2025-02-20 10:07:20 UTC (rev 10011)
@@ -747,12 +747,8 @@
         el1.text = '1'
         el1 = SubElement(root, 'meta:editing-duration', nsdict=METNSD)
         el1.text = 'PT00M01S'
-        title = self.visitor.get_title()
         el1 = SubElement(root, 'dc:title', nsdict=METNSD)
-        if title:
-            el1.text = title
-        else:
-            el1.text = '[no title]'
+        el1.text = self.document.get('title', '[no title]')
         for prop, value in self.visitor.get_meta_dict().items():
             # 'keywords', 'description', and 'subject' have their own fields:
             if prop == 'keywords':

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