コード例 #1
0
 /**
  * Adds the actual Crayon instance.
  * $mode can be: 0 = return crayon content, 1 = return only code, 2 = return only plain code
  */
 public static function shortcode($atts, $content = NULL, $id = NULL)
 {
     CrayonLog::debug('shortcode');
     // Load attributes from shortcode
     $filtered_atts = shortcode_atts(self::$allowed_atts, $atts);
     // Clean attributes
     $keys = array_keys($filtered_atts);
     for ($i = 0; $i < count($keys); $i++) {
         $key = $keys[$i];
         $value = $filtered_atts[$key];
         if ($value !== NULL) {
             $filtered_atts[$key] = trim(strip_tags($value));
         }
     }
     // Contains all other attributes not found in allowed, used to override global settings
     $extra_attr = array();
     if (!empty($atts)) {
         $extra_attr = array_diff_key($atts, self::$allowed_atts);
         $extra_attr = CrayonSettings::smart_settings($extra_attr);
     }
     $url = $lang = $title = $mark = $range = $inline = '';
     extract($filtered_atts);
     $crayon = self::instance($extra_attr, $id);
     // Set URL
     $crayon->url($url);
     $crayon->code($content);
     // Set attributes, should be set after URL to allow language auto detection
     $crayon->language($lang);
     $crayon->title($title);
     $crayon->marked($mark);
     $crayon->range($range);
     $crayon->is_inline($inline);
     // Determine if we should highlight
     $highlight = array_key_exists('highlight', $atts) ? CrayonUtil::str_to_bool($atts['highlight'], FALSE) : TRUE;
     $crayon->is_highlighted($highlight);
     return $crayon;
 }
コード例 #2
0
require_once CRAYON_HIGHLIGHTER_PHP;
// These will depend on your framework
CrayonGlobalSettings::site_http('http://localhost/crayon/wp-content/plugins/crayon-syntax-highlighter/');
CrayonGlobalSettings::site_path(dirname(__FILE__));
CrayonGlobalSettings::plugin_path('http://localhost/crayon/wp-content/plugins/crayon-syntax-highlighter/');
// Should be in the header
crayon_resources();
$crayon = new CrayonHighlighter();
$crayon->code('some code');
$crayon->language('php');
$crayon->title('the title');
$crayon->marked('1-2');
$crayon->is_inline(FALSE);
// Settings
$settings = array(CrayonSettings::NUMS => FALSE, CrayonSettings::TOOLBAR => TRUE, CrayonSettings::ENQUEUE_THEMES => FALSE, CrayonSettings::ENQUEUE_FONTS => FALSE);
$settings = CrayonSettings::smart_settings($settings);
$crayon->settings($settings);
// Print the Crayon
$crayon_formatted = $crayon->output(TRUE, FALSE);
echo $crayon_formatted;
// Utility Functions
function crayon_print_style($id, $url, $version)
{
    echo '<link id="', $id, '" href="', $url, '?v=', $version, '" type="text/css" rel="stylesheet" />', "\n";
}
function crayon_print_script($id, $url, $version)
{
    echo '<script id="', $id, '" src="', $url, '?v=', $version, '" type="text/javascript"></script>', "\n";
}
function crayon_resources()
{