From: Cédric V. R. <ced...@gm...> - 2018-05-26 09:38:15
|
Hi, When switching from "html" to "html5" writer, I got the following problem: the docinfo is now included in the "body" parts when using "publish_parts". For details see my question of StackOverflow: https://stackoverflow.com/q/50423279/3025740 As I say in StackOverflow it seems to contradict the documentation which says that "body" should not contain the docinfo. Searching in docutils mailing list, I found this message suggesting to use "strip_elements_with_classes": https://sourceforge.net/p/docutils/mailman/message/35973538/ But it does not seem to work for me. Code example: import docutils.core SOURCE = '''\ :key: value Title ======== Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. ''' docutils_params = { 'input_encoding': 'utf-8', 'strip_elements_with_classes': ['docinfo simple'] } body = docutils.core.publish_parts( SOURCE, writer_name='html5', settings_overrides=docutils_params )['body'] print(body) (using Python 3) Any idea ? -- Cédric Van Rompay |
From: Guenter M. <mi...@us...> - 2018-06-04 20:34:22
|
On 2018-05-26, Cédric Van Rompay wrote: > Hi, > When switching from "html" to "html5" writer, I got the following > problem: the docinfo is now included in the "body" parts when using > "publish_parts". > For details see my question of StackOverflow: > https://stackoverflow.com/q/50423279/3025740 > As I say in StackOverflow it seems to contradict the documentation > which says that "body" should not contain the docinfo. You found a bug in the html5 writer. I have a local fix (patch below). Unfortunately, work on Docutils stalled (still waiting for a go-ahead for the patch fixing https://sourceforge.net/p/docutils/bugs/342/ and https://sourceforge.net/p/docutils/bugs/332/ ). > Searching in docutils mailing list, I found this message suggesting to > use "strip_elements_with_classes": > https://sourceforge.net/p/docutils/mailman/message/35973538/ > But it does not seem to work for me. This was an untested suggestion. It turns out that class arguments are lost during the docinfo transformation (this may be another bug) and therefore the proposed option does not work in this case. Günter diff --git a/trunk/docutils/docutils/writers/_html_base.py b/trunk/docutils/docutils/writers/_html_base.py index d9275d846..bca1db922 100644 --- a/trunk/docutils/docutils/writers/_html_base.py +++ b/trunk/docutils/docutils/writers/_html_base.py @@ -681,6 +681,7 @@ class HTMLTranslator(nodes.NodeVisitor): self.body.append('</dd>\n') def visit_docinfo(self, node): + self.context.append(len(self.body)) classes = 'docinfo' if (self.is_compactable(node)): classes += ' simple' @@ -688,6 +689,9 @@ class HTMLTranslator(nodes.NodeVisitor): def depart_docinfo(self, node): self.body.append('</dl>\n') + start = self.context.pop() + self.docinfo = self.body[start:] + self.body = [] def visit_docinfo_item(self, node, name, meta=True): if meta: @@ -1403,14 +1407,14 @@ class HTMLTranslator(nodes.NodeVisitor): classes = 'sidebar-subtitle' elif isinstance(node.parent, nodes.document): classes = 'subtitle' - self.in_document_title = len(self.body) + self.in_document_title = len(self.body)+1 elif isinstance(node.parent, nodes.section): classes = 'section-subtitle' self.body.append(self.starttag(node, 'p', '', CLASS=classes)) def depart_subtitle(self, node): self.body.append('</p>\n') - if self.in_document_title: + if isinstance(node.parent, nodes.document): self.subtitle = self.body[self.in_document_title:-1] self.in_document_title = 0 self.body_pre_docinfo.extend(self.body) |
From: Guenter M. <mi...@us...> - 2018-06-05 14:37:25
|
On 2018-05-26, Cédric Van Rompay wrote: > Hi, > When switching from "html" to "html5" writer, I got the following > problem: the docinfo is now included in the "body" parts when using > "publish_parts". Fixed in rev. 8217 https://sourceforge.net/p/docutils/code/8217/ Thank you for reporting, Günter |