/**
  * 转换 mark 文本
  * @param $markdownText
  * @return string
  */
 public static function MarkDecode($markdownText)
 {
     /* $parsedown = new \Outshine\Editor\Parsedown();
        return $parsedown->text($markdownText);*/
     $parser = new \cebe\markdown\Markdown();
     return $parser->parse($markdownText);
 }
Example #2
0
 public function save(\Temgen\Document $document, $filename = null)
 {
     $parser = new \cebe\markdown\Markdown();
     $result = str_replace("{BODY}", $parser->parse($document->getContents()), $this->full);
     if ($filename) {
         return file_put_contents($filename, $result);
     }
     return $result;
 }
Example #3
0
 /**
  * Parse markdown using the standard format
  * 
  * @param  string $markdown The Markdown you want to parse
  * @return string           The resulting HTML
  */
 public function parse($markdown)
 {
     $instance = $this->instances['standard'];
     if (empty($instance)) {
         $instance = new \cebe\markdown\Markdown();
         $instance->html5 =& $this->use_html5;
         $instance->keepListStartNumber =& $this->keep_list_number;
     }
     return $instance->parse($markdown);
 }
Example #4
0
 public function convert($filePathIn, $filePathOut)
 {
     $replace = [];
     $replace['js_app'] = file_get_contents(__DIR__ . "/../../templates/{$this->usedTemplate}/" . "{$this->usedTemplate}.js");
     $replace['js_bootstrap'] = file_get_contents(self::PATH_DIST_BOOTSTRAP_JS);
     $replace['css_app'] = file_get_contents(__DIR__ . "/../../templates/{$this->usedTemplate}/" . "{$this->usedTemplate}.css");
     $replace['css_bootstrap'] = file_get_contents(self::PATH_DIST_BOOTSTRAP_CSS);
     $replace['content'] = $this->mdParser->parse(file_get_contents($filePathIn));
     $output['html'] = $this->latte->renderToString(__DIR__ . "/../../templates/{$this->usedTemplate}/" . "{$this->usedTemplate}.latte", $replace);
     $output['pdf'] = "@todo :)";
     $this->fs->write("{$filePathOut}.html", $output['html']);
     $this->fs->write("{$filePathOut}.pdf", $output['pdf']);
 }
Example #5
0
 /**
  * @return  self
  */
 public function convert($filePathIn, $filePathOut, $formats = ['html', 'pdf'])
 {
     $output = ['html' => '', 'pdf' => ''];
     $replace = ['content' => '', 'js' => '', 'css' => ''];
     try {
         $tpl = TemplatesRegistry::get($this->usedTemplate);
         foreach (['js', 'css'] as $type) {
             foreach ($tpl[$type] as $file) {
                 if (!is_readable($file)) {
                     throw new \Exception("Cannot load file {$file}.");
                 }
                 $file = file_get_contents($file);
                 $replace[$type] .= $file . "\n";
             }
         }
         if (file_exists("{$filePathOut}.html")) {
             unlink("{$filePathOut}.html");
         }
         $replace['content'] = $this->mdParser->parse(file_get_contents($filePathIn));
         $output['html'] = $this->latte->renderToString($tpl['layout'], $replace);
         $this->fs->write("{$filePathOut}.html", $output['html']);
         if (in_array('pdf', $formats)) {
             try {
                 $html2pdf = new \HTML2PDF('P', 'A4', 'cs');
                 $html2pdf->setDefaultFont('dejavusans');
                 //$html2pdf->addFont('dejavusans');
                 $html2pdf->pdf->SetDisplayMode('real');
                 $output['html'] = str_replace('\\xe28087', "  ", $output['html']);
                 $html2pdf->writeHTML($output['html']);
                 $pdf = $html2pdf->Output("{$filePathOut}.pdf", 'S');
                 $this->fs->write("{$filePathOut}.pdf", $pdf);
             } catch (Html2PdfException $e) {
                 $formatter = new ExceptionFormatter($e);
                 echo "PDF: " . $formatter->getHtmlMessage();
             }
         }
         if (!in_array('html', $formats)) {
             //unlink("{$filePathOut}.html");
         }
     } catch (\InvalidArgumentException $e) {
         echo $e->getMessage(), "\n";
     }
     return $this;
 }
Example #6
0
<?php

require __DIR__ . '/../Parser.php';
require __DIR__ . '/../Markdown.php';
$markdown = '';
$markdown = file_get_contents(__DIR__ . '/markdown-data/specs.md');
//$markdown = file_get_contents(__DIR__ . '/github-data/github-sample.md');
//ini_set('xhprof.output_dir', __DIR__ . '/xhprof');
// http://de3.php.net/manual/en/xhprof.examples.php
xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
for ($n = 0; $n < 100; $n++) {
    $pd = new \cebe\markdown\Markdown();
    $pd->parse($markdown);
}
$xhprof_data = xhprof_disable();
$XHPROF_ROOT = __DIR__ . '/../vendor/facebook/xhprof/';
include_once $XHPROF_ROOT . '/xhprof_lib/utils/xhprof_lib.php';
include_once $XHPROF_ROOT . '/xhprof_lib/utils/xhprof_runs.php';
$xhprof_runs = new XHProfRuns_Default();
$run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_testing");
echo "http://localhost/xhprof/xhprof_html/index.php?run={$run_id}&source=xhprof_testing\n";
<?php

/**
 * Configuration for the Markdown Parser twig filter. Markdown Parser from Carsten Brandt https://github.com/cebe
 *
 * @author Matthew Seremet
 * @link https://github.com/frostbitten
 */
$twig = $app->view()->getEnvironment();
$twig->addFilter(new \Twig_SimpleFilter('md', function ($input, $type) {
    if ($type == "git") {
        $parser = new \cebe\markdown\GithubMarkdown();
    } elseif ($type == "extra") {
        $parser = new \cebe\markdown\MarkdownExtra();
    } else {
        $parser = new \cebe\markdown\Markdown();
    }
    return $parser->parse($input);
}));
Example #8
0
$html = '';
$type = isset($_GET['t']) ? $_GET['t'] : '';
$flavor = isset($_GET['f']) ? $_GET['f'] : '';
if ($type == 'michelf') {
    if ($flavor == 'extra') {
        $html = \Michelf\MarkdownExtra::defaultTransform($md);
    } else {
        $html = \Michelf\Markdown::defaultTransform($md);
    }
} elseif ($type == 'cebe') {
    if ($flavor == 'extra') {
        $parser = new \cebe\markdown\MarkdownExtra();
    } elseif ($flavor == 'github') {
        $parser = new \cebe\markdown\GithubMarkdown();
    } else {
        $parser = new \cebe\markdown\Markdown();
    }
    $html = $parser->parse($md);
} elseif ($type == 'parsedown') {
    $parser = new Parsedown();
    $html = $parser->text($md);
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Comparison of the Markdown library</title>
<link rel="stylesheet" href="github-markdown.css">
<style>
.markdown-body {overflow: auto; padding: 2em;}
Example #9
0
 /**
  * parseMarkdown
  * @return object
  */
 public function parseMarkdown()
 {
     $dom = new \DomDocument();
     $dom->loadHTML($this->html);
     $finder = new \DomXPath($dom);
     $nodes = $finder->query("//*[contains(concat(' ', normalize-space(@class), ' '), ' cacheLogText ')]");
     $MdParser = new \cebe\markdown\Markdown();
     foreach ($nodes as $node) {
         $raw_log = $node->ownerDocument->saveHTML($node);
         $raw_log = trim(str_replace(array('<td class="cacheLogText" colspan="2">', '</td>'), '', $raw_log));
         $log = preg_replace('/<br>$/', '', $raw_log);
         $node->nodeValue = $MdParser->parse($log);
     }
     $this->html = htmlspecialchars_decode($dom->saveHtml());
     return $this;
 }
Example #10
0
 /**
  * @param $filename String
  * @return string html content of .md file
  */
 public static function getContent($filename)
 {
     $markdown = file_get_contents(Yii::getAlias(self::ARTICLES_DIR . '/' . $filename . '.md'));
     $parser = new \cebe\markdown\Markdown();
     return $parser->parse($markdown);
 }