Skip to content

miscellaneous issue52 improvements - #266

Merged
waylan merged 1 commit into
Python-Markdown:masterfrom
ryneeverett:issue52
Dec 23, 2013
Merged

waylan merged 1 commit into
Python-Markdown:masterfrom
ryneeverett:issue52

Conversation

@ryneeverett

Copy link
Copy Markdown
Contributor

Just cleans up some of my previously merged code.

Comment thread docs/extensions/extra.txt Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I missed this before. Is this always the case? Because it is only the case some of the time in PHP Markdown Extra - which this should be emulating. For example, in PHP’s implementation a heading (h1-6) before the raw HTML block does require a blank line, while a paragraph does. I realize that the difference in the implementation has some effect on these edge cases, but I try to go with what feels less buggy. So, for example, if the document author leaves out the blank line after a paragraph, that feels more like a bug- unless, of course, the docs specifically say otherwise. Unfortunately, PHP’s docs make no mention of this requirement.

So my question to you is, did you change the behavior, or has Python-markdown always had this behavior? If this has previously Been the case, then let's leave it for now, but if not, then I'm inclined to consider this a regression and back out the changes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a requirement before my initial PR. To me, this seems like an unsurprising limitation of the blockparser, which depends on line breaks for pattern matching. Here's what I get with the official package:

No linebreak before block:

import markdown


example = """\
before
<div markdown="1" name="Example">
The text of the `Example` element.
</div>

after
"""

output = markdown.markdown(example, extensions=['extra'])
print ("""-----------------------------------------------
%s
-------------------------------------------------""") % output

Result:

-----------------------------------------------
<p>before
<div markdown="1" name="Example">
The text of the <code>Example</code> element.
</div></p>
<p>after</p>
-------------------------------------------------

Linebreak before block:

import markdown


example = """\
before

<div markdown="1" name="Example">
The text of the `Example` element.
</div>

after
"""

output = markdown.markdown(example, extensions=['extra'])
print ("""-----------------------------------------------
%s
-------------------------------------------------""") % output

Result:

-----------------------------------------------
<p>before</p>
<div name="Example">

<p>The text of the <code>Example</code> element.</p>
</div>

<p>after</p>
-------------------------------------------------

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, which is the exact same behavior as PHP's implementation. However, if the input is:

#before
<div markdown="1" name="Example">
The text of the `Example` element.
</div>

after

Then the output should be (because this is what PHP does):

<h1>before</h1>

<p><div markdown="1" name="Example">
The text of the <code>Example</code> element.
</div></p>

<p>after</p>

But it is actually this:

<h1>before</h1>
<p><div markdown="1" name="Example">
The text of the <code>Example</code> element.
</div></p>
<p>after</p>

So that is a bug in this implementation. My point is that it should not be a hard and fast rule that a blank line must come between a raw block and the preceding block. So the docs shouldn't document it as a rule. Of course, it could be documented as a recommendation. Perhaps something like "To avoid unexpected results, it is generally best to include a blank line before and after any raw html blocks." This doesn't make it a hard and fast rule. It still stands even if the above bug is later fixed. And it is generally good advice anyway.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I think I understand the distinction you're making: Markdown's rules are completely external to this implementation. Anything else is a bug or recommendation.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry. I've been leading you the wrong way. I forgot that markdown has the following rule:

The only restrictions are that block-level HTML elements — e.g. <div>, <table>, <pre>, <p>, etc. — must be separated from surrounding content by blank lines, and the start and end tags of the block should not be indented with tabs or spaces.

The 'markdown=1" feature is supposed to be a copy of PHP's implementation and I was checking against that. But apparently PHP's implementation goes outside markdown's syntax rules and is a little overzealous in some cases.

So yes, you were initially correct, a blank line before and after is required. However, as that is the case for all raw html blocks, whether 'markdown=1' or not, I'm not sure why we need to document it for the extension specifically. Just stating that 'any block level raw html block as defined in the syntax rules with markdown=1 will work' should be sufficient.

Again, sorry for the confusion. That's what I get for trying to respond from my mobile device.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree.

@ryneeverett

Copy link
Copy Markdown
Contributor Author

Content issues aside, I hope I correctly pushed that commit. I'm still a git noob.

@ryneeverett

Copy link
Copy Markdown
Contributor Author

I believe I've addressed all concerns.

@ryneeverett

Copy link
Copy Markdown
Contributor Author

I finally noticed how massively I screwed up this branch the other night. I fixed it up and removed the offending lines.

waylan pushed a commit that referenced this pull request Dec 23, 2013
miscellaneous issue52 improvements
@waylan
waylan merged commit 2587fae into Python-Markdown:master Dec 23, 2013
@ryneeverett
ryneeverett deleted the issue52 branch May 16, 2014 02:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants