Skip to content

Commit 4594a0d

Browse files
committed
update
1 parent 93d40a9 commit 4594a0d

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/Translator/TranslationCallAdder.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public function addToPhtml(string $content): string
1515

1616
// replace doctype with fake tag
1717
$content = preg_replace('/<!DOCTYPE(.*?)>/is', '<fakedoctype$1></fakedoctype>', $content);
18-
// replace html tag with fake tag
19-
$content = preg_replace('/<(\/)?html(.*?)>/is', '<$1fakehtml$2>', $content);
18+
// replace html or head tag with fake tag
19+
$content = preg_replace('/<(\/)?(html|head)(.*?)>/is', '<$1fake$2$3>', $content);
2020

2121
// replace PHP blocks
2222
$content = preg_replace_callback(
@@ -51,8 +51,8 @@ function ($matches) use (&$phpBlocks, &$phpId) {
5151
}
5252
// Restore doctype
5353
$html = preg_replace('/<fakedoctype(.*?)><\/fakedoctype>/is', '<!DOCTYPE$1>', $html);
54-
// Restore html tag
55-
$html = preg_replace('/<(\/)?fakehtml(.*?)>/is', '<$1html$2>', $html);
54+
// Restore html or head tag
55+
$html = preg_replace('/<(\/)?fake(html|head)(.*?)>/is', '<$1$2$3>', $html);
5656

5757
// Step 5: Replace all fake PHP tags back with actual PHP blocks using string replacement
5858
foreach ($phpBlocks as $id => $block) {

tests/TranslationCallAdderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,10 @@ public function testAddToPhtml_NonClosingPhpBlock(): void
185185

186186
public function testAddToPhtml_FullHtmlDocument(): void
187187
{
188-
$input = '<?php use bla; ?><!DOCTYPE html><html lang="en"><body></body></html>';
188+
$input = '<?php use bla; ?><!DOCTYPE html><html lang="en"><head></head><body></body></html>';
189189
$output = $this->adder->addToPhtml($input);
190190

191191
// Should preserve DOCTYPE and html tags
192-
$this->assertEquals('<?php use bla; ?><!DOCTYPE html><html lang="en"><body></body></html>', $output);
192+
$this->assertEquals('<?php use bla; ?><!DOCTYPE html><html lang="en"><head></head><body></body></html>', $output);
193193
}
194194
}

0 commit comments

Comments
 (0)