function output($show_lines = TRUE, $print = TRUE) { $this->process(); if (empty($this->error)) { // If no errors have occured, print the formatted code $ret = CrayonFormatter::print_code($this, $this->formatted_code, $show_lines, $print); } else { $ret = CrayonFormatter::print_error($this, $this->error, '', $print); } // Reset the error message at the end of the print session $this->error = ''; // If $print = FALSE, $ret will contain the output return $ret; }
public static function the_content($the_content) { CrayonLog::debug('the_content'); // Some themes make redundant queries and don't need extra work... if (strlen($the_content) == 0) { CrayonLog::debug('the_content blank'); return $the_content; } global $post; // Go through queued posts and find crayons $post_id = strval($post->ID); if (self::$is_excerpt) { CrayonLog::debug('excerpt'); if (CrayonGlobalSettings::val(CrayonSettings::EXCERPT_STRIP)) { CrayonLog::debug('excerpt strip'); // Remove Crayon from content if we are displaying an excerpt $the_content = preg_replace(self::REGEX_WITH_ID, '', $the_content); } // Otherwise Crayon remains with ID and replaced later return $the_content; } // Find if this post has Crayons if (array_key_exists($post_id, self::$post_queue)) { self::enqueue_resources(); // XXX We want the plain post content, no formatting $the_content_original = $the_content; // Replacing may cause <p> tags to become disjoint with a <div> inside them, close and reopen them if needed $the_content = preg_replace_callback('#' . self::REGEX_BETWEEN_PARAGRAPH_SIMPLE . '#msi', 'CrayonWP::add_paragraphs', $the_content); // Loop through Crayons $post_in_queue = self::$post_queue[$post_id]; foreach ($post_in_queue as $id => $v) { $atts = $v['atts']; $content = $v['code']; // The code we replace post content with $crayon = self::shortcode($atts, $content, $id); if (is_feed()) { // Convert the plain code to entities and put in a <pre></pre> tag $crayon_formatted = CrayonFormatter::plain_code($crayon->code(), $crayon->setting_val(CrayonSettings::DECODE)); } else { // Apply shortcode to the content $crayon_formatted = $crayon->output(TRUE, FALSE); } // Replace the code with the Crayon CrayonLog::debug('the_content: id ' . $post_id . ' has UID ' . $id . ' : ' . intval(stripos($the_content, $id) !== FALSE)); $the_content = CrayonUtil::preg_replace_escape_back(self::regex_with_id($id), $crayon_formatted, $the_content, 1, $count); CrayonLog::debug('the_content: REPLACED for id ' . $post_id . ' from len ' . strlen($the_content_original) . ' to ' . strlen($the_content)); } } return $the_content; }
public static function delim_to_internal($matches) { // Mark as mixed so we can show (+) self::$curr->is_mixed(TRUE); $capture_group = count($matches) - 2; $capture_groups = array_keys(self::$delimiters); $lang_id = $capture_groups[$capture_group]; if (($lang = CrayonResources::langs()->get($lang_id)) === NULL) { return $matches[0]; } $internal = sprintf('{{crayon-internal:%d}}', count(self::$delim_pieces)); // TODO fix self::$delim_pieces[] = CrayonFormatter::format_code($matches[0], $lang, self::$curr); return $internal; }