Hello, I've spent many hours with this problem and I want to share if
someone have the samee, I don't know if this solution will be commited
to some revision, by the way:

I'm including a python file with:

.. literalinclude:: file.py

But the syntax highlight never worked, so I've seen on silent
exception on (highlighting.py), on line 148:

        try:
            parser.suite(src)
        except parsing_exceptions, a:
            return False
        else:
            return True

The parser was throwing an exception: "syntax error". But the source
was not with any syntax error. So I took a look in the code.py to see
how the file is open, and I saw:

f = codecs.open(fn, 'r', encoding)

The problem here, is that codecs.open will always open files in binary
mode to avoid data loss, so the automatic "\n" conversion is never
done on reading. My file.py is a CRLF (windows) and not LF (unix) end-
line terminated, so I have added this line of code in the code.py on
line 129:

text = re.sub("\r\n", "\n", text)

and have imported the "re" module on the head of the code.py file.

This line will replace the CRLF with LF, so the parser will not throw
the exception and the pygments can do the job.

I have seen this problem on the 0.5 and in the 0.6 latest version...

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sphinx-dev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sphinx-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to