Skip to content

h is singled out in parsing #185

Description

@RTUnreal

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"
      ]
    ]
  ]
]

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions