/** * Check for the availability of the function in the `utf8_strlen` property * (initially `mb_strlen`). If the function is not available, create a * function that will loosely count the number of UTF-8 characters with a * regular expression. */ public function init() { if (!function_exists($this->utf8_strlen)) { $this->utf8_strlen = create_function('$text', 'return preg_match_all( "/[\\\\x00-\\\\xBF]|[\\\\xC0-\\\\xFF][\\\\x80-\\\\xBF]*/", $text, $m);'); } Kernel::setConfig('utf8_strlen', $this->utf8_strlen); }
/** * Prepare all required arrays */ public function _setup() { Kernel::setConfig('footnotes', array()); Kernel::setConfig('glossaries', array()); Kernel::setConfig('bibliographies', array()); self::$notes_ordered = array(); self::$written_notes = array(); self::$footnote_counter = 1; self::$notes_counter = 0; }
private function _clearHashes() { Kernel::setConfig('html_hashes', array()); Kernel::setConfig('cross_references', array()); Kernel::setConfig('urls', Kernel::getConfig('predefined_urls', array())); Kernel::setConfig('titles', Kernel::getConfig('predefined_titles', array())); Kernel::setConfig('attributes', Kernel::getConfig('predefined_attributes', array())); Kernel::setConfig('predefined_abbr', Kernel::getConfig('predefined_abbr', array())); }
/** * Turn Markdown link shortcuts into XHTML <a> tags. * * @param string $text * @return string */ public function transform($text) { if (Kernel::getConfig('in_anchor') === true) { return $text; } Kernel::setConfig('in_anchor', true); // First, handle reference-style links: [link text] [id] $text = preg_replace_callback('{ ( # wrap whole match in $1 \\[ (' . Kernel::getConfig('nested_brackets_re') . ') # link text = $2 \\] [ ]? # one optional space (?:\\n[ ]*)? # one optional newline followed by spaces \\[ (.*?) # id = $3 \\] ) }xs', array($this, '_reference_callback'), $text); // Next, inline-style links: [link text](url "optional title") $text = preg_replace_callback('{ ( # wrap whole match in $1 \\[ (' . Kernel::getConfig('nested_brackets_re') . ') # link text = $2 \\] \\( # literal paren [ \\n]* (?: <(.+?)> # href = $3 | (' . Kernel::getConfig('nested_parenthesis_re') . ') # href = $4 ) [ \\n]* ( # $5 ([\'"]) # quote char = $6 (.*?) # Title = $7 \\6 # matching quote [ \\n]* # ignore any spaces/tabs between closing quote and ) )? # title is optional \\) ) }xs', array($this, '_inline_callback'), $text); // Last, handle reference-style shortcuts: [link text] // These must come last in case you've also got [link text][1] // or [link text](/foo) $text = preg_replace_callback('{ ( # wrap whole match in $1 \\[ ([^\\[\\]]+) # link text = $2; can\'t contain [ or ] \\] ) }xs', array($this, '_reference_callback'), $text); Kernel::setConfig('in_anchor', false); return $text; }
/** * Build meta data strings */ public function append($text) { $metadata = Kernel::getConfig('metadata'); if (!empty($metadata)) { foreach ($metadata as $meta_name => $meta_value) { if (!empty($meta_name) && is_string($meta_name)) { if (in_array($meta_name, $this->special_metadata)) { Kernel::setConfig($meta_name, $meta_value); } elseif ($meta_name == 'title') { Kernel::get(Kernel::TYPE_CONTENT)->setTitle($meta_value); } } } } return $text; }
/** * Reset masks created by the `_setup()` method */ public function _teardown() { Kernel::setConfig('abbr_desciptions', array()); Kernel::setConfig('abbr_word_re', ''); }