|
From: <mi...@us...> - 2021-01-08 23:34:12
|
Revision: 8604
http://sourceforge.net/p/docutils/code/8604
Author: milde
Date: 2021-01-08 23:34:09 +0000 (Fri, 08 Jan 2021)
Log Message:
-----------
Fix/improve "odf" writer metadata handling.
Fix "keyword" splitting,
patch by Casper Meijn, https://github.com/caspermeijn/docutils/commit/af5c7718f68abfb15f5225524b42c9bd1179fce1
Allow generic fields (stored as "Custom Properties"),
based on patch #122 by pifi.
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/docs/user/odt.txt
trunk/docutils/docutils/writers/odf_odt/__init__.py
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2021-01-08 15:24:32 UTC (rev 8603)
+++ trunk/docutils/HISTORY.txt 2021-01-08 23:34:09 UTC (rev 8604)
@@ -157,6 +157,12 @@
- Fix #126 manpage title with spaces.
- Fix #380 commandline option problem in sphinx.
+* docutils/writers/odf_odt/__init__.py:
+
+ - Fix/improve metadata handling:
+ fix "keyword" splitting,
+ allow generic fields (stored as "Custom Properties").
+
* docutils/writers/pseudoxml.py:
- New option `detailled`__.
Modified: trunk/docutils/docs/user/odt.txt
===================================================================
--- trunk/docutils/docs/user/odt.txt 2021-01-08 15:24:32 UTC (rev 8603)
+++ trunk/docutils/docs/user/odt.txt 2021-01-08 23:34:09 UTC (rev 8604)
@@ -90,7 +90,7 @@
The following command line options are specific to ``odtwriter``:
---stylesheet=<URL> Specify a stylesheet URL, used verbatim.
+--stylesheet=<URL> Specify a stylesheet URL, used verbatim.
Default: writers/odf_odt/styles.odt in the
installation directory.
--odf-config-file=<file>
@@ -147,8 +147,8 @@
`Custom header/footers: inserting page numbers, date, time, etc`_
for details
-
+
Styles and Classes
==================
@@ -157,7 +157,7 @@
describes those styles.
Note that with the ``--stylesheet`` command line option, you can
-use either ``styles.odt`` or ``styles.xml``, as described below.
+use either ``styles.odt`` or ``styles.xml``, as described below.
Use of ``styles.odt`` is recommended over ``styles.xml``.
You can modify the look of documents generated by ``odtwriter`` in
@@ -497,7 +497,7 @@
~~~~~~~~~~~~
A table style is generated by ``oowriter`` for each table that you
-create. Therefore, ``odtwriter`` attempts to do something similar.
+create. Therefore, ``odtwriter`` attempts to do something similar.
These styles are created in the ``content.xml`` document in the
generated ``.odt`` file. These styles have names prefixed with
"rststyle-table-".
@@ -514,7 +514,7 @@
apply different styles to different tables within the same document
by customizing and using tables in your stylesheet: ``styles.odt``
or whatever you name your copy of it using the --stylesheet command
-line option. Then, follow these rules to apply a table style to
+line option. Then, follow these rules to apply a table style to
the tables in your document:
- The default table style -- Optionally, alter and customize the
@@ -541,7 +541,7 @@
do not specify a style with the ".. class::" directive.
Customize the table properties in ``oowriter`` using the table
-properties dialog for the table (style) that you wish to customize.
+properties dialog for the table (style) that you wish to customize.
Note that "--table-border-thickness" command line option overrides
the border thickness specified in the stylesheet.
@@ -605,7 +605,7 @@
rststyle-citation
The style for citations. This style affects the citation
- content, *not* the citation reference in the body of the document.
+ content, *not* the citation reference in the body of the document.
You might need to adjust the indentation in this style
depending on the length of the label used in your citations.
@@ -714,7 +714,7 @@
1. Create a configuration file containing a "Formats" section. The
configuration file obeys the file format supported by the Python
- ConfigParser module:
+ ConfigParser module:
`ConfigParser -- Configuration file parser --
http://docs.python.org/lib/module-ConfigParser.html
<http://docs.python.org/lib/module-ConfigParser.html>`_.
@@ -754,7 +754,7 @@
control of the generation of ODF content:
- Class ``wrap`` -- Use this to cause the wrapping of text around
- an image. The default is *not* to wrap text around images.
+ an image. The default is *not* to wrap text around images.
Here is an example::
.. class:: wrap
@@ -778,7 +778,7 @@
In order to use this capability, do the following:
- Define the character style for your custom role in a stylesheet
- (a copy of ``styles.odt``) with the prefix "rststyle-".
+ (a copy of ``styles.odt``) with the prefix "rststyle-".
Remember: (1) If the name of your custom role is "pretty", then
define a character style named "rststyle-pretty". (2) Define the
style as a *character* style, and *not*, for example as a
@@ -817,7 +817,7 @@
The ``..contents::`` directive causes ``odtwriter`` to generate
either:
-1. A static, outline style table of contents, if the
+1. A static, outline style table of contents, if the
``--generate-list-toc`` command line option is specified, or
2. An ODF/``oowriter`` style table of contents containing
@@ -929,7 +929,7 @@
Line 2 of container.
More information on how to define a new style (for example, in your
-``styles.odt``) can be found in section
+``styles.odt``) can be found in section
`Defining and using custom style names`_.
@@ -960,7 +960,7 @@
Footnotes and citations are supported.
There are additional styles ``rststyle-footnote`` and
-``rststyle-citation`` for footnotes and citations. See
+``rststyle-citation`` for footnotes and citations. See
`Footnote and citation styles`_.
You may need to modify the citation style to fit the length of your
@@ -1027,17 +1027,21 @@
The meta directive
------------------
-``odtwriter`` supports the ``meta`` directive. Two fields are
-recognized: "keywords" and "description". Here is an example::
+``odtwriter`` supports the ``meta`` directive. "keywords"
+and "description" are set in their respective odt fields.
+Other meta fields are set as "Custom Properties".
+Here is an example::
.. meta::
:keywords: reStructuredText, docutils, formatting
:description lang=en: A reST document, contains formatted
text in a formatted style.
+ :custom_var: Value
To see the results of the ``meta`` directive in ``oowriter``,
select menu item "File/Properties...", then click on the
-"Description" tab.
+"Description" tab ("keywords" and "description" fields) and the
+"Custom Properties" tab.
Footnote references inside footnotes
@@ -1064,8 +1068,8 @@
the default page size for your locale. In order for this to work,
the following conditions must be met:
-1. The program ``paperconf`` must be available on your system.
- ``odtwriter`` uses ``paperconf -s`` to obtain the paper size.
+1. The program ``paperconf`` must be available on your system.
+ ``odtwriter`` uses ``paperconf -s`` to obtain the paper size.
See ``man paperconf`` for more information.
2. The default page height and width must be removed from the
@@ -1188,6 +1192,3 @@
.. _`OASIS Open Document Format for Office Applications (OpenDocument) TC`:
http://www.oasis-open.org/committees/tc_home.php?wg_abbrev=office
-
-
-
Modified: trunk/docutils/docutils/writers/odf_odt/__init__.py
===================================================================
--- trunk/docutils/docutils/writers/odf_odt/__init__.py 2021-01-08 15:24:32 UTC (rev 8603)
+++ trunk/docutils/docutils/writers/odf_odt/__init__.py 2021-01-08 23:34:09 UTC (rev 8604)
@@ -328,23 +328,6 @@
return ascii
-WORD_SPLIT_PAT1 = re.compile(r'\b(\w*)\b\W*')
-
-
-def split_words(line):
- # We need whitespace at the end of the string for our regexpr.
- line += ' '
- words = []
- pos1 = 0
- mo = WORD_SPLIT_PAT1.search(line, pos1)
- while mo is not None:
- word = mo.groups()[0]
- words.append(word)
- pos1 = mo.end()
- mo = WORD_SPLIT_PAT1.search(line, pos1)
- return words
-
-
#
# Classes
#
@@ -808,17 +791,24 @@
el1.text = title
else:
el1.text = '[no title]'
- meta_dict = self.visitor.get_meta_dict()
- keywordstr = meta_dict.get('keywords')
- if keywordstr is not None:
- keywords = split_words(keywordstr)
- for keyword in keywords:
- el1 = SubElement(root, 'meta:keyword', nsdict=METNSD)
- el1.text = keyword
- description = meta_dict.get('description')
- if description is not None:
- el1 = SubElement(root, 'dc:description', nsdict=METNSD)
- el1.text = description
+ for prop, value in self.visitor.get_meta_dict().items():
+ # 'keywords', 'description', and 'subject' have their own fields:
+ if prop == 'keywords':
+ keywords = re.split(', *', value)
+ for keyword in keywords:
+ el1 = SubElement(root, 'meta:keyword', nsdict=METNSD)
+ el1.text = keyword
+ elif prop == 'description':
+ el1 = SubElement(root, 'dc:description', nsdict=METNSD)
+ el1.text = value
+ # TODO: handle "subject" (which element is it?)
+ ## elif prop == 'subject':
+ ## el1 = SubElement(root, 'xxxxxxxx', nsdict=METNSD)
+ ## el1.text = value
+ else: # Store remaining properties as custom/user-defined
+ el1 = SubElement(root, 'meta:user-defined',
+ attrib={'meta:name': prop}, nsdict=METNSD)
+ el1.text = value
s1 = ToString(doc)
#doc = minidom.parseString(s1)
#s1 = doc.toprettyxml(' ')
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|