Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsedown stops parsing after <img> tag #370

Closed
adam-boduch opened this issue Nov 30, 2015 · 7 comments
Closed

Parsedown stops parsing after <img> tag #370

adam-boduch opened this issue Nov 30, 2015 · 7 comments
Milestone

Comments

@adam-boduch
Copy link

Input:

<html>test</html> <img src="#">
# one
# two

expected result:

<p><html>test</html> <img src="#"></p>

<h1>one</h1>

<h1>two</h1>

Got:

<html>test</html> <img src="#">
# one
# two
@skoop
Copy link

skoop commented Dec 19, 2015

I've had a look at this, the problem seems to be using two html tags on a single line. I get the same erronous result with other tags. Also, it is not specifically the image tag, because when you put the image tag on a new line, it parses fine. I'll dig a bit deeper

@jvelo
Copy link

jvelo commented Feb 17, 2016

I witness the same : if there are several HTML tags on the same line, parsing stops for the rest of the document.

A simple test to showcase the bug is :

public function test_that_breaks() {
        $markdownWithHtml = <<<MARKDOWN
<div></div><span></span>

# Test
MARKDOWN;

        $expectedHtml = <<<EXPECTED_HTML
<div></div><span></span>
<h1>Test</h1>
EXPECTED_HTML;
        $parsedown = new Parsedown();
        $this->assertEquals($expectedHtml, $parsedown->text($markdownWithHtml));
    }

It fails with :

--- Expected
+++ Actual
@@ @@
 '<div></div><span></span>
-<h1>Test</h1>'
+
+# Test'

@jvelo
Copy link

jvelo commented Feb 17, 2016

I could pin down the cause to the regex test that checks if the opening element closes at the end of the line at line 714 https://github.com/erusev/parsedown/blob/master/Parsedown.php#L714 i.e.

                if (preg_match('/<\/'.$matches[1].'>[ ]*$/i', $remainder))
                {
                    $Block['closed'] = true;
                }

@jvelo
Copy link

jvelo commented Feb 17, 2016

Not sure what's the best course of action here. Iterate over the remaining found elements in the line while we find them closed ?

@erusev
Copy link
Owner

erusev commented Feb 17, 2016

Thanks @jvelo I'll investigate.

@jvelo
Copy link

jvelo commented Feb 17, 2016

@erusev great ! Thanks.

@aidantwoods
Copy link
Collaborator

This will be fixed in the next release, you'd just need to add a newline after HTML to tell Parsedown to process markdown again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants