Skip to content
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

Open
wants to merge 3 commits into
base: 2.x
Choose a base branch
from

Conversation

Sarke
Copy link

@Sarke Sarke commented Apr 19, 2022

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 into 3.x as well. Let me know if this is incorrect (I didn't see a CONTRIBUTING.md).

extra/markdown-extra/MarkdownRuntime.php Outdated Show resolved Hide resolved
@stof
Copy link
Member

stof commented Apr 20, 2022

I forked 2.x assuming it can then be merged into 3.x as well. Let me know if this is incorrect

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.

@Sarke Sarke requested a review from stof April 26, 2022 11:54

private function minIndentations(string $body): int
{
$non_empty_lines = preg_split('%(\r|\n)%', $body, -1, PREG_SPLIT_NO_EMPTY);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$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);
Copy link
Contributor

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)
{
Copy link
Contributor

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());
Copy link
Contributor

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
Copy link
Contributor

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?

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

Successfully merging this pull request may close these issues.

3 participants