/**
  * On strict mode
  *
  * @param string $name     Name of the test case
  * @param string $markdown The Markdown content
  * @param string $expected Expected output
  *
  * @dataProvider strictModeProvider
  * @expectedException \Ciconia\Exception\SyntaxError
  */
 public function testStrictMode($name, $markdown, $expected)
 {
     $ciconia = new Ciconia();
     $ciconia->addExtensions([new FencedCodeBlockExtension(), new InlineStyleExtension(), new WhiteSpaceExtension(), new TaskListExtension(), new TableExtension(), new UrlAutoLinkExtension()]);
     $html = $ciconia->render($markdown, ['strict' => true]);
     $this->assertEquals($expected, $html, sprintf('%s failed', $name));
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function register(Application $app)
 {
     $app->register(new SilexTwigServiceProvider(), ['twig.path' => $app->templatesPath(), 'twig.options' => ['debug' => !$app->isProduction(), 'cache' => $app->config('cache.enabled') ? $app->cacheTwigPath() : false]]);
     /* @var Twig_Environment $twig */
     $twig = $app['twig'];
     $twig->addGlobal('current_page', function () use($app) {
         return $app['request']->getRequestUri();
     });
     $twig->addGlobal('cfp_open', strtotime('now') < strtotime($app->config('application.enddate') . ' 11:59 PM'));
     if (!$app->isProduction()) {
         $twig->addExtension(new Twig_Extension_Debug());
     }
     $twig->addFunction(new Twig_SimpleFunction('uploads', function ($path) {
         return '/uploads/' . $path;
     }));
     $twig->addFunction(new Twig_SimpleFunction('assets', function ($path) {
         return '/assets/' . $path;
     }));
     $twig->addGlobal('site', $app->config('application'));
     // Twig Markdown Extension
     $markdown = new Ciconia();
     $markdown->addExtension(new InlineStyleExtension());
     $markdown->addExtension(new WhiteSpaceExtension());
     $engine = new CiconiaEngine($markdown);
     $twig->addExtension(new MarkdownExtension($engine));
     $twig->addGlobal('talkHelper', new TalkHelper($app->config('talk.categories'), $app->config('talk.levels'), $app->config('talk.types')));
 }
Esempio n. 3
0
 /**
  * @param $name
  * @param $markdown
  * @param $expected
  *
  * @dataProvider pygmentsModeProvider
  */
 public function testPygmentsMode($name, $markdown, $expected)
 {
     $ciconia = new Ciconia();
     $ciconia->addExtensions([new FencedCodeBlockExtension()]);
     $html = $ciconia->render($markdown, ['pygments' => true]);
     $this->assertEquals($expected, $html, sprintf('%s failed', $name));
 }
Esempio n. 4
0
 /**
  * @dataProvider htmlProvider
  */
 public function testHtmlPatterns($name, $textile, $expected)
 {
     $ciconia = new Ciconia(new XhtmlRenderer());
     $ciconia->addExtensions([new \Ciconia\Extension\Html\AttributesExtension()]);
     $expected = str_replace("\r\n", "\n", $expected);
     $expected = str_replace("\r", "\n", $expected);
     $html = $ciconia->render($textile);
     $this->assertEquals($expected, $html, sprintf('%s failed', $name));
 }
Esempio n. 5
0
 /**
  * @dataProvider textileProvider
  */
 public function testTextilePatterns($name, $textile, $expected)
 {
     $ciconia = new Ciconia();
     $ciconia->addExtensions([new HeaderExtension(), new DefinitionListExtension(), new CommentExtension()]);
     $expected = str_replace("\r\n", "\n", $expected);
     $expected = str_replace("\r", "\n", $expected);
     $html = $ciconia->render($textile);
     $this->assertEquals($expected, $html, sprintf('%s failed', $name));
 }
Esempio n. 6
0
 public function parsedDescription()
 {
     $content = $this->description;
     $parser = new Ciconia();
     $config = HTMLPurifier_Config::createDefault();
     $purifier = new HTMLPurifier($config);
     $htmltopurify = $parser->render($content);
     return $purifier->purify($htmltopurify);
 }
 /**
  * Initialize the provider, register classes to the container
  *
  * @return void
  */
 public function initialize()
 {
     $ciconia = new Ciconia();
     $that = $this;
     if ($this->gfmEnabled()) {
         $ciconia->addExtension(new Gfm\FencedCodeBlockExtension());
         $ciconia->addExtension(new Gfm\TaskListExtension());
         $ciconia->addExtension(new Gfm\InlineStyleExtension());
         $ciconia->addExtension(new Gfm\WhiteSpaceExtension());
         $ciconia->addExtension(new Gfm\TableExtension());
         $ciconia->addExtension(new Gfm\UrlAutoLinkExtension());
     }
     $this->app->container->singleton('markdown', function () use($ciconia) {
         return $ciconia;
     });
     $this->app->container->singleton('markdown.form', function () use($that) {
         return new Helper\Form($that->options);
     });
     $this->app->container->singleton('markdown.config', function () use($that) {
         return $that;
     });
     if ($this->serviceEnabled()) {
         $this->registerService();
     }
 }
 /**
  * {@inheritdoc}
  * @param string $text The text
  */
 public function render($text)
 {
     $this->ciconia->addExtension(new Gfm\FencedCodeBlockExtension());
     $this->ciconia->addExtension(new Gfm\TaskListExtension());
     $this->ciconia->addExtension(new Gfm\InlineStyleExtension());
     $this->ciconia->addExtension(new Gfm\WhiteSpaceExtension());
     $this->ciconia->addExtension(new Gfm\TableExtension());
     $this->ciconia->addExtension(new Gfm\UrlAutoLinkExtension());
     return $this->ciconia->render($text);
 }
Esempio n. 9
0
 /**
  * {@inheritdoc}
  */
 public function register(Application $app)
 {
     $app->register(new SilexTwigServiceProvider(), ['twig.path' => $app->templatesPath(), 'twig.options' => ['debug' => !$app->isProduction(), 'cache' => $app->config('cache.enabled') ? $app->cacheTwigPath() : false]]);
     if (!$app->isProduction()) {
         $app['twig']->addExtension(new Twig_Extension_Debug());
     }
     $app['twig']->addFunction(new Twig_SimpleFunction('uploads', function ($path) {
         return '/uploads/' . $path;
     }));
     $app['twig']->addFunction(new Twig_SimpleFunction('assets', function ($path) {
         return '/assets/' . $path;
     }));
     $app['twig']->addGlobal('site', $app->config('application'));
     // Twig Markdown Extension
     $markdown = new Ciconia();
     $markdown->addExtension(new InlineStyleExtension());
     $markdown->addExtension(new WhiteSpaceExtension());
     $engine = new CiconiaEngine($markdown);
     $app['twig']->addExtension(new MarkdownExtension($engine));
 }
Esempio n. 10
0
 /**
  * {@inheritdoc}
  */
 public function register(Application $app)
 {
     $app->register(new SilexTwigServiceProvider(), ['twig.path' => $app->templatesPath(), 'twig.options' => ['debug' => !$app->isProduction(), 'cache' => $app->config('cache.enabled') ? $app->cacheTwigPath() : false]]);
     if ($app->isProduction()) {
         $app->error(function (\Exception $e, $code) use($app) {
             switch ($code) {
                 case 401:
                     $message = $app['twig']->render('error/401.twig');
                     break;
                 case 403:
                     $message = $app['twig']->render('error/403.twig');
                     break;
                 case 404:
                     $message = $app['twig']->render('error/404.twig');
                     break;
                 default:
                     $message = $app['twig']->render('error/500.twig');
             }
             return new Response($message, $code);
         });
     } else {
         $app['twig']->addExtension(new Twig_Extension_Debug());
     }
     $app['twig']->addFunction(new Twig_SimpleFunction('uploads', function ($path) {
         return '/uploads/' . $path;
     }));
     $app['twig']->addFunction(new Twig_SimpleFunction('assets', function ($path) {
         return '/assets/' . $path;
     }));
     $app['twig']->addGlobal('site', $app->config('application'));
     // Twig Markdown Extension
     $markdown = new Ciconia();
     $markdown->addExtension(new InlineStyleExtension());
     $markdown->addExtension(new WhiteSpaceExtension());
     $engine = new CiconiaEngine($markdown);
     $app['twig']->addExtension(new MarkdownExtension($engine));
 }
Esempio n. 11
0
 public function __construct(RendererInterface $renderer = null)
 {
     parent::__construct($renderer);
     $this->addExtension(new FencedCodeBlockExtension());
     $this->addExtension(new TaskListExtension());
     $this->addExtension(new InlineStyleExtension());
     $this->addExtension(new WhiteSpaceExtension());
     $this->addExtension(new TableExtension());
     $this->addExtension(new UrlAutoLinkExtension());
     $this->addExtension(new MentionExtension());
     $extension = new IssueExtension();
     $extension->setAccountName('phalcon')->setProjectName('cphalcon');
     $this->addExtension($extension);
     $extension = new PullRequestExtension();
     $extension->setAccountName('phalcon')->setProjectName('cphalcon');
     $this->addExtension($extension);
 }
Esempio n. 12
0
<?php

/**
 * This file contains bindings for IoC container / View
 */
use Ciconia\Ciconia;
use Ciconia\Extension\Gfm;
App::singleton('Ciconia\\Ciconia', function () {
    $markdown = new Ciconia();
    $markdown->addExtension(new Gfm\FencedCodeBlockExtension());
    $markdown->addExtension(new Gfm\TaskListExtension());
    $markdown->addExtension(new Gfm\InlineStyleExtension());
    $markdown->addExtension(new Gfm\WhiteSpaceExtension());
    $markdown->addExtension(new Gfm\TableExtension());
    $markdown->addExtension(new Gfm\UrlAutoLinkExtension());
    return $markdown;
});
View::share('categories', Config::get('site.postCategories'));
Esempio n. 13
0
 /**
  * {@inheritdoc}
  */
 public function transform($content)
 {
     return $this->engine->render($content);
 }
Esempio n. 14
0
 public function renderContent()
 {
     $ciconia = new Ciconia();
     $ciconia->addExtension(new Gfm\FencedCodeBlockExtension());
     $ciconia->addExtension(new Gfm\TaskListExtension());
     $ciconia->addExtension(new Gfm\InlineStyleExtension());
     $ciconia->addExtension(new Gfm\WhiteSpaceExtension());
     $ciconia->addExtension(new Gfm\TableExtension());
     $ciconia->addExtension(new Gfm\UrlAutoLinkExtension());
     $content = $ciconia->render(@$this['body']);
     echo $content;
 }
Esempio n. 15
0
 /**
  * Initialize the Markdown renderer.
  *
  * @param DiInterface   $di     Dependency Injector
  * @param Config        $config App config
  * @param EventsManager $em     Events Manager
  *
  * @return void
  */
 protected function initMarkdown(DiInterface $di, Config $config, EventsManager $em)
 {
     $di->setShared('markdown', function () {
         $ciconia = new Ciconia();
         $ciconia->addExtension(new Markdown\UnderscoredUrlsExtension());
         $ciconia->addExtension(new Markdown\TableExtension());
         $ciconia->addExtension(new Markdown\MentionExtension());
         $ciconia->addExtension(new Markdown\BlockQuoteExtension());
         $ciconia->addExtension(new Markdown\UrlAutoLinkExtension());
         $ciconia->addExtension(new FencedCodeBlockExtension());
         return $ciconia;
     });
 }
Esempio n. 16
0
 /**
  * Transform markdown into html
  */
 public function markdown($text, $options = array())
 {
     return $this->ciconia->render($text, $options);
 }
Esempio n. 17
0
 /**
  * {@inheritdoc}
  */
 public function run($markdown = '')
 {
     return $this->ciconia->render($markdown);
 }
Esempio n. 18
0
 /**
  * Lints the content
  *
  * @param OutputInterface $output  The OutputInterface instance
  * @param Ciconia         $ciconia The Ciconia instance
  * @param string          $content The markdown content
  *
  * @return int
  */
 protected function lint(OutputInterface $output, Ciconia $ciconia, $content)
 {
     try {
         $ciconia->render($content, array('strict' => true));
         $output->writeln('No syntax errors detected.');
         return 0;
     } catch (SyntaxError $e) {
         $output->writeln('<error>' . $e->getMessage() . '</error>');
         return 1;
     }
 }
Esempio n. 19
0
 public static function run(DiInterface $di, array $options = [])
 {
     $memoryUsage = memory_get_usage();
     $currentTime = microtime(true);
     /**
      * The app path
      */
     if (!defined('K_PATH')) {
         define('K_PATH', dirname(dirname(dirname(__FILE__))));
     }
     /**
      * We will need the Utils class
      */
     require_once K_PATH . '/library/Kitsune/Utils.php';
     /**
      * Utils class
      */
     $utils = new Utils();
     $di->set('utils', $utils, true);
     /**
      * Check if this is a CLI app or not
      */
     $cli = $utils->fetch($options, 'cli', false);
     if (!defined('K_CLI')) {
         define('K_CLI', $cli);
     }
     $tests = $utils->fetch($options, 'tests', false);
     if (!defined('K_TESTS')) {
         define('K_TESTS', $tests);
     }
     /**
      * The configuration is split into two different files. The first one
      * is the base configuration. The second one is machine/installation
      * specific.
      */
     if (!file_exists(K_PATH . '/var/config/base.php')) {
         throw new \Exception('Base configuration files are missing');
     }
     if (!file_exists(K_PATH . '/var/config/config.php')) {
         throw new \Exception('Configuration files are missing');
     }
     /**
      * Get the config files and merge them
      */
     $base = (require K_PATH . '/var/config/base.php');
     $specific = (require K_PATH . '/var/config/config.php');
     $combined = array_replace_recursive($base, $specific);
     $config = new Config($combined);
     $di->set('config', $config, true);
     $config = $di->get('config');
     /**
      * Check if we are in debug/dev mode
      */
     if (!defined('K_DEBUG')) {
         $debugMode = boolval($utils->fetch($config, 'debugMode', false));
         define('K_DEBUG', $debugMode);
     }
     /**
      * Access to the debug/dev helper functions
      */
     if (K_DEBUG) {
         require_once K_PATH . '/library/Kitsune/Debug.php';
     }
     /**
      * We're a registering a set of directories taken from the
      * configuration file
      */
     $loader = new Loader();
     $loader->registerNamespaces($config->namespaces->toArray());
     $loader->register();
     require K_PATH . '/vendor/autoload.php';
     /**
      * LOGGER
      *
      * The essential logging service
      */
     $format = '[%date%][%type%] %message%';
     $name = K_PATH . '/var/log/' . date('Y-m-d') . '-kitsune.log';
     $logger = new LoggerFile($name);
     $formatter = new LoggerFormatter($format);
     $logger->setFormatter($formatter);
     $di->set('logger', $logger, true);
     /**
      * ERROR HANDLING
      */
     ini_set('display_errors', boolval(K_DEBUG));
     error_reporting(E_ALL);
     set_error_handler(function ($exception) use($logger) {
         if ($exception instanceof \Exception) {
             $logger->error($exception->__toString());
         } else {
             $logger->error(json_encode(debug_backtrace()));
         }
     });
     set_exception_handler(function (\Exception $exception) use($logger) {
         $logger->error($exception->getMessage());
     });
     register_shutdown_function(function () use($logger, $memoryUsage, $currentTime) {
         $memoryUsed = number_format((memory_get_usage() - $memoryUsage) / 1024, 3);
         $executionTime = number_format(microtime(true) - $currentTime, 4);
         if (K_DEBUG) {
             $logger->info('Shutdown completed [Memory: ' . $memoryUsed . 'Kb] ' . '[Execution: ' . $executionTime . ']');
         }
     });
     $timezone = $config->get('app_timezone', 'US/Eastern');
     date_default_timezone_set($timezone);
     /**
      * Routes
      */
     if (!K_CLI) {
         $di->set('router', function () use($config) {
             $router = new Router(false);
             $router->removeExtraSlashes(true);
             $routes = $config->routes->toArray();
             foreach ($routes as $pattern => $options) {
                 $router->add($pattern, $options);
             }
             return $router;
         }, true);
     }
     /**
      * We register the events manager
      */
     $di->set('dispatcher', function () use($di) {
         $eventsManager = new EventsManager();
         /**
          * Handle exceptions and not-found exceptions using NotFoundPlugin
          */
         $eventsManager->attach('dispatch:beforeException', new NotFoundPlugin());
         $dispatcher = new Dispatcher();
         $dispatcher->setEventsManager($eventsManager);
         $dispatcher->setDefaultNamespace('Kitsune\\Controllers');
         return $dispatcher;
     });
     /**
      * The URL component is used to generate all kind of urls in the application
      */
     $di->set('url', function () use($config) {
         $url = new UrlProvider();
         $url->setBaseUri($config->baseUri);
         return $url;
     });
     $di->set('view', function () use($config) {
         $view = new View();
         $view->setViewsDir(K_PATH . '/app/views/');
         $view->registerEngines([".volt" => 'volt']);
         return $view;
     });
     /**
      * Setting up volt
      */
     $di->set('volt', function ($view, $di) {
         $volt = new VoltEngine($view, $di);
         $volt->setOptions(["compiledPath" => K_PATH . '/var/cache/volt/', 'stat' => K_DEBUG, 'compileAlways' => K_DEBUG]);
         return $volt;
     }, true);
     /**
      * Start the session the first time some component request the session
      * service
      */
     $di->set('session', function () {
         $session = new SessionAdapter();
         $session->start();
         return $session;
     });
     /**
      * Cache
      */
     $frontConfig = $config->cache_data->front->toArray();
     $backConfig = $config->cache_data->back->toArray();
     $class = '\\Phalcon\\Cache\\Frontend\\' . $frontConfig['adapter'];
     $frontCache = new $class($frontConfig['params']);
     $class = '\\Phalcon\\Cache\\Backend\\' . $backConfig['adapter'];
     $cache = new $class($frontCache, $backConfig['params']);
     $di->set('cache', $cache, true);
     /**
      * viewCache
      */
     $di->set('viewCache', function () use($config) {
         $frontConfig = $config->cache_view->front->toArray();
         $backConfig = $config->cache_view->back->toArray();
         $class = '\\Phalcon\\Cache\\Frontend\\' . $frontConfig['adapter'];
         $frontCache = new $class($frontConfig['params']);
         $class = '\\Phalcon\\Cache\\Backend\\' . $backConfig['adapter'];
         $cache = new $class($frontCache, $backConfig['params']);
         return $cache;
     });
     /**
      * Markdown renderer
      */
     $di->set('markdown', function () {
         $ciconia = new Ciconia();
         $ciconia->addExtension(new FencedCodeBlockExtension());
         $ciconia->addExtension(new TaskListExtension());
         $ciconia->addExtension(new InlineStyleExtension());
         $ciconia->addExtension(new WhiteSpaceExtension());
         $ciconia->addExtension(new TableExtension());
         $ciconia->addExtension(new UrlAutoLinkExtension());
         $ciconia->addExtension(new MentionExtension());
         $extension = new IssueExtension();
         $extension->setIssueUrl('[#%s](https://github.com/phalcon/cphalcon/issues/%s)');
         $ciconia->addExtension($extension);
         $extension = new PullRequestExtension();
         $extension->setIssueUrl('[#%s](https://github.com/phalcon/cphalcon/pull/%s)');
         $ciconia->addExtension($extension);
         return $ciconia;
     }, true);
     /**
      * Posts Finder
      */
     $di->set('finder', function () use($utils, $cache) {
         $key = 'post.finder.cache';
         $postFinder = $utils->cacheGet($key);
         if (null === $postFinder) {
             $postFinder = new PostFinder();
             $cache->save($key, $postFinder);
         }
         return $postFinder;
     }, true);
     /**
      * For CLI I only need the dependency injector
      */
     if (K_CLI) {
         return $di;
     } else {
         $application = new Application($di);
         if (K_TESTS) {
             return $application;
         } else {
             return $application->handle()->getContent();
         }
     }
 }
Esempio n. 20
0
 /**
  * Initialize the Markdown renderer.
  */
 protected function initMarkdown()
 {
     $this->di->setShared('markdown', function () {
         $ciconia = new Ciconia();
         $ciconia->addExtension(new Markdown\UnderscoredUrlsExtension());
         $ciconia->addExtension(new Markdown\TableExtension());
         $ciconia->addExtension(new Markdown\MentionExtension());
         $ciconia->addExtension(new Markdown\BlockQuoteExtension());
         $ciconia->addExtension(new Markdown\UrlAutoLinkExtension());
         //$ciconia->addExtension(new Markdown\NewLineExtension);
         $ciconia->addExtension(new FencedCodeBlockExtension());
         return $ciconia;
     });
 }
Esempio n. 21
0
/**
 * Cache
 */
$di->set('modelsCache', function () use($config) {
    if ($config->application->debug) {
        $frontCache = new FrontendNone();
        return new MemoryBackend($frontCache);
    } else {
        //Cache data for one day by default
        $frontCache = new \Phalcon\Cache\Frontend\Data(["lifetime" => 86400 * 30]);
        return new \Phalcon\Cache\Backend\File($frontCache, ["cacheDir" => APP_PATH . "/app/cache/data/", "prefix" => "forum-cache-data-"]);
    }
});
/**
 * Markdown renderer
 */
$di->set('markdown', function () {
    $ciconia = new Ciconia();
    $ciconia->addExtension(new \Phosphorum\Markdown\TableExtension());
    $ciconia->addExtension(new \Phosphorum\Markdown\MentionExtension());
    $ciconia->addExtension(new \Phosphorum\Markdown\BlockQuoteExtension());
    $ciconia->addExtension(new \Phosphorum\Markdown\UrlAutoLinkExtension());
    $ciconia->addExtension(new \Ciconia\Extension\Gfm\FencedCodeBlockExtension());
    return $ciconia;
}, true);
/**
 * Real-Time notifications checker
 */
$di->set('notifications', function () {
    return new NotificationsChecker();
}, true);
Esempio n. 22
0
 /**
  * On strict mode
  *
  * @param string $name     Name of the test case
  * @param string $markdown The Markdown content
  * @param string $expected Expected output
  *
  * @dataProvider strictModeProvider
  * @expectedException \Ciconia\Exception\SyntaxError
  */
 public function testStrictMode($name, $markdown, $expected)
 {
     $ciconia = new Ciconia();
     $html = $ciconia->render($markdown, ['strict' => true]);
     $this->assertEquals($expected, $html, sprintf('%s failed', $name));
 }