rst2odp icon indicating copy to clipboard operation
rst2odp copied to clipboard

raw not handled

Open clach04 opened this issue 12 years ago • 12 comments

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

clach04 avatar May 04 '12 17:05 clach04

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.

mattharrison avatar May 04 '12 17:05 mattharrison

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.

clach04 avatar May 04 '12 19:05 clach04

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.

clach04 avatar May 04 '12 20:05 clach04

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...

mattharrison avatar May 04 '12 20:05 mattharrison

BTW I'm wondering about the use case for raw html in a slide deck...

mattharrison avatar May 04 '12 20:05 mattharrison

https://github.com/mattharrison/rst2odp/pull/12 now ignores raw directives with a warning.

clach04 avatar May 04 '12 20:05 clach04

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 :-)

clach04 avatar May 04 '12 20:05 clach04

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.

mattharrison avatar May 04 '12 20:05 mattharrison

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?

clach04 avatar May 04 '12 21:05 clach04

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)

mattharrison avatar May 04 '12 22:05 mattharrison

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

clach04 avatar May 04 '12 22:05 clach04

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

mattharrison avatar May 04 '12 22:05 mattharrison