erusev / parsedown

Better Markdown Parser in PHP
https://parsedown.org
MIT License
14.68k stars 1.12k forks source link

[Bug] Element h1 inside list element when having no newline (1.7.4, 2.0.0 Beta 1) #835

Open Tooa opened 2 years ago

Tooa commented 2 years ago

Description

Parsedown places the h1 element inside the list element when having a markdown file like the following:

* element1
* element2
# Troubleshooting

The issue is present for the latest stable release and the latest public beta. The problem does not occur with Markdown PHP 1.3 featured in the Parsedown Demo though.

Let me know how I can further assist @erusev @aidantwoods.

Expected Behavior

<ul>
<li>element1</li>
<li>element2</li>
</ul>

<h1>Troubleshooting</h1>

Actual Behavior

<ul>
<li>element1</li>
<li>element2
<h1>Troubleshooting</h1></li>
</ul>

Steps to reproduce

Reproduce with Parsedown 1.7.4

indent-issue-demo

Reproduce with Parsedown 2.0.0 Beta 1

Setup

$ sudo apt install php8.1
$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
$ php composer-setup.php
$ php -r "unlink('composer-setup.php');"
# Dependencies
$ sudo apt-get install php8.1-mbstring
$ php ../composer.phar require erusev/parsedown:v2.0.0-beta-1
$ php demo.php

demo.php

<?php

require __DIR__ . '/vendor/autoload.php';

use Erusev\Parsedown\Configurables\Breaks;
use Erusev\Parsedown\Configurables\SafeMode;
use Erusev\Parsedown\Configurables\StrictMode;
use Erusev\Parsedown\State;
use Erusev\Parsedown\Parsedown;

$markdown = <<<EOD
* element1
* element2
# Troubleshooting
EOD;

$state = new State([
    new Breaks(true),
    new SafeMode(true),
    new StrictMode(false)
]);

$Parsedown = new Parsedown($state);
echo $Parsedown->toHtml($markdown);
?>

indent-issue-beta