cebe / cebe/markdown

h is singled out in parsing

Open
#185 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
HTML
Stars
1k
Forks
137
PR merge metrics
No merged PRs in 30d

Description

I want to use this library for a [changelog](https://keepachangelog.com/en/1.0.0/) 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](https://symfony.com/doc/current/components/var_dumper.html)):
```php
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:
```markdown
qwertzuiopüasdfghjklöäyxcvbnm
```
output:
```php
^ array:1 [▼
0 => array:2 [▼
0 => "paragraph"
"content" => array:1 [▼
0 => array:2 [▼
0 => "text"
1 => "qwertzuiopüasdfghjklöäyxcvbnm"
]
]
]
]
```

but these do:
```markdown
qwertzuiopüasdfghjklöäyxcvbnm[test](https://github.com)
```
output:
```php
^ 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 => ""
]
]
]
]
```
```markdown
qwertzuiopüasdfghjklöäyxcvbnm[test]

[test]: https://github.com
```
output:
```php
^ 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 => ""
]
]
]
]
```
```markdown
qwertzuiopüasdfghjklöäyxcvbnm

[test]: https://github.com
```
output:
```php
^ 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"
]
]
]
]
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.