text() public method

You can control the text-style with the arguments
public text ( string $indentStyle = ' ', string $newLine = " ", integer $level ) : string
$indentStyle string the indentation to use (multiplies with level)
$newLine string the new-line style to use
$level integer the initial indentation level
return string the compiled text-block
Beispiel #1
0
 /**
  * Compiles the SASS content to CSS
  *
  * @param Node   $node    the node to be compiled
  * @param string $indent  the indentation to use on each child
  * @param string $newLine the new-line to append after each line
  *
  * @return string the wrapped SASS-CSS-string
  * @throws Compiler\Exception when the Stylus package is not installed
  */
 public static function filterSass(Node $node, $indent, $newLine)
 {
     if (!class_exists('Leafo\\ScssPhp\\Compiler')) {
         throw new Compiler\Exception("Failed to compile SASS: " . "Please install the leafo/scssphp composer package");
     }
     $sass = new \Leafo\ScssPhp\Compiler();
     $css = $sass->compile($node->text());
     return '<style>' . $newLine . $indent . $css . $newLine . $indent . '</style>';
 }
Beispiel #2
0
 /**
  * A plain-text filter that just corrects indentation and new-lines.
  *
  * @param Node   $node    the node to be wrapped
  * @param string $indent  the indentation to use on each child
  * @param string $newLine the new-line to append after each line
  *
  * @return string the wrapped PTHML-string
  */
 public static function filterPlain(Node $node, $indent, $newLine)
 {
     $text = trim($node->text());
     //Normalize newlines to $newLine and append our indent
     $i = 0;
     return implode($newLine, array_map(function ($value) use($indent, $newLine, &$i) {
         if (strlen($indent) < 1 && $i++ !== 0 && strlen($value) > 0) {
             //Make sure we separate with at least one white-space
             $indent = ' ';
         }
         return $indent . trim($value);
     }, explode("\n", $text)));
 }