ticket id
000044
status
open
priority
???
assigned to
NOBODY
Reported by: Joshua Inkenbrandt
Component:

I'm assuming their is a bug in the HTMLBlockPreprocessor that messes up the tabbing of the content in a pre or code block. If you have an empty line, then the following line loses its tabs/spaces.

Here's an example:

>>> import markdown
>>>
>>> code = """  
... <pre>
... class Test:
...     hello = "world"
... 
...     def greet(self, name): #WILL FAIL
...         print name
... </pre>
... """
>>>
>>> md = markdown.markdown(code)
>>>
>>> print md
<pre>
class Test:
    hello = "world"

def greet(self, name): #FAILED
        print name
</pre>
>>>

As you can see, it will remove the tab from the beginning of def greet. I haven't had a chance to dive into the code, but I can only assume it has something to do with how it's splitting the lines. Let me know if you need any further examples.

Comments

By Waylan on 9/11/09

Joshua, thanks for the report. You are correct. It is a problem with the raw html code. If you were to do the following with your example we can see the problem more clearly:

>>> md = markdown.Markdown()
>>> print md.convert(t)
<pre>
class Test:
    hello = "world"

def greet(self, name):
        print name
</pre>
>>> md.htmlStash.rawHtmlBlocks
[(u'<pre>\nclass Test:\n    hello = "world"\n\ndef greet(self, name):\n        print name\n</pre>',  False)]

The first thing to note is that all of the block was inserted into the stash as a single block as it should (this is were most bugs have been). However, a single block should never alter anything within it -- which is happening here.

We have at least one other outstanding ticket regarding the rawhtml processor and I've been kicking around some ideas for a refactor. Guess it's time to dig in.

I should also point out that this used to work correct in 1.7. Not sure when we broke it, but the current testing framework won't even catch this bug because of some weird stuff it does to with whitespace.

Powered by Sputnik | XHTML 1.1