Re: Removing docinfo in "body" part with html5 writer
Guenter Milde via Docutils-users <[email protected]>
| Newsgroups | gmane.text.docutils.user |
|---|---|
| Message-ID | <[email protected]> |
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)
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Docutils-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/docutils-users
Please use "Reply All" to reply to the list.