-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix for twigphp/Twig/issues/3685 (markdown leading linebreaks and indentation) #3688
base: 2.x
Are you sure you want to change the base?
Conversation
This is correct. Twig follows the same policy than Symfony: fixes are merged in the lowest maintained branch, and then the maintainers are merging branches up. |
|
||
private function minIndentations(string $body): int | ||
{ | ||
$non_empty_lines = preg_split('%(\r|\n)%', $body, -1, PREG_SPLIT_NO_EMPTY); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$non_empty_lines = preg_split('%(\r|\n)%', $body, -1, PREG_SPLIT_NO_EMPTY); | |
$nonEmptyLines = preg_split('%(\r|\n)%', $body, -1, PREG_SPLIT_NO_EMPTY); |
if ($white = substr($body, 0, strspn($body, " \t\r\n\0\x0B"))) { | ||
$body = preg_replace("{^$white}m", '', $body); | ||
} | ||
$body = $this->commonWhitespace($body); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should change the content, except for maybe the beginning of the lines. Here, you are removing all occurrences.
public function load($c) | ||
{ | ||
if (MarkdownRuntime::class === $c) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be on the previous line
{ | ||
if (MarkdownRuntime::class === $c) | ||
{ | ||
return new $c(new $this->class()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing empty line above.
[<<<EOF | ||
{% apply markdown_to_html %} | ||
Hello |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we keep this example in the tests?
Fix for #3685.
Reworked the "remove indentation" to properly account for all lines, work with leading linebreaks, and retain codeblocks at start of markdown.
Reworked the tests, to among other things compare with the markdown generated by the markdown library directly.
I forked
2.x
assuming it can then be merged into3.x
as well. Let me know if this is incorrect (I didn't see aCONTRIBUTING.md
).