protected function jsTagsAfter($asset, $rawHtml, $insidehead = false)
    {
        if ($insidehead) {
            $pos = strpos($rawHtml, '</head>');
            $context = substr($rawHtml, 0, $pos);
        } else {
            $context = $rawHtml;
        }

        // This match tag is a unique case
        if ($matches = $this->getMatches($context, '(.*)</script>', false, true)) {
            // Attempt to insert it after the last <script> tag within context, matching indentation.
            $last = count($matches[0]) - 1;
            $replacement = sprintf("%s\n%s%s", $matches[0][$last], $matches[1][$last], (string) $asset);

            return Str::replaceFirst($rawHtml, $matches[0][$last], $replacement);
        } elseif ($insidehead) {
            // Second attempt: entire document
            return $this->jsTagsAfter($asset, $rawHtml, false);
        }

        return $this->headTagEnd($asset, $rawHtml);
    }
protected function jsTagsAfter($asset, $rawHtml, $insidehead = false)
    {
        if ($insidehead) {
            $pos = strpos($rawHtml, '</head>');
            $context = substr($rawHtml, 0, $pos);
        } else {
            $context = $rawHtml;
        }

        // This match tag is a unique case
        if ($matches = $this->getMatches($context, '(.*)</script>', false, true)) {
            // Attempt to insert it after the last <script> tag within context, matching indentation.
            $last = count($matches[0]) - 1;
            $replacement = sprintf("%s\n%s%s", $matches[0][$last], $matches[1][$last], (string) $asset);

            return Str::replaceFirst($rawHtml, $matches[0][$last], $replacement);
        } elseif ($insidehead) {
            // Second attempt: entire document
            return $this->jsTagsAfter($asset, $rawHtml, false);
        }

        return $this->headTagEnd($asset, $rawHtml);
    }
protected function jsTagsAfter ( $ asset , $ rawHtml , $ insidehead = false ) { if ( $ insidehead ) { $ pos = strpos ( $ rawHtml , '</head>' ) ; $ context = substr ( $ rawHtml , 0 , $ pos ) ; } else { $ context = $ rawHtml ; } // This match tag is a unique case if ( $ matches = $ this -> getMatches ( $ context , '(.*)</script>' , false , true ) ) { // Attempt to insert it after the last <script> tag within context, matching indentation. $ last = count ( $ matches [ 0 ] ) - 1 ; $ replacement = sprintf ( "%s\n%s%s" , $ matches [ 0 ] [ $ last ] , $ matches [ 1 ] [ $ last ] , ( string ) $ asset ) ; return Str :: replaceFirst ( $ rawHtml , $ matches [ 0 ] [ $ last ] , $ replacement ) ; } elseif ( $ insidehead ) { // Second attempt: entire document return $ this -> jsTagsAfter ( $ asset , $ rawHtml , false ) ; } return $ this -> headTagEnd ( $ asset , $ rawHtml ) ; }
Helper function to insert some HTML after the last javascript include.
First in the head section, but if there is no script in the head, place
it anywhere.

@param AssetInterface $asset
@param string         $rawHtml
@param bool           $insidehead

@return string
Helper function to insert some HTML after the last javascript include . First in the head section but if there is no script in the head place it anywhere .