8
0

Initialize the markdown parser only once.

Dieser Commit ist enthalten in:
Stéphane Goetz 2015-07-19 01:05:43 +02:00
Ursprung e3a3438ccd
Commit 87fbb6f15d
6 geänderte Dateien mit 30 neuen und 15 gelöschten Zeilen

Datei anzeigen

@ -1,7 +1,7 @@
<?php namespace Todaymade\Daux\Format\Base;
use League\CommonMark\CommonMarkConverter;
use Todaymade\Daux\Config;
use Todaymade\Daux\Format\Base\CommonMark\CommonMarkConverter;
use Todaymade\Daux\Tree\Content;
abstract class MarkdownPage extends SimplePage
@ -16,6 +16,11 @@ abstract class MarkdownPage extends SimplePage
*/
protected $params;
/**
* @var CommonMarkConverter
*/
protected $converter;
public function __construct($title, $content)
{
$this->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;
}

Datei anzeigen

@ -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

Datei anzeigen

@ -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();

Datei anzeigen

@ -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());
}
);

Datei anzeigen

@ -1,6 +1,5 @@
<?php namespace Todaymade\Daux\Format\HTML;
use Todaymade\Daux\Daux;
use Todaymade\Daux\Tree\Root;
class MarkdownPage extends \Todaymade\Daux\Format\Base\MarkdownPage

Datei anzeigen

@ -3,6 +3,7 @@
use Todaymade\Daux\Daux;
use Todaymade\Daux\DauxHelper;
use Todaymade\Daux\Exception;
use Todaymade\Daux\Format\Base\CommonMark\CommonMarkConverter;
use Todaymade\Daux\Format\HTML\MarkdownPage;
use Todaymade\Daux\Format\HTML\RawPage;
use Todaymade\Daux\Tree\Raw;
@ -133,7 +134,7 @@ class Server
if ($request !== 'index') {
$params['entry_page'] = $file->getFirstPage();
}
return MarkdownPage::fromFile($file, $params);
return MarkdownPage::fromFile($file, $params, new CommonMarkConverter(['daux' => $params]));
}
public function getRequest()