Exemple #1
0
 /**
  * Converts markdown into HTML
  *
  * @param string $content
  * @param array  $config . Options to configure MarkdownExtra and smarty
  *  - markdown: array for MarkdownExtra configuration parameters
  *  - smarty: array for SmartyPantsTypographer configuration parameters
  *  - custom: array for Custom configuration parameters
  * @param int    $smartyMode the SmartyPantsTypographer processing mode
  *
  * @return string
  * @throws InvalidConfigException if module not set
  */
 public static function convert($content, $config = [], $smartyMode = self::SMARTYPANTS_ATTR_LONG_EM_DASH_SHORT_EN)
 {
     $module = Config::initModule(Module::classname());
     $output = $content;
     if (strlen($output) > 0) {
         $mdConfig = empty($config['markdown']) ? [] : $config['markdown'];
         $output = static::process($content, $mdConfig);
         if ($module->smartyPants) {
             $smConfig = empty($config['smarty']) ? [] : $config['smarty'];
             $smarty = new SmartyPants($smartyMode);
             foreach ($smConfig as $name => $value) {
                 $smarty->{$name} = $value;
             }
             $output = $smarty->transform($output);
             $cuConfig = empty($config['custom']) ? $module->customConversion : $config['custom'];
             $output = static::customProcess($output, $cuConfig);
         }
         if (is_bool($module->smarty) && $module->smarty || (is_string($module->smarty) || is_callable($module->smarty)) && call_user_func($module->smarty, $module)) {
             $smarty = new \Smarty();
             if ($module->smartyYiiApp) {
                 $smarty->assign('app', Yii::$app);
             }
             if ($module->smartyYiiParams) {
                 $smarty->config_vars = Yii::$app->params;
             }
             $output = $smarty->fetch('string:' . $output, null, null, $module->smartyParams);
         }
     }
     return $output;
 }
 public function convert($content)
 {
     $content = $this->markdown->transform($content);
     if (!is_null($this->smartypants)) {
         $content = $this->smartypants->transform($content);
     }
     $content = trim($content);
     return $content;
 }
 protected function generateHtml($source, $template, $refresh)
 {
     // Check that the source file is sane
     if (!file_exists($source)) {
         throw new \Exception("Unable to open source file: {$source}");
     }
     // Check that our template is sane, or set to the default one
     if (!$template) {
         $template = $this->app->defaultTemplate;
     }
     $templatePath = join(DIRECTORY_SEPARATOR, array($this->app->templatePath, basename($template)));
     $templateIndexPath = join(DIRECTORY_SEPARATOR, array($templatePath, 'index.html'));
     if (!file_exists($templateIndexPath)) {
         throw new \Exception("Unable to open template file: {$templateIndexPath}");
     }
     $style = $this->generateContent($templatePath, 'css');
     $links = $this->generateContent($templatePath, 'links');
     $templateContent = file_get_contents($templateIndexPath);
     $resumeContent = file_get_contents($source);
     // Process with Markdown, and then use SmartyPants to clean up punctuation.
     $resumeHtml = MarkdownExtra::defaultTransform($resumeContent);
     $resumeHtml = SmartyPants::defaultTransform($resumeHtml);
     // Construct the title for the html document from the h1 and h2 tags
     $simpleDom = HtmlDomParser::str_get_html($resumeHtml);
     $title = sprintf('%s | %s', $simpleDom->find('h1', 0)->innertext, $simpleDom->find('h2', 0)->innertext);
     // Render the Markdown into an html file with Mustache Templates
     $m = new \Mustache_Engine();
     $rendered = $m->render($templateContent, array('title' => $title, 'style' => $style, 'links' => $links, 'resume' => $resumeHtml, 'reload' => (bool) $refresh, 'refresh_rate' => $refresh));
     return $rendered;
 }
 public function smartypantsFilter($content, $options = null)
 {
     if (!$options) {
         $options = $this->config->get('plugins.smartypants.options');
     }
     return \Michelf\SmartyPants::defaultTransform($content, $options);
 }
Exemple #5
0
 /**
  * Runs the given string through "typography" parser (SmartyPants).
  *
  * @param string $source
  *
  * @return string
  */
 public function parseTypography($source)
 {
     $source = $this->callHook('modifySmartDownTypographyInput', $source);
     $source = SmartyPants::defaultTransform($source);
     $source = $this->callHook('modifySmartDownTypographyOutput', $source);
     return $source;
 }
 function do_format($value)
 {
     $value = stripcslashes($value);
     $value = SmartyPants::defaultTransform($value);
     $value = html_entity_decode($value);
     return $value;
 }
 public function toHTML($text)
 {
     $text = $this->preTransformText($text);
     $text = MarkdownExtra::defaultTransform($text);
     $text = SmartyPants::defaultTransform($text);
     $text = $this->postTransformText($text);
     return $text;
 }
 /**
  * Apply smartypants to content
  */
 public function onPageContentProcessed(Event $event)
 {
     $page = $event['page'];
     $config = $this->mergeConfig($page);
     if ($config->get('process_content')) {
         $page->setRawContent(\Michelf\SmartyPants::defaultTransform($page->getRawContent(), $config->get('options')));
     }
 }
Exemple #9
0
 public function toHtml($mdStr)
 {
     $html = $this->preTransformText($mdStr);
     $html = MarkdownExtra::defaultTransform($html);
     $html = SmartyPants::defaultTransform($html);
     $html = $this->postTransformText($html);
     return $html;
 }
Exemple #10
0
 public function toHTML($text)
 {
     $html = new MarkdownExtra();
     $html->code_attr_on_pre = true;
     $text = $this->preTransformText($text);
     $text = $html->defaultTransform($text);
     $text = SmartyPants::defaultTransform($text);
     $text = $this->postTransformText($text);
     return $text;
 }
Exemple #11
0
 /**
  * Translate plain ASCII punctuation characters into "smart" typographic punctuation HTML entities.
  *
  * @param string  $string  text to transform
  * @return array
  */
 public static function smartypants($string)
 {
     // start measuring
     $hash = Debug::markStart('parsing', 'smartypants');
     if (Config::get('enable_smartypants', true) === 'typographer') {
         $result = SmartyPantsTypographer::defaultTransform($string);
     } else {
         $result = SmartyPants::defaultTransform($string);
     }
     // end measuring
     Debug::markEnd($hash);
     Debug::increment('parses', 'smartypants');
     return $result;
 }
Exemple #12
0
 protected function processEscapes($_)
 {
     #
     #   Adding a few more escapes to SmartyPants's escapes:
     #
     #               Escape  Value
     #               ------  -----
     #               \,      ,
     #               \<      &#60;
     #               \>      &#62;
     #
     $_ = parent::processEscapes($_);
     $_ = str_replace(array('\\,', '\\<', '\\>', '\\&lt;', '\\&gt;'), array('&#44;', '&#60;', '&#62;', '&#60;', '&#62;'), $_);
     return $_;
 }
 protected function doFilter($text)
 {
     return $this->smartyPants->transform($text);
 }
Exemple #14
0
 /**
  * Fixes punctuation with SmartyPants
  *
  * @param  string $content String to be parsed
  * @return string          Parsed string
  */
 public static function fixPunctuation($content)
 {
     if (!is_string($content)) {
         return null;
     }
     if (!class_exists('Michelf\\SmartyPants')) {
         return $content;
     }
     return \Michelf\SmartyPants::defaultTransform($content);
 }
Exemple #15
0
 /**
  * Apply smart quotes and other stylistic enhancements to HTML.
  * 
  * @param string $html
  * @return string
  */
 public static function applySmartQuotes($html)
 {
     return \Michelf\SmartyPants::defaultTransform($html, 'qbBdDiew');
 }
Exemple #16
0
 /**
  * Runs $text through a SmartyPants translator, returning the translated text.
  *
  * @param string $text The text to translate.
  * @return string The translated text.
  * @access public
  * @static
  */
 public static function smartypants($text)
 {
     $result = \Michelf\SmartyPants::defaultTransform($text);
     return $result;
 }
 /**
  * Sets a GLOBAL plaintext body by first transforming the body to HTML, then stripping HTML tags from the body
  * @see http://board.s9y.org/viewtopic.php?f=11&t=18351 Discussion of this feature in the S9y forum.
  *
  * @param array $eventData
  * @param int   $version    Markdown Classic or Lib  default 2
  * @param int   $pants      SmartyPants option       default 0
  */
 function setPlaintextBody(array $eventData, $version = 2, $pants = 0)
 {
     if (isset($GLOBALS['entry'][0]['plaintext_body'])) {
         $html = $version == 2 ? Markdown::defaultTransform($GLOBALS['entry'][0]['plaintext_body']) : Markdown($GLOBALS['entry'][0]['plaintext_body']);
     } else {
         $html = $version == 2 ? Markdown::defaultTransform(html_entity_decode($eventData['body'], ENT_COMPAT, LANG_CHARSET)) : Markdown(html_entity_decode($eventData['body'], ENT_COMPAT, LANG_CHARSET));
     }
     if ($pants > 0) {
         $html = $pants == 2 ? SmartyPantsTypographer::defaultTransform($html) : SmartyPants::defaultTransform($html);
     }
     $GLOBALS['entry'][0]['plaintext_body'] = trim(strip_tags(str_replace('javascript:', '', $html)));
 }
Exemple #18
0
# This file passes the content of the Readme.md file in the same directory
# through the SmartyPants filter. You can adapt this sample code in any way
# you like.
########
# NOTE : This file requires Markdown to be available to parse the readme file.
########
# Install PSR-0-compatible class autoloader
spl_autoload_register(function ($class) {
    require preg_replace('{\\\\|_(?!.*\\\\)}', DIRECTORY_SEPARATOR, ltrim($class, '\\')) . '.php';
});
# Get SmartyPants and Markdown classes
use Michelf\SmartyPants;
use Michelf\MarkdownExtra;
# Read file and pass content through the Markdown praser
$text = file_get_contents('Readme.md');
$html = MarkdownExtra::defaultTransform($text);
$html = SmartyPants::defaultTransform($html);
?>
<!DOCTYPE html>
<html>
    <head>
        <title>PHP Markdown Lib - Readme</title>
    </head>
    <body>
		<?php 
# Put HTML content in the document
echo $html;
?>
    </body>
</html>
 public function it_should_throw_an_exception_on_an_exception(SmartyPants $smartyPants)
 {
     $smartyPants->transform('bar')->willThrow('Exception');
     $this->shouldThrow('TheWilkyBarKid\\TextFilter\\Exception\\TextFilterFailedException')->during('filter', array('foo'));
 }
 /**
  * @param $html
  * @return \Twig_Markup
  */
 public function format($html)
 {
     $html = SmartyPants::defaultTransform($html);
     return TemplateHelper::getRaw($html);
 }