protected function newCommonMarkConverter(RootConfig $config)
 {
     $environment = Environment::createCommonMarkEnvironment();
     foreach ($config->getCommonMarkExtensions() as $extension) {
         if (!class_exists($extension)) {
             throw new \RuntimeException(sprintf('CommonMark extension class "%s" does not exists. You must use a FCQN!', $extension));
         }
         $environment->addExtension(new $extension());
     }
     return new \League\CommonMark\Converter(new DocParser($environment), new HtmlRenderer($environment));
 }
 protected function setTemplate(View $view, RootConfig $config)
 {
     $template = $config->getTemplate();
     if (!$template) {
         $template = dirname(dirname(dirname(__DIR__))) . '/templates/main.php';
     }
     if (!file_exists($template) && !is_readable($template)) {
         throw new Exception("Cannot find template '{$template}'.");
     }
     $registry = $view->getViewRegistry();
     $registry->set('__BOOKDOWN__', $template);
     $view->setView('__BOOKDOWN__');
 }
 protected function downloadImage(DomNode $node)
 {
     $image = $node->attributes->getNamedItem('src')->nodeValue;
     # no image or absolute URI
     if (!$image || preg_match('#^(http(s)?|//)#', $image)) {
         return '';
     }
     $imageName = basename($image);
     $originFile = dirname($this->page->getOrigin()) . '/' . ltrim($image, '/');
     $dir = dirname($this->page->getTarget()) . '/img/';
     $file = $dir . $imageName;
     if (!$this->fsio->isDir($dir)) {
         $this->fsio->mkdir($dir);
     }
     $this->fsio->put($file, $this->fsio->get($originFile));
     return $this->config->getRootHref() . str_replace($this->config->getTarget(), '', $dir) . $imageName;
 }
 public function newRootConfig($file, $data)
 {
     $config = new RootConfig($file, $data);
     $config->setOverrides($this->rootConfigOverrides);
     return $config;
 }
 public function __construct(RootConfig $config)
 {
     $this->config = $config;
     $this->setTitle($config->getTitle());
 }
 public function __invoke(Page $page)
 {
     $page->setCopyright($this->config->getCopyright());
 }