/** * 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 SmartyPantsTypographer($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; }
/** * 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 SmartyPantsTypographer($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); } } return $output; }
/** * 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 = \Yii::$app->getModule('markdown'); if ($module === null) { throw new InvalidConfigException("The module 'markdown' was not found. Ensure you have setup the 'markdown' module in your Yii configuration file."); } $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 SmartyPantsTypographer($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); } } return $output; }
public function getHtml() { $cacheKey = $this->getHtmlCacheKey(); if (false === ($result = Cache::fetch($cacheKey))) { $result = ''; switch ($this->Renderer) { case 'text': $result = htmlspecialchars($this->Content); break; case 'html': $result = $this->Content; break; case 'markdown': $result = \Michelf\SmartyPantsTypographer::defaultTransform(\Michelf\MarkdownExtra::defaultTransform($this->Content)); break; } Cache::store($cacheKey, $result); } return $result; }
public function renderBody() { return '<div class="content-item content-markdown" data-itemId="' . $this->ID . '">' . \Michelf\SmartyPantsTypographer::defaultTransform(\Michelf\MarkdownExtra::defaultTransform($this->Data)) . '</div>'; }
/** * 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; }
/** * 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))); }
/** * @param $html * @return \Twig_Markup */ public function typographer($html) { $html = SmartyPantsTypographer::defaultTransform($html); return TemplateHelper::getRaw($html); }