public function actionView()
 {
     $topic = $this->getTopic();
     $file = Yii::getPathOfAlias('application.data.guide') . DIRECTORY_SEPARATOR . $this->getVersion() . DIRECTORY_SEPARATOR . $this->getLanguage() . DIRECTORY_SEPARATOR . $topic . '.txt';
     if (!is_file($file)) {
         $file = Yii::getPathOfAlias('application.data.guide') . DIRECTORY_SEPARATOR . $this->getVersion() . DIRECTORY_SEPARATOR . $topic . '.txt';
     }
     if (!strcasecmp($topic, 'toc') || !is_file($file)) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     $content = file_get_contents($file);
     $markdown = new MarkdownParser();
     $markdown->purifierOptions['Attr.EnableID'] = true;
     $content = $markdown->safeTransform($content);
     $highlightCss = Yii::app()->assetManager->publish($markdown->getDefaultCssFile());
     Yii::app()->clientScript->registerCssFile($highlightCss);
     $imageUrl = Yii::app()->baseUrl . '/images/guide';
     $content = preg_replace('/<p>\\s*<img(.*?)src="(.*?)"\\s+alt="(.*?)"\\s*\\/>\\s*<\\/p>/', '<div class="image"><p>\\3</p><img\\1src="' . $imageUrl . '/\\2" alt="\\3" /></div>', $content);
     $content = preg_replace_callback('/href="\\/guide\\/(.*?)\\/?"/', array($this, 'replaceGuideLink'), $content);
     $content = preg_replace('/href="(\\/api\\/.*?)"/', 'href="http://sourcebans.net$1"', $content);
     $content = preg_replace_callback('/<h2([^>]*)>(.*?)<\\/h2>/', array($this, 'replaceSection'), $content);
     $content = preg_replace_callback('/<h1([^>]*)>(.*?)<\\/h1>/', array($this, 'replaceTitle'), $content, 1);
     $this->pageTitle = 'User Guide « SourceBans';
     if ($topic !== 'index' && preg_match('/<h1[^>]*>(.*?)</', $content, $matches)) {
         $this->pageTitle = CHtml::encode($matches[1]) . ' « ' . $this->pageTitle;
     }
     $this->render('view', array('content' => $content));
 }
 /**
  * @param string $basePath
  */
 public function extractToFiles(string $basePath)
 {
     $this->pathExtractor->extractPaths($basePath)->apply(function (string $path) {
         $this->parser->extractCodes(file_get_contents($path));
     });
     $this->publisher->publish($this->parser->getCodes());
 }
 function testParsingMarkdown()
 {
     $text = "**A test**\n\nAnd a new paragraph.";
     $expected = "<p><strong>A test</strong></p><p>And a new paragraph.</p>";
     $parser = new MarkdownParser($text);
     // we ignore wrapping whitespace and newlines
     $result = trim(str_replace("\n", '', $parser->parse()));
     $this->assertEquals($result, $expected, 'Translation markdown to HTML.');
 }
 protected function createHighLighter($options)
 {
     $hi = parent::createHighLighter($options);
     $renderer = new Text_Highlighter_Renderer_Latex($this->getHiglightConfig($options));
     $hi->setRenderer($renderer);
     return $hi;
 }
 private function initialize()
 {
     self::$md_nested_brackets = str_repeat('(?>[^\\[\\]]+|\\[', self::$md_nested_brackets_depth) . str_repeat('\\])*', self::$md_nested_brackets_depth);
     self::$md_escape_table = array("\\" => md5("\\"), "`" => md5("`"), "*" => md5("*"), "_" => md5("_"), "{" => md5("{"), "}" => md5("}"), "[" => md5("["), "]" => md5("]"), "(" => md5("("), ")" => md5(")"), ">" => md5(">"), "#" => md5("#"), "+" => md5("+"), "-" => md5("-"), "." => md5("."), "!" => md5("!"));
     # Table of hash values for escaped characters:
     # Create an identical table but for escaped characters.
     foreach (self::$md_escape_table as $key => $char) {
         self::$md_backslash_escape_table["\\{$key}"] = $char;
     }
 }
 protected function teardown()
 {
     #
     # Clearing Extra-specific variables.
     #
     $this->footnotes = array();
     $this->footnotes_ordered = array();
     $this->abbr_desciptions = array();
     $this->abbr_word_re = '';
     parent::teardown();
 }
 public function actionView()
 {
     $topic = $this->getTopic();
     $file = Yii::getPathOfAlias("docs.guide.{$this->language}") . DIRECTORY_SEPARATOR . $topic . '.txt';
     if (!is_file($file)) {
         $file = Yii::getPathOfAlias("docs.guide") . DIRECTORY_SEPARATOR . $topic . '.txt';
     }
     if (!strcasecmp($topic, 'toc') || !is_file($file)) {
         throw new CHttpException(404, 'The page you looked for does not exist.');
     }
     $content = file_get_contents($file);
     $markdown = new MarkdownParser();
     $content = $markdown->safeTransform($content);
     $imageUrl = Yii::app()->baseUrl . '/guide/images';
     $content = preg_replace('/<p>\\s*<img(.*?)src="(.*?)"\\s+alt="(.*?)"\\s*\\/>\\s*<\\/p>/', "<div class=\"image\"><p>\\3</p><img\\1src=\"{$imageUrl}/\\2\" alt=\"\\3\" /></div>", $content);
     $content = preg_replace_callback('/href="\\/doc\\/guide\\/(.*?)\\/?"/', array($this, 'replaceGuideLink'), $content);
     $content = preg_replace('/href="(\\/doc\\/api\\/.*?)"/', 'href="http://www.yiiframework.com$1"', $content);
     $this->pageTitle = 'The Definitive Guide to Yii';
     if ($topic !== 'index' && preg_match('/<h1[^>]*>(.*?)</', $content, $matches)) {
         $this->pageTitle .= ' - ' . CHtml::encode($matches[1]);
     }
     $this->render('view', array('content' => $content));
 }
 /**
  * Return MarkdownExtra content as HTML
  * @return string HTML
  */
 public function MarkdownExtraAsHTML()
 {
     $parser = new MarkdownParser($this->value);
     return $parser->parseExtra();
 }
 /**
  * Tutorials & Category RSS
  */
 public function actionrss()
 {
     $criteria = new CDbCriteria();
     if (isset($_GET['id']) && ($model = TutorialsCats::model()->findByPk($_GET['id']))) {
         $criteria->condition = 'catid=:catid AND status=:status';
         $criteria->params = array(':catid' => $model->id, ':status' => 1);
     } else {
         $criteria->condition = 'status=:status';
         $criteria->params = array(':status' => 1);
     }
     $rows = array();
     // Load some tutorials
     $criteria->order = 'postdate DESC';
     $criteria->limit = 50;
     $tutorials = Tutorials::model()->with(array('author'))->findAll($criteria);
     $markdown = new MarkdownParser();
     if ($tutorials) {
         foreach ($tutorials as $r) {
             $r->content = $markdown->safeTransform($r->content);
             $rows[] = array('title' => $r->title, 'link' => Yii::app()->createAbsoluteUrl('/tutorials/view/' . $r->alias, array('lang' => false)), 'charset' => Yii::app()->charset, 'description' => $r->description, 'author' => $r->author ? $r->author->username : Yii::app()->name, 'generator' => Yii::app()->name, 'language' => Yii::app()->language, 'guid' => $r->id, 'content' => $r->content);
         }
     }
     $data = array('title' => isset($model) ? $model->title : Yii::t('tutorials', 'Tutorials RSS Feed'), 'link' => isset($model) ? Yii::app()->createAbsoluteUrl('/tutorials/category/' . $model->alias, array('lang' => false)) : Yii::app()->createAbsoluteUrl('tutorials', array('lang' => false)), 'charset' => Yii::app()->charset, 'description' => isset($model) ? $model->description : Yii::t('tutorials', 'Tutorials'), 'author' => Yii::app()->name, 'generator' => Yii::app()->name, 'language' => Yii::app()->language, 'ttl' => 10, 'entries' => $rows);
     Yii::app()->func->displayRss($data);
 }
 /**
  * Parse markdown into html
  * @return string html
  */
 public function parse()
 {
     $parser = new MarkdownParser($this->request['markdown']);
     return $this->enable_extra ? $parser->parseExtra() : $parser->parse();
 }
/**
 * Converts a markdown text into purified HTML
 */
function mh($text)
{
    static $parser;
    if ($parser === null) {
        $parser = new MarkdownParser();
    }
    return $parser->safeTransform($text);
}
 /**
  * Integration-esque tests ensuring that markdown is correctly parsed to HTML
  *
  * @dataProvider markdownProvider
  *
  * @param string $markdown
  * @param string $expected
  */
 public function testParseMarkdown($markdown, $expected)
 {
     $parser = new MarkdownParser($markdown);
     $result = $parser->parse($parser);
     $this->assertSame($expected, $result);
 }
Exemple #13
0
 /**
  * Processes a text string.
  * This method is required by the parent class.
  * @param string text string to be processed
  * @return string the processed text result
  */
 public function processText($text)
 {
     $renderer = new MarkdownParser();
     $result = $renderer->parse($text);
     return preg_replace_callback('/<pre><code>\\[\\s*(\\w+)\\s*\\]\\n+((.|\\n)*?)\\s*<\\/code><\\/pre>/im', array($this, 'highlightCode'), $result);
 }
Exemple #14
0
/**
 * Returns the given markdown text as purified HTML.
 * @param $text
 * @return string
 */
function markdown($text)
{
    static $parser;
    if (!isset($parser)) {
        $parser = new MarkdownParser();
    }
    return $parser->safeTransform($text);
}
 /**
  * Markit up ajax parser callback
  */
 public function actionparser()
 {
     // Grab file contents and parse them
     $content = $_POST['dontvalidate'];
     $markdown = new MarkdownParser();
     $content = $markdown->safeTransform($content);
     $this->layout = false;
     echo $this->render('parser', array('content' => $content), true);
     Yii::app()->end();
 }
 /**
  *
  */
 private function _ParseFormatter()
 {
     $parser = new MarkdownParser();
     $this->text = $parser->transform($this->text);
 }