rst2odp
rst2odp copied to clipboard
raw not handled
A file containing:
.. raw:: html
<style type="text/css">
.strike {
text-decoration: line-through;
}
</style>
=================
Demo presentation
=================
Overview
Slide 2
=======
A slide.
Fails with:
Could not import pygments code highlighting will not work
Traceback (most recent call last):
File "E:\svn\rst2odp\rst2odp.py", line 992, in ?
sys.exit(main(sys.argv) or 0)
File "E:\svn\rst2odp\rst2odp.py", line 979, in main
enable_exit_status=enable_exit_status)
File "E:\svn\docutils\docutils\core.py", line 223, in publish
output = self.writer.write(self.document, self.destination)
File "E:\svn\docutils\docutils\writers\__init__.py", line 77, in write
self.translate()
File "E:\svn\rst2odp\rst2odp.py", line 124, in translate
self.document.walkabout(self.visitor)
File "E:\svn\docutils\docutils\nodes.py", line 173, in walkabout
if child.walkabout(visitor):
File "E:\svn\docutils\docutils\nodes.py", line 165, in walkabout
visitor.dispatch_visit(self)
File "E:\svn\rst2odp\rst2odp.py", line 181, in dispatch_visit
nodes.GenericNodeVisitor.dispatch_visit(self, node)
File "E:\svn\docutils\docutils\nodes.py", line 1611, in dispatch_visit
return method(node)
File "E:\svn\docutils\docutils\nodes.py", line 1688, in _call_default_visit
self.default_visit(node)
File "E:\svn\rst2odp\rst2odp.py", line 190, in default_visit
raise NotImplementedError('node is %r, tag is %s' % (node, node.tagname))
NotImplementedError: node is <raw: <#text: '<style type="t ...'>>, tag is raw
>Exit code: 0
If the docutils ignore raw directive (--no-raw ) is used get error:
Could not import pygments code highlighting will not work
problems.txt:1: (WARNING/2) "raw" directive disabled.
Traceback (most recent call last):
File "E:\svn\rst2odp\rst2odp.py", line 992, in ?
sys.exit(main(sys.argv) or 0)
File "E:\svn\rst2odp\rst2odp.py", line 979, in main
enable_exit_status=enable_exit_status)
File "E:\svn\docutils\docutils\core.py", line 223, in publish
output = self.writer.write(self.document, self.destination)
File "E:\svn\docutils\docutils\writers\__init__.py", line 77, in write
self.translate()
File "E:\svn\rst2odp\rst2odp.py", line 124, in translate
self.document.walkabout(self.visitor)
File "E:\svn\docutils\docutils\nodes.py", line 173, in walkabout
if child.walkabout(visitor):
File "E:\svn\docutils\docutils\nodes.py", line 165, in walkabout
visitor.dispatch_visit(self)
File "E:\svn\rst2odp\rst2odp.py", line 181, in dispatch_visit
nodes.GenericNodeVisitor.dispatch_visit(self, node)
File "E:\svn\docutils\docutils\nodes.py", line 1611, in dispatch_visit
return method(node)
File "E:\svn\docutils\docutils\nodes.py", line 1688, in _call_default_visit
self.default_visit(node)
File "E:\svn\rst2odp\rst2odp.py", line 190, in default_visit
raise NotImplementedError('node is %r, tag is %s' % (node, node.tagname))
NotImplementedError: node is <system_message: <paragraph...><literal_block...>>, tag is system_message
Yep, this is patch-able, feel free to send a pull request :) That's not a use case I currently have, but I'll merge something that works for it.
From issue 8
Ideally rst2odp should support the full gamut of rst that docutils offers. Sadly, I haven't felt the need to implement the full spec. Hence the errors about NotImplemented... I could silence those (which might be nicer for end users), but that wouldn't allow nice folks such as yourself to tell me that you are actually interested in said functionality.
I'd like to have a command line option that will ignore unknown directives (I like hard fails as the default). Ideally supporting extra things as they are found. I'll have an experiment but may need some hints as I've not work on docutils internals before.
After a quick hack (without reading docutils docs.....) I came up with:
diff --git a/bin/rst2odp b/bin/rst2odp
index 9a9b44f..58ea1bd 100755
--- a/bin/rst2odp
+++ b/bin/rst2odp
@@ -452,6 +452,14 @@ class ODPTranslator(nodes.GenericNodeVisitor):
def depart_comment(self, node):
pass
+ """this results in the raw contents showing up in the slide :-(
+ really want it read and then disgarded.
+ """
+ def visit_raw(self, node):
+ pass
+ def depart_raw(self, node):
+ pass
+
visit_topic = _dumb_visit
depart_topic = _dumb_depart
So it no longer errors but the raw content then ends up in the first slide.
Yeah, I'm not too sure about that one, I'd rather have it complaining loudly or ignoring the raw rather than putting it up...
BTW I'm wondering about the use case for raw html in a slide deck...
https://github.com/mattharrison/rst2odp/pull/12 now ignores raw directives with a warning.
BTW I'm wondering about the use case for raw html in a slide deck...
In my case I have some slides that work great in S5 but I'm probably going to have to present this using PowerPoint (with a corporate template/theme, I don't have an S5 theme and "politically" S5 may be tricky to use).
I.e. there is no good use case, I want them ignored without having to remove from my src doc :-)
The use case for raw is to enable you to enter "raw" content, so html makes sense for s5 since it is natively html. OTH html is not native to odp, so my inclination would be to ignore that. If you want the source for html to appear that's a different issue.
I have have an rst doc with raw directives, e.g.:
.. raw:: latex
\setlength{\parindent}{0pt}
.. raw:: html
<style type="text/css">
.strike {
text-decoration: line-through;
}
</style>
Then both rst2html and rst2latex work as expected, the html output has the raw html but NOT the latex and vice versa.
If you want the source for html to appear [in the ODP output] that's a different issue.
I do not want the raw html (or latex) content in the odp file.
From the pull comments it sounds like you're still wondering about how "ignore raw" would work. Would you prefer an "ignore raw" command line option for rst2odp so that raw content causes errors, but that users can then override?
Yeah, the visit_Text method needs to check if it is in raw, then ignore the text... I'm not sure that raw odp makes sense (that would be an ultra power user)
Why do it in visit_Text() rather than the visit_raw() in the pull request (different to the diff above)? I'm not sure how the docutils visitor works so any tips will be useful :-S
if you run with "-r 3" (I think) it will be more verbose and I believe will show you the underlying document tree. The basic gist is that there is <Text>
inside of <raw>
. So the filtering needs to be done at that level. There are other examples of similar behavior in visit_Text