Ejemplo n.º 1
0
 public static function highlight($raw_body)
 {
     $body = sfMarkdown::doConvert($raw_body);
     $matches = array();
     $langs = array();
     preg_match_all("/<pre><code>\\[(\\w*)\\](\\r?\\n)+(.+)(\\r?\\n)+<\\/code><\\/pre>/isU", $body, $matches, PREG_SET_ORDER);
     if (sizeof($matches) > 0) {
         $service = new SnippetServiceClient();
         $cnt = 1;
         foreach ($matches as $match) {
             sfLogger::getInstance()->info("From myUtils: " . $match[3]);
             $languageLower = $match[1];
             $languageUpper = strtoupper($match[1]);
             sfLogger::getInstance()->info("myUtils languages: {$languageLower} {$languageUpper}" . sizeof(self::$languages));
             if (in_array($languageUpper, self::$languages)) {
                 $highlighted = $service->highlight($languageUpper, htmlspecialchars_decode($match[3]));
                 $highlighted['snippet'] = "<div class=\"code-wrapper\">{$highlighted['snippet']}</div>";
                 $body = str_replace($match[0], $highlighted['snippet'], $body, $cnt);
                 $langs[$languageLower] = $langs[$languageLower] ? $langs[$languageLower] + 1 : 1;
             } else {
                 sfLogger::getInstance()->info("myUtils : {$languageLower} is not supported.");
                 $langs[$languageLower] = $langs[$languageLower] ? $langs[$languageLower] + 1 : 1;
                 $body = str_replace($match[0], "<div class=\"code-wrapper\"><pre><code>{$match[3]}</code></pre></div>", $body, $cnt);
             }
         }
     }
     return array('body' => $body, 'langs' => $langs);
 }
Ejemplo n.º 2
0
 public static function doConvert($content)
 {
     if (class_exists('sfMarkdown')) {
         return sfMarkdown::doConvert($content);
     } else {
         return $content;
     }
 }
 public function parse()
 {
     $html = sfMarkdown::doConvert($this->data);
     if (!$html) {
         return;
     }
     $html = str_replace(array('</pre></code>', '<code>', '</code>', '<br>'), array('</pre>', '', '', '<br />'), preg_replace('/<pre><code>#(ruby|asp|js|php|x?html|css)/ie', 'strtolower("<pre class=\\"$1\\">")', $html));
     $this->xml = simplexml_load_string('<div>' . $html . '</div>');
     $stack = array();
     $section = null;
     foreach ($this->xml as $node) {
         $content = (string) $node->asXml();
         switch ($tag = strtolower($node->getName())) {
             case 'h1':
                 $this->plugin['name'] = strip_tags($content);
             case 'h2':
                 if ($section) {
                     $img = null;
                     if ($section['tag'] == 'h1') {
                         $img = $section['node']->xpath('//img');
                         if (!empty($img) && $img[0]) {
                             $this->plugin['screenshot'] = (string) $img[0]->attributes()->src;
                             $img = $img[0]->asXml();
                         }
                     }
                     if (!empty($img)) {
                         foreach ($stack as $key => $value) {
                             $stack[$key] = str_replace($img, '', $value);
                         }
                     }
                     $this->endSection($section, $stack);
                     $stack = array();
                 }
                 $section = array('tag' => $tag, 'content' => $content, 'node' => $node);
                 break;
             default:
                 $stack[] = $content;
                 break;
         }
     }
     $this->endSection($section, $stack);
     foreach ($this->sections as $name => $content) {
         if (!in_array($name, $this->options['defaultSections'])) {
             $this->arbitrarySections[$name] = $content;
         }
     }
     $images = $this->xml->xpath('//img');
     if (!empty($images)) {
         foreach ($images as $img) {
             if ($this->getScreenshot() == $img->attributes()->src) {
                 continue;
             }
             $this->images[(string) $img->attributes()->src] = (string) $img->attributes()->alt;
         }
     }
 }
Ejemplo n.º 4
0
 public function executeAbout()
 {
     //require_once('lib/markdown.php');
     $file = sfConfig::get('app_directorio_modulos') . '/content/data/about_' . $this->getUser()->getCulture() . '.txt';
     if (!is_readable($file)) {
         $file = sfConfig::get('app_directorio_modulos') . '/content/data/about_es.txt';
     }
     $this->html = sfMarkdown::doConvertFile($file);
     //$this->getResponse()->setTitle('askeet! &raquo; about');
 }
Ejemplo n.º 5
0
 public function executeDoc(sfWebRequest $request)
 {
     $file = sfConfig::get('sf_data_dir') . '/docs/' . $request->getParameter('page') . '.txt';
     $this->html = sfMarkdown::doConvertFile($file);
     $this->getResponse()->setTitle('Bee Project - ' . $request->getParameter('page'));
 }
Ejemplo n.º 6
0
/**
 * Convert Markdown file content to HTML
 *
 * Right now, this is simply a bridge to sfMarkdown class static functions.
 * I have some interesting ideas for the future.
 *
 * @param   string  $file
 * @return  string
 * @see     sfMarkdown::doConvertFile()
 */
function convert_markdown_file($file)
{
    return sfMarkdown::doConvertFile($file);
}
 function getContent()
 {
     return sfMarkdown::doConvert($this->getBody());
 }
 public function getContent()
 {
     return sfMarkdown::doConvert($this->getDescription());
 }