Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3671ee1

Browse files
authored
Merge pull request#64 from goetas/doctype
HTML5 doctype is case insensitive
2 parentsfb367c7 +35e36d6 commit3671ee1

File tree

5 files changed

+29
-11
lines changed

5 files changed

+29
-11
lines changed

‎src/SourceAdapter/HTML5Adapter.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,16 @@ class HTML5Adapter implements SourceAdapter
2020
publicfunctionload($source)
2121
{
2222
$html5 =$this->getHtml5();
23-
$f =$html5->loadHTMLFragment($source);
24-
$dom =new \DOMDocument('1.0','UTF-8');
25-
if ('' !==trim($source)) {
26-
$dom->appendChild($dom->importNode($f,true));
27-
}
2823

24+
if (stripos(rtrim($source),'<!DOCTYPE html>') ===0) {
25+
$dom =$html5->loadHTML($source);
26+
}else {
27+
$f =$html5->loadHTMLFragment($source);
28+
$dom =new \DOMDocument('1.0','UTF-8');
29+
if ('' !==trim($source)) {
30+
$dom->appendChild($dom->importNode($f,true));
31+
}
32+
}
2933
returnnewTemplate($dom,$this->collectMetadata($dom,$source));
3034
}
3135

@@ -51,7 +55,7 @@ protected function collectMetadata(\DOMDocument $dom, $source)
5155
$metadata =array();
5256

5357
$metadata['doctype'] = !!$dom->doctype;
54-
$metadata['fragment'] =strpos(rtrim($source),'<!DOCTYPE html>') !==0;
58+
$metadata['fragment'] =stripos(rtrim($source),'<!DOCTYPE html>') !==0;
5559

5660
return$metadata;
5761
}

‎tests/Tests/CoreNodesTest.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,14 @@ public function getDataFormTemplates()
192192
publicfunctiontestVisitNodeTemplates($source,$expected)
193193
{
194194
$compiled =$this->twital->compile($this->sourceAdapter,$source);
195-
$cleanup =function ($str) {
196-
returnpreg_replace("/\s+/","",$str);
197-
};
198-
$this->assertEquals($cleanup($expected),$cleanup($compiled));
195+
$this->assertEquals($this->cleanup($expected),$this->cleanup($compiled));
199196
}
200197

201198
abstractprotectedfunctiongetSourceAdapter();
199+
200+
protectedfunctioncleanup($str)
201+
{
202+
$str =str_ireplace('<!DOCTYPE html>','<!DOCTYPE html>',$str);
203+
returnpreg_replace("/\s+/","",$str);
204+
}
202205
}

‎tests/Tests/Html5CoreNodesTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class Html5CoreNodesTest extends CoreNodesTest
77
{
88
publicfunctiongetDataFormTemplates()
99
{
10-
$all =glob(__DIR__."/templates/*.xml");
10+
$all =glob(__DIR__."/templates/*.{htm,xml}",GLOB_BRACE);
1111
$data =array();
1212
foreach ($allas$file) {
1313
$source =file_get_contents($file);
@@ -32,4 +32,10 @@ protected function getSourceAdapter()
3232
{
3333
returnnewHTML5Adapter();
3434
}
35+
36+
protectedfunctioncleanup($str)
37+
{
38+
$str =str_ireplace('<!DOCTYPE html>','<!DOCTYPE html>',$str);
39+
returnparent::cleanup($str);
40+
}
3541
}

‎tests/Tests/templates/doctype-02.htm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<!doctype html>
2+
<html><body>foo</body></html>

‎tests/Tests/templates/doctype-02.twig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<!doctype html>
2+
<html><body>foo</body>
3+
</html>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp