예제 #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $html = $input->getArgument('html-file');
     $output = $input->getOption('output-file');
     $css = $input->getOption('css-file');
     $disableLinkNodeProcessing = $input->getOption('disable-link-node-processing');
     $removeHiddenNodes = $input->getOption('remove-hidden-nodes');
     $backupNode = $input->getOption('disable-backup-node');
     $inlineStyleAttributes = $input->getOption('disable-inline-style-attributes');
     $appendStyleToHead = $input->getOption('append-styles-to-head');
     $htmlContent = $this->fileSystem->getFileContents($html, 'Could not find HTML file \'%s\'');
     $cssContent = '';
     if ($css) {
         $cssContent = $this->fileSystem->getFileContents($css, 'Could not find CSS file \'%s\'');
     }
     if ($output) {
         $output = $this->fileSystem->getFilePath($output);
     } else {
         $output = $html;
     }
     if (!$disableLinkNodeProcessing) {
         $cssReader = new LinkedCssImporter($htmlContent, $html, $this->fileSystem);
         $htmlContent = $cssReader->getHtmlWithoutCssLinks();
         $cssContent .= $cssReader->getCssFromLinkedStyleSheets();
     }
     $inlineProcessor = new InlineProcessor();
     $inlinedHtml = $inlineProcessor->process($htmlContent, $cssContent, !$removeHiddenNodes, $backupNode, $inlineStyleAttributes, $appendStyleToHead);
     $this->fileSystem->saveFile($output, $inlinedHtml);
 }
예제 #2
0
 /**
  * @return string
  */
 public function getCssFromLinkedStyleSheets()
 {
     $xpathDom = new \DOMXPath($this->document);
     $nodes = $xpathDom->evaluate('//link[@type=\'text/css\' and @rel=\'stylesheet\' and @href]');
     $css = '';
     $missingPathLineNos = [];
     /** @var \DOMNode $node */
     foreach ($nodes as $node) {
         $path = $this->fileSystem->getFilePath($node->attributes->getNamedItem('href')->nodeValue, $this->filePath);
         try {
             $css .= PHP_EOL . $this->fileSystem->getFileContents($path);
         } catch (\Exception $exception) {
             $missingPathLineNos[] = $node->getLineNo();
         }
     }
     if (count($missingPathLineNos) > 0) {
         throw new \InvalidArgumentException('Invalid Link nodes exist on line(s): ' . implode(',', $missingPathLineNos));
     }
     return $css . PHP_EOL;
 }