function apply($text) { require_once 'classMarkdown.php'; $markdown = new MarkdownExtra_Parser(); $text = $markdown->transform($text); return SmartyPants($text); }
public function filter($text) { if (Options::get('typogrify__do_amp')) { $text = amp($text); } if (Options::get('typogrify__do_widont')) { $text = widont($text); } if (Options::get('typogrify__do_smartypants')) { // Standard options plus convert_quot ('w') to // convert " entities, that Habari might // already have converted '"' characters into. $text = SmartyPants($text, "qbdew"); } if (Options::get('typogrify__do_caps')) { $text = caps($text); } if (Options::get('typogrify__do_initial_quotes')) { $text = initial_quotes($text); } if (Options::get('typogrify__do_guillemets')) { $text = initial_quotes($text, true); } if (Options::get('typogrify__do_dash')) { $text = dash($text); } return $text; }
function TextToHTML($string, $stringLanguage = false) { global $_JAM; // Look for Markdown preference if ($_JAM->projectConfig['useMarkdown']) { require_once 'engine/libraries/smartypants.php'; require_once 'engine/libraries/markdown.php'; return SmartyPants(Markdown($string)); } // First find backticked portions and store them for later use $backtickmatch = '{`([^`]*)`}u'; preg_match_all($backtickmatch, $string, $metaFillOutArray, PREG_PATTERN_ORDER); // Only index 1 is suitable for use $fillOutArray = $metaFillOutArray[1]; // Replace matches with placeholders $string = preg_replace($backtickmatch, '%PLACEHOLDER', $string); $match = array('{\\r}u', '{^([^\\n]+)$}mu', '{<p>-(=)+-</p>}u', '{<p>([^\\n]+)</p>[\\n\\s]*<p>-*</p>}u', '{<p>[-·•]\\s?([^\\n]+)</p>(\\n{1}|$)}u', '{</ul>\\n<ul>}u', '{<p>(\\d)\\. ([^\\n]+)</p>(\\n{1}|$)}u', '{</ol>\\n<ol type="1" start="\\d">}u', '{</p>\\n<p>([^\\t])}u', "{(/?)>\\[([^\\s=>\\]]*)=([^\\s>\\]]*)\\]}u", '{<p>%PLACEHOLDER</p>}u'); $replace = array('', e('p', '$1'), e('hr'), e('h2', '$1'), e('ul', e('li', '$1')) . "\n", "\n", e('ol', array('type' => 1, 'start' => '$1'), e('li', '$2')) . "\n", "\n", e('br') . "\n\$1", ' $2="$3"$1>', '%PLACEHOLDER'); $smartizedString = TextRenderer::SmartizeText($string, $language); $HTMLString = preg_replace($match, $replace, $smartizedString); // Reinsert backticked portions while ($fillout = array_shift($fillOutArray)) { $HTMLString = preg_replace('{%PLACEHOLDER}u', $fillout, $HTMLString, 1); } return $HTMLString; }
function execute_smartypants($data) { static $smartypants; if (!$smartypants) { require IXG_PATH_PREFIX . "pipes/engines/smartypants/smartypants.php"; $smartypants = true; } return SmartyPants($data); }
function TextileThis($text, $lite = '', $encode = '') { if ($lite == '' && $encode == '') { $text = Markdown($text); } if (function_exists('SmartyPants')) { $text = SmartyPants($text); } return $text; }
function run($string) { if (!function_exists('Markdown')) { include_once EXTENSIONS . '/markdown/lib/markdown_extra.php'; } if (!function_exists('SmartyPants')) { include_once EXTENSIONS . '/markdown/lib/smartypants.php'; } $result = stripslashes(Markdown($string)); return SmartyPants($result); }
function run($string) { if (!self::$_parser) { include_once EXTENSIONS . '/markdown/lib/markdown.php'; self::$_parser = new MarkdownExtra_Parser(); } if (!function_exists('SmartyPants')) { include_once EXTENSIONS . '/markdown/lib/smartypants.php'; } return SmartyPants(stripslashes(self::$_parser->transform($string))); }
function htmlFormatted($text, $media = false, $model = null, $media_link_attributes = null) { $text = $this->sanitiseText($text, false); $text = SmartyPants(Markdown($text)); if ($media && count($media)) { $text = $this->_formatTextFragments($text, $media, $model, $media_link_attributes); } else { $text = $this->_stripTextFragments($text); } return $text; }
function event_hook($event, &$bag, &$eventData, $addData = null) { global $serendipity; $hooks =& $bag->get('event_hooks'); if (isset($hooks[$event])) { switch ($event) { case 'frontend_display': if ($this->get_config('SMARTYPANTS_INSTEAD', false)) { include_once dirname(__FILE__) . '/smartypants.php'; foreach ($this->markup_elements as $temp) { if (serendipity_db_bool($this->get_config($temp['name'], true)) && !empty($eventData[$temp['element']]) && !$eventData['properties']['ep_disable_markup_' . $this->instance] && !isset($serendipity['POST']['properties']['disable_markup_' . $this->instance])) { $element = $temp['element']; $eventData[$element] = SmartyPants($eventData[$element]); } } } else { foreach ($this->markup_elements as $temp) { if (serendipity_db_bool($this->get_config($temp['name'], true)) && isset($eventData[$temp['element']]) && !$eventData['properties']['ep_disable_markup_' . $this->instance] && !isset($serendipity['POST']['properties']['disable_markup_' . $this->instance])) { $element = $temp['element']; # First find all the tags... We want to keep straight quotes in them. # So we remember all the tags, and replace them temporarily preg_match_all("/<[^>]*>/", $eventData[$element], $matches); $count = count($matches[0]); for ($i = 0; $i < $count; $i++) { $temp = $matches[0][$i]; $new = "<!-- tag number {$i} -->"; $eventData[$element] = str_replace($temp, $new, $eventData[$element]); } # Now we perform our replacements... All sets of quotes turned smart, then single quotes are dealt with... $eventData[$element] = preg_replace("/\"(.*?)\"/", "“\\1”", $eventData[$element]); $eventData[$element] = preg_replace("/"(.*?)"/", "“\\1”", $eventData[$element]); $eventData[$element] = preg_replace("/(?<! )' /", "’ ", $eventData[$element]); $eventData[$element] = preg_replace("/(?<! )'(?! )/", "’", $eventData[$element]); $eventData[$element] = preg_replace("/ '(?! )/", " ‘", $eventData[$element]); #Finally we add the tags back into the body of our entry. for ($i = 0; $i < $count; $i++) { $tag_body = $matches[0][$i]; $old = "<!-- tag number {$i} -->"; $eventData[$element] = str_replace($old, $tag_body, $eventData[$element]); } } } } return true; break; default: return false; } } else { return false; } }
public function run($string) { if (!self::$_parser) { include_once EXTENSIONS . '/markdown/lib/php-markdown-extra-1.2.4/markdown.php'; self::$_parser = new Markdown_Parser(); } // Markdown transformation $result = stripslashes(self::$_parser->transform($string)); if (!function_exists('SmartyPants')) { include_once EXTENSIONS . '/markdown/lib/php-smartypants-1.5.1e/smartypants.php'; } // Apply "Smarty Pants" formatting $result = SmartyPants(stripslashes(self::$_parser->transform($string))); return $result; }
function tc_post_process($text, $do_text = '', $do_char = '') { if ($do_text == 'textile2') { require_once 'text-control/textile2.php'; $t = new Textile(); $text = $t->process($text); } else { if ($do_text == 'textile1') { require_once 'text-control/textile1.php'; $text = textile($text); } else { if ($do_text == 'markdown') { require_once 'text-control/markdown.php'; $text = Markdown($text); } else { if ($do_text == 'wpautop') { $text = wpautop($text); } else { if ($do_text == 'nl2br') { $text = nl2br($text); } else { if ($do_text == 'none') { $text = $text; } else { $text = wpautop($text); } } } } } } if ($do_char == 'smartypants') { require_once 'text-control/smartypants.php'; $text = SmartyPants($text); } else { if ($do_char == 'wptexturize') { $text = wptexturize($text); } else { if ($do_char == 'none') { $text = $text; } else { $text = wptexturize($text); } } } return $text; }
public static function transform($string) { $path = dirname(__FILE__) . '/../vendor/' . sfConfig::get('app_majaxMarkdown_style', 'markdown_extra') . '/markdown.php'; require_once $path; $string = Markdown($string); if (sfConfig::get('app_majaxMarkdown_smartypants_enabled', true)) { $style = sfConfig::get('app_majaxMarkdown_smartypants_style', 'smartypants_typographer'); $path = dirname(__FILE__) . '/../vendor/' . $style . '/smartypants.php'; require_once $path; $string = SmartyPants($string, sfConfig::get('app_majaxMarkdown_smartypants_options', 1)); } if (sfConfig::get('app_majaxMarkdown_post_render', false)) { $render = sfConfig::get('app_majaxMarkdown_post_render'); $string = call_user_func($render, $string); } return $string; }
function google_docs_markdown_parse($url) { include_once 'markdown.php'; include_once 'smartypants.php'; $doc = curl_get_contents($url); $start_of_div = strpos($doc, '<div id="doc-contents">'); $end_of_div = strpos($doc, '<div id="google-view-footer">'); if ($start_of_div === false) { return 'Sorry, cannot retrieve content at this time.'; } // get just the content div $content = substr($doc, $start_of_div, $end_of_div - $start_of_div); // strip new lines, replace div's with new lines // strip remaining tags, trim the ends $content = trim(strip_tags(str_replace(array("\n", '<div>'), array('', "\n"), $content))); // format with Markdown and return return SmartyPants(Markdown($content)); }
function htmlFormatted($text, $media = false, $model = null, $media_link_attributes = null) { $text = $this->sanitiseText($text, false); if (!preg_match('/{\\[markdown\\]}/', $text)) { $txtl = new Textile(); $text = SmartyPants($txtl->TextileThis($text), 1); $text = $txtl->TextileThis($text); } else { $text = str_replace('{[markdown]}', '', $text); $text = SmartyPants(Markdown($text), 1); } if ($media && count($media)) { $text = $this->_formatTextFragments($text, $media, $model, $media_link_attributes); } else { $text = $this->_stripTextFragments($text); } return $text; }
/** * Handle $data, and return the results. * * @param string data The data to handle. * @return string * @access public */ public function input($data, $options = array()) { include_once CURATOR_APP_DIR . DS . 'Vendors' . DS . 'php-markdown' . DS . 'dist' . DS . 'markdown.php'; include_once CURATOR_APP_DIR . DS . 'Vendors' . DS . 'php-smartypants' . DS . 'dist' . DS . 'smartypants.php'; $result = null; try { if (strpos($data, NL) === false && is_file($data)) { $data = file_get_contents($data); if ($data === false) { throw new \Exception('Could not load file: ' . $data); } } $result = \SmartyPants(\Markdown($data)); } catch (\Exception $e) { \Curator\Console::stderr('** Could not handle Mardkwon data:'); \Curator\Console::stderr(' ' . $e->getMessage()); } return $result; }
/** * Render content via a given $content_type * * @param string $content Content to render * @param mixed $content_type Content type to use (overrides configured content_type) * @return string */ public static function transform($content, $content_type = NULL) { $content_type = Helper::pick($content_type, Config::getContentType()); // render HTML from the given $content_type switch (strtolower($content_type)) { case "markdown": case "md": $content = Markdown($content); break; case "text": case "txt": $content = nl2br(strip_tags($content)); break; case "textile": $textile = new Textile(); $content = $textile->TextileThis($content); } if (Config::get('_enable_smartypants', TRUE) == TRUE) { $content = SmartyPants($content, 2); } return trim($content); }
function twitter_get_toot($username) { $url = "http://twitter.com/statuses/user_timeline.json?count=25&screen_name={$username}"; $toots = json_decode_file($url); foreach ($toots as $toot) { $toot = $toot->text; # Find the first toot that starts with "I" (or "I'm" etc.) and isn't all caps if (preg_match('/^I[^A-Za-z]/', $toot) and $toot != strtoupper($toot)) { $toot = SmartyPants($toot); # Turns *asterisized* text into <em>emphasized</em> text # This could be more complex but (bold, underline) but it works for me $toot = preg_replace('/\\*(.+?)\\*/', '<em>\\1</em>', $toot); # Add a hyperlink to text that ends in a URL if (preg_match('/http:\\/\\/[^ ]+/', $toot, $urls)) { $url = $urls[0]; # Pull that guy outta there $toot = trim(str_replace($url, '', $toot)); $toot = "<a href=\"{$url}\" rel=\"nofollow\">{$toot}</a>"; } return $toot; } } }
/** * Constructor. * * @access public * @param string $tagdata The tagdata to process. * @return void */ public function __construct($tagdata = '') { $ee =& get_instance(); $config = $ee->config; $functions = $ee->functions; $tmpl = $ee->TMPL; $default_smartquotes = '2'; $this->return_data = ''; if ($tagdata) { // Fieldtype. $encode = $config->item('smartdown:ee_tags:encode') == 'yes'; $fix_images = !($config->item('smartdown:ee_tags:fix_transplanted_images') == 'no'); $smart_quotes = $config->item('smartdown:smart_quotes') ? $config->item('smartdown:smart_quotes') : $default_smartquotes; } else { // Template tag. $tagdata = $tmpl->tagdata; $encode = ($tmpl->fetch_param('ee_tags:encode') == 'yes') OR ($tmpl->fetch_param('encode_ee_tags') == 'yes'); $fix_images = !($tmpl->fetch_param('ee_tags:fix_transplanted_images') == 'no'); $smart_quotes = $tmpl->fetch_param('smart_quotes') ? $tmpl->fetch_param('smart_quotes') : $default_smartquotes; } if ($encode) { $tagdata = Markdown($functions->encode_ee_tags($tagdata, TRUE)); // Fix EE code samples. $tagdata = preg_replace_callback( '|' .preg_quote('<code>') .'(.*?)' .preg_quote('</code>') .'|s', array($this, '_fix_encoded_ee_code_samples'), $tagdata ); // Fix {path=} URLs. $tagdata = preg_replace('/{(path=.*?)}/i', '{$1}', $tagdata); // Play nicely with NSM Transplant and the {image_xx} technique. if ($fix_images) { $tagdata = preg_replace('/{(image_[0-9]+)}/i', '{$1}', $tagdata); } } else { $tagdata = Markdown($tagdata); } $this->return_data = SmartyPants($tagdata, $smart_quotes); }
<body> <header> <h1>Scattered Feed</h1> <p>I’m scattering feed for the chickens. Now it’s all scattered.</p> </header> <ul class="feed"> <?php foreach ($items as $item) { ?> <li> <h2><a href="<?php echo $item['link']; ?> "><span><?php echo SmartyPants($item['title']); ?> </span></a></h2> <p><?php echo $item['description']; ?> </p> <p class="date"><?php echo date('F j', $item['published_at']); ?> </p> </li> <?php } ?> </ul>
$content = $purifier->purify($content, $config); // run through Tidy one last time (TODO: check if this step can be avoided) $tidy = tidy_parse_string($content, $tidy_config, 'UTF8'); $tidy->cleanRepair(); $content = $tidy->value; // a little additional cleanup... $content = str_replace('<p><br /></p>', '<br />', $content); $content = preg_replace('!<br />\s*<(/?(h2|p))>!', '<$1>', $content); //$content = preg_replace('!<br />\s*</p>!', '</p>', $content); $content = preg_replace('!\s*<br />\s*!', '<br />', $content); $content = preg_replace('!</(p|blockquote)>\s*<br />\s*!', '</$1>', $content); $content = str_replace('<p> </p>', '', $content); //$content = preg_replace('/\s+/', ' ', $content); // run content through SmartyPants to make things pretty $content = SmartyPants($content); $title = SmartyPants($item->get_title()); $story .= $content; // add enclosure link if ($enclosure = $item->get_enclosure()) { $story = '<p><a href="'.$enclosure->get_link().'">Click here to view or listen to the audio/video.</a></p>'.$story; } //die($story); //die($purifier->purify($item->get_content())); $pdf->addItem('<a href="'.$item->get_permalink().'">'.$title.'</a>', $story, (int)$item->get_date('U')); } // make PDF $pdf->makePdf(); // output PDF $pdf->Output($cache_file, 'F'); $pdf->Output('news.pdf', 'I');
function text($text) { return SmartyPants(Markdown($text)); }
/** * Parse content to Markdown * @param string $str String to parse * @param array $options Associative array containing options * - encode_ee_tags (yes/no) can be used to disable * ee tag encoding * - smartypants (yes/no) enable or disable * smartypants * - no_markup (TRUE/FALSE) set to TRUE to disable * the parsing of markup in Markdown * @return string Parsed Markdown content */ public function markdown($str, $options = array()) { require_once APPPATH . 'libraries/typography/Markdown/markdown.php'; // Encode EE Tags if (!isset($options['encode_ee_tags']) or $options['encode_ee_tags'] == 'yes') { $str = ee()->functions->encode_ee_tags($str); } // Ignore [code] $code_blocks = array(); preg_match_all("/\\[code\\](.*?)\\[\\/code\\]/uis", $str, $matches); foreach ($matches[0] as $match) { $hash = random_string('md5'); $code_blocks[$hash] = $match; $str = str_replace($match, $hash, $str); } $parser = new Markdown_Parser(); // Disable other markup if this is set if (isset($options['no_markup']) && $options['no_markup'] === TRUE) { $parser->no_markup = TRUE; } // Protect any quotes in EE tags from the Markdown and SmartyPants // processors. $str = $this->protect_quotes_in_tags($str); // Parse the Markdown $str = $parser->transform($str); // Run everything through SmartyPants if (!isset($options['smartypants']) or $options['smartypants'] == 'yes') { require_once APPPATH . 'libraries/typography/SmartyPants/smartypants.php'; $str = SmartyPants($str); } // Restore the quotes we protected earlier. $str = $this->restore_quotes_in_tags($str); // Replace <pre><code> with [code] // Only relevant IF being called by typography parser $backtrace = debug_backtrace(); if (!in_array($backtrace[1]['class'], array('EE_Typography', 'Markdown'))) { $str = preg_replace("/<pre><code>(.*?)<\\/code><\\/pre>/uis", "[code]\$1[/code]", $str); } // Replace [code] foreach ($code_blocks as $hash => $code_block) { $str = str_replace($hash, $code_block, $str); } return $str; }
function smarty_modifier_smartypants($text, $attr = NULL) { return SmartyPants($text, $attr); }
function niceHTML($text) { $html = SmartyPants(Markdown($text)); return $html; }
/** * @private */ function process_quotes($str) { if (!$this->options['do_quotes'] || !function_exists('SmartyPants')) { return $str; } return SmartyPants($str, $this->options['smarty_mode']); }
function fs_MarkdownAndSmartyPants($content) { $content = MarkDown($content); $content = SmartyPants($content); return $content; }
public function write_index_sequence($dest_path, $title, $type, array $posts, $template = 'main.html', $archive_array = false, $posts_per_page = 20) { $sequence = 0; $new_dest_path = $dest_path; // $dest_uri = substring_after(substring_before($dest_path, '.', true), Updater::$dest_path); $dest_uri = substring_after(substring_after($dest_path, '/', true), Updater::$dest_path); $total_sequences = ceil(count($posts) / $posts_per_page); while ($posts) { $sequence++; $seq_array = array_splice($posts, 0, $posts_per_page); if ($sequence == 1) { continue; } // skip writing the redundant "-1" page $new_dest_path = $dest_path . '-' . $sequence . '.html'; $posts_data = array(); foreach ($seq_array as $p) { $posts_data[] = $p->array_for_template(); } $t = new Template($template); $t->content = array('page-title' => html_entity_decode(SmartyPants($title), ENT_QUOTES, 'UTF-8'), 'blog-title' => html_entity_decode(SmartyPants(self::$blog_title), ENT_QUOTES, 'UTF-8'), 'blog-url' => self::$blog_url, 'blog-description' => html_entity_decode(SmartyPants(self::$blog_description), ENT_QUOTES, 'UTF-8'), 'page-type' => $type, 'posts' => $posts_data, 'previous_page_url' => $sequence != 1 ? $sequence == 2 ? $dest_uri : $dest_uri . '-' . ($sequence - 1) : false, 'next_page_url' => $sequence < $total_sequences ? $dest_uri . '-' . ($sequence + 1) : false, 'archives' => $archive_array ? $archive_array : array()); $output_html = $t->outputHTML(); $output_path = dirname($new_dest_path); if (!file_exists($output_path)) { mkdir_as_parent_owner($output_path, 0755, true); } file_put_contents_as_dir_owner($new_dest_path, $output_html); } return $total_sequences; }
/** * Constructor. * * @access public * @param string $tagdata The tagdata to process. * @return void */ public function __construct($tagdata = '') { global $REGX, $TMPL; $this->return_data = ''; if ( ! $tagdata) { $tagdata = $TMPL->tagdata; } if ($TMPL->fetch_param('encode_ee_tags') == 'yes') { $tagdata = Markdown($REGX->encode_ee_tags($tagdata, TRUE)); $tagdata = preg_replace_callback( '|' .preg_quote('<code>') .'(.*?)' .preg_quote('</code>') .'|s', create_function( '$matches', 'return str_replace( array( "&#123;&#47;", "&#123;", "&#125;" ), array( "{/", "{", "}" ), $matches[0] );' ), $tagdata ); } else { $tagdata = Markdown($tagdata); } // Apply SmartyPants. $smart_quotes = $TMPL->fetch_param('smart_quotes') ? $TMPL->fetch_param('smart_quotes') : '2'; $this->return_data = SmartyPants($tagdata, $smart_quotes); }
public function write_archive($posts) { $template = Updater::$archive_page_template; $t = new Template($template); $t->content = array('post-title' => 'Archive', 'post-type' => 'archive', 'page-type' => 'archive', 'page-title' => 'Archive', 'blog-title' => html_entity_decode(SmartyPants(self::$blog_title), ENT_QUOTES, 'UTF-8')); foreach ($posts as $post) { $t->content['posts'][] = array('title' => html_entity_decode(SmartyPants($post->title), ENT_QUOTES, 'UTF-8'), 'timestamp' => $post->timestamp, 'uri' => '/' . $post->year . '/' . str_pad($post->month, 2, '0', STR_PAD_LEFT) . '/' . $post->slug, 'tags' => $post->tags); $output_html = $t->outputHTML(); } if (!file_exists(Updater::$dest_path)) { mkdir_as_parent_owner(Updater::$dest_path, 0755, true); } file_put_contents_as_dir_owner(Updater::$dest_path . '/archive.html', $output_html); }
function TextileThis($text, $lite='', $encode='', $noimage='', $strict='') { if ($lite == '' && $encode == '') $text = Markdown($text); if (function_exists('SmartyPants')) $text = SmartyPants($text); return $text; }