You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using this library I ran into challenges when parsing web page's HTML where headers were not always on a new line. I wrote a regex to adjust this so that it was always parsed correctly. I'm posting this issue here in case someone wants to adapt it to this project.
publicfunctionheadersNeverAtEndOfLine(string$markdown) : string
{
// any non-whitespace charcater$regex = "([\S])";
// don't match pound signs that are part of a markdown link, are already next to a newline// or are part of a larger markdown header, such as "##### My Header"$regex .= "[^\n(#]";
// match h1-h5 equivalents$regex .= "(#{1,5})";
returntrim(preg_replace("/".$regex."/", "$1".PHP_EOL."$2", $markdown));
}
And then the test to show what this is actually doing:
/** @test */publicfunctionverifyHeadersNeverAtEndOfLine()
{
$original = <<<EOFThis is a quick # Header test to ##See how### Headers are #### Never at the end of an #####Existing lineEOF;
$expected = <<<EOFThis is a quick# Header test to##See how### Headers are#### Never at the end of an#####Existing lineEOF;
$this->assertEquals($expected, $this->parsesMarkdown->headersNeverAtEndOfLine($original));
}
The text was updated successfully, but these errors were encountered:
Hey there! I think we'll probably stick with CommonMark here – i.e. require atx headings to start on a new line for compatibility, but thank you for the suggestion anyway :)
When using this library I ran into challenges when parsing web page's HTML where headers were not always on a new line. I wrote a regex to adjust this so that it was always parsed correctly. I'm posting this issue here in case someone wants to adapt it to this project.
And then the test to show what this is actually doing:
The text was updated successfully, but these errors were encountered: