SF.net SVN: docutils:[9563 ] trunk/sandbox/manpage-wri ter/multiple_definition_list _terms.py

grubert--- via Docutils-checkins <[email protected]>
Newsgroups gmane.text.docutils.cvs
Message-ID <[email protected]>
Revision: 9563
          http://sourceforge.net/p/docutils/code/9563
Author:   grubert
Date:     2024-03-15 12:16:24 +0000 (Fri, 15 Mar 2024)
Log Message:
-----------
extensive multiple definition list terms

Added Paths:
-----------
    trunk/sandbox/manpage-writer/multiple_definition_list_terms.py

Added: trunk/sandbox/manpage-writer/multiple_definition_list_terms.py
===================================================================
--- trunk/sandbox/manpage-writer/multiple_definition_list_terms.py	                        (rev 0)
+++ trunk/sandbox/manpage-writer/multiple_definition_list_terms.py	2024-03-15 12:16:24 UTC (rev 9563)
@@ -0,0 +1,132 @@
+#!/usr/bin/env python3
+# :Copyright: © 2023 Günter Milde.
+
+#             Released without warranty under the terms of the
+#             GNU General Public License (v. 2 or later)
+
+# :License: Released under the terms of the `2-Clause BSD license`_, in short:
+#
+#    Copying and distribution of this file, with or without modification,
+#    are permitted in any medium without royalty provided the copyright
+#    notice and this notice are preserved.
+#    This file is offered as-is, without any warranty.
+#
+# .. _2-Clause BSD license: https://opensource.org/licenses/BSD-2-Clause
+#
+# Test definition list items with extra terms  with Docutils writers
+# =================================================================
+
+# `Feature-Request #60`__ asks for the legitimation of definition list
+# items with more than one term for two reasons:
+# 
+# * it is legal and supported in HTML,
+# * the custom directive `"glossary"`_ may generate definition list items
+#   with multiple terms.
+#
+# __ https://sourceforge.net/p/docutils/feature-requests/60/
+# __ https://www.sphinx-doc.org/en/master/
+#            usage/restructuredtext/directives.html#glossary
+# 
+# In Docutils <= 0.20, there is no rST syntax construct that can generate a 
+# definition list item with more than one term.
+#
+# To allow testing and improving writer support, this skript generates a
+# document tree programatically and exports it with the writers defined in
+# Docutils to temporary files.
+
+from docutils.core import publish_doctree, publish_from_doctree
+from docutils.nodes import term, classifier
+
+sample = """\
+term 1
+  definition 1
+term 2a
+  definition 2
+term 3a : classifier 3a : classifier 3aa
+  definition 3
+"""
+expected = """\
+<document source="<string>">
+    <definition_list>
+        <definition_list_item>
+            <term>
+                term 1
+            <definition>
+                <paragraph>
+                    definition 1
+        <definition_list_item>
+            <term>
+                term 2a
+            <term>
+                term 2b
+            <definition>
+                <paragraph>
+                    definition 2
+        <definition_list_item>
+            <term>
+                term 3a
+            <classifier>
+                classifier 3a
+            <classifier>
+                classifier 3aa
+            <term>
+                term 3b
+            <classifier>
+                classifier 3b
+            <definition>
+                <paragraph>
+                    definition 3
+"""
+
+settings = {'_disable_config': True,
+            'datestamp': False,
+            'generator': False,
+            'embed_stylesheet': False,
+            'indents': True,  # XML writer
+            'use_latex_citations': True,
+            'legacy_column_widths': False,            
+            }
+
+
+doctree = publish_doctree(sample, settings_overrides=settings)
+
+# print(doctree)
+
+# Insert extra <term> node:
+# print(doctree[0][1].children)
+doctree[0][1].insert(1, term('test', 'term 2b'))
+# Insert extra <term> and <classifier> nodes:
+# print(doctree[0][2].children)
+doctree[0][2].insert(3, term('test', 'term 3b'))
+doctree[0][2].insert(4, classifier('test', 'classifier 3b'))
+
+output = publish_from_doctree(doctree, writer_name='pseudoxml',
+                              settings_overrides=settings)
+assert output.decode() == expected
+
+
+extensions = {'html': 'html',
+              'html4': 'html',
+              'html5': 'html',
+              'latex': 'tex',
+              'xetex': 'tex',
+              'manpage': 'troff',
+              'odt': 'odt',
+              'xml': 'xml',
+              'pseudoxml': 'txt',
+              }
+
+for format in extensions.keys():
+    output = publish_from_doctree(doctree, writer_name=format,
+                                  settings_overrides=settings)
+
+    # print(output.decode())
+    filename = f'/tmp/termtest-{format}.{extensions[format]}'
+    with open(filename, 'bw') as outfile:
+        outfile.write(output)
+        print(f'output written to /tmp/{filename}')
+
+
+# output = publish_from_doctree(doctree, writer_name='odf')
+# with open('/tmp/termtest.troff', 'bw') as outfile:
+#     outfile.write(output)


Property changes on: trunk/sandbox/manpage-writer/multiple_definition_list_terms.py
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision
\ No newline at end of property
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
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.