markdown icon indicating copy to clipboard operation
markdown copied to clipboard

h is singled out in parsing

Open RTUnreal opened this issue 4 years ago • 0 comments

I want to use this library for a changelog parser.

But while testing out the output structure of the parser, i found out, it singles out h's in text while using links or references in the text.

The following code sample is used as a baseline (dd is a function from symfony link):

class ChangelogParser extends GithubMarkdown
{
    public function parseChangelog(string $text)
    {
        parent::prepare();

        if (ltrim($text) === '') {
            return '';
        }

        $text = str_replace(["\r\n", "\n\r", "\r"], "\n", $text);

        parent::prepareMarkers($text);

        $blocks = parent::parseBlocks(explode("\n", $text));

        dd($blocks);
    }
}

the following markdown doesn't trigger the error:

qwertzuiopüasdfghjklöäyxcvbnm

output:

^ array:1 [▼
  0 => array:2 [▼
    0 => "paragraph"
    "content" => array:1 [▼
      0 => array:2 [▼
        0 => "text"
        1 => "qwertzuiopüasdfghjklöäyxcvbnm"
      ]
    ]
  ]
]

but these do:

qwertzuiopüasdfghjklöäyxcvbnm[test](https://github.com)

output:

^ array:1 [▼
  0 => array:2 [▼
    0 => "paragraph"
    "content" => array:5 [▼
      0 => array:2 [▼
        0 => "text"
        1 => "qwertzuiopüasdfg"
      ]
      1 => array:2 [▼
        0 => "text"
        1 => "h"
      ]
      2 => array:2 [▼
        0 => "text"
        1 => "jklöäyxcvbnm"
      ]
      3 => array:6 [▼
        0 => "link"
        "text" => array:1 [▼
          0 => array:2 [▼
            0 => "text"
            1 => "test"
          ]
        ]
        "url" => "https://github.com"
        "title" => null
        "refkey" => null
        "orig" => "[test](https://github.com)"
      ]
      4 => array:2 [▼
        0 => "text"
        1 => ""
      ]
    ]
  ]
]
qwertzuiopüasdfghjklöäyxcvbnm[test]

[test]: https://github.com

output:

^ array:1 [▼
  0 => array:2 [▼
    0 => "paragraph"
    "content" => array:5 [▼
      0 => array:2 [▼
        0 => "text"
        1 => "qwertzuiopüasdfg"
      ]
      1 => array:2 [▼
        0 => "text"
        1 => "h"
      ]
      2 => array:2 [▼
        0 => "text"
        1 => "jklöäyxcvbnm"
      ]
      3 => array:6 [▼
        0 => "link"
        "text" => array:1 [▼
          0 => array:2 [▼
            0 => "text"
            1 => "test"
          ]
        ]
        "url" => null
        "title" => null
        "refkey" => "test"
        "orig" => "[test]"
      ]
      4 => array:2 [▼
        0 => "text"
        1 => ""
      ]
    ]
  ]
]
qwertzuiopüasdfghjklöäyxcvbnm

[test]: https://github.com

output:

^ array:1 [▼
  0 => array:2 [▼
    0 => "paragraph"
    "content" => array:3 [▼
      0 => array:2 [▼
        0 => "text"
        1 => "qwertzuiopüasdfg"
      ]
      1 => array:2 [▼
        0 => "text"
        1 => "h"
      ]
      2 => array:2 [▼
        0 => "text"
        1 => "jklöäyxcvbnm"
      ]
    ]
  ]
]

RTUnreal avatar Oct 03 '21 19:10 RTUnreal