diff options
| author | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2021-01-08 23:34:09 +0000 |
|---|---|---|
| committer | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2021-01-08 23:34:09 +0000 |
| commit | 45c01de2d84ef53367d644cbae9020c9802a0a62 (patch) | |
| tree | 9a5ca2b960ad7d1153ce73263ccca7bf9a609b12 /docutils | |
| parent | 9bb51c83368f6027101c116717bea5eaf2a82c20 (diff) | |
| download | docutils-45c01de2d84ef53367d644cbae9020c9802a0a62.tar.gz | |
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.
git-svn-id: https://svn.code.sf.net/p/docutils/code/trunk@8604 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
Diffstat (limited to 'docutils')
| -rw-r--r-- | docutils/HISTORY.txt | 6 | ||||
| -rw-r--r-- | docutils/docs/user/odt.txt | 43 | ||||
| -rw-r--r-- | docutils/docutils/writers/odf_odt/__init__.py | 46 |
3 files changed, 46 insertions, 49 deletions
diff --git a/docutils/HISTORY.txt b/docutils/HISTORY.txt index c14bf7146..7445e1f89 100644 --- a/docutils/HISTORY.txt +++ b/docutils/HISTORY.txt @@ -157,6 +157,12 @@ Changes Since 0.16 - 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`__. diff --git a/docutils/docs/user/odt.txt b/docutils/docs/user/odt.txt index 03a78a4e7..2e6083dab 100644 --- a/docutils/docs/user/odt.txt +++ b/docutils/docs/user/odt.txt @@ -90,7 +90,7 @@ Command line options 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,7 +147,7 @@ The following command line options are specific to ``odtwriter``: `Custom header/footers: inserting page numbers, date, time, etc`_ for details - + Styles and Classes ================== @@ -157,7 +157,7 @@ Styles and Classes 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 @@ Table styles ~~~~~~~~~~~~ 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 @@ Second, you can control additional table properties and you can 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 @@ The default table style will be applied to all tables for which you 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-footnote 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 @@ contain them, do the following: 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 @@ Classes 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 @@ role. 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 @@ Table of contents 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 @@ predefined style) to each paragraph/line in the container:: 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 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 @@ Here is an example:: 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 @@ On machines which support ``paperconf``, ``odtwriter`` can insert 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 @@ pick up the default paper size on platforms where the program .. _`OASIS Open Document Format for Office Applications (OpenDocument) TC`: http://www.oasis-open.org/committees/tc_home.php?wg_abbrev=office - - - diff --git a/docutils/docutils/writers/odf_odt/__init__.py b/docutils/docutils/writers/odf_odt/__init__.py index 49fac6559..8f795dabb 100644 --- a/docutils/docutils/writers/odf_odt/__init__.py +++ b/docutils/docutils/writers/odf_odt/__init__.py @@ -328,23 +328,6 @@ def escape_cdata(text): 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 @@ class Writer(writers.Writer): 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(' ') |
