diff --git a/libs/Format/Base/MarkdownPage.php b/libs/Format/Base/MarkdownPage.php index cc8659b..2111c28 100644 --- a/libs/Format/Base/MarkdownPage.php +++ b/libs/Format/Base/MarkdownPage.php @@ -1,7 +1,7 @@ initializePage($title, $content); @@ -38,7 +43,7 @@ abstract class MarkdownPage extends SimplePage protected function getMarkdownConverter() { - return new CommonMarkConverter(['daux' => $this->params]); + return $this->converter; } protected function convertPage($content) @@ -51,11 +56,12 @@ abstract class MarkdownPage extends SimplePage return $this->convertPage($this->content); } - public static function fromFile(Content $file, $params) + public static function fromFile(Content $file, $params, CommonMarkConverter $converter) { $page = new static($file->getTitle(), $file->getContent()); $page->setFile($file); $page->setParams($params); + $page->converter = $converter; return $page; } diff --git a/libs/Format/Confluence/Generator.php b/libs/Format/Confluence/Generator.php index 5c64e0b..8a1e6c0 100644 --- a/libs/Format/Confluence/Generator.php +++ b/libs/Format/Confluence/Generator.php @@ -4,6 +4,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Todaymade\Daux\Config; use Todaymade\Daux\Daux; +use Todaymade\Daux\Format\Confluence\CommonMark\CommonMarkConverter; use Todaymade\Daux\Format\Base\RunAction; use Todaymade\Daux\Tree\Content; use Todaymade\Daux\Tree\Directory; @@ -17,13 +18,19 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator */ protected $prefix; + /** + * @var CommonMarkConverter + */ + protected $converter; + public function generate(Daux $daux, InputInterface $input, OutputInterface $output, $width) { - $confluence = $daux->getParams()['confluence']; + $params = $daux->getParams(); + $confluence = $params['confluence']; $this->prefix = trim($confluence['prefix']) . " "; - $params = $daux->getParams(); + $this->converter = new CommonMarkConverter(['daux' => $params]); $tree = $this->runAction( "Generating Tree ...", @@ -68,7 +75,7 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator $data = [ 'title' => $this->prefix . $node->getTitle(), 'file' => $node, - 'page' => MarkdownPage::fromFile($node, $params), + 'page' => MarkdownPage::fromFile($node, $params, $this->converter), ]; // As the page is lazily generated diff --git a/libs/Format/Confluence/MarkdownPage.php b/libs/Format/Confluence/MarkdownPage.php index e8b1d5f..cd8018a 100644 --- a/libs/Format/Confluence/MarkdownPage.php +++ b/libs/Format/Confluence/MarkdownPage.php @@ -2,17 +2,11 @@ use DOMDocument; use Todaymade\Daux\DauxHelper; -use Todaymade\Daux\Format\Confluence\CommonMark\CommonMarkConverter; class MarkdownPage extends \Todaymade\Daux\Format\Base\MarkdownPage { public $attachments = []; - protected function getMarkdownConverter() - { - return new CommonMarkConverter(['daux' => $this->params]); - } - protected function generatePage() { $page = parent::generatePage(); diff --git a/libs/Format/HTML/Generator.php b/libs/Format/HTML/Generator.php index 7bac65d..4bf3610 100644 --- a/libs/Format/HTML/Generator.php +++ b/libs/Format/HTML/Generator.php @@ -5,6 +5,7 @@ use Symfony\Component\Console\Output\OutputInterface; use Todaymade\Daux\Config; use Todaymade\Daux\Daux; use Todaymade\Daux\DauxHelper; +use Todaymade\Daux\Format\Base\CommonMark\CommonMarkConverter; use Todaymade\Daux\Format\Base\RunAction; use Todaymade\Daux\Generator\Helper; use Todaymade\Daux\Tree\Directory; @@ -14,6 +15,11 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator { use RunAction; + /** + * @var CommonMarkConverter + */ + protected $converter; + public function generate(Daux $daux, InputInterface $input, OutputInterface $output, $width) { $destination = $input->getOption('destination'); @@ -23,6 +29,8 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator $destination = $daux->local_base . DS . 'static'; } + $this->converter = new CommonMarkConverter(['daux' => $params]); + $this->runAction( "Copying Static assets ...", $output, @@ -85,7 +93,7 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator $params['request'] = $node->getUrl(); $params['file_uri'] = $node->getName(); - $page = MarkdownPage::fromFile($node, $params); + $page = MarkdownPage::fromFile($node, $params, $this->converter); file_put_contents($output_dir . DS . $key, $page->getContent()); } ); diff --git a/libs/Format/HTML/MarkdownPage.php b/libs/Format/HTML/MarkdownPage.php index ba2c0bd..6717ee7 100644 --- a/libs/Format/HTML/MarkdownPage.php +++ b/libs/Format/HTML/MarkdownPage.php @@ -1,6 +1,5 @@ getFirstPage(); } - return MarkdownPage::fromFile($file, $params); + return MarkdownPage::fromFile($file, $params, new CommonMarkConverter(['daux' => $params])); } public function getRequest()