public static function format_code($code, $language, $hl = NULL) { // Ensure the language is defined if ($language != NULL && $hl->is_highlighted()) { $code = self::clean_code($code, FALSE, FALSE, FALSE, TRUE); /* Perform the replace on the code using the regex, pass the captured matches for formatting before they are replaced */ try { CrayonParser::parse($language->id()); // Match language regex $elements = $language->elements(); $regex = $language->regex(); if (!empty($regex) && !empty($elements)) { // Get array of CrayonElements self::$elements = array_values($elements); $code = preg_replace_callback($regex, 'CrayonFormatter::format_match', $code); } } catch (Exception $e) { $error = 'An error occured when formatting: ' . $e->message(); $hl ? $hl->log($error) : CrayonLog::syslog($error); } return $code; } else { return self::clean_code($code, TRUE, TRUE, TRUE, TRUE); } }
public function add_default() { $result = parent::add_default(); if ($this->is_state_loading() && !$result) { // Default not added, must already be loaded, ready to parse CrayonParser::parse(self::DEFAULT_LANG); } }
function language($id = NULL) { if ($id === NULL || !is_string($id)) { return $this->language; } if (($lang = CrayonResources::langs()->get($id)) != FALSE || ($lang = CrayonResources::langs()->alias($id)) != FALSE) { // Set the language if it exists or look for an alias $this->language = $lang; } else { $this->language_detect(); } // Prepare the language for use, even if we have no code, we need the name CrayonParser::parse($this->language->id()); }
function language($id = NULL) { if ($id === NULL || !is_string($id)) { return $this->language; } if (($lang = CrayonResources::langs()->get($id)) != FALSE || ($lang = CrayonResources::langs()->alias($id)) != FALSE) { // Set the language if it exists or look for an alias $this->language = $lang; } else { // Attempt to detect the language if (!empty($id)) { $this->log("The language '{$id}' could not be loaded."); } $this->language = CrayonResources::langs()->detect($this->url, $this->setting_val(CrayonSettings::FALLBACK_LANG)); } // Prepare the language for use, even if we have no code, we need the name CrayonParser::parse($this->language->id()); }