Browse Source

Starting working on indention of templates

pretty-print
Dustin Wilson 3 years ago
parent
commit
422b94581e
  1. 26
      lib/Parser/Serializer.php

26
lib/Parser/Serializer.php

@ -238,15 +238,18 @@ abstract class Serializer {
$ss = self::serializeTemplate($n, $templateConfig);
// If reformatting whitespace indention needs to be applied to the template's
// serialized contents if not preformatted content.
/*if ($reformatWhitespace && !$isPreformattedContent && $indentionLevel > 0) {
$ss = explode("\n", $ss);
foreach ($ss as $key => $value) {
$ss[$key] = str_repeat($indentChar, $indentionLevel * $indentStep) . $ss[$key];
if ($reformatWhitespace) {
if (!$isPreformattedContent && $indentionLevel > 0) {
$firstChild = self::templateFirstChild($n);
if (self::treatAsBlock($firstChild)) {
$ss = explode("\n", $ss);
foreach ($ss as $key => $value) {
$ss[$key] = str_repeat($indentChar, ($indentionLevel + 1) * $indentStep) . $ss[$key];
}
$ss = implode("\n", $ss);
}
}
$ss = implode("\n", $ss);
}*/
}
$s .= $ss;
} elseif ($n->hasChildNodes()) {
@ -537,6 +540,13 @@ abstract class Serializer {
return false;
}
protected static function templateFirstChild(\DOMElement $template): \DOMNode {
// NOTE: This method is used only when pretty printing. Implementors of userland
// PHP DOM solutions with template contents will need to extend this method to
// be able to get the template's first child.
return $template->firstChild;
}
protected static function treatAsBlock(\DOMNode $node): bool {
// NOTE: This method is used only when pretty printing. Implementors of userland
// PHP DOM solutions with template contents will need to extend this method to

Loading…
Cancel
Save