@@ -879,6 +879,10 @@ discard block |
||
| 879 | 879 | |
| 880 | 880 | protected $list_level = 0; |
| 881 | 881 | |
| 882 | + /** |
|
| 883 | + * @param string $list_str |
|
| 884 | + * @param string $marker_any_re |
|
| 885 | + */ |
|
| 882 | 886 | protected function processListItems($list_str, $marker_any_re) { |
| 883 | 887 | # |
| 884 | 888 | # Process the contents of a single ordered or unordered list, splitting it |
@@ -982,6 +986,9 @@ discard block |
||
| 982 | 986 | } |
| 983 | 987 | |
| 984 | 988 | |
| 989 | + /** |
|
| 990 | + * @param string $code |
|
| 991 | + */ |
|
| 985 | 992 | protected function makeCodeSpan($code) { |
| 986 | 993 | # |
| 987 | 994 | # Create a code span markup for $code. Called from handleSpanToken. |
@@ -1513,6 +1520,9 @@ discard block |
||
| 1513 | 1520 | # hanlde UTF-8 if the default function does not exist. |
| 1514 | 1521 | protected $utf8_strlen = 'mb_strlen'; |
| 1515 | 1522 | |
| 1523 | + /** |
|
| 1524 | + * @param string $text |
|
| 1525 | + */ |
|
| 1516 | 1526 | protected function detab($text) { |
| 1517 | 1527 | # |
| 1518 | 1528 | # Replace tabs with the appropriate amount of space. |
@@ -2066,6 +2076,12 @@ discard block |
||
| 2066 | 2076 | |
| 2067 | 2077 | return array($parsed, $text); |
| 2068 | 2078 | } |
| 2079 | + |
|
| 2080 | + /** |
|
| 2081 | + * @param string $text |
|
| 2082 | + * @param string $hash_method |
|
| 2083 | + * @param boolean $md_attr |
|
| 2084 | + */ |
|
| 2069 | 2085 | protected function _hashHTMLBlocks_inHTML($text, $hash_method, $md_attr) { |
| 2070 | 2086 | # |
| 2071 | 2087 | # Parse HTML, calling _HashHTMLBlocks_InMarkdown for block tags. |
@@ -2616,6 +2632,10 @@ discard block |
||
| 2616 | 2632 | |
| 2617 | 2633 | return $this->_doTable_callback(array($matches[0], $head, $underline, $content)); |
| 2618 | 2634 | } |
| 2635 | + |
|
| 2636 | + /** |
|
| 2637 | + * @param string $alignname |
|
| 2638 | + */ |
|
| 2619 | 2639 | protected function _doTable_makeAlignAttr($alignname) |
| 2620 | 2640 | { |
| 2621 | 2641 | if (empty($this->table_align_class_tmpl)) |
@@ -2742,6 +2762,9 @@ discard block |
||
| 2742 | 2762 | } |
| 2743 | 2763 | |
| 2744 | 2764 | |
| 2765 | + /** |
|
| 2766 | + * @return string |
|
| 2767 | + */ |
|
| 2745 | 2768 | protected function processDefListItems($list_str) { |
| 2746 | 2769 | # |
| 2747 | 2770 | # Process the contents of a single definition list, splitting it |
@@ -40,138 +40,138 @@ discard block |
||
| 40 | 40 | |
| 41 | 41 | class _Markdown { |
| 42 | 42 | |
| 43 | - ### Version ### |
|
| 43 | + ### Version ### |
|
| 44 | 44 | |
| 45 | - const MARKDOWNLIB_VERSION = "1.3"; |
|
| 45 | + const MARKDOWNLIB_VERSION = "1.3"; |
|
| 46 | 46 | |
| 47 | - ### Configuration Variables ### |
|
| 47 | + ### Configuration Variables ### |
|
| 48 | 48 | |
| 49 | - # Change to ">" for HTML output. |
|
| 50 | - public $empty_element_suffix = " />"; |
|
| 51 | - public $tab_width = 4; |
|
| 49 | + # Change to ">" for HTML output. |
|
| 50 | + public $empty_element_suffix = " />"; |
|
| 51 | + public $tab_width = 4; |
|
| 52 | 52 | |
| 53 | - # Change to `true` to disallow markup or entities. |
|
| 54 | - public $no_markup = false; |
|
| 55 | - public $no_entities = false; |
|
| 53 | + # Change to `true` to disallow markup or entities. |
|
| 54 | + public $no_markup = false; |
|
| 55 | + public $no_entities = false; |
|
| 56 | 56 | |
| 57 | - # Predefined urls and titles for reference links and images. |
|
| 58 | - public $predef_urls = array(); |
|
| 59 | - public $predef_titles = array(); |
|
| 57 | + # Predefined urls and titles for reference links and images. |
|
| 58 | + public $predef_urls = array(); |
|
| 59 | + public $predef_titles = array(); |
|
| 60 | 60 | |
| 61 | 61 | |
| 62 | - ### Parser Implementation ### |
|
| 62 | + ### Parser Implementation ### |
|
| 63 | 63 | |
| 64 | - # Regex to match balanced [brackets]. |
|
| 65 | - # Needed to insert a maximum bracked depth while converting to PHP. |
|
| 66 | - protected $nested_brackets_depth = 6; |
|
| 67 | - protected $nested_brackets_re; |
|
| 64 | + # Regex to match balanced [brackets]. |
|
| 65 | + # Needed to insert a maximum bracked depth while converting to PHP. |
|
| 66 | + protected $nested_brackets_depth = 6; |
|
| 67 | + protected $nested_brackets_re; |
|
| 68 | 68 | |
| 69 | - protected $nested_url_parenthesis_depth = 4; |
|
| 70 | - protected $nested_url_parenthesis_re; |
|
| 69 | + protected $nested_url_parenthesis_depth = 4; |
|
| 70 | + protected $nested_url_parenthesis_re; |
|
| 71 | 71 | |
| 72 | - # Table of hash values for escaped characters: |
|
| 73 | - protected $escape_chars = '\`*_{}[]()>#+-.!'; |
|
| 74 | - protected $escape_chars_re; |
|
| 72 | + # Table of hash values for escaped characters: |
|
| 73 | + protected $escape_chars = '\`*_{}[]()>#+-.!'; |
|
| 74 | + protected $escape_chars_re; |
|
| 75 | 75 | |
| 76 | 76 | |
| 77 | - public function __construct() { |
|
| 78 | - # |
|
| 79 | - # Constructor function. Initialize appropriate member variables. |
|
| 80 | - # |
|
| 81 | - $this->_initDetab(); |
|
| 82 | - $this->prepareItalicsAndBold(); |
|
| 77 | + public function __construct() { |
|
| 78 | + # |
|
| 79 | + # Constructor function. Initialize appropriate member variables. |
|
| 80 | + # |
|
| 81 | + $this->_initDetab(); |
|
| 82 | + $this->prepareItalicsAndBold(); |
|
| 83 | 83 | |
| 84 | - $this->nested_brackets_re = |
|
| 85 | - str_repeat('(?>[^\[\]]+|\[', $this->nested_brackets_depth). |
|
| 86 | - str_repeat('\])*', $this->nested_brackets_depth); |
|
| 84 | + $this->nested_brackets_re = |
|
| 85 | + str_repeat('(?>[^\[\]]+|\[', $this->nested_brackets_depth). |
|
| 86 | + str_repeat('\])*', $this->nested_brackets_depth); |
|
| 87 | 87 | |
| 88 | - $this->nested_url_parenthesis_re = |
|
| 89 | - str_repeat('(?>[^()\s]+|\(', $this->nested_url_parenthesis_depth). |
|
| 90 | - str_repeat('(?>\)))*', $this->nested_url_parenthesis_depth); |
|
| 88 | + $this->nested_url_parenthesis_re = |
|
| 89 | + str_repeat('(?>[^()\s]+|\(', $this->nested_url_parenthesis_depth). |
|
| 90 | + str_repeat('(?>\)))*', $this->nested_url_parenthesis_depth); |
|
| 91 | 91 | |
| 92 | - $this->escape_chars_re = '['.preg_quote($this->escape_chars).']'; |
|
| 92 | + $this->escape_chars_re = '['.preg_quote($this->escape_chars).']'; |
|
| 93 | 93 | |
| 94 | - # Sort document, block, and span gamut in ascendent priority order. |
|
| 95 | - asort($this->document_gamut); |
|
| 96 | - asort($this->block_gamut); |
|
| 97 | - asort($this->span_gamut); |
|
| 98 | - } |
|
| 94 | + # Sort document, block, and span gamut in ascendent priority order. |
|
| 95 | + asort($this->document_gamut); |
|
| 96 | + asort($this->block_gamut); |
|
| 97 | + asort($this->span_gamut); |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | 100 | |
| 101 | - # Internal hashes used during transformation. |
|
| 102 | - protected $urls = array(); |
|
| 103 | - protected $titles = array(); |
|
| 104 | - protected $html_hashes = array(); |
|
| 101 | + # Internal hashes used during transformation. |
|
| 102 | + protected $urls = array(); |
|
| 103 | + protected $titles = array(); |
|
| 104 | + protected $html_hashes = array(); |
|
| 105 | 105 | |
| 106 | - # Status flag to avoid invalid nesting. |
|
| 107 | - protected $in_anchor = false; |
|
| 106 | + # Status flag to avoid invalid nesting. |
|
| 107 | + protected $in_anchor = false; |
|
| 108 | 108 | |
| 109 | 109 | |
| 110 | - protected function setup() { |
|
| 111 | - # |
|
| 112 | - # Called before the transformation process starts to setup parser |
|
| 113 | - # states. |
|
| 114 | - # |
|
| 115 | - # Clear global hashes. |
|
| 116 | - $this->urls = $this->predef_urls; |
|
| 117 | - $this->titles = $this->predef_titles; |
|
| 118 | - $this->html_hashes = array(); |
|
| 119 | - |
|
| 120 | - $this->in_anchor = false; |
|
| 121 | - } |
|
| 110 | + protected function setup() { |
|
| 111 | + # |
|
| 112 | + # Called before the transformation process starts to setup parser |
|
| 113 | + # states. |
|
| 114 | + # |
|
| 115 | + # Clear global hashes. |
|
| 116 | + $this->urls = $this->predef_urls; |
|
| 117 | + $this->titles = $this->predef_titles; |
|
| 118 | + $this->html_hashes = array(); |
|
| 119 | + |
|
| 120 | + $this->in_anchor = false; |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | - protected function teardown() { |
|
| 124 | - # |
|
| 125 | - # Called after the transformation process to clear any variable |
|
| 126 | - # which may be taking up memory unnecessarly. |
|
| 127 | - # |
|
| 128 | - $this->urls = array(); |
|
| 129 | - $this->titles = array(); |
|
| 130 | - $this->html_hashes = array(); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - |
|
| 134 | - public function transform($text) { |
|
| 135 | - # |
|
| 136 | - # Main function. Performs some preprocessing on the input text |
|
| 137 | - # and pass it through the document gamut. |
|
| 138 | - # |
|
| 139 | - $this->setup(); |
|
| 123 | + protected function teardown() { |
|
| 124 | + # |
|
| 125 | + # Called after the transformation process to clear any variable |
|
| 126 | + # which may be taking up memory unnecessarly. |
|
| 127 | + # |
|
| 128 | + $this->urls = array(); |
|
| 129 | + $this->titles = array(); |
|
| 130 | + $this->html_hashes = array(); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + |
|
| 134 | + public function transform($text) { |
|
| 135 | + # |
|
| 136 | + # Main function. Performs some preprocessing on the input text |
|
| 137 | + # and pass it through the document gamut. |
|
| 138 | + # |
|
| 139 | + $this->setup(); |
|
| 140 | 140 | |
| 141 | - # Remove UTF-8 BOM and marker character in input, if present. |
|
| 142 | - $text = preg_replace('{^\xEF\xBB\xBF|\x1A}', '', $text); |
|
| 141 | + # Remove UTF-8 BOM and marker character in input, if present. |
|
| 142 | + $text = preg_replace('{^\xEF\xBB\xBF|\x1A}', '', $text); |
|
| 143 | 143 | |
| 144 | - # Standardize line endings: |
|
| 145 | - # DOS to Unix and Mac to Unix |
|
| 146 | - $text = preg_replace('{\r\n?}', "\n", $text); |
|
| 144 | + # Standardize line endings: |
|
| 145 | + # DOS to Unix and Mac to Unix |
|
| 146 | + $text = preg_replace('{\r\n?}', "\n", $text); |
|
| 147 | 147 | |
| 148 | - # Make sure $text ends with a couple of newlines: |
|
| 149 | - $text .= "\n\n"; |
|
| 148 | + # Make sure $text ends with a couple of newlines: |
|
| 149 | + $text .= "\n\n"; |
|
| 150 | 150 | |
| 151 | - # Convert all tabs to spaces. |
|
| 152 | - $text = $this->detab($text); |
|
| 151 | + # Convert all tabs to spaces. |
|
| 152 | + $text = $this->detab($text); |
|
| 153 | 153 | |
| 154 | - # Turn block-level HTML blocks into hash entries |
|
| 155 | - $text = $this->hashHTMLBlocks($text); |
|
| 154 | + # Turn block-level HTML blocks into hash entries |
|
| 155 | + $text = $this->hashHTMLBlocks($text); |
|
| 156 | 156 | |
| 157 | - # Strip any lines consisting only of spaces and tabs. |
|
| 158 | - # This makes subsequent regexen easier to write, because we can |
|
| 159 | - # match consecutive blank lines with /\n+/ instead of something |
|
| 160 | - # contorted like /[ ]*\n+/ . |
|
| 161 | - $text = preg_replace('/^[ ]+$/m', '', $text); |
|
| 157 | + # Strip any lines consisting only of spaces and tabs. |
|
| 158 | + # This makes subsequent regexen easier to write, because we can |
|
| 159 | + # match consecutive blank lines with /\n+/ instead of something |
|
| 160 | + # contorted like /[ ]*\n+/ . |
|
| 161 | + $text = preg_replace('/^[ ]+$/m', '', $text); |
|
| 162 | 162 | |
| 163 | - # Run document gamut methods. |
|
| 164 | - foreach ($this->document_gamut as $method => $priority) { |
|
| 165 | - $text = $this->$method($text); |
|
| 166 | - } |
|
| 163 | + # Run document gamut methods. |
|
| 164 | + foreach ($this->document_gamut as $method => $priority) { |
|
| 165 | + $text = $this->$method($text); |
|
| 166 | + } |
|
| 167 | 167 | |
| 168 | - $this->teardown(); |
|
| 168 | + $this->teardown(); |
|
| 169 | 169 | |
| 170 | 170 | $text = preg_replace_callback("/<\/?(\!doctype|html|head|body|link|title|input|select|button|textarea|style|noscript)[^>]*>/is", |
| 171 | 171 | array($this, '_doEscape_callback'), $text); |
| 172 | 172 | |
| 173 | - return $text . "\n"; |
|
| 174 | - } |
|
| 173 | + return $text . "\n"; |
|
| 174 | + } |
|
| 175 | 175 | |
| 176 | 176 | /** |
| 177 | 177 | * _doEscape_callback |
@@ -184,23 +184,23 @@ discard block |
||
| 184 | 184 | return htmlspecialchars($matches[0], ENT_NOQUOTES); |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | - protected $document_gamut = array( |
|
| 188 | - # Strip link definitions, store in hashes. |
|
| 189 | - "stripLinkDefinitions" => 20, |
|
| 187 | + protected $document_gamut = array( |
|
| 188 | + # Strip link definitions, store in hashes. |
|
| 189 | + "stripLinkDefinitions" => 20, |
|
| 190 | 190 | |
| 191 | - "runBasicBlockGamut" => 30, |
|
| 192 | - ); |
|
| 191 | + "runBasicBlockGamut" => 30, |
|
| 192 | + ); |
|
| 193 | 193 | |
| 194 | 194 | |
| 195 | - protected function stripLinkDefinitions($text) { |
|
| 196 | - # |
|
| 197 | - # Strips link definitions from text, stores the URLs and titles in |
|
| 198 | - # hash references. |
|
| 199 | - # |
|
| 200 | - $less_than_tab = $this->tab_width - 1; |
|
| 195 | + protected function stripLinkDefinitions($text) { |
|
| 196 | + # |
|
| 197 | + # Strips link definitions from text, stores the URLs and titles in |
|
| 198 | + # hash references. |
|
| 199 | + # |
|
| 200 | + $less_than_tab = $this->tab_width - 1; |
|
| 201 | 201 | |
| 202 | - # Link defs are in the form: ^[id]: url "optional title" |
|
| 203 | - $text = preg_replace_callback('{ |
|
| 202 | + # Link defs are in the form: ^[id]: url "optional title" |
|
| 203 | + $text = preg_replace_callback('{ |
|
| 204 | 204 | ^[ ]{0,'.$less_than_tab.'}\[(.+)\][ ]?: # id = $1 |
| 205 | 205 | [ ]* |
| 206 | 206 | \n? # maybe *one* newline |
@@ -222,46 +222,46 @@ discard block |
||
| 222 | 222 | )? # title is optional |
| 223 | 223 | (?:\n+|\Z) |
| 224 | 224 | }xm', |
| 225 | - array($this, '_stripLinkDefinitions_callback'), |
|
| 226 | - $text); |
|
| 227 | - return $text; |
|
| 228 | - } |
|
| 229 | - protected function _stripLinkDefinitions_callback($matches) { |
|
| 230 | - $link_id = strtolower($matches[1]); |
|
| 231 | - $url = $matches[2] == '' ? $matches[3] : $matches[2]; |
|
| 232 | - $this->urls[$link_id] = $url; |
|
| 233 | - $this->titles[$link_id] =& $matches[4]; |
|
| 234 | - return ''; # String that will replace the block |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - |
|
| 238 | - protected function hashHTMLBlocks($text) { |
|
| 239 | - if ($this->no_markup) return $text; |
|
| 240 | - |
|
| 241 | - $less_than_tab = $this->tab_width - 1; |
|
| 242 | - |
|
| 243 | - # Hashify HTML blocks: |
|
| 244 | - # We only want to do this for block-level HTML tags, such as headers, |
|
| 245 | - # lists, and tables. That's because we still want to wrap <p>s around |
|
| 246 | - # "paragraphs" that are wrapped in non-block-level tags, such as anchors, |
|
| 247 | - # phrase emphasis, and spans. The list of tags we're looking for is |
|
| 248 | - # hard-coded: |
|
| 249 | - # |
|
| 250 | - # * List "a" is made of tags which can be both inline or block-level. |
|
| 251 | - # These will be treated block-level when the start tag is alone on |
|
| 252 | - # its line, otherwise they're not matched here and will be taken as |
|
| 253 | - # inline later. |
|
| 254 | - # * List "b" is made of tags which are always block-level; |
|
| 255 | - # |
|
| 256 | - $block_tags_a_re = 'ins|del'; |
|
| 257 | - $block_tags_b_re = 'p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|address|'. |
|
| 258 | - 'script|noscript|form|fieldset|iframe|math|svg|'. |
|
| 259 | - 'article|section|nav|aside|hgroup|header|footer|'. |
|
| 260 | - 'figure'; |
|
| 261 | - |
|
| 262 | - # Regular expression for the content of a block tag. |
|
| 263 | - $nested_tags_level = 4; |
|
| 264 | - $attr = ' |
|
| 225 | + array($this, '_stripLinkDefinitions_callback'), |
|
| 226 | + $text); |
|
| 227 | + return $text; |
|
| 228 | + } |
|
| 229 | + protected function _stripLinkDefinitions_callback($matches) { |
|
| 230 | + $link_id = strtolower($matches[1]); |
|
| 231 | + $url = $matches[2] == '' ? $matches[3] : $matches[2]; |
|
| 232 | + $this->urls[$link_id] = $url; |
|
| 233 | + $this->titles[$link_id] =& $matches[4]; |
|
| 234 | + return ''; # String that will replace the block |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + |
|
| 238 | + protected function hashHTMLBlocks($text) { |
|
| 239 | + if ($this->no_markup) return $text; |
|
| 240 | + |
|
| 241 | + $less_than_tab = $this->tab_width - 1; |
|
| 242 | + |
|
| 243 | + # Hashify HTML blocks: |
|
| 244 | + # We only want to do this for block-level HTML tags, such as headers, |
|
| 245 | + # lists, and tables. That's because we still want to wrap <p>s around |
|
| 246 | + # "paragraphs" that are wrapped in non-block-level tags, such as anchors, |
|
| 247 | + # phrase emphasis, and spans. The list of tags we're looking for is |
|
| 248 | + # hard-coded: |
|
| 249 | + # |
|
| 250 | + # * List "a" is made of tags which can be both inline or block-level. |
|
| 251 | + # These will be treated block-level when the start tag is alone on |
|
| 252 | + # its line, otherwise they're not matched here and will be taken as |
|
| 253 | + # inline later. |
|
| 254 | + # * List "b" is made of tags which are always block-level; |
|
| 255 | + # |
|
| 256 | + $block_tags_a_re = 'ins|del'; |
|
| 257 | + $block_tags_b_re = 'p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|address|'. |
|
| 258 | + 'script|noscript|form|fieldset|iframe|math|svg|'. |
|
| 259 | + 'article|section|nav|aside|hgroup|header|footer|'. |
|
| 260 | + 'figure'; |
|
| 261 | + |
|
| 262 | + # Regular expression for the content of a block tag. |
|
| 263 | + $nested_tags_level = 4; |
|
| 264 | + $attr = ' |
|
| 265 | 265 | (?> # optional tag attributes |
| 266 | 266 | \s # starts with whitespace |
| 267 | 267 | (?> |
@@ -275,8 +275,8 @@ discard block |
||
| 275 | 275 | )* |
| 276 | 276 | )? |
| 277 | 277 | '; |
| 278 | - $content = |
|
| 279 | - str_repeat(' |
|
| 278 | + $content = |
|
| 279 | + str_repeat(' |
|
| 280 | 280 | (?> |
| 281 | 281 | [^<]+ # content without tag |
| 282 | 282 | | |
@@ -286,29 +286,29 @@ discard block |
||
| 286 | 286 | /> |
| 287 | 287 | | |
| 288 | 288 | >', $nested_tags_level). # end of opening tag |
| 289 | - '.*?'. # last level nested tag content |
|
| 290 | - str_repeat(' |
|
| 289 | + '.*?'. # last level nested tag content |
|
| 290 | + str_repeat(' |
|
| 291 | 291 | </\2\s*> # closing nested tag |
| 292 | 292 | ) |
| 293 | 293 | | |
| 294 | 294 | <(?!/\2\s*> # other tags with a different name |
| 295 | 295 | ) |
| 296 | 296 | )*', |
| 297 | - $nested_tags_level); |
|
| 298 | - $content2 = str_replace('\2', '\3', $content); |
|
| 299 | - |
|
| 300 | - # First, look for nested blocks, e.g.: |
|
| 301 | - # <div> |
|
| 302 | - # <div> |
|
| 303 | - # tags for inner block must be indented. |
|
| 304 | - # </div> |
|
| 305 | - # </div> |
|
| 306 | - # |
|
| 307 | - # The outermost tags must start at the left margin for this to match, and |
|
| 308 | - # the inner nested divs must be indented. |
|
| 309 | - # We need to do this before the next, more liberal match, because the next |
|
| 310 | - # match will start at the first `<div>` and stop at the first `</div>`. |
|
| 311 | - $text = preg_replace_callback('{(?> |
|
| 297 | + $nested_tags_level); |
|
| 298 | + $content2 = str_replace('\2', '\3', $content); |
|
| 299 | + |
|
| 300 | + # First, look for nested blocks, e.g.: |
|
| 301 | + # <div> |
|
| 302 | + # <div> |
|
| 303 | + # tags for inner block must be indented. |
|
| 304 | + # </div> |
|
| 305 | + # </div> |
|
| 306 | + # |
|
| 307 | + # The outermost tags must start at the left margin for this to match, and |
|
| 308 | + # the inner nested divs must be indented. |
|
| 309 | + # We need to do this before the next, more liberal match, because the next |
|
| 310 | + # match will start at the first `<div>` and stop at the first `</div>`. |
|
| 311 | + $text = preg_replace_callback('{(?> |
|
| 312 | 312 | (?> |
| 313 | 313 | (?<=\n\n) # Starting after a blank line |
| 314 | 314 | | # or |
@@ -369,97 +369,97 @@ discard block |
||
| 369 | 369 | |
| 370 | 370 | ) |
| 371 | 371 | )}Sxmi', |
| 372 | - array($this, '_hashHTMLBlocks_callback'), |
|
| 373 | - $text); |
|
| 374 | - |
|
| 375 | - return $text; |
|
| 376 | - } |
|
| 377 | - protected function _hashHTMLBlocks_callback($matches) { |
|
| 378 | - $text = $matches[1]; |
|
| 379 | - return $this->hashBlock($text); |
|
| 380 | - // return "\n\n$key\n\n"; |
|
| 381 | - } |
|
| 372 | + array($this, '_hashHTMLBlocks_callback'), |
|
| 373 | + $text); |
|
| 374 | + |
|
| 375 | + return $text; |
|
| 376 | + } |
|
| 377 | + protected function _hashHTMLBlocks_callback($matches) { |
|
| 378 | + $text = $matches[1]; |
|
| 379 | + return $this->hashBlock($text); |
|
| 380 | + // return "\n\n$key\n\n"; |
|
| 381 | + } |
|
| 382 | 382 | |
| 383 | 383 | |
| 384 | - protected function hashPart($text, $boundary = 'X') { |
|
| 385 | - # |
|
| 386 | - # Called whenever a tag must be hashed when a function insert an atomic |
|
| 387 | - # element in the text stream. Passing $text to through this function gives |
|
| 388 | - # a unique text-token which will be reverted back when calling unhash. |
|
| 389 | - # |
|
| 390 | - # The $boundary argument specify what character should be used to surround |
|
| 391 | - # the token. By convension, "B" is used for block elements that needs not |
|
| 392 | - # to be wrapped into paragraph tags at the end, ":" is used for elements |
|
| 393 | - # that are word separators and "X" is used in the general case. |
|
| 394 | - # |
|
| 395 | - # Swap back any tag hash found in $text so we do not have to `unhash` |
|
| 396 | - # multiple times at the end. |
|
| 397 | - $text = $this->unhash($text); |
|
| 398 | - |
|
| 399 | - # Then hash the block. |
|
| 400 | - static $i = 0; |
|
| 401 | - $key = "$boundary\x1A" . ++$i . $boundary; |
|
| 402 | - $this->html_hashes[$key] = $text; |
|
| 403 | - return $key; # String that will replace the tag. |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - |
|
| 407 | - protected function hashBlock($text) { |
|
| 408 | - # |
|
| 409 | - # Shortcut function for hashPart with block-level boundaries. |
|
| 410 | - # |
|
| 411 | - return $this->hashPart($text, 'B'); |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - |
|
| 415 | - protected $block_gamut = array( |
|
| 416 | - # |
|
| 417 | - # These are all the transformations that form block-level |
|
| 418 | - # tags like paragraphs, headers, and list items. |
|
| 419 | - # |
|
| 420 | - "doHeaders" => 10, |
|
| 421 | - "doHorizontalRules" => 20, |
|
| 422 | - |
|
| 423 | - "doLists" => 40, |
|
| 424 | - "doCodeBlocks" => 50, |
|
| 425 | - "doBlockQuotes" => 60, |
|
| 426 | - ); |
|
| 384 | + protected function hashPart($text, $boundary = 'X') { |
|
| 385 | + # |
|
| 386 | + # Called whenever a tag must be hashed when a function insert an atomic |
|
| 387 | + # element in the text stream. Passing $text to through this function gives |
|
| 388 | + # a unique text-token which will be reverted back when calling unhash. |
|
| 389 | + # |
|
| 390 | + # The $boundary argument specify what character should be used to surround |
|
| 391 | + # the token. By convension, "B" is used for block elements that needs not |
|
| 392 | + # to be wrapped into paragraph tags at the end, ":" is used for elements |
|
| 393 | + # that are word separators and "X" is used in the general case. |
|
| 394 | + # |
|
| 395 | + # Swap back any tag hash found in $text so we do not have to `unhash` |
|
| 396 | + # multiple times at the end. |
|
| 397 | + $text = $this->unhash($text); |
|
| 398 | + |
|
| 399 | + # Then hash the block. |
|
| 400 | + static $i = 0; |
|
| 401 | + $key = "$boundary\x1A" . ++$i . $boundary; |
|
| 402 | + $this->html_hashes[$key] = $text; |
|
| 403 | + return $key; # String that will replace the tag. |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + |
|
| 407 | + protected function hashBlock($text) { |
|
| 408 | + # |
|
| 409 | + # Shortcut function for hashPart with block-level boundaries. |
|
| 410 | + # |
|
| 411 | + return $this->hashPart($text, 'B'); |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + |
|
| 415 | + protected $block_gamut = array( |
|
| 416 | + # |
|
| 417 | + # These are all the transformations that form block-level |
|
| 418 | + # tags like paragraphs, headers, and list items. |
|
| 419 | + # |
|
| 420 | + "doHeaders" => 10, |
|
| 421 | + "doHorizontalRules" => 20, |
|
| 422 | + |
|
| 423 | + "doLists" => 40, |
|
| 424 | + "doCodeBlocks" => 50, |
|
| 425 | + "doBlockQuotes" => 60, |
|
| 426 | + ); |
|
| 427 | 427 | |
| 428 | - protected function runBlockGamut($text) { |
|
| 429 | - # |
|
| 430 | - # Run block gamut tranformations. |
|
| 431 | - # |
|
| 432 | - # We need to escape raw HTML in Markdown source before doing anything |
|
| 433 | - # else. This need to be done for each block, and not only at the |
|
| 434 | - # begining in the Markdown function since hashed blocks can be part of |
|
| 435 | - # list items and could have been indented. Indented blocks would have |
|
| 436 | - # been seen as a code block in a previous pass of hashHTMLBlocks. |
|
| 437 | - $text = $this->hashHTMLBlocks($text); |
|
| 438 | - |
|
| 439 | - return $this->runBasicBlockGamut($text); |
|
| 440 | - } |
|
| 428 | + protected function runBlockGamut($text) { |
|
| 429 | + # |
|
| 430 | + # Run block gamut tranformations. |
|
| 431 | + # |
|
| 432 | + # We need to escape raw HTML in Markdown source before doing anything |
|
| 433 | + # else. This need to be done for each block, and not only at the |
|
| 434 | + # begining in the Markdown function since hashed blocks can be part of |
|
| 435 | + # list items and could have been indented. Indented blocks would have |
|
| 436 | + # been seen as a code block in a previous pass of hashHTMLBlocks. |
|
| 437 | + $text = $this->hashHTMLBlocks($text); |
|
| 438 | + |
|
| 439 | + return $this->runBasicBlockGamut($text); |
|
| 440 | + } |
|
| 441 | 441 | |
| 442 | - protected function runBasicBlockGamut($text) { |
|
| 443 | - # |
|
| 444 | - # Run block gamut tranformations, without hashing HTML blocks. This is |
|
| 445 | - # useful when HTML blocks are known to be already hashed, like in the first |
|
| 446 | - # whole-document pass. |
|
| 447 | - # |
|
| 448 | - foreach ($this->block_gamut as $method => $priority) { |
|
| 449 | - $text = $this->$method($text); |
|
| 450 | - } |
|
| 451 | - |
|
| 452 | - # Finally form paragraph and restore hashed blocks. |
|
| 453 | - $text = $this->formParagraphs($text); |
|
| 454 | - |
|
| 455 | - return $text; |
|
| 456 | - } |
|
| 442 | + protected function runBasicBlockGamut($text) { |
|
| 443 | + # |
|
| 444 | + # Run block gamut tranformations, without hashing HTML blocks. This is |
|
| 445 | + # useful when HTML blocks are known to be already hashed, like in the first |
|
| 446 | + # whole-document pass. |
|
| 447 | + # |
|
| 448 | + foreach ($this->block_gamut as $method => $priority) { |
|
| 449 | + $text = $this->$method($text); |
|
| 450 | + } |
|
| 451 | + |
|
| 452 | + # Finally form paragraph and restore hashed blocks. |
|
| 453 | + $text = $this->formParagraphs($text); |
|
| 454 | + |
|
| 455 | + return $text; |
|
| 456 | + } |
|
| 457 | 457 | |
| 458 | 458 | |
| 459 | - protected function doHorizontalRules($text) { |
|
| 460 | - # Do Horizontal Rules: |
|
| 461 | - return preg_replace( |
|
| 462 | - '{ |
|
| 459 | + protected function doHorizontalRules($text) { |
|
| 460 | + # Do Horizontal Rules: |
|
| 461 | + return preg_replace( |
|
| 462 | + '{ |
|
| 463 | 463 | ^[ ]{0,3} # Leading space |
| 464 | 464 | ([-*_]) # $1: First marker |
| 465 | 465 | (?> # Repeated marker group |
@@ -469,68 +469,68 @@ discard block |
||
| 469 | 469 | [ ]* # Tailing spaces |
| 470 | 470 | $ # End of line. |
| 471 | 471 | }mx', |
| 472 | - "\n".$this->hashBlock("<hr$this->empty_element_suffix")."\n", |
|
| 473 | - $text); |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - |
|
| 477 | - protected $span_gamut = array( |
|
| 478 | - # |
|
| 479 | - # These are all the transformations that occur *within* block-level |
|
| 480 | - # tags like paragraphs, headers, and list items. |
|
| 481 | - # |
|
| 482 | - # Process character escapes, code spans, and inline HTML |
|
| 483 | - # in one shot. |
|
| 484 | - "parseSpan" => -30, |
|
| 485 | - |
|
| 486 | - # Process anchor and image tags. Images must come first, |
|
| 487 | - # because ![foo][f] looks like an anchor. |
|
| 488 | - "doImages" => 10, |
|
| 489 | - "doAnchors" => 20, |
|
| 490 | - |
|
| 491 | - # Make links out of things like `<http://example.com/>` |
|
| 492 | - # Must come after doAnchors, because you can use < and > |
|
| 493 | - # delimiters in inline links like [this](<url>). |
|
| 494 | - "doAutoLinks" => 30, |
|
| 495 | - "encodeAmpsAndAngles" => 40, |
|
| 496 | - |
|
| 497 | - "doItalicsAndBold" => 50, |
|
| 498 | - "doHardBreaks" => 60, |
|
| 499 | - ); |
|
| 472 | + "\n".$this->hashBlock("<hr$this->empty_element_suffix")."\n", |
|
| 473 | + $text); |
|
| 474 | + } |
|
| 475 | + |
|
| 500 | 476 | |
| 501 | - protected function runSpanGamut($text) { |
|
| 502 | - # |
|
| 503 | - # Run span gamut tranformations. |
|
| 504 | - # |
|
| 505 | - foreach ($this->span_gamut as $method => $priority) { |
|
| 506 | - $text = $this->$method($text); |
|
| 507 | - } |
|
| 477 | + protected $span_gamut = array( |
|
| 478 | + # |
|
| 479 | + # These are all the transformations that occur *within* block-level |
|
| 480 | + # tags like paragraphs, headers, and list items. |
|
| 481 | + # |
|
| 482 | + # Process character escapes, code spans, and inline HTML |
|
| 483 | + # in one shot. |
|
| 484 | + "parseSpan" => -30, |
|
| 485 | + |
|
| 486 | + # Process anchor and image tags. Images must come first, |
|
| 487 | + # because ![foo][f] looks like an anchor. |
|
| 488 | + "doImages" => 10, |
|
| 489 | + "doAnchors" => 20, |
|
| 490 | + |
|
| 491 | + # Make links out of things like `<http://example.com/>` |
|
| 492 | + # Must come after doAnchors, because you can use < and > |
|
| 493 | + # delimiters in inline links like [this](<url>). |
|
| 494 | + "doAutoLinks" => 30, |
|
| 495 | + "encodeAmpsAndAngles" => 40, |
|
| 496 | + |
|
| 497 | + "doItalicsAndBold" => 50, |
|
| 498 | + "doHardBreaks" => 60, |
|
| 499 | + ); |
|
| 500 | + |
|
| 501 | + protected function runSpanGamut($text) { |
|
| 502 | + # |
|
| 503 | + # Run span gamut tranformations. |
|
| 504 | + # |
|
| 505 | + foreach ($this->span_gamut as $method => $priority) { |
|
| 506 | + $text = $this->$method($text); |
|
| 507 | + } |
|
| 508 | 508 | |
| 509 | - return $text; |
|
| 510 | - } |
|
| 509 | + return $text; |
|
| 510 | + } |
|
| 511 | 511 | |
| 512 | 512 | |
| 513 | - protected function doHardBreaks($text) { |
|
| 514 | - # Do hard breaks: |
|
| 515 | - return preg_replace_callback('/ {2,}\n/', |
|
| 516 | - array($this, '_doHardBreaks_callback'), $text); |
|
| 517 | - } |
|
| 518 | - protected function _doHardBreaks_callback($matches) { |
|
| 519 | - return $this->hashPart("<br$this->empty_element_suffix\n"); |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - |
|
| 523 | - protected function doAnchors($text) { |
|
| 524 | - # |
|
| 525 | - # Turn Markdown link shortcuts into XHTML <a> tags. |
|
| 526 | - # |
|
| 527 | - if ($this->in_anchor) return $text; |
|
| 528 | - $this->in_anchor = true; |
|
| 529 | - |
|
| 530 | - # |
|
| 531 | - # First, handle reference-style links: [link text] [id] |
|
| 532 | - # |
|
| 533 | - $text = preg_replace_callback('{ |
|
| 513 | + protected function doHardBreaks($text) { |
|
| 514 | + # Do hard breaks: |
|
| 515 | + return preg_replace_callback('/ {2,}\n/', |
|
| 516 | + array($this, '_doHardBreaks_callback'), $text); |
|
| 517 | + } |
|
| 518 | + protected function _doHardBreaks_callback($matches) { |
|
| 519 | + return $this->hashPart("<br$this->empty_element_suffix\n"); |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + |
|
| 523 | + protected function doAnchors($text) { |
|
| 524 | + # |
|
| 525 | + # Turn Markdown link shortcuts into XHTML <a> tags. |
|
| 526 | + # |
|
| 527 | + if ($this->in_anchor) return $text; |
|
| 528 | + $this->in_anchor = true; |
|
| 529 | + |
|
| 530 | + # |
|
| 531 | + # First, handle reference-style links: [link text] [id] |
|
| 532 | + # |
|
| 533 | + $text = preg_replace_callback('{ |
|
| 534 | 534 | ( # wrap whole match in $1 |
| 535 | 535 | \[ |
| 536 | 536 | ('.$this->nested_brackets_re.') # link text = $2 |
@@ -544,12 +544,12 @@ discard block |
||
| 544 | 544 | \] |
| 545 | 545 | ) |
| 546 | 546 | }xs', |
| 547 | - array($this, '_doAnchors_reference_callback'), $text); |
|
| 547 | + array($this, '_doAnchors_reference_callback'), $text); |
|
| 548 | 548 | |
| 549 | - # |
|
| 550 | - # Next, inline-style links: [link text](url "optional title") |
|
| 551 | - # |
|
| 552 | - $text = preg_replace_callback('{ |
|
| 549 | + # |
|
| 550 | + # Next, inline-style links: [link text](url "optional title") |
|
| 551 | + # |
|
| 552 | + $text = preg_replace_callback('{ |
|
| 553 | 553 | ( # wrap whole match in $1 |
| 554 | 554 | \[ |
| 555 | 555 | ('.$this->nested_brackets_re.') # link text = $2 |
@@ -571,88 +571,88 @@ discard block |
||
| 571 | 571 | \) |
| 572 | 572 | ) |
| 573 | 573 | }xs', |
| 574 | - array($this, '_doAnchors_inline_callback'), $text); |
|
| 575 | - |
|
| 576 | - # |
|
| 577 | - # Last, handle reference-style shortcuts: [link text] |
|
| 578 | - # These must come last in case you've also got [link text][1] |
|
| 579 | - # or [link text](/foo) |
|
| 580 | - # |
|
| 581 | - $text = preg_replace_callback('{ |
|
| 574 | + array($this, '_doAnchors_inline_callback'), $text); |
|
| 575 | + |
|
| 576 | + # |
|
| 577 | + # Last, handle reference-style shortcuts: [link text] |
|
| 578 | + # These must come last in case you've also got [link text][1] |
|
| 579 | + # or [link text](/foo) |
|
| 580 | + # |
|
| 581 | + $text = preg_replace_callback('{ |
|
| 582 | 582 | ( # wrap whole match in $1 |
| 583 | 583 | \[ |
| 584 | 584 | ([^\[\]]+) # link text = $2; can\'t contain [ or ] |
| 585 | 585 | \] |
| 586 | 586 | ) |
| 587 | 587 | }xs', |
| 588 | - array($this, '_doAnchors_reference_callback'), $text); |
|
| 589 | - |
|
| 590 | - $this->in_anchor = false; |
|
| 591 | - return $text; |
|
| 592 | - } |
|
| 593 | - protected function _doAnchors_reference_callback($matches) { |
|
| 594 | - $whole_match = $matches[1]; |
|
| 595 | - $link_text = $matches[2]; |
|
| 596 | - $link_id =& $matches[3]; |
|
| 597 | - |
|
| 598 | - if ($link_id == "") { |
|
| 599 | - # for shortcut links like [this][] or [this]. |
|
| 600 | - $link_id = $link_text; |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - # lower-case and turn embedded newlines into spaces |
|
| 604 | - $link_id = strtolower($link_id); |
|
| 605 | - $link_id = preg_replace('{[ ]?\n}', ' ', $link_id); |
|
| 606 | - |
|
| 607 | - if (isset($this->urls[$link_id])) { |
|
| 608 | - $url = $this->urls[$link_id]; |
|
| 609 | - $url = $this->encodeAttribute($url); |
|
| 588 | + array($this, '_doAnchors_reference_callback'), $text); |
|
| 589 | + |
|
| 590 | + $this->in_anchor = false; |
|
| 591 | + return $text; |
|
| 592 | + } |
|
| 593 | + protected function _doAnchors_reference_callback($matches) { |
|
| 594 | + $whole_match = $matches[1]; |
|
| 595 | + $link_text = $matches[2]; |
|
| 596 | + $link_id =& $matches[3]; |
|
| 597 | + |
|
| 598 | + if ($link_id == "") { |
|
| 599 | + # for shortcut links like [this][] or [this]. |
|
| 600 | + $link_id = $link_text; |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + # lower-case and turn embedded newlines into spaces |
|
| 604 | + $link_id = strtolower($link_id); |
|
| 605 | + $link_id = preg_replace('{[ ]?\n}', ' ', $link_id); |
|
| 606 | + |
|
| 607 | + if (isset($this->urls[$link_id])) { |
|
| 608 | + $url = $this->urls[$link_id]; |
|
| 609 | + $url = $this->encodeAttribute($url); |
|
| 610 | 610 | |
| 611 | - $result = "<a href=\"$url\""; |
|
| 612 | - if ( isset( $this->titles[$link_id] ) ) { |
|
| 613 | - $title = $this->titles[$link_id]; |
|
| 614 | - $title = $this->encodeAttribute($title); |
|
| 615 | - $result .= " title=\"$title\""; |
|
| 616 | - } |
|
| 617 | - |
|
| 618 | - $link_text = $this->runSpanGamut($link_text); |
|
| 619 | - $result .= ">$link_text</a>"; |
|
| 620 | - $result = $this->hashPart($result); |
|
| 621 | - } |
|
| 622 | - else { |
|
| 623 | - $result = $whole_match; |
|
| 624 | - } |
|
| 625 | - return $result; |
|
| 626 | - } |
|
| 627 | - protected function _doAnchors_inline_callback($matches) { |
|
| 628 | - $whole_match = $matches[1]; |
|
| 629 | - $link_text = $this->runSpanGamut($matches[2]); |
|
| 630 | - $url = $matches[3] == '' ? $matches[4] : $matches[3]; |
|
| 631 | - $title =& $matches[7]; |
|
| 632 | - |
|
| 633 | - $url = $this->encodeAttribute($url); |
|
| 634 | - |
|
| 635 | - $result = "<a href=\"$url\""; |
|
| 636 | - if (isset($title)) { |
|
| 637 | - $title = $this->encodeAttribute($title); |
|
| 638 | - $result .= " title=\"$title\""; |
|
| 639 | - } |
|
| 640 | - |
|
| 641 | - $link_text = $this->runSpanGamut($link_text); |
|
| 642 | - $result .= ">$link_text</a>"; |
|
| 643 | - |
|
| 644 | - return $this->hashPart($result); |
|
| 645 | - } |
|
| 646 | - |
|
| 647 | - |
|
| 648 | - protected function doImages($text) { |
|
| 649 | - # |
|
| 650 | - # Turn Markdown image shortcuts into <img> tags. |
|
| 651 | - # |
|
| 652 | - # |
|
| 653 | - # First, handle reference-style labeled images: ![alt text][id] |
|
| 654 | - # |
|
| 655 | - $text = preg_replace_callback('{ |
|
| 611 | + $result = "<a href=\"$url\""; |
|
| 612 | + if ( isset( $this->titles[$link_id] ) ) { |
|
| 613 | + $title = $this->titles[$link_id]; |
|
| 614 | + $title = $this->encodeAttribute($title); |
|
| 615 | + $result .= " title=\"$title\""; |
|
| 616 | + } |
|
| 617 | + |
|
| 618 | + $link_text = $this->runSpanGamut($link_text); |
|
| 619 | + $result .= ">$link_text</a>"; |
|
| 620 | + $result = $this->hashPart($result); |
|
| 621 | + } |
|
| 622 | + else { |
|
| 623 | + $result = $whole_match; |
|
| 624 | + } |
|
| 625 | + return $result; |
|
| 626 | + } |
|
| 627 | + protected function _doAnchors_inline_callback($matches) { |
|
| 628 | + $whole_match = $matches[1]; |
|
| 629 | + $link_text = $this->runSpanGamut($matches[2]); |
|
| 630 | + $url = $matches[3] == '' ? $matches[4] : $matches[3]; |
|
| 631 | + $title =& $matches[7]; |
|
| 632 | + |
|
| 633 | + $url = $this->encodeAttribute($url); |
|
| 634 | + |
|
| 635 | + $result = "<a href=\"$url\""; |
|
| 636 | + if (isset($title)) { |
|
| 637 | + $title = $this->encodeAttribute($title); |
|
| 638 | + $result .= " title=\"$title\""; |
|
| 639 | + } |
|
| 640 | + |
|
| 641 | + $link_text = $this->runSpanGamut($link_text); |
|
| 642 | + $result .= ">$link_text</a>"; |
|
| 643 | + |
|
| 644 | + return $this->hashPart($result); |
|
| 645 | + } |
|
| 646 | + |
|
| 647 | + |
|
| 648 | + protected function doImages($text) { |
|
| 649 | + # |
|
| 650 | + # Turn Markdown image shortcuts into <img> tags. |
|
| 651 | + # |
|
| 652 | + # |
|
| 653 | + # First, handle reference-style labeled images: ![alt text][id] |
|
| 654 | + # |
|
| 655 | + $text = preg_replace_callback('{ |
|
| 656 | 656 | ( # wrap whole match in $1 |
| 657 | 657 | !\[ |
| 658 | 658 | ('.$this->nested_brackets_re.') # alt text = $2 |
@@ -667,13 +667,13 @@ discard block |
||
| 667 | 667 | |
| 668 | 668 | ) |
| 669 | 669 | }xs', |
| 670 | - array($this, '_doImages_reference_callback'), $text); |
|
| 670 | + array($this, '_doImages_reference_callback'), $text); |
|
| 671 | 671 | |
| 672 | - # |
|
| 673 | - # Next, handle inline images:  |
|
| 674 | - # Don't forget: encode * and _ |
|
| 675 | - # |
|
| 676 | - $text = preg_replace_callback('{ |
|
| 672 | + # |
|
| 673 | + # Next, handle inline images:  |
|
| 674 | + # Don't forget: encode * and _ |
|
| 675 | + # |
|
| 676 | + $text = preg_replace_callback('{ |
|
| 677 | 677 | ( # wrap whole match in $1 |
| 678 | 678 | !\[ |
| 679 | 679 | ('.$this->nested_brackets_re.') # alt text = $2 |
@@ -696,76 +696,76 @@ discard block |
||
| 696 | 696 | \) |
| 697 | 697 | ) |
| 698 | 698 | }xs', |
| 699 | - array($this, '_doImages_inline_callback'), $text); |
|
| 700 | - |
|
| 701 | - return $text; |
|
| 702 | - } |
|
| 703 | - protected function _doImages_reference_callback($matches) { |
|
| 704 | - $whole_match = $matches[1]; |
|
| 705 | - $alt_text = $matches[2]; |
|
| 706 | - $link_id = strtolower($matches[3]); |
|
| 707 | - |
|
| 708 | - if ($link_id == "") { |
|
| 709 | - $link_id = strtolower($alt_text); # for shortcut links like ![this][]. |
|
| 710 | - } |
|
| 711 | - |
|
| 712 | - $alt_text = $this->encodeAttribute($alt_text); |
|
| 713 | - if (isset($this->urls[$link_id])) { |
|
| 714 | - $url = $this->encodeAttribute($this->urls[$link_id]); |
|
| 715 | - $result = "<img src=\"$url\" alt=\"$alt_text\""; |
|
| 716 | - if (isset($this->titles[$link_id])) { |
|
| 717 | - $title = $this->titles[$link_id]; |
|
| 718 | - $title = $this->encodeAttribute($title); |
|
| 719 | - $result .= " title=\"$title\""; |
|
| 720 | - } |
|
| 721 | - $result .= $this->empty_element_suffix; |
|
| 722 | - $result = $this->hashPart($result); |
|
| 723 | - } |
|
| 724 | - else { |
|
| 725 | - # If there's no such link ID, leave intact: |
|
| 726 | - $result = $whole_match; |
|
| 727 | - } |
|
| 728 | - |
|
| 729 | - return $result; |
|
| 730 | - } |
|
| 731 | - protected function _doImages_inline_callback($matches) { |
|
| 732 | - $whole_match = $matches[1]; |
|
| 733 | - $alt_text = $matches[2]; |
|
| 734 | - $url = $matches[3] == '' ? $matches[4] : $matches[3]; |
|
| 735 | - $title =& $matches[7]; |
|
| 736 | - |
|
| 737 | - $alt_text = $this->encodeAttribute($alt_text); |
|
| 738 | - $url = $this->encodeAttribute($url); |
|
| 739 | - $result = "<img src=\"$url\" alt=\"$alt_text\""; |
|
| 740 | - if (isset($title)) { |
|
| 741 | - $title = $this->encodeAttribute($title); |
|
| 742 | - $result .= " title=\"$title\""; # $title already quoted |
|
| 743 | - } |
|
| 744 | - $result .= $this->empty_element_suffix; |
|
| 745 | - |
|
| 746 | - return $this->hashPart($result); |
|
| 747 | - } |
|
| 748 | - |
|
| 749 | - |
|
| 750 | - protected function doHeaders($text) { |
|
| 751 | - # Setext-style headers: |
|
| 752 | - # Header 1 |
|
| 753 | - # ======== |
|
| 754 | - # |
|
| 755 | - # Header 2 |
|
| 756 | - # -------- |
|
| 757 | - # |
|
| 758 | - $text = preg_replace_callback('{ ^(.+?)[ ]*\n(=+|-+)[ ]*\n+ }mx', |
|
| 759 | - array($this, '_doHeaders_callback_setext'), $text); |
|
| 760 | - |
|
| 761 | - # atx-style headers: |
|
| 762 | - # # Header 1 |
|
| 763 | - # ## Header 2 |
|
| 764 | - # ## Header 2 with closing hashes ## |
|
| 765 | - # ... |
|
| 766 | - # ###### Header 6 |
|
| 767 | - # |
|
| 768 | - $text = preg_replace_callback('{ |
|
| 699 | + array($this, '_doImages_inline_callback'), $text); |
|
| 700 | + |
|
| 701 | + return $text; |
|
| 702 | + } |
|
| 703 | + protected function _doImages_reference_callback($matches) { |
|
| 704 | + $whole_match = $matches[1]; |
|
| 705 | + $alt_text = $matches[2]; |
|
| 706 | + $link_id = strtolower($matches[3]); |
|
| 707 | + |
|
| 708 | + if ($link_id == "") { |
|
| 709 | + $link_id = strtolower($alt_text); # for shortcut links like ![this][]. |
|
| 710 | + } |
|
| 711 | + |
|
| 712 | + $alt_text = $this->encodeAttribute($alt_text); |
|
| 713 | + if (isset($this->urls[$link_id])) { |
|
| 714 | + $url = $this->encodeAttribute($this->urls[$link_id]); |
|
| 715 | + $result = "<img src=\"$url\" alt=\"$alt_text\""; |
|
| 716 | + if (isset($this->titles[$link_id])) { |
|
| 717 | + $title = $this->titles[$link_id]; |
|
| 718 | + $title = $this->encodeAttribute($title); |
|
| 719 | + $result .= " title=\"$title\""; |
|
| 720 | + } |
|
| 721 | + $result .= $this->empty_element_suffix; |
|
| 722 | + $result = $this->hashPart($result); |
|
| 723 | + } |
|
| 724 | + else { |
|
| 725 | + # If there's no such link ID, leave intact: |
|
| 726 | + $result = $whole_match; |
|
| 727 | + } |
|
| 728 | + |
|
| 729 | + return $result; |
|
| 730 | + } |
|
| 731 | + protected function _doImages_inline_callback($matches) { |
|
| 732 | + $whole_match = $matches[1]; |
|
| 733 | + $alt_text = $matches[2]; |
|
| 734 | + $url = $matches[3] == '' ? $matches[4] : $matches[3]; |
|
| 735 | + $title =& $matches[7]; |
|
| 736 | + |
|
| 737 | + $alt_text = $this->encodeAttribute($alt_text); |
|
| 738 | + $url = $this->encodeAttribute($url); |
|
| 739 | + $result = "<img src=\"$url\" alt=\"$alt_text\""; |
|
| 740 | + if (isset($title)) { |
|
| 741 | + $title = $this->encodeAttribute($title); |
|
| 742 | + $result .= " title=\"$title\""; # $title already quoted |
|
| 743 | + } |
|
| 744 | + $result .= $this->empty_element_suffix; |
|
| 745 | + |
|
| 746 | + return $this->hashPart($result); |
|
| 747 | + } |
|
| 748 | + |
|
| 749 | + |
|
| 750 | + protected function doHeaders($text) { |
|
| 751 | + # Setext-style headers: |
|
| 752 | + # Header 1 |
|
| 753 | + # ======== |
|
| 754 | + # |
|
| 755 | + # Header 2 |
|
| 756 | + # -------- |
|
| 757 | + # |
|
| 758 | + $text = preg_replace_callback('{ ^(.+?)[ ]*\n(=+|-+)[ ]*\n+ }mx', |
|
| 759 | + array($this, '_doHeaders_callback_setext'), $text); |
|
| 760 | + |
|
| 761 | + # atx-style headers: |
|
| 762 | + # # Header 1 |
|
| 763 | + # ## Header 2 |
|
| 764 | + # ## Header 2 with closing hashes ## |
|
| 765 | + # ... |
|
| 766 | + # ###### Header 6 |
|
| 767 | + # |
|
| 768 | + $text = preg_replace_callback('{ |
|
| 769 | 769 | ^(\#{1,6}) # $1 = string of #\'s |
| 770 | 770 | [ ]* |
| 771 | 771 | (.+?) # $2 = Header text |
@@ -773,45 +773,45 @@ discard block |
||
| 773 | 773 | \#* # optional closing #\'s (not counted) |
| 774 | 774 | \n+ |
| 775 | 775 | }xm', |
| 776 | - array($this, '_doHeaders_callback_atx'), $text); |
|
| 777 | - |
|
| 778 | - return $text; |
|
| 779 | - } |
|
| 780 | - protected function _doHeaders_callback_setext($matches) { |
|
| 781 | - # Terrible hack to check we haven't found an empty list item. |
|
| 782 | - if ($matches[2] == '-' && preg_match('{^-(?: |$)}', $matches[1])) |
|
| 783 | - return $matches[0]; |
|
| 784 | - |
|
| 785 | - $level = $matches[2]{0} == '=' ? 1 : 2; |
|
| 786 | - $block = "<h$level>".$this->runSpanGamut($matches[1])."</h$level>"; |
|
| 787 | - return "\n" . $this->hashBlock($block) . "\n\n"; |
|
| 788 | - } |
|
| 789 | - protected function _doHeaders_callback_atx($matches) { |
|
| 790 | - $level = strlen($matches[1]); |
|
| 791 | - $block = "<h$level>".$this->runSpanGamut($matches[2])."</h$level>"; |
|
| 792 | - return "\n" . $this->hashBlock($block) . "\n\n"; |
|
| 793 | - } |
|
| 794 | - |
|
| 795 | - |
|
| 796 | - protected function doLists($text) { |
|
| 797 | - # |
|
| 798 | - # Form HTML ordered (numbered) and unordered (bulleted) lists. |
|
| 799 | - # |
|
| 800 | - $less_than_tab = $this->tab_width - 1; |
|
| 801 | - |
|
| 802 | - # Re-usable patterns to match list item bullets and number markers: |
|
| 803 | - $marker_ul_re = '[*+-]'; |
|
| 804 | - $marker_ol_re = '\d+[\.]'; |
|
| 805 | - $marker_any_re = "(?:$marker_ul_re|$marker_ol_re)"; |
|
| 806 | - |
|
| 807 | - $markers_relist = array( |
|
| 808 | - $marker_ul_re => $marker_ol_re, |
|
| 809 | - $marker_ol_re => $marker_ul_re, |
|
| 810 | - ); |
|
| 811 | - |
|
| 812 | - foreach ($markers_relist as $marker_re => $other_marker_re) { |
|
| 813 | - # Re-usable pattern to match any entirel ul or ol list: |
|
| 814 | - $whole_list_re = ' |
|
| 776 | + array($this, '_doHeaders_callback_atx'), $text); |
|
| 777 | + |
|
| 778 | + return $text; |
|
| 779 | + } |
|
| 780 | + protected function _doHeaders_callback_setext($matches) { |
|
| 781 | + # Terrible hack to check we haven't found an empty list item. |
|
| 782 | + if ($matches[2] == '-' && preg_match('{^-(?: |$)}', $matches[1])) |
|
| 783 | + return $matches[0]; |
|
| 784 | + |
|
| 785 | + $level = $matches[2]{0} == '=' ? 1 : 2; |
|
| 786 | + $block = "<h$level>".$this->runSpanGamut($matches[1])."</h$level>"; |
|
| 787 | + return "\n" . $this->hashBlock($block) . "\n\n"; |
|
| 788 | + } |
|
| 789 | + protected function _doHeaders_callback_atx($matches) { |
|
| 790 | + $level = strlen($matches[1]); |
|
| 791 | + $block = "<h$level>".$this->runSpanGamut($matches[2])."</h$level>"; |
|
| 792 | + return "\n" . $this->hashBlock($block) . "\n\n"; |
|
| 793 | + } |
|
| 794 | + |
|
| 795 | + |
|
| 796 | + protected function doLists($text) { |
|
| 797 | + # |
|
| 798 | + # Form HTML ordered (numbered) and unordered (bulleted) lists. |
|
| 799 | + # |
|
| 800 | + $less_than_tab = $this->tab_width - 1; |
|
| 801 | + |
|
| 802 | + # Re-usable patterns to match list item bullets and number markers: |
|
| 803 | + $marker_ul_re = '[*+-]'; |
|
| 804 | + $marker_ol_re = '\d+[\.]'; |
|
| 805 | + $marker_any_re = "(?:$marker_ul_re|$marker_ol_re)"; |
|
| 806 | + |
|
| 807 | + $markers_relist = array( |
|
| 808 | + $marker_ul_re => $marker_ol_re, |
|
| 809 | + $marker_ol_re => $marker_ul_re, |
|
| 810 | + ); |
|
| 811 | + |
|
| 812 | + foreach ($markers_relist as $marker_re => $other_marker_re) { |
|
| 813 | + # Re-usable pattern to match any entirel ul or ol list: |
|
| 814 | + $whole_list_re = ' |
|
| 815 | 815 | ( # $1 = whole list |
| 816 | 816 | ( # $2 |
| 817 | 817 | ([ ]{0,'.$less_than_tab.'}) # $3 = number of spaces |
@@ -838,79 +838,79 @@ discard block |
||
| 838 | 838 | ) |
| 839 | 839 | '; // mx |
| 840 | 840 | |
| 841 | - # We use a different prefix before nested lists than top-level lists. |
|
| 842 | - # See extended comment in _ProcessListItems(). |
|
| 841 | + # We use a different prefix before nested lists than top-level lists. |
|
| 842 | + # See extended comment in _ProcessListItems(). |
|
| 843 | 843 | |
| 844 | - if ($this->list_level) { |
|
| 845 | - $text = preg_replace_callback('{ |
|
| 844 | + if ($this->list_level) { |
|
| 845 | + $text = preg_replace_callback('{ |
|
| 846 | 846 | ^ |
| 847 | 847 | '.$whole_list_re.' |
| 848 | 848 | }mx', |
| 849 | - array($this, '_doLists_callback'), $text); |
|
| 850 | - } |
|
| 851 | - else { |
|
| 852 | - $text = preg_replace_callback('{ |
|
| 849 | + array($this, '_doLists_callback'), $text); |
|
| 850 | + } |
|
| 851 | + else { |
|
| 852 | + $text = preg_replace_callback('{ |
|
| 853 | 853 | (?:(?<=\n)\n?|\A\n?) # Must eat the newline |
| 854 | 854 | '.$whole_list_re.' |
| 855 | 855 | }mx', |
| 856 | - array($this, '_doLists_callback'), $text); |
|
| 857 | - } |
|
| 858 | - } |
|
| 859 | - |
|
| 860 | - return $text; |
|
| 861 | - } |
|
| 862 | - protected function _doLists_callback($matches) { |
|
| 863 | - # Re-usable patterns to match list item bullets and number markers: |
|
| 864 | - $marker_ul_re = '[*+-]'; |
|
| 865 | - $marker_ol_re = '\d+[\.]'; |
|
| 866 | - $marker_any_re = "(?:$marker_ul_re|$marker_ol_re)"; |
|
| 867 | - |
|
| 868 | - $list = $matches[1]; |
|
| 869 | - $list_type = preg_match("/$marker_ul_re/", $matches[4]) ? "ul" : "ol"; |
|
| 870 | - |
|
| 871 | - $marker_any_re = ( $list_type == "ul" ? $marker_ul_re : $marker_ol_re ); |
|
| 872 | - |
|
| 873 | - $list .= "\n"; |
|
| 874 | - $result = $this->processListItems($list, $marker_any_re); |
|
| 875 | - |
|
| 876 | - $result = $this->hashBlock("<$list_type>\n" . $result . "</$list_type>"); |
|
| 877 | - return "\n". $result ."\n\n"; |
|
| 878 | - } |
|
| 879 | - |
|
| 880 | - protected $list_level = 0; |
|
| 881 | - |
|
| 882 | - protected function processListItems($list_str, $marker_any_re) { |
|
| 883 | - # |
|
| 884 | - # Process the contents of a single ordered or unordered list, splitting it |
|
| 885 | - # into individual list items. |
|
| 886 | - # |
|
| 887 | - # The $this->list_level global keeps track of when we're inside a list. |
|
| 888 | - # Each time we enter a list, we increment it; when we leave a list, |
|
| 889 | - # we decrement. If it's zero, we're not in a list anymore. |
|
| 890 | - # |
|
| 891 | - # We do this because when we're not inside a list, we want to treat |
|
| 892 | - # something like this: |
|
| 893 | - # |
|
| 894 | - # I recommend upgrading to version |
|
| 895 | - # 8. Oops, now this line is treated |
|
| 896 | - # as a sub-list. |
|
| 897 | - # |
|
| 898 | - # As a single paragraph, despite the fact that the second line starts |
|
| 899 | - # with a digit-period-space sequence. |
|
| 900 | - # |
|
| 901 | - # Whereas when we're inside a list (or sub-list), that line will be |
|
| 902 | - # treated as the start of a sub-list. What a kludge, huh? This is |
|
| 903 | - # an aspect of Markdown's syntax that's hard to parse perfectly |
|
| 904 | - # without resorting to mind-reading. Perhaps the solution is to |
|
| 905 | - # change the syntax rules such that sub-lists must start with a |
|
| 906 | - # starting cardinal number; e.g. "1." or "a.". |
|
| 907 | - |
|
| 908 | - $this->list_level++; |
|
| 909 | - |
|
| 910 | - # trim trailing blank lines: |
|
| 911 | - $list_str = preg_replace("/\n{2,}\\z/", "\n", $list_str); |
|
| 912 | - |
|
| 913 | - $list_str = preg_replace_callback('{ |
|
| 856 | + array($this, '_doLists_callback'), $text); |
|
| 857 | + } |
|
| 858 | + } |
|
| 859 | + |
|
| 860 | + return $text; |
|
| 861 | + } |
|
| 862 | + protected function _doLists_callback($matches) { |
|
| 863 | + # Re-usable patterns to match list item bullets and number markers: |
|
| 864 | + $marker_ul_re = '[*+-]'; |
|
| 865 | + $marker_ol_re = '\d+[\.]'; |
|
| 866 | + $marker_any_re = "(?:$marker_ul_re|$marker_ol_re)"; |
|
| 867 | + |
|
| 868 | + $list = $matches[1]; |
|
| 869 | + $list_type = preg_match("/$marker_ul_re/", $matches[4]) ? "ul" : "ol"; |
|
| 870 | + |
|
| 871 | + $marker_any_re = ( $list_type == "ul" ? $marker_ul_re : $marker_ol_re ); |
|
| 872 | + |
|
| 873 | + $list .= "\n"; |
|
| 874 | + $result = $this->processListItems($list, $marker_any_re); |
|
| 875 | + |
|
| 876 | + $result = $this->hashBlock("<$list_type>\n" . $result . "</$list_type>"); |
|
| 877 | + return "\n". $result ."\n\n"; |
|
| 878 | + } |
|
| 879 | + |
|
| 880 | + protected $list_level = 0; |
|
| 881 | + |
|
| 882 | + protected function processListItems($list_str, $marker_any_re) { |
|
| 883 | + # |
|
| 884 | + # Process the contents of a single ordered or unordered list, splitting it |
|
| 885 | + # into individual list items. |
|
| 886 | + # |
|
| 887 | + # The $this->list_level global keeps track of when we're inside a list. |
|
| 888 | + # Each time we enter a list, we increment it; when we leave a list, |
|
| 889 | + # we decrement. If it's zero, we're not in a list anymore. |
|
| 890 | + # |
|
| 891 | + # We do this because when we're not inside a list, we want to treat |
|
| 892 | + # something like this: |
|
| 893 | + # |
|
| 894 | + # I recommend upgrading to version |
|
| 895 | + # 8. Oops, now this line is treated |
|
| 896 | + # as a sub-list. |
|
| 897 | + # |
|
| 898 | + # As a single paragraph, despite the fact that the second line starts |
|
| 899 | + # with a digit-period-space sequence. |
|
| 900 | + # |
|
| 901 | + # Whereas when we're inside a list (or sub-list), that line will be |
|
| 902 | + # treated as the start of a sub-list. What a kludge, huh? This is |
|
| 903 | + # an aspect of Markdown's syntax that's hard to parse perfectly |
|
| 904 | + # without resorting to mind-reading. Perhaps the solution is to |
|
| 905 | + # change the syntax rules such that sub-lists must start with a |
|
| 906 | + # starting cardinal number; e.g. "1." or "a.". |
|
| 907 | + |
|
| 908 | + $this->list_level++; |
|
| 909 | + |
|
| 910 | + # trim trailing blank lines: |
|
| 911 | + $list_str = preg_replace("/\n{2,}\\z/", "\n", $list_str); |
|
| 912 | + |
|
| 913 | + $list_str = preg_replace_callback('{ |
|
| 914 | 914 | (\n)? # leading line = $1 |
| 915 | 915 | (^[ ]*) # leading whitespace = $2 |
| 916 | 916 | ('.$marker_any_re.' # list marker and space = $3 |
@@ -920,41 +920,41 @@ discard block |
||
| 920 | 920 | (?:(\n+(?=\n))|\n) # tailing blank line = $5 |
| 921 | 921 | (?= \n* (\z | \2 ('.$marker_any_re.') (?:[ ]+|(?=\n)))) |
| 922 | 922 | }xm', |
| 923 | - array($this, '_processListItems_callback'), $list_str); |
|
| 924 | - |
|
| 925 | - $this->list_level--; |
|
| 926 | - return $list_str; |
|
| 927 | - } |
|
| 928 | - protected function _processListItems_callback($matches) { |
|
| 929 | - $item = $matches[4]; |
|
| 930 | - $leading_line =& $matches[1]; |
|
| 931 | - $leading_space =& $matches[2]; |
|
| 932 | - $marker_space = $matches[3]; |
|
| 933 | - $tailing_blank_line =& $matches[5]; |
|
| 934 | - |
|
| 935 | - if ($leading_line || $tailing_blank_line || |
|
| 936 | - preg_match('/\n{2,}/', $item)) |
|
| 937 | - { |
|
| 938 | - # Replace marker with the appropriate whitespace indentation |
|
| 939 | - $item = $leading_space . str_repeat(' ', strlen($marker_space)) . $item; |
|
| 940 | - $item = $this->runBlockGamut($this->outdent($item)."\n"); |
|
| 941 | - } |
|
| 942 | - else { |
|
| 943 | - # Recursion for sub-lists: |
|
| 944 | - $item = $this->doLists($this->outdent($item)); |
|
| 945 | - $item = preg_replace('/\n+$/', '', $item); |
|
| 946 | - $item = $this->runSpanGamut($item); |
|
| 947 | - } |
|
| 948 | - |
|
| 949 | - return "<li>" . $item . "</li>\n"; |
|
| 950 | - } |
|
| 951 | - |
|
| 952 | - |
|
| 953 | - protected function doCodeBlocks($text) { |
|
| 954 | - # |
|
| 955 | - # Process Markdown `<pre><code>` blocks. |
|
| 956 | - # |
|
| 957 | - $text = preg_replace_callback('{ |
|
| 923 | + array($this, '_processListItems_callback'), $list_str); |
|
| 924 | + |
|
| 925 | + $this->list_level--; |
|
| 926 | + return $list_str; |
|
| 927 | + } |
|
| 928 | + protected function _processListItems_callback($matches) { |
|
| 929 | + $item = $matches[4]; |
|
| 930 | + $leading_line =& $matches[1]; |
|
| 931 | + $leading_space =& $matches[2]; |
|
| 932 | + $marker_space = $matches[3]; |
|
| 933 | + $tailing_blank_line =& $matches[5]; |
|
| 934 | + |
|
| 935 | + if ($leading_line || $tailing_blank_line || |
|
| 936 | + preg_match('/\n{2,}/', $item)) |
|
| 937 | + { |
|
| 938 | + # Replace marker with the appropriate whitespace indentation |
|
| 939 | + $item = $leading_space . str_repeat(' ', strlen($marker_space)) . $item; |
|
| 940 | + $item = $this->runBlockGamut($this->outdent($item)."\n"); |
|
| 941 | + } |
|
| 942 | + else { |
|
| 943 | + # Recursion for sub-lists: |
|
| 944 | + $item = $this->doLists($this->outdent($item)); |
|
| 945 | + $item = preg_replace('/\n+$/', '', $item); |
|
| 946 | + $item = $this->runSpanGamut($item); |
|
| 947 | + } |
|
| 948 | + |
|
| 949 | + return "<li>" . $item . "</li>\n"; |
|
| 950 | + } |
|
| 951 | + |
|
| 952 | + |
|
| 953 | + protected function doCodeBlocks($text) { |
|
| 954 | + # |
|
| 955 | + # Process Markdown `<pre><code>` blocks. |
|
| 956 | + # |
|
| 957 | + $text = preg_replace_callback('{ |
|
| 958 | 958 | (?:\n\n|\A\n?) |
| 959 | 959 | ( # $1 = the code block -- one or more lines, starting with a space/tab |
| 960 | 960 | (?> |
@@ -964,197 +964,197 @@ discard block |
||
| 964 | 964 | ) |
| 965 | 965 | ((?=^[ ]{0,'.$this->tab_width.'}\S)|\Z) # Lookahead for non-space at line-start, or end of doc |
| 966 | 966 | }xm', |
| 967 | - array($this, '_doCodeBlocks_callback'), $text); |
|
| 967 | + array($this, '_doCodeBlocks_callback'), $text); |
|
| 968 | 968 | |
| 969 | - return $text; |
|
| 970 | - } |
|
| 971 | - protected function _doCodeBlocks_callback($matches) { |
|
| 972 | - $codeblock = $this->unhash($matches[1]); |
|
| 969 | + return $text; |
|
| 970 | + } |
|
| 971 | + protected function _doCodeBlocks_callback($matches) { |
|
| 972 | + $codeblock = $this->unhash($matches[1]); |
|
| 973 | 973 | |
| 974 | - $codeblock = $this->outdent($codeblock); |
|
| 975 | - $codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES); |
|
| 974 | + $codeblock = $this->outdent($codeblock); |
|
| 975 | + $codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES); |
|
| 976 | 976 | |
| 977 | - # trim leading newlines and trailing newlines |
|
| 978 | - $codeblock = preg_replace('/\A\n+|\n+\z/', '', $codeblock); |
|
| 977 | + # trim leading newlines and trailing newlines |
|
| 978 | + $codeblock = preg_replace('/\A\n+|\n+\z/', '', $codeblock); |
|
| 979 | 979 | |
| 980 | - $codeblock = "<pre><code>$codeblock\n</code></pre>"; |
|
| 981 | - return "\n\n".$this->hashBlock($codeblock)."\n\n"; |
|
| 982 | - } |
|
| 980 | + $codeblock = "<pre><code>$codeblock\n</code></pre>"; |
|
| 981 | + return "\n\n".$this->hashBlock($codeblock)."\n\n"; |
|
| 982 | + } |
|
| 983 | 983 | |
| 984 | 984 | |
| 985 | - protected function makeCodeSpan($code) { |
|
| 986 | - # |
|
| 987 | - # Create a code span markup for $code. Called from handleSpanToken. |
|
| 988 | - # |
|
| 989 | - $code = htmlspecialchars(trim($code), ENT_NOQUOTES); |
|
| 990 | - return $this->hashPart("<code>$code</code>"); |
|
| 991 | - } |
|
| 985 | + protected function makeCodeSpan($code) { |
|
| 986 | + # |
|
| 987 | + # Create a code span markup for $code. Called from handleSpanToken. |
|
| 988 | + # |
|
| 989 | + $code = htmlspecialchars(trim($code), ENT_NOQUOTES); |
|
| 990 | + return $this->hashPart("<code>$code</code>"); |
|
| 991 | + } |
|
| 992 | 992 | |
| 993 | 993 | |
| 994 | - protected $em_relist = array( |
|
| 995 | - '' => '(?:(?<!\*)\*(?!\*)|(?<!_)_(?!_))(?=\S|$)(?![\.,:;]\s)', |
|
| 996 | - '*' => '(?<=\S|^)(?<!\*)\*(?!\*)', |
|
| 997 | - '_' => '(?<=\S|^)(?<!_)_(?!_)', |
|
| 998 | - ); |
|
| 999 | - protected $strong_relist = array( |
|
| 1000 | - '' => '(?:(?<!\*)\*\*(?!\*)|(?<!_)__(?!_))(?=\S|$)(?![\.,:;]\s)', |
|
| 1001 | - '**' => '(?<=\S|^)(?<!\*)\*\*(?!\*)', |
|
| 1002 | - '__' => '(?<=\S|^)(?<!_)__(?!_)', |
|
| 1003 | - ); |
|
| 1004 | - protected $em_strong_relist = array( |
|
| 1005 | - '' => '(?:(?<!\*)\*\*\*(?!\*)|(?<!_)___(?!_))(?=\S|$)(?![\.,:;]\s)', |
|
| 1006 | - '***' => '(?<=\S|^)(?<!\*)\*\*\*(?!\*)', |
|
| 1007 | - '___' => '(?<=\S|^)(?<!_)___(?!_)', |
|
| 1008 | - ); |
|
| 1009 | - protected $em_strong_prepared_relist; |
|
| 994 | + protected $em_relist = array( |
|
| 995 | + '' => '(?:(?<!\*)\*(?!\*)|(?<!_)_(?!_))(?=\S|$)(?![\.,:;]\s)', |
|
| 996 | + '*' => '(?<=\S|^)(?<!\*)\*(?!\*)', |
|
| 997 | + '_' => '(?<=\S|^)(?<!_)_(?!_)', |
|
| 998 | + ); |
|
| 999 | + protected $strong_relist = array( |
|
| 1000 | + '' => '(?:(?<!\*)\*\*(?!\*)|(?<!_)__(?!_))(?=\S|$)(?![\.,:;]\s)', |
|
| 1001 | + '**' => '(?<=\S|^)(?<!\*)\*\*(?!\*)', |
|
| 1002 | + '__' => '(?<=\S|^)(?<!_)__(?!_)', |
|
| 1003 | + ); |
|
| 1004 | + protected $em_strong_relist = array( |
|
| 1005 | + '' => '(?:(?<!\*)\*\*\*(?!\*)|(?<!_)___(?!_))(?=\S|$)(?![\.,:;]\s)', |
|
| 1006 | + '***' => '(?<=\S|^)(?<!\*)\*\*\*(?!\*)', |
|
| 1007 | + '___' => '(?<=\S|^)(?<!_)___(?!_)', |
|
| 1008 | + ); |
|
| 1009 | + protected $em_strong_prepared_relist; |
|
| 1010 | 1010 | |
| 1011 | - protected function prepareItalicsAndBold() { |
|
| 1012 | - # |
|
| 1013 | - # Prepare regular expressions for searching emphasis tokens in any |
|
| 1014 | - # context. |
|
| 1015 | - # |
|
| 1016 | - foreach ($this->em_relist as $em => $em_re) { |
|
| 1017 | - foreach ($this->strong_relist as $strong => $strong_re) { |
|
| 1018 | - # Construct list of allowed token expressions. |
|
| 1019 | - $token_relist = array(); |
|
| 1020 | - if (isset($this->em_strong_relist["$em$strong"])) { |
|
| 1021 | - $token_relist[] = $this->em_strong_relist["$em$strong"]; |
|
| 1022 | - } |
|
| 1023 | - $token_relist[] = $em_re; |
|
| 1024 | - $token_relist[] = $strong_re; |
|
| 1011 | + protected function prepareItalicsAndBold() { |
|
| 1012 | + # |
|
| 1013 | + # Prepare regular expressions for searching emphasis tokens in any |
|
| 1014 | + # context. |
|
| 1015 | + # |
|
| 1016 | + foreach ($this->em_relist as $em => $em_re) { |
|
| 1017 | + foreach ($this->strong_relist as $strong => $strong_re) { |
|
| 1018 | + # Construct list of allowed token expressions. |
|
| 1019 | + $token_relist = array(); |
|
| 1020 | + if (isset($this->em_strong_relist["$em$strong"])) { |
|
| 1021 | + $token_relist[] = $this->em_strong_relist["$em$strong"]; |
|
| 1022 | + } |
|
| 1023 | + $token_relist[] = $em_re; |
|
| 1024 | + $token_relist[] = $strong_re; |
|
| 1025 | 1025 | |
| 1026 | - # Construct master expression from list. |
|
| 1027 | - $token_re = '{('. implode('|', $token_relist) .')}'; |
|
| 1028 | - $this->em_strong_prepared_relist["$em$strong"] = $token_re; |
|
| 1029 | - } |
|
| 1030 | - } |
|
| 1031 | - } |
|
| 1026 | + # Construct master expression from list. |
|
| 1027 | + $token_re = '{('. implode('|', $token_relist) .')}'; |
|
| 1028 | + $this->em_strong_prepared_relist["$em$strong"] = $token_re; |
|
| 1029 | + } |
|
| 1030 | + } |
|
| 1031 | + } |
|
| 1032 | 1032 | |
| 1033 | - protected function doItalicsAndBold($text) { |
|
| 1034 | - $token_stack = array(''); |
|
| 1035 | - $text_stack = array(''); |
|
| 1036 | - $em = ''; |
|
| 1037 | - $strong = ''; |
|
| 1038 | - $tree_char_em = false; |
|
| 1039 | - |
|
| 1040 | - while (1) { |
|
| 1041 | - # |
|
| 1042 | - # Get prepared regular expression for seraching emphasis tokens |
|
| 1043 | - # in current context. |
|
| 1044 | - # |
|
| 1045 | - $token_re = $this->em_strong_prepared_relist["$em$strong"]; |
|
| 1033 | + protected function doItalicsAndBold($text) { |
|
| 1034 | + $token_stack = array(''); |
|
| 1035 | + $text_stack = array(''); |
|
| 1036 | + $em = ''; |
|
| 1037 | + $strong = ''; |
|
| 1038 | + $tree_char_em = false; |
|
| 1039 | + |
|
| 1040 | + while (1) { |
|
| 1041 | + # |
|
| 1042 | + # Get prepared regular expression for seraching emphasis tokens |
|
| 1043 | + # in current context. |
|
| 1044 | + # |
|
| 1045 | + $token_re = $this->em_strong_prepared_relist["$em$strong"]; |
|
| 1046 | 1046 | |
| 1047 | - # |
|
| 1048 | - # Each loop iteration search for the next emphasis token. |
|
| 1049 | - # Each token is then passed to handleSpanToken. |
|
| 1050 | - # |
|
| 1051 | - $parts = preg_split($token_re, $text, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 1052 | - $text_stack[0] .= $parts[0]; |
|
| 1053 | - $token =& $parts[1]; |
|
| 1054 | - $text =& $parts[2]; |
|
| 1047 | + # |
|
| 1048 | + # Each loop iteration search for the next emphasis token. |
|
| 1049 | + # Each token is then passed to handleSpanToken. |
|
| 1050 | + # |
|
| 1051 | + $parts = preg_split($token_re, $text, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 1052 | + $text_stack[0] .= $parts[0]; |
|
| 1053 | + $token =& $parts[1]; |
|
| 1054 | + $text =& $parts[2]; |
|
| 1055 | 1055 | |
| 1056 | - if (empty($token)) { |
|
| 1057 | - # Reached end of text span: empty stack without emitting. |
|
| 1058 | - # any more emphasis. |
|
| 1059 | - while ($token_stack[0]) { |
|
| 1060 | - $text_stack[1] .= array_shift($token_stack); |
|
| 1061 | - $text_stack[0] .= array_shift($text_stack); |
|
| 1062 | - } |
|
| 1063 | - break; |
|
| 1064 | - } |
|
| 1056 | + if (empty($token)) { |
|
| 1057 | + # Reached end of text span: empty stack without emitting. |
|
| 1058 | + # any more emphasis. |
|
| 1059 | + while ($token_stack[0]) { |
|
| 1060 | + $text_stack[1] .= array_shift($token_stack); |
|
| 1061 | + $text_stack[0] .= array_shift($text_stack); |
|
| 1062 | + } |
|
| 1063 | + break; |
|
| 1064 | + } |
|
| 1065 | 1065 | |
| 1066 | - $token_len = strlen($token); |
|
| 1067 | - if ($tree_char_em) { |
|
| 1068 | - # Reached closing marker while inside a three-char emphasis. |
|
| 1069 | - if ($token_len == 3) { |
|
| 1070 | - # Three-char closing marker, close em and strong. |
|
| 1071 | - array_shift($token_stack); |
|
| 1072 | - $span = array_shift($text_stack); |
|
| 1073 | - $span = $this->runSpanGamut($span); |
|
| 1074 | - $span = "<strong><em>$span</em></strong>"; |
|
| 1075 | - $text_stack[0] .= $this->hashPart($span); |
|
| 1076 | - $em = ''; |
|
| 1077 | - $strong = ''; |
|
| 1078 | - } else { |
|
| 1079 | - # Other closing marker: close one em or strong and |
|
| 1080 | - # change current token state to match the other |
|
| 1081 | - $token_stack[0] = str_repeat($token{0}, 3-$token_len); |
|
| 1082 | - $tag = $token_len == 2 ? "strong" : "em"; |
|
| 1083 | - $span = $text_stack[0]; |
|
| 1084 | - $span = $this->runSpanGamut($span); |
|
| 1085 | - $span = "<$tag>$span</$tag>"; |
|
| 1086 | - $text_stack[0] = $this->hashPart($span); |
|
| 1087 | - $$tag = ''; # $$tag stands for $em or $strong |
|
| 1088 | - } |
|
| 1089 | - $tree_char_em = false; |
|
| 1090 | - } else if ($token_len == 3) { |
|
| 1091 | - if ($em) { |
|
| 1092 | - # Reached closing marker for both em and strong. |
|
| 1093 | - # Closing strong marker: |
|
| 1094 | - for ($i = 0; $i < 2; ++$i) { |
|
| 1095 | - $shifted_token = array_shift($token_stack); |
|
| 1096 | - $tag = strlen($shifted_token) == 2 ? "strong" : "em"; |
|
| 1097 | - $span = array_shift($text_stack); |
|
| 1098 | - $span = $this->runSpanGamut($span); |
|
| 1099 | - $span = "<$tag>$span</$tag>"; |
|
| 1100 | - $text_stack[0] .= $this->hashPart($span); |
|
| 1101 | - $$tag = ''; # $$tag stands for $em or $strong |
|
| 1102 | - } |
|
| 1103 | - } else { |
|
| 1104 | - # Reached opening three-char emphasis marker. Push on token |
|
| 1105 | - # stack; will be handled by the special condition above. |
|
| 1106 | - $em = $token{0}; |
|
| 1107 | - $strong = "$em$em"; |
|
| 1108 | - array_unshift($token_stack, $token); |
|
| 1109 | - array_unshift($text_stack, ''); |
|
| 1110 | - $tree_char_em = true; |
|
| 1111 | - } |
|
| 1112 | - } else if ($token_len == 2) { |
|
| 1113 | - if ($strong) { |
|
| 1114 | - # Unwind any dangling emphasis marker: |
|
| 1115 | - if (strlen($token_stack[0]) == 1) { |
|
| 1116 | - $text_stack[1] .= array_shift($token_stack); |
|
| 1117 | - $text_stack[0] .= array_shift($text_stack); |
|
| 1118 | - } |
|
| 1119 | - # Closing strong marker: |
|
| 1120 | - array_shift($token_stack); |
|
| 1121 | - $span = array_shift($text_stack); |
|
| 1122 | - $span = $this->runSpanGamut($span); |
|
| 1123 | - $span = "<strong>$span</strong>"; |
|
| 1124 | - $text_stack[0] .= $this->hashPart($span); |
|
| 1125 | - $strong = ''; |
|
| 1126 | - } else { |
|
| 1127 | - array_unshift($token_stack, $token); |
|
| 1128 | - array_unshift($text_stack, ''); |
|
| 1129 | - $strong = $token; |
|
| 1130 | - } |
|
| 1131 | - } else { |
|
| 1132 | - # Here $token_len == 1 |
|
| 1133 | - if ($em) { |
|
| 1134 | - if (strlen($token_stack[0]) == 1) { |
|
| 1135 | - # Closing emphasis marker: |
|
| 1136 | - array_shift($token_stack); |
|
| 1137 | - $span = array_shift($text_stack); |
|
| 1138 | - $span = $this->runSpanGamut($span); |
|
| 1139 | - $span = "<em>$span</em>"; |
|
| 1140 | - $text_stack[0] .= $this->hashPart($span); |
|
| 1141 | - $em = ''; |
|
| 1142 | - } else { |
|
| 1143 | - $text_stack[0] .= $token; |
|
| 1144 | - } |
|
| 1145 | - } else { |
|
| 1146 | - array_unshift($token_stack, $token); |
|
| 1147 | - array_unshift($text_stack, ''); |
|
| 1148 | - $em = $token; |
|
| 1149 | - } |
|
| 1150 | - } |
|
| 1151 | - } |
|
| 1152 | - return $text_stack[0]; |
|
| 1153 | - } |
|
| 1154 | - |
|
| 1155 | - |
|
| 1156 | - protected function doBlockQuotes($text) { |
|
| 1157 | - $text = preg_replace_callback('/ |
|
| 1066 | + $token_len = strlen($token); |
|
| 1067 | + if ($tree_char_em) { |
|
| 1068 | + # Reached closing marker while inside a three-char emphasis. |
|
| 1069 | + if ($token_len == 3) { |
|
| 1070 | + # Three-char closing marker, close em and strong. |
|
| 1071 | + array_shift($token_stack); |
|
| 1072 | + $span = array_shift($text_stack); |
|
| 1073 | + $span = $this->runSpanGamut($span); |
|
| 1074 | + $span = "<strong><em>$span</em></strong>"; |
|
| 1075 | + $text_stack[0] .= $this->hashPart($span); |
|
| 1076 | + $em = ''; |
|
| 1077 | + $strong = ''; |
|
| 1078 | + } else { |
|
| 1079 | + # Other closing marker: close one em or strong and |
|
| 1080 | + # change current token state to match the other |
|
| 1081 | + $token_stack[0] = str_repeat($token{0}, 3-$token_len); |
|
| 1082 | + $tag = $token_len == 2 ? "strong" : "em"; |
|
| 1083 | + $span = $text_stack[0]; |
|
| 1084 | + $span = $this->runSpanGamut($span); |
|
| 1085 | + $span = "<$tag>$span</$tag>"; |
|
| 1086 | + $text_stack[0] = $this->hashPart($span); |
|
| 1087 | + $$tag = ''; # $$tag stands for $em or $strong |
|
| 1088 | + } |
|
| 1089 | + $tree_char_em = false; |
|
| 1090 | + } else if ($token_len == 3) { |
|
| 1091 | + if ($em) { |
|
| 1092 | + # Reached closing marker for both em and strong. |
|
| 1093 | + # Closing strong marker: |
|
| 1094 | + for ($i = 0; $i < 2; ++$i) { |
|
| 1095 | + $shifted_token = array_shift($token_stack); |
|
| 1096 | + $tag = strlen($shifted_token) == 2 ? "strong" : "em"; |
|
| 1097 | + $span = array_shift($text_stack); |
|
| 1098 | + $span = $this->runSpanGamut($span); |
|
| 1099 | + $span = "<$tag>$span</$tag>"; |
|
| 1100 | + $text_stack[0] .= $this->hashPart($span); |
|
| 1101 | + $$tag = ''; # $$tag stands for $em or $strong |
|
| 1102 | + } |
|
| 1103 | + } else { |
|
| 1104 | + # Reached opening three-char emphasis marker. Push on token |
|
| 1105 | + # stack; will be handled by the special condition above. |
|
| 1106 | + $em = $token{0}; |
|
| 1107 | + $strong = "$em$em"; |
|
| 1108 | + array_unshift($token_stack, $token); |
|
| 1109 | + array_unshift($text_stack, ''); |
|
| 1110 | + $tree_char_em = true; |
|
| 1111 | + } |
|
| 1112 | + } else if ($token_len == 2) { |
|
| 1113 | + if ($strong) { |
|
| 1114 | + # Unwind any dangling emphasis marker: |
|
| 1115 | + if (strlen($token_stack[0]) == 1) { |
|
| 1116 | + $text_stack[1] .= array_shift($token_stack); |
|
| 1117 | + $text_stack[0] .= array_shift($text_stack); |
|
| 1118 | + } |
|
| 1119 | + # Closing strong marker: |
|
| 1120 | + array_shift($token_stack); |
|
| 1121 | + $span = array_shift($text_stack); |
|
| 1122 | + $span = $this->runSpanGamut($span); |
|
| 1123 | + $span = "<strong>$span</strong>"; |
|
| 1124 | + $text_stack[0] .= $this->hashPart($span); |
|
| 1125 | + $strong = ''; |
|
| 1126 | + } else { |
|
| 1127 | + array_unshift($token_stack, $token); |
|
| 1128 | + array_unshift($text_stack, ''); |
|
| 1129 | + $strong = $token; |
|
| 1130 | + } |
|
| 1131 | + } else { |
|
| 1132 | + # Here $token_len == 1 |
|
| 1133 | + if ($em) { |
|
| 1134 | + if (strlen($token_stack[0]) == 1) { |
|
| 1135 | + # Closing emphasis marker: |
|
| 1136 | + array_shift($token_stack); |
|
| 1137 | + $span = array_shift($text_stack); |
|
| 1138 | + $span = $this->runSpanGamut($span); |
|
| 1139 | + $span = "<em>$span</em>"; |
|
| 1140 | + $text_stack[0] .= $this->hashPart($span); |
|
| 1141 | + $em = ''; |
|
| 1142 | + } else { |
|
| 1143 | + $text_stack[0] .= $token; |
|
| 1144 | + } |
|
| 1145 | + } else { |
|
| 1146 | + array_unshift($token_stack, $token); |
|
| 1147 | + array_unshift($text_stack, ''); |
|
| 1148 | + $em = $token; |
|
| 1149 | + } |
|
| 1150 | + } |
|
| 1151 | + } |
|
| 1152 | + return $text_stack[0]; |
|
| 1153 | + } |
|
| 1154 | + |
|
| 1155 | + |
|
| 1156 | + protected function doBlockQuotes($text) { |
|
| 1157 | + $text = preg_replace_callback('/ |
|
| 1158 | 1158 | ( # Wrap whole match in $1 |
| 1159 | 1159 | (?> |
| 1160 | 1160 | ^[ ]*>[ ]? # ">" at the start of a line |
@@ -1164,58 +1164,58 @@ discard block |
||
| 1164 | 1164 | )+ |
| 1165 | 1165 | ) |
| 1166 | 1166 | /xm', |
| 1167 | - array($this, '_doBlockQuotes_callback'), $text); |
|
| 1168 | - |
|
| 1169 | - return $text; |
|
| 1170 | - } |
|
| 1171 | - protected function _doBlockQuotes_callback($matches) { |
|
| 1172 | - $bq = $matches[1]; |
|
| 1173 | - # trim one level of quoting - trim whitespace-only lines |
|
| 1174 | - $bq = preg_replace('/^[ ]*>[ ]?|^[ ]+$/m', '', $bq); |
|
| 1175 | - $bq = $this->runBlockGamut($bq); # recurse |
|
| 1176 | - |
|
| 1177 | - $bq = preg_replace('/^/m', " ", $bq); |
|
| 1178 | - # These leading spaces cause problem with <pre> content, |
|
| 1179 | - # so we need to fix that: |
|
| 1180 | - $bq = preg_replace_callback('{(\s*<pre>.+?</pre>)}sx', |
|
| 1181 | - array($this, '_doBlockQuotes_callback2'), $bq); |
|
| 1182 | - |
|
| 1183 | - return "\n". $this->hashBlock("<blockquote>\n$bq\n</blockquote>")."\n\n"; |
|
| 1184 | - } |
|
| 1185 | - protected function _doBlockQuotes_callback2($matches) { |
|
| 1186 | - $pre = $matches[1]; |
|
| 1187 | - $pre = preg_replace('/^ /m', '', $pre); |
|
| 1188 | - return $pre; |
|
| 1189 | - } |
|
| 1190 | - |
|
| 1191 | - |
|
| 1192 | - protected function formParagraphs($text) { |
|
| 1193 | - # |
|
| 1194 | - # Params: |
|
| 1195 | - # $text - string to process with html <p> tags |
|
| 1196 | - # |
|
| 1197 | - # Strip leading and trailing lines: |
|
| 1198 | - $text = preg_replace('/\A\n+|\n+\z/', '', $text); |
|
| 1199 | - |
|
| 1200 | - $grafs = preg_split('/\n{2,}/', $text, -1, PREG_SPLIT_NO_EMPTY); |
|
| 1201 | - |
|
| 1202 | - # |
|
| 1203 | - # Wrap <p> tags and unhashify HTML blocks |
|
| 1204 | - # |
|
| 1205 | - foreach ($grafs as $key => $value) { |
|
| 1206 | - if (!preg_match('/^B\x1A[0-9]+B$/', $value)) { |
|
| 1207 | - # Is a paragraph. |
|
| 1208 | - $value = $this->runSpanGamut($value); |
|
| 1209 | - $value = preg_replace('/^([ ]*)/', "<p>", $value); |
|
| 1210 | - $value .= "</p>"; |
|
| 1211 | - $grafs[$key] = $this->unhash($value); |
|
| 1212 | - } |
|
| 1213 | - else { |
|
| 1214 | - # Is a block. |
|
| 1215 | - # Modify elements of @grafs in-place... |
|
| 1216 | - $graf = $value; |
|
| 1217 | - $block = $this->html_hashes[$graf]; |
|
| 1218 | - $graf = $block; |
|
| 1167 | + array($this, '_doBlockQuotes_callback'), $text); |
|
| 1168 | + |
|
| 1169 | + return $text; |
|
| 1170 | + } |
|
| 1171 | + protected function _doBlockQuotes_callback($matches) { |
|
| 1172 | + $bq = $matches[1]; |
|
| 1173 | + # trim one level of quoting - trim whitespace-only lines |
|
| 1174 | + $bq = preg_replace('/^[ ]*>[ ]?|^[ ]+$/m', '', $bq); |
|
| 1175 | + $bq = $this->runBlockGamut($bq); # recurse |
|
| 1176 | + |
|
| 1177 | + $bq = preg_replace('/^/m', " ", $bq); |
|
| 1178 | + # These leading spaces cause problem with <pre> content, |
|
| 1179 | + # so we need to fix that: |
|
| 1180 | + $bq = preg_replace_callback('{(\s*<pre>.+?</pre>)}sx', |
|
| 1181 | + array($this, '_doBlockQuotes_callback2'), $bq); |
|
| 1182 | + |
|
| 1183 | + return "\n". $this->hashBlock("<blockquote>\n$bq\n</blockquote>")."\n\n"; |
|
| 1184 | + } |
|
| 1185 | + protected function _doBlockQuotes_callback2($matches) { |
|
| 1186 | + $pre = $matches[1]; |
|
| 1187 | + $pre = preg_replace('/^ /m', '', $pre); |
|
| 1188 | + return $pre; |
|
| 1189 | + } |
|
| 1190 | + |
|
| 1191 | + |
|
| 1192 | + protected function formParagraphs($text) { |
|
| 1193 | + # |
|
| 1194 | + # Params: |
|
| 1195 | + # $text - string to process with html <p> tags |
|
| 1196 | + # |
|
| 1197 | + # Strip leading and trailing lines: |
|
| 1198 | + $text = preg_replace('/\A\n+|\n+\z/', '', $text); |
|
| 1199 | + |
|
| 1200 | + $grafs = preg_split('/\n{2,}/', $text, -1, PREG_SPLIT_NO_EMPTY); |
|
| 1201 | + |
|
| 1202 | + # |
|
| 1203 | + # Wrap <p> tags and unhashify HTML blocks |
|
| 1204 | + # |
|
| 1205 | + foreach ($grafs as $key => $value) { |
|
| 1206 | + if (!preg_match('/^B\x1A[0-9]+B$/', $value)) { |
|
| 1207 | + # Is a paragraph. |
|
| 1208 | + $value = $this->runSpanGamut($value); |
|
| 1209 | + $value = preg_replace('/^([ ]*)/', "<p>", $value); |
|
| 1210 | + $value .= "</p>"; |
|
| 1211 | + $grafs[$key] = $this->unhash($value); |
|
| 1212 | + } |
|
| 1213 | + else { |
|
| 1214 | + # Is a block. |
|
| 1215 | + # Modify elements of @grafs in-place... |
|
| 1216 | + $graf = $value; |
|
| 1217 | + $block = $this->html_hashes[$graf]; |
|
| 1218 | + $graf = $block; |
|
| 1219 | 1219 | // if (preg_match('{ |
| 1220 | 1220 | // \A |
| 1221 | 1221 | // ( # $1 = <div> tag |
@@ -1251,54 +1251,54 @@ discard block |
||
| 1251 | 1251 | // |
| 1252 | 1252 | // $graf = $div_open . "\n" . $div_content . "\n" . $div_close; |
| 1253 | 1253 | // } |
| 1254 | - $grafs[$key] = $graf; |
|
| 1255 | - } |
|
| 1256 | - } |
|
| 1257 | - |
|
| 1258 | - return implode("\n\n", $grafs); |
|
| 1259 | - } |
|
| 1260 | - |
|
| 1261 | - |
|
| 1262 | - protected function encodeAttribute($text) { |
|
| 1263 | - # |
|
| 1264 | - # Encode text for a double-quoted HTML attribute. This function |
|
| 1265 | - # is *not* suitable for attributes enclosed in single quotes. |
|
| 1266 | - # |
|
| 1267 | - $text = $this->encodeAmpsAndAngles($text); |
|
| 1268 | - $text = str_replace('"', '"', $text); |
|
| 1269 | - return $text; |
|
| 1270 | - } |
|
| 1254 | + $grafs[$key] = $graf; |
|
| 1255 | + } |
|
| 1256 | + } |
|
| 1257 | + |
|
| 1258 | + return implode("\n\n", $grafs); |
|
| 1259 | + } |
|
| 1260 | + |
|
| 1261 | + |
|
| 1262 | + protected function encodeAttribute($text) { |
|
| 1263 | + # |
|
| 1264 | + # Encode text for a double-quoted HTML attribute. This function |
|
| 1265 | + # is *not* suitable for attributes enclosed in single quotes. |
|
| 1266 | + # |
|
| 1267 | + $text = $this->encodeAmpsAndAngles($text); |
|
| 1268 | + $text = str_replace('"', '"', $text); |
|
| 1269 | + return $text; |
|
| 1270 | + } |
|
| 1271 | 1271 | |
| 1272 | 1272 | |
| 1273 | - protected function encodeAmpsAndAngles($text) { |
|
| 1274 | - # |
|
| 1275 | - # Smart processing for ampersands and angle brackets that need to |
|
| 1276 | - # be encoded. Valid character entities are left alone unless the |
|
| 1277 | - # no-entities mode is set. |
|
| 1278 | - # |
|
| 1279 | - if ($this->no_entities) { |
|
| 1280 | - $text = str_replace('&', '&', $text); |
|
| 1281 | - } else { |
|
| 1282 | - # Ampersand-encoding based entirely on Nat Irons's Amputator |
|
| 1283 | - # MT plugin: <http://bumppo.net/projects/amputator/> |
|
| 1284 | - $text = preg_replace('/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/', |
|
| 1285 | - '&', $text);; |
|
| 1286 | - } |
|
| 1287 | - # Encode remaining <'s |
|
| 1288 | - $text = str_replace('<', '<', $text); |
|
| 1289 | - |
|
| 1290 | - return $text; |
|
| 1291 | - } |
|
| 1292 | - |
|
| 1293 | - |
|
| 1294 | - protected function doAutoLinks($text) { |
|
| 1295 | - $text = preg_replace_callback('/(="|<)?\b(https?|ftp)(:\/\/[-A-Z0-9+&@#\/%?=~_|\[\]\(\)!:,\.;]*[-A-Z0-9+&@#\/%=~_|\[\])])(?=$|\W)/i', |
|
| 1296 | - array($this, '_doAutoLinks_url_callback'), $text); |
|
| 1297 | - $text = preg_replace_callback('{<((https?|ftp|dict):[^\'">\s]+)>}i', |
|
| 1298 | - array($this, '_doAutoLinks_url_callback_replace'), $text); |
|
| 1299 | - |
|
| 1300 | - # Email addresses: <[email protected]> |
|
| 1301 | - $text = preg_replace_callback('{ |
|
| 1273 | + protected function encodeAmpsAndAngles($text) { |
|
| 1274 | + # |
|
| 1275 | + # Smart processing for ampersands and angle brackets that need to |
|
| 1276 | + # be encoded. Valid character entities are left alone unless the |
|
| 1277 | + # no-entities mode is set. |
|
| 1278 | + # |
|
| 1279 | + if ($this->no_entities) { |
|
| 1280 | + $text = str_replace('&', '&', $text); |
|
| 1281 | + } else { |
|
| 1282 | + # Ampersand-encoding based entirely on Nat Irons's Amputator |
|
| 1283 | + # MT plugin: <http://bumppo.net/projects/amputator/> |
|
| 1284 | + $text = preg_replace('/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/', |
|
| 1285 | + '&', $text);; |
|
| 1286 | + } |
|
| 1287 | + # Encode remaining <'s |
|
| 1288 | + $text = str_replace('<', '<', $text); |
|
| 1289 | + |
|
| 1290 | + return $text; |
|
| 1291 | + } |
|
| 1292 | + |
|
| 1293 | + |
|
| 1294 | + protected function doAutoLinks($text) { |
|
| 1295 | + $text = preg_replace_callback('/(="|<)?\b(https?|ftp)(:\/\/[-A-Z0-9+&@#\/%?=~_|\[\]\(\)!:,\.;]*[-A-Z0-9+&@#\/%=~_|\[\])])(?=$|\W)/i', |
|
| 1296 | + array($this, '_doAutoLinks_url_callback'), $text); |
|
| 1297 | + $text = preg_replace_callback('{<((https?|ftp|dict):[^\'">\s]+)>}i', |
|
| 1298 | + array($this, '_doAutoLinks_url_callback_replace'), $text); |
|
| 1299 | + |
|
| 1300 | + # Email addresses: <[email protected]> |
|
| 1301 | + $text = preg_replace_callback('{ |
|
| 1302 | 1302 | < |
| 1303 | 1303 | (?:mailto:)? |
| 1304 | 1304 | ( |
@@ -1316,10 +1316,10 @@ discard block |
||
| 1316 | 1316 | ) |
| 1317 | 1317 | > |
| 1318 | 1318 | }xi', |
| 1319 | - array($this, '_doAutoLinks_email_callback'), $text); |
|
| 1319 | + array($this, '_doAutoLinks_email_callback'), $text); |
|
| 1320 | 1320 | |
| 1321 | - return $text; |
|
| 1322 | - } |
|
| 1321 | + return $text; |
|
| 1322 | + } |
|
| 1323 | 1323 | protected function _doAutoLinks_url_callback_replace($matches) { |
| 1324 | 1324 | $url = $this->encodeAttribute($matches[1]); |
| 1325 | 1325 | $link = "<a href=\"$url\">$url</a>"; |
@@ -1328,7 +1328,7 @@ discard block |
||
| 1328 | 1328 | |
| 1329 | 1329 | private $tail; |
| 1330 | 1330 | |
| 1331 | - protected function _doAutoLinks_url_callback($matches) { |
|
| 1331 | + protected function _doAutoLinks_url_callback($matches) { |
|
| 1332 | 1332 | list ($wholeMatch, $lookbehind, $protocol, $link) = $matches; |
| 1333 | 1333 | |
| 1334 | 1334 | if ($lookbehind) { |
@@ -1360,71 +1360,71 @@ discard block |
||
| 1360 | 1360 | array($this, '_doAutoLinks_url_callback_callback'), $link); |
| 1361 | 1361 | } |
| 1362 | 1362 | |
| 1363 | - $url = $this->encodeAttribute($protocol . $link); |
|
| 1364 | - $link = "<a href=\"$url\">$url</a>"; |
|
| 1365 | - return $this->hashPart($link) . $this->tail; |
|
| 1366 | - } |
|
| 1363 | + $url = $this->encodeAttribute($protocol . $link); |
|
| 1364 | + $link = "<a href=\"$url\">$url</a>"; |
|
| 1365 | + return $this->hashPart($link) . $this->tail; |
|
| 1366 | + } |
|
| 1367 | 1367 | |
| 1368 | - protected function _doAutoLinks_email_callback($matches) { |
|
| 1369 | - $address = $matches[1]; |
|
| 1370 | - $link = $this->encodeEmailAddress($address); |
|
| 1371 | - return $this->hashPart($link); |
|
| 1372 | - } |
|
| 1368 | + protected function _doAutoLinks_email_callback($matches) { |
|
| 1369 | + $address = $matches[1]; |
|
| 1370 | + $link = $this->encodeEmailAddress($address); |
|
| 1371 | + return $this->hashPart($link); |
|
| 1372 | + } |
|
| 1373 | 1373 | |
| 1374 | 1374 | protected function _doAutoLinks_url_callback_callback($matches) { |
| 1375 | 1375 | $this->tail = $matches[0]; |
| 1376 | 1376 | return ''; |
| 1377 | 1377 | } |
| 1378 | 1378 | |
| 1379 | - protected function encodeEmailAddress($addr) { |
|
| 1380 | - # |
|
| 1381 | - # Input: an email address, e.g. "[email protected]" |
|
| 1382 | - # |
|
| 1383 | - # Output: the email address as a mailto link, with each character |
|
| 1384 | - # of the address encoded as either a decimal or hex entity, in |
|
| 1385 | - # the hopes of foiling most address harvesting spam bots. E.g.: |
|
| 1386 | - # |
|
| 1387 | - # <p><a href="mailto:foo |
|
| 1388 | - # @example.co |
|
| 1389 | - # m">foo@exampl |
|
| 1390 | - # e.com</a></p> |
|
| 1391 | - # |
|
| 1392 | - # Based by a filter by Matthew Wickline, posted to BBEdit-Talk. |
|
| 1393 | - # With some optimizations by Milian Wolff. |
|
| 1394 | - # |
|
| 1395 | - $addr = "mailto:" . $addr; |
|
| 1396 | - $chars = preg_split('/(?<!^)(?!$)/', $addr); |
|
| 1397 | - $seed = (int)abs(crc32($addr) / strlen($addr)); # Deterministic seed. |
|
| 1398 | - |
|
| 1399 | - foreach ($chars as $key => $char) { |
|
| 1400 | - $ord = ord($char); |
|
| 1401 | - # Ignore non-ascii chars. |
|
| 1402 | - if ($ord < 128) { |
|
| 1403 | - $r = ($seed * (1 + $key)) % 100; # Pseudo-random function. |
|
| 1404 | - # roughly 10% raw, 45% hex, 45% dec |
|
| 1405 | - # '@' *must* be encoded. I insist. |
|
| 1406 | - if ($r > 90 && $char != '@') /* do nothing */; |
|
| 1407 | - else if ($r < 45) $chars[$key] = '&#x'.dechex($ord).';'; |
|
| 1408 | - else $chars[$key] = '&#'.$ord.';'; |
|
| 1409 | - } |
|
| 1410 | - } |
|
| 1411 | - |
|
| 1412 | - $addr = implode('', $chars); |
|
| 1413 | - $text = implode('', array_slice($chars, 7)); # text without `mailto:` |
|
| 1414 | - $addr = "<a href=\"$addr\">$text</a>"; |
|
| 1415 | - |
|
| 1416 | - return $addr; |
|
| 1417 | - } |
|
| 1418 | - |
|
| 1419 | - |
|
| 1420 | - protected function parseSpan($str) { |
|
| 1421 | - # |
|
| 1422 | - # Take the string $str and parse it into tokens, hashing embeded HTML, |
|
| 1423 | - # escaped characters and handling code spans. |
|
| 1424 | - # |
|
| 1425 | - $output = ''; |
|
| 1426 | - |
|
| 1427 | - $span_re = '{ |
|
| 1379 | + protected function encodeEmailAddress($addr) { |
|
| 1380 | + # |
|
| 1381 | + # Input: an email address, e.g. "[email protected]" |
|
| 1382 | + # |
|
| 1383 | + # Output: the email address as a mailto link, with each character |
|
| 1384 | + # of the address encoded as either a decimal or hex entity, in |
|
| 1385 | + # the hopes of foiling most address harvesting spam bots. E.g.: |
|
| 1386 | + # |
|
| 1387 | + # <p><a href="mailto:foo |
|
| 1388 | + # @example.co |
|
| 1389 | + # m">foo@exampl |
|
| 1390 | + # e.com</a></p> |
|
| 1391 | + # |
|
| 1392 | + # Based by a filter by Matthew Wickline, posted to BBEdit-Talk. |
|
| 1393 | + # With some optimizations by Milian Wolff. |
|
| 1394 | + # |
|
| 1395 | + $addr = "mailto:" . $addr; |
|
| 1396 | + $chars = preg_split('/(?<!^)(?!$)/', $addr); |
|
| 1397 | + $seed = (int)abs(crc32($addr) / strlen($addr)); # Deterministic seed. |
|
| 1398 | + |
|
| 1399 | + foreach ($chars as $key => $char) { |
|
| 1400 | + $ord = ord($char); |
|
| 1401 | + # Ignore non-ascii chars. |
|
| 1402 | + if ($ord < 128) { |
|
| 1403 | + $r = ($seed * (1 + $key)) % 100; # Pseudo-random function. |
|
| 1404 | + # roughly 10% raw, 45% hex, 45% dec |
|
| 1405 | + # '@' *must* be encoded. I insist. |
|
| 1406 | + if ($r > 90 && $char != '@') /* do nothing */; |
|
| 1407 | + else if ($r < 45) $chars[$key] = '&#x'.dechex($ord).';'; |
|
| 1408 | + else $chars[$key] = '&#'.$ord.';'; |
|
| 1409 | + } |
|
| 1410 | + } |
|
| 1411 | + |
|
| 1412 | + $addr = implode('', $chars); |
|
| 1413 | + $text = implode('', array_slice($chars, 7)); # text without `mailto:` |
|
| 1414 | + $addr = "<a href=\"$addr\">$text</a>"; |
|
| 1415 | + |
|
| 1416 | + return $addr; |
|
| 1417 | + } |
|
| 1418 | + |
|
| 1419 | + |
|
| 1420 | + protected function parseSpan($str) { |
|
| 1421 | + # |
|
| 1422 | + # Take the string $str and parse it into tokens, hashing embeded HTML, |
|
| 1423 | + # escaped characters and handling code spans. |
|
| 1424 | + # |
|
| 1425 | + $output = ''; |
|
| 1426 | + |
|
| 1427 | + $span_re = '{ |
|
| 1428 | 1428 | ( |
| 1429 | 1429 | \\\\'.$this->escape_chars_re.' |
| 1430 | 1430 | | |
@@ -1450,127 +1450,127 @@ discard block |
||
| 1450 | 1450 | ) |
| 1451 | 1451 | }xs'; |
| 1452 | 1452 | |
| 1453 | - while (1) { |
|
| 1454 | - # |
|
| 1455 | - # Each loop iteration seach for either the next tag, the next |
|
| 1456 | - # openning code span marker, or the next escaped character. |
|
| 1457 | - # Each token is then passed to handleSpanToken. |
|
| 1458 | - # |
|
| 1459 | - $parts = preg_split($span_re, $str, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 1453 | + while (1) { |
|
| 1454 | + # |
|
| 1455 | + # Each loop iteration seach for either the next tag, the next |
|
| 1456 | + # openning code span marker, or the next escaped character. |
|
| 1457 | + # Each token is then passed to handleSpanToken. |
|
| 1458 | + # |
|
| 1459 | + $parts = preg_split($span_re, $str, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 1460 | 1460 | |
| 1461 | - # Create token from text preceding tag. |
|
| 1462 | - if ($parts[0] != "") { |
|
| 1463 | - $output .= $parts[0]; |
|
| 1464 | - } |
|
| 1461 | + # Create token from text preceding tag. |
|
| 1462 | + if ($parts[0] != "") { |
|
| 1463 | + $output .= $parts[0]; |
|
| 1464 | + } |
|
| 1465 | 1465 | |
| 1466 | - # Check if we reach the end. |
|
| 1467 | - if (isset($parts[1])) { |
|
| 1468 | - $output .= $this->handleSpanToken($parts[1], $parts[2]); |
|
| 1469 | - $str = $parts[2]; |
|
| 1470 | - } |
|
| 1471 | - else { |
|
| 1472 | - break; |
|
| 1473 | - } |
|
| 1474 | - } |
|
| 1475 | - |
|
| 1476 | - return $output; |
|
| 1477 | - } |
|
| 1466 | + # Check if we reach the end. |
|
| 1467 | + if (isset($parts[1])) { |
|
| 1468 | + $output .= $this->handleSpanToken($parts[1], $parts[2]); |
|
| 1469 | + $str = $parts[2]; |
|
| 1470 | + } |
|
| 1471 | + else { |
|
| 1472 | + break; |
|
| 1473 | + } |
|
| 1474 | + } |
|
| 1475 | + |
|
| 1476 | + return $output; |
|
| 1477 | + } |
|
| 1478 | 1478 | |
| 1479 | 1479 | |
| 1480 | - protected function handleSpanToken($token, &$str) { |
|
| 1481 | - # |
|
| 1482 | - # Handle $token provided by parseSpan by determining its nature and |
|
| 1483 | - # returning the corresponding value that should replace it. |
|
| 1484 | - # |
|
| 1485 | - switch ($token{0}) { |
|
| 1486 | - case "\\": |
|
| 1487 | - return $this->hashPart("&#". ord($token{1}). ";"); |
|
| 1488 | - case "`": |
|
| 1489 | - # Search for end marker in remaining text. |
|
| 1490 | - if (preg_match('/^(.*?[^`])'.preg_quote($token).'(?!`)(.*)$/sm', |
|
| 1491 | - $str, $matches)) |
|
| 1492 | - { |
|
| 1493 | - $str = $matches[2]; |
|
| 1494 | - $codespan = $this->makeCodeSpan($matches[1]); |
|
| 1495 | - return $this->hashPart($codespan); |
|
| 1496 | - } |
|
| 1497 | - return $token; // return as text since no ending marker found. |
|
| 1498 | - default: |
|
| 1499 | - return $this->hashPart($token); |
|
| 1500 | - } |
|
| 1501 | - } |
|
| 1502 | - |
|
| 1503 | - |
|
| 1504 | - protected function outdent($text) { |
|
| 1505 | - # |
|
| 1506 | - # Remove one level of line-leading tabs or spaces |
|
| 1507 | - # |
|
| 1508 | - return preg_replace('/^(\t|[ ]{1,'.$this->tab_width.'})/m', '', $text); |
|
| 1509 | - } |
|
| 1510 | - |
|
| 1511 | - |
|
| 1512 | - # String length function for detab. `_initDetab` will create a function to |
|
| 1513 | - # hanlde UTF-8 if the default function does not exist. |
|
| 1514 | - protected $utf8_strlen = 'mb_strlen'; |
|
| 1480 | + protected function handleSpanToken($token, &$str) { |
|
| 1481 | + # |
|
| 1482 | + # Handle $token provided by parseSpan by determining its nature and |
|
| 1483 | + # returning the corresponding value that should replace it. |
|
| 1484 | + # |
|
| 1485 | + switch ($token{0}) { |
|
| 1486 | + case "\\": |
|
| 1487 | + return $this->hashPart("&#". ord($token{1}). ";"); |
|
| 1488 | + case "`": |
|
| 1489 | + # Search for end marker in remaining text. |
|
| 1490 | + if (preg_match('/^(.*?[^`])'.preg_quote($token).'(?!`)(.*)$/sm', |
|
| 1491 | + $str, $matches)) |
|
| 1492 | + { |
|
| 1493 | + $str = $matches[2]; |
|
| 1494 | + $codespan = $this->makeCodeSpan($matches[1]); |
|
| 1495 | + return $this->hashPart($codespan); |
|
| 1496 | + } |
|
| 1497 | + return $token; // return as text since no ending marker found. |
|
| 1498 | + default: |
|
| 1499 | + return $this->hashPart($token); |
|
| 1500 | + } |
|
| 1501 | + } |
|
| 1502 | + |
|
| 1503 | + |
|
| 1504 | + protected function outdent($text) { |
|
| 1505 | + # |
|
| 1506 | + # Remove one level of line-leading tabs or spaces |
|
| 1507 | + # |
|
| 1508 | + return preg_replace('/^(\t|[ ]{1,'.$this->tab_width.'})/m', '', $text); |
|
| 1509 | + } |
|
| 1510 | + |
|
| 1511 | + |
|
| 1512 | + # String length function for detab. `_initDetab` will create a function to |
|
| 1513 | + # hanlde UTF-8 if the default function does not exist. |
|
| 1514 | + protected $utf8_strlen = 'mb_strlen'; |
|
| 1515 | 1515 | |
| 1516 | - protected function detab($text) { |
|
| 1517 | - # |
|
| 1518 | - # Replace tabs with the appropriate amount of space. |
|
| 1519 | - # |
|
| 1520 | - # For each line we separate the line in blocks delemited by |
|
| 1521 | - # tab characters. Then we reconstruct every line by adding the |
|
| 1522 | - # appropriate number of space between each blocks. |
|
| 1523 | - |
|
| 1524 | - $text = preg_replace_callback('/^.*\t.*$/m', |
|
| 1525 | - array($this, '_detab_callback'), $text); |
|
| 1526 | - |
|
| 1527 | - return $text; |
|
| 1528 | - } |
|
| 1529 | - protected function _detab_callback($matches) { |
|
| 1530 | - $line = $matches[0]; |
|
| 1531 | - $strlen = $this->utf8_strlen; # strlen function for UTF-8. |
|
| 1532 | - |
|
| 1533 | - # Split in blocks. |
|
| 1534 | - $blocks = explode("\t", $line); |
|
| 1535 | - # Add each blocks to the line. |
|
| 1536 | - $line = $blocks[0]; |
|
| 1537 | - unset($blocks[0]); # Do not add first block twice. |
|
| 1538 | - foreach ($blocks as $block) { |
|
| 1539 | - # Calculate amount of space, insert spaces, insert block. |
|
| 1540 | - $amount = $this->tab_width - |
|
| 1541 | - call_user_func($strlen, $line, 'UTF-8') % $this->tab_width; |
|
| 1542 | - $line .= str_repeat(" ", $amount) . $block; |
|
| 1543 | - } |
|
| 1544 | - return $line; |
|
| 1545 | - } |
|
| 1546 | - protected function _initDetab() { |
|
| 1547 | - # |
|
| 1548 | - # Check for the availability of the function in the `utf8_strlen` property |
|
| 1549 | - # (initially `mb_strlen`). If the function is not available, create a |
|
| 1550 | - # function that will loosely count the number of UTF-8 characters with a |
|
| 1551 | - # regular expression. |
|
| 1552 | - # |
|
| 1553 | - if (function_exists($this->utf8_strlen)) return; |
|
| 1554 | - $this->utf8_strlen = array($this, '_utf8_strlen'); |
|
| 1555 | - } |
|
| 1516 | + protected function detab($text) { |
|
| 1517 | + # |
|
| 1518 | + # Replace tabs with the appropriate amount of space. |
|
| 1519 | + # |
|
| 1520 | + # For each line we separate the line in blocks delemited by |
|
| 1521 | + # tab characters. Then we reconstruct every line by adding the |
|
| 1522 | + # appropriate number of space between each blocks. |
|
| 1523 | + |
|
| 1524 | + $text = preg_replace_callback('/^.*\t.*$/m', |
|
| 1525 | + array($this, '_detab_callback'), $text); |
|
| 1526 | + |
|
| 1527 | + return $text; |
|
| 1528 | + } |
|
| 1529 | + protected function _detab_callback($matches) { |
|
| 1530 | + $line = $matches[0]; |
|
| 1531 | + $strlen = $this->utf8_strlen; # strlen function for UTF-8. |
|
| 1532 | + |
|
| 1533 | + # Split in blocks. |
|
| 1534 | + $blocks = explode("\t", $line); |
|
| 1535 | + # Add each blocks to the line. |
|
| 1536 | + $line = $blocks[0]; |
|
| 1537 | + unset($blocks[0]); # Do not add first block twice. |
|
| 1538 | + foreach ($blocks as $block) { |
|
| 1539 | + # Calculate amount of space, insert spaces, insert block. |
|
| 1540 | + $amount = $this->tab_width - |
|
| 1541 | + call_user_func($strlen, $line, 'UTF-8') % $this->tab_width; |
|
| 1542 | + $line .= str_repeat(" ", $amount) . $block; |
|
| 1543 | + } |
|
| 1544 | + return $line; |
|
| 1545 | + } |
|
| 1546 | + protected function _initDetab() { |
|
| 1547 | + # |
|
| 1548 | + # Check for the availability of the function in the `utf8_strlen` property |
|
| 1549 | + # (initially `mb_strlen`). If the function is not available, create a |
|
| 1550 | + # function that will loosely count the number of UTF-8 characters with a |
|
| 1551 | + # regular expression. |
|
| 1552 | + # |
|
| 1553 | + if (function_exists($this->utf8_strlen)) return; |
|
| 1554 | + $this->utf8_strlen = array($this, '_utf8_strlen'); |
|
| 1555 | + } |
|
| 1556 | 1556 | |
| 1557 | 1557 | protected function _utf8_strlen($text) { |
| 1558 | 1558 | return preg_match_all( |
| 1559 | - "/[\\x00-\\xBF]|[\\xC0-\\xFF][\\x80-\\xBF]*/", |
|
| 1560 | - $text, $m); |
|
| 1559 | + "/[\\x00-\\xBF]|[\\xC0-\\xFF][\\x80-\\xBF]*/", |
|
| 1560 | + $text, $m); |
|
| 1561 | 1561 | } |
| 1562 | 1562 | |
| 1563 | 1563 | |
| 1564 | - protected function unhash($text) { |
|
| 1565 | - # |
|
| 1566 | - # Swap back in all the tags hashed by _HashHTMLBlocks. |
|
| 1567 | - # |
|
| 1568 | - return preg_replace_callback('/(.)\x1A[0-9]+\1/', |
|
| 1569 | - array($this, '_unhash_callback'), $text); |
|
| 1570 | - } |
|
| 1571 | - protected function _unhash_callback($matches) { |
|
| 1572 | - return $this->html_hashes[trim($matches[0])]; |
|
| 1573 | - } |
|
| 1564 | + protected function unhash($text) { |
|
| 1565 | + # |
|
| 1566 | + # Swap back in all the tags hashed by _HashHTMLBlocks. |
|
| 1567 | + # |
|
| 1568 | + return preg_replace_callback('/(.)\x1A[0-9]+\1/', |
|
| 1569 | + array($this, '_unhash_callback'), $text); |
|
| 1570 | + } |
|
| 1571 | + protected function _unhash_callback($matches) { |
|
| 1572 | + return $this->html_hashes[trim($matches[0])]; |
|
| 1573 | + } |
|
| 1574 | 1574 | } |
| 1575 | 1575 | |
| 1576 | 1576 | # |
@@ -1587,167 +1587,167 @@ discard block |
||
| 1587 | 1587 | |
| 1588 | 1588 | class MarkdownExtra extends _Markdown { |
| 1589 | 1589 | |
| 1590 | - ### Configuration Variables ### |
|
| 1590 | + ### Configuration Variables ### |
|
| 1591 | 1591 | |
| 1592 | - # Prefix for footnote ids. |
|
| 1593 | - public $fn_id_prefix = ""; |
|
| 1592 | + # Prefix for footnote ids. |
|
| 1593 | + public $fn_id_prefix = ""; |
|
| 1594 | 1594 | |
| 1595 | - # Optional title attribute for footnote links and backlinks. |
|
| 1596 | - public $fn_link_title = ""; |
|
| 1597 | - public $fn_backlink_title = ""; |
|
| 1595 | + # Optional title attribute for footnote links and backlinks. |
|
| 1596 | + public $fn_link_title = ""; |
|
| 1597 | + public $fn_backlink_title = ""; |
|
| 1598 | 1598 | |
| 1599 | - # Optional class attribute for footnote links and backlinks. |
|
| 1600 | - public $fn_link_class = "footnote-ref"; |
|
| 1601 | - public $fn_backlink_class = "footnote-backref"; |
|
| 1602 | - |
|
| 1603 | - # Class name for table cell alignment (%% replaced left/center/right) |
|
| 1604 | - # For instance: 'go-%%' becomes 'go-left' or 'go-right' or 'go-center' |
|
| 1605 | - # If empty, the align attribute is used instead of a class name. |
|
| 1606 | - public $table_align_class_tmpl = ''; |
|
| 1607 | - |
|
| 1608 | - # Optional class prefix for fenced code block. |
|
| 1609 | - public $code_class_prefix = ""; |
|
| 1610 | - # Class attribute for code blocks goes on the `code` tag; |
|
| 1611 | - # setting this to true will put attributes on the `pre` tag instead. |
|
| 1612 | - public $code_attr_on_pre = false; |
|
| 1599 | + # Optional class attribute for footnote links and backlinks. |
|
| 1600 | + public $fn_link_class = "footnote-ref"; |
|
| 1601 | + public $fn_backlink_class = "footnote-backref"; |
|
| 1602 | + |
|
| 1603 | + # Class name for table cell alignment (%% replaced left/center/right) |
|
| 1604 | + # For instance: 'go-%%' becomes 'go-left' or 'go-right' or 'go-center' |
|
| 1605 | + # If empty, the align attribute is used instead of a class name. |
|
| 1606 | + public $table_align_class_tmpl = ''; |
|
| 1607 | + |
|
| 1608 | + # Optional class prefix for fenced code block. |
|
| 1609 | + public $code_class_prefix = ""; |
|
| 1610 | + # Class attribute for code blocks goes on the `code` tag; |
|
| 1611 | + # setting this to true will put attributes on the `pre` tag instead. |
|
| 1612 | + public $code_attr_on_pre = false; |
|
| 1613 | 1613 | |
| 1614 | - # Predefined abbreviations. |
|
| 1615 | - public $predef_abbr = array(); |
|
| 1616 | - |
|
| 1617 | - |
|
| 1618 | - ### Parser Implementation ### |
|
| 1619 | - |
|
| 1620 | - public function __construct() { |
|
| 1621 | - # |
|
| 1622 | - # Constructor function. Initialize the parser object. |
|
| 1623 | - # |
|
| 1624 | - # Add extra escapable characters before parent constructor |
|
| 1625 | - # initialize the table. |
|
| 1626 | - $this->escape_chars .= ':|'; |
|
| 1627 | - |
|
| 1628 | - # Insert extra document, block, and span transformations. |
|
| 1629 | - # Parent constructor will do the sorting. |
|
| 1630 | - $this->document_gamut += array( |
|
| 1631 | - "doFencedCodeBlocks" => 5, |
|
| 1632 | - "stripFootnotes" => 15, |
|
| 1633 | - "stripAbbreviations" => 25, |
|
| 1634 | - "appendFootnotes" => 50, |
|
| 1635 | - ); |
|
| 1636 | - $this->block_gamut += array( |
|
| 1637 | - "doFencedCodeBlocks" => 5, |
|
| 1638 | - "doTables" => 15, |
|
| 1639 | - "doDefLists" => 45, |
|
| 1640 | - ); |
|
| 1641 | - $this->span_gamut += array( |
|
| 1642 | - "doFootnotes" => 5, |
|
| 1643 | - "doAbbreviations" => 70, |
|
| 1644 | - ); |
|
| 1645 | - |
|
| 1646 | - parent::__construct(); |
|
| 1647 | - } |
|
| 1614 | + # Predefined abbreviations. |
|
| 1615 | + public $predef_abbr = array(); |
|
| 1616 | + |
|
| 1617 | + |
|
| 1618 | + ### Parser Implementation ### |
|
| 1619 | + |
|
| 1620 | + public function __construct() { |
|
| 1621 | + # |
|
| 1622 | + # Constructor function. Initialize the parser object. |
|
| 1623 | + # |
|
| 1624 | + # Add extra escapable characters before parent constructor |
|
| 1625 | + # initialize the table. |
|
| 1626 | + $this->escape_chars .= ':|'; |
|
| 1627 | + |
|
| 1628 | + # Insert extra document, block, and span transformations. |
|
| 1629 | + # Parent constructor will do the sorting. |
|
| 1630 | + $this->document_gamut += array( |
|
| 1631 | + "doFencedCodeBlocks" => 5, |
|
| 1632 | + "stripFootnotes" => 15, |
|
| 1633 | + "stripAbbreviations" => 25, |
|
| 1634 | + "appendFootnotes" => 50, |
|
| 1635 | + ); |
|
| 1636 | + $this->block_gamut += array( |
|
| 1637 | + "doFencedCodeBlocks" => 5, |
|
| 1638 | + "doTables" => 15, |
|
| 1639 | + "doDefLists" => 45, |
|
| 1640 | + ); |
|
| 1641 | + $this->span_gamut += array( |
|
| 1642 | + "doFootnotes" => 5, |
|
| 1643 | + "doAbbreviations" => 70, |
|
| 1644 | + ); |
|
| 1645 | + |
|
| 1646 | + parent::__construct(); |
|
| 1647 | + } |
|
| 1648 | 1648 | |
| 1649 | 1649 | |
| 1650 | - # Extra variables used during extra transformations. |
|
| 1651 | - protected $footnotes = array(); |
|
| 1652 | - protected $footnotes_ordered = array(); |
|
| 1653 | - protected $footnotes_ref_count = array(); |
|
| 1654 | - protected $footnotes_numbers = array(); |
|
| 1655 | - protected $abbr_desciptions = array(); |
|
| 1656 | - protected $abbr_word_re = ''; |
|
| 1650 | + # Extra variables used during extra transformations. |
|
| 1651 | + protected $footnotes = array(); |
|
| 1652 | + protected $footnotes_ordered = array(); |
|
| 1653 | + protected $footnotes_ref_count = array(); |
|
| 1654 | + protected $footnotes_numbers = array(); |
|
| 1655 | + protected $abbr_desciptions = array(); |
|
| 1656 | + protected $abbr_word_re = ''; |
|
| 1657 | 1657 | |
| 1658 | - # Give the current footnote number. |
|
| 1659 | - protected $footnote_counter = 1; |
|
| 1658 | + # Give the current footnote number. |
|
| 1659 | + protected $footnote_counter = 1; |
|
| 1660 | 1660 | |
| 1661 | 1661 | |
| 1662 | - protected function setup() { |
|
| 1663 | - # |
|
| 1664 | - # Setting up Extra-specific variables. |
|
| 1665 | - # |
|
| 1666 | - parent::setup(); |
|
| 1667 | - |
|
| 1668 | - $this->footnotes = array(); |
|
| 1669 | - $this->footnotes_ordered = array(); |
|
| 1670 | - $this->footnotes_ref_count = array(); |
|
| 1671 | - $this->footnotes_numbers = array(); |
|
| 1672 | - $this->abbr_desciptions = array(); |
|
| 1673 | - $this->abbr_word_re = ''; |
|
| 1674 | - $this->footnote_counter = 1; |
|
| 1675 | - |
|
| 1676 | - foreach ($this->predef_abbr as $abbr_word => $abbr_desc) { |
|
| 1677 | - if ($this->abbr_word_re) |
|
| 1678 | - $this->abbr_word_re .= '|'; |
|
| 1679 | - $this->abbr_word_re .= preg_quote($abbr_word); |
|
| 1680 | - $this->abbr_desciptions[$abbr_word] = trim($abbr_desc); |
|
| 1681 | - } |
|
| 1682 | - } |
|
| 1662 | + protected function setup() { |
|
| 1663 | + # |
|
| 1664 | + # Setting up Extra-specific variables. |
|
| 1665 | + # |
|
| 1666 | + parent::setup(); |
|
| 1667 | + |
|
| 1668 | + $this->footnotes = array(); |
|
| 1669 | + $this->footnotes_ordered = array(); |
|
| 1670 | + $this->footnotes_ref_count = array(); |
|
| 1671 | + $this->footnotes_numbers = array(); |
|
| 1672 | + $this->abbr_desciptions = array(); |
|
| 1673 | + $this->abbr_word_re = ''; |
|
| 1674 | + $this->footnote_counter = 1; |
|
| 1675 | + |
|
| 1676 | + foreach ($this->predef_abbr as $abbr_word => $abbr_desc) { |
|
| 1677 | + if ($this->abbr_word_re) |
|
| 1678 | + $this->abbr_word_re .= '|'; |
|
| 1679 | + $this->abbr_word_re .= preg_quote($abbr_word); |
|
| 1680 | + $this->abbr_desciptions[$abbr_word] = trim($abbr_desc); |
|
| 1681 | + } |
|
| 1682 | + } |
|
| 1683 | 1683 | |
| 1684 | - protected function teardown() { |
|
| 1685 | - # |
|
| 1686 | - # Clearing Extra-specific variables. |
|
| 1687 | - # |
|
| 1688 | - $this->footnotes = array(); |
|
| 1689 | - $this->footnotes_ordered = array(); |
|
| 1690 | - $this->footnotes_ref_count = array(); |
|
| 1691 | - $this->footnotes_numbers = array(); |
|
| 1692 | - $this->abbr_desciptions = array(); |
|
| 1693 | - $this->abbr_word_re = ''; |
|
| 1694 | - |
|
| 1695 | - parent::teardown(); |
|
| 1696 | - } |
|
| 1684 | + protected function teardown() { |
|
| 1685 | + # |
|
| 1686 | + # Clearing Extra-specific variables. |
|
| 1687 | + # |
|
| 1688 | + $this->footnotes = array(); |
|
| 1689 | + $this->footnotes_ordered = array(); |
|
| 1690 | + $this->footnotes_ref_count = array(); |
|
| 1691 | + $this->footnotes_numbers = array(); |
|
| 1692 | + $this->abbr_desciptions = array(); |
|
| 1693 | + $this->abbr_word_re = ''; |
|
| 1694 | + |
|
| 1695 | + parent::teardown(); |
|
| 1696 | + } |
|
| 1697 | 1697 | |
| 1698 | 1698 | |
| 1699 | - ### Extra Attribute Parser ### |
|
| 1700 | - |
|
| 1701 | - # Expression to use to catch attributes (includes the braces) |
|
| 1702 | - protected $id_class_attr_catch_re = '\{((?:[ ]*[#.][-_:a-zA-Z0-9]+){1,})[ ]*\}'; |
|
| 1703 | - # Expression to use when parsing in a context when no capture is desired |
|
| 1704 | - protected $id_class_attr_nocatch_re = '\{(?:[ ]*[#.][-_:a-zA-Z0-9]+){1,}[ ]*\}'; |
|
| 1705 | - |
|
| 1706 | - protected function doExtraAttributes($tag_name, $attr) { |
|
| 1707 | - # |
|
| 1708 | - # Parse attributes caught by the $this->id_class_attr_catch_re expression |
|
| 1709 | - # and return the HTML-formatted list of attributes. |
|
| 1710 | - # |
|
| 1711 | - # Currently supported attributes are .class and #id. |
|
| 1712 | - # |
|
| 1713 | - if (empty($attr)) return ""; |
|
| 1714 | - |
|
| 1715 | - # Split on components |
|
| 1716 | - preg_match_all('/[#.][-_:a-zA-Z0-9]+/', $attr, $matches); |
|
| 1717 | - $elements = $matches[0]; |
|
| 1718 | - |
|
| 1719 | - # handle classes and ids (only first id taken into account) |
|
| 1720 | - $classes = array(); |
|
| 1721 | - $id = false; |
|
| 1722 | - foreach ($elements as $element) { |
|
| 1723 | - if ($element{0} == '.') { |
|
| 1724 | - $classes[] = substr($element, 1); |
|
| 1725 | - } else if ($element{0} == '#') { |
|
| 1726 | - if ($id === false) $id = substr($element, 1); |
|
| 1727 | - } |
|
| 1728 | - } |
|
| 1729 | - |
|
| 1730 | - # compose attributes as string |
|
| 1731 | - $attr_str = ""; |
|
| 1732 | - if (!empty($id)) { |
|
| 1733 | - $attr_str .= ' id="'.$id.'"'; |
|
| 1734 | - } |
|
| 1735 | - if (!empty($classes)) { |
|
| 1736 | - $attr_str .= ' class="'.implode(" ", $classes).'"'; |
|
| 1737 | - } |
|
| 1738 | - return $attr_str; |
|
| 1739 | - } |
|
| 1740 | - |
|
| 1741 | - |
|
| 1742 | - protected function stripLinkDefinitions($text) { |
|
| 1743 | - # |
|
| 1744 | - # Strips link definitions from text, stores the URLs and titles in |
|
| 1745 | - # hash references. |
|
| 1746 | - # |
|
| 1747 | - $less_than_tab = $this->tab_width - 1; |
|
| 1748 | - |
|
| 1749 | - # Link defs are in the form: ^[id]: url "optional title" |
|
| 1750 | - $text = preg_replace_callback('{ |
|
| 1699 | + ### Extra Attribute Parser ### |
|
| 1700 | + |
|
| 1701 | + # Expression to use to catch attributes (includes the braces) |
|
| 1702 | + protected $id_class_attr_catch_re = '\{((?:[ ]*[#.][-_:a-zA-Z0-9]+){1,})[ ]*\}'; |
|
| 1703 | + # Expression to use when parsing in a context when no capture is desired |
|
| 1704 | + protected $id_class_attr_nocatch_re = '\{(?:[ ]*[#.][-_:a-zA-Z0-9]+){1,}[ ]*\}'; |
|
| 1705 | + |
|
| 1706 | + protected function doExtraAttributes($tag_name, $attr) { |
|
| 1707 | + # |
|
| 1708 | + # Parse attributes caught by the $this->id_class_attr_catch_re expression |
|
| 1709 | + # and return the HTML-formatted list of attributes. |
|
| 1710 | + # |
|
| 1711 | + # Currently supported attributes are .class and #id. |
|
| 1712 | + # |
|
| 1713 | + if (empty($attr)) return ""; |
|
| 1714 | + |
|
| 1715 | + # Split on components |
|
| 1716 | + preg_match_all('/[#.][-_:a-zA-Z0-9]+/', $attr, $matches); |
|
| 1717 | + $elements = $matches[0]; |
|
| 1718 | + |
|
| 1719 | + # handle classes and ids (only first id taken into account) |
|
| 1720 | + $classes = array(); |
|
| 1721 | + $id = false; |
|
| 1722 | + foreach ($elements as $element) { |
|
| 1723 | + if ($element{0} == '.') { |
|
| 1724 | + $classes[] = substr($element, 1); |
|
| 1725 | + } else if ($element{0} == '#') { |
|
| 1726 | + if ($id === false) $id = substr($element, 1); |
|
| 1727 | + } |
|
| 1728 | + } |
|
| 1729 | + |
|
| 1730 | + # compose attributes as string |
|
| 1731 | + $attr_str = ""; |
|
| 1732 | + if (!empty($id)) { |
|
| 1733 | + $attr_str .= ' id="'.$id.'"'; |
|
| 1734 | + } |
|
| 1735 | + if (!empty($classes)) { |
|
| 1736 | + $attr_str .= ' class="'.implode(" ", $classes).'"'; |
|
| 1737 | + } |
|
| 1738 | + return $attr_str; |
|
| 1739 | + } |
|
| 1740 | + |
|
| 1741 | + |
|
| 1742 | + protected function stripLinkDefinitions($text) { |
|
| 1743 | + # |
|
| 1744 | + # Strips link definitions from text, stores the URLs and titles in |
|
| 1745 | + # hash references. |
|
| 1746 | + # |
|
| 1747 | + $less_than_tab = $this->tab_width - 1; |
|
| 1748 | + |
|
| 1749 | + # Link defs are in the form: ^[id]: url "optional title" |
|
| 1750 | + $text = preg_replace_callback('{ |
|
| 1751 | 1751 | ^[ ]{0,'.$less_than_tab.'}\[(.+)\][ ]?: # id = $1 |
| 1752 | 1752 | [ ]* |
| 1753 | 1753 | \n? # maybe *one* newline |
@@ -1770,106 +1770,106 @@ discard block |
||
| 1770 | 1770 | (?:[ ]* '.$this->id_class_attr_catch_re.' )? # $5 = extra id & class attr |
| 1771 | 1771 | (?:\n+|\Z) |
| 1772 | 1772 | }xm', |
| 1773 | - array($this, '_stripLinkDefinitions_callback'), |
|
| 1774 | - $text); |
|
| 1775 | - return $text; |
|
| 1776 | - } |
|
| 1777 | - protected function _stripLinkDefinitions_callback($matches) { |
|
| 1778 | - $link_id = strtolower($matches[1]); |
|
| 1779 | - $url = $matches[2] == '' ? $matches[3] : $matches[2]; |
|
| 1780 | - $this->urls[$link_id] = $url; |
|
| 1781 | - $this->titles[$link_id] =& $matches[4]; |
|
| 1782 | - $this->ref_attr[$link_id] = $this->doExtraAttributes("", $dummy =& $matches[5]); |
|
| 1783 | - return ''; # String that will replace the block |
|
| 1784 | - } |
|
| 1785 | - |
|
| 1786 | - |
|
| 1787 | - ### HTML Block Parser ### |
|
| 1773 | + array($this, '_stripLinkDefinitions_callback'), |
|
| 1774 | + $text); |
|
| 1775 | + return $text; |
|
| 1776 | + } |
|
| 1777 | + protected function _stripLinkDefinitions_callback($matches) { |
|
| 1778 | + $link_id = strtolower($matches[1]); |
|
| 1779 | + $url = $matches[2] == '' ? $matches[3] : $matches[2]; |
|
| 1780 | + $this->urls[$link_id] = $url; |
|
| 1781 | + $this->titles[$link_id] =& $matches[4]; |
|
| 1782 | + $this->ref_attr[$link_id] = $this->doExtraAttributes("", $dummy =& $matches[5]); |
|
| 1783 | + return ''; # String that will replace the block |
|
| 1784 | + } |
|
| 1785 | + |
|
| 1786 | + |
|
| 1787 | + ### HTML Block Parser ### |
|
| 1788 | 1788 | |
| 1789 | - # Tags that are always treated as block tags: |
|
| 1790 | - protected $block_tags_re = 'p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|address|form|fieldset|iframe|hr|legend|article|section|nav|aside|hgroup|header|footer|figcaption'; |
|
| 1789 | + # Tags that are always treated as block tags: |
|
| 1790 | + protected $block_tags_re = 'p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|address|form|fieldset|iframe|hr|legend|article|section|nav|aside|hgroup|header|footer|figcaption'; |
|
| 1791 | 1791 | |
| 1792 | - # Tags treated as block tags only if the opening tag is alone on its line: |
|
| 1793 | - protected $context_block_tags_re = 'script|noscript|ins|del|iframe|object|source|track|param|math|svg|canvas|audio|video'; |
|
| 1792 | + # Tags treated as block tags only if the opening tag is alone on its line: |
|
| 1793 | + protected $context_block_tags_re = 'script|noscript|ins|del|iframe|object|source|track|param|math|svg|canvas|audio|video'; |
|
| 1794 | 1794 | |
| 1795 | - # Tags where markdown="1" default to span mode: |
|
| 1796 | - protected $contain_span_tags_re = 'p|h[1-6]|li|dd|dt|td|th|legend|address'; |
|
| 1795 | + # Tags where markdown="1" default to span mode: |
|
| 1796 | + protected $contain_span_tags_re = 'p|h[1-6]|li|dd|dt|td|th|legend|address'; |
|
| 1797 | 1797 | |
| 1798 | - # Tags which must not have their contents modified, no matter where |
|
| 1799 | - # they appear: |
|
| 1800 | - protected $clean_tags_re = 'script|math|svg'; |
|
| 1798 | + # Tags which must not have their contents modified, no matter where |
|
| 1799 | + # they appear: |
|
| 1800 | + protected $clean_tags_re = 'script|math|svg'; |
|
| 1801 | 1801 | |
| 1802 | - # Tags that do not need to be closed. |
|
| 1803 | - protected $auto_close_tags_re = 'hr|img|param|source|track'; |
|
| 1802 | + # Tags that do not need to be closed. |
|
| 1803 | + protected $auto_close_tags_re = 'hr|img|param|source|track'; |
|
| 1804 | 1804 | |
| 1805 | 1805 | |
| 1806 | - protected function hashHTMLBlocks($text) { |
|
| 1807 | - # |
|
| 1808 | - # Hashify HTML Blocks and "clean tags". |
|
| 1809 | - # |
|
| 1810 | - # We only want to do this for block-level HTML tags, such as headers, |
|
| 1811 | - # lists, and tables. That's because we still want to wrap <p>s around |
|
| 1812 | - # "paragraphs" that are wrapped in non-block-level tags, such as anchors, |
|
| 1813 | - # phrase emphasis, and spans. The list of tags we're looking for is |
|
| 1814 | - # hard-coded. |
|
| 1815 | - # |
|
| 1816 | - # This works by calling _HashHTMLBlocks_InMarkdown, which then calls |
|
| 1817 | - # _HashHTMLBlocks_InHTML when it encounter block tags. When the markdown="1" |
|
| 1818 | - # attribute is found within a tag, _HashHTMLBlocks_InHTML calls back |
|
| 1819 | - # _HashHTMLBlocks_InMarkdown to handle the Markdown syntax within the tag. |
|
| 1820 | - # These two functions are calling each other. It's recursive! |
|
| 1821 | - # |
|
| 1822 | - if ($this->no_markup) return $text; |
|
| 1823 | - |
|
| 1824 | - # |
|
| 1825 | - # Call the HTML-in-Markdown hasher. |
|
| 1826 | - # |
|
| 1827 | - list($text, ) = $this->_hashHTMLBlocks_inMarkdown($text); |
|
| 1828 | - |
|
| 1829 | - return $text; |
|
| 1830 | - } |
|
| 1831 | - protected function _hashHTMLBlocks_inMarkdown($text, $indent = 0, |
|
| 1832 | - $enclosing_tag_re = '', $span = false) |
|
| 1833 | - { |
|
| 1834 | - # |
|
| 1835 | - # Parse markdown text, calling _HashHTMLBlocks_InHTML for block tags. |
|
| 1836 | - # |
|
| 1837 | - # * $indent is the number of space to be ignored when checking for code |
|
| 1838 | - # blocks. This is important because if we don't take the indent into |
|
| 1839 | - # account, something like this (which looks right) won't work as expected: |
|
| 1840 | - # |
|
| 1841 | - # <div> |
|
| 1842 | - # <div markdown="1"> |
|
| 1843 | - # Hello World. <-- Is this a Markdown code block or text? |
|
| 1844 | - # </div> <-- Is this a Markdown code block or a real tag? |
|
| 1845 | - # <div> |
|
| 1846 | - # |
|
| 1847 | - # If you don't like this, just don't indent the tag on which |
|
| 1848 | - # you apply the markdown="1" attribute. |
|
| 1849 | - # |
|
| 1850 | - # * If $enclosing_tag_re is not empty, stops at the first unmatched closing |
|
| 1851 | - # tag with that name. Nested tags supported. |
|
| 1852 | - # |
|
| 1853 | - # * If $span is true, text inside must treated as span. So any double |
|
| 1854 | - # newline will be replaced by a single newline so that it does not create |
|
| 1855 | - # paragraphs. |
|
| 1856 | - # |
|
| 1857 | - # Returns an array of that form: ( processed text , remaining text ) |
|
| 1858 | - # |
|
| 1859 | - if ($text === '') return array('', ''); |
|
| 1860 | - |
|
| 1861 | - # Regex to check for the presense of newlines around a block tag. |
|
| 1862 | - $newline_before_re = '/(?:^\n?|\n\n)*$/'; |
|
| 1863 | - $newline_after_re = |
|
| 1864 | - '{ |
|
| 1806 | + protected function hashHTMLBlocks($text) { |
|
| 1807 | + # |
|
| 1808 | + # Hashify HTML Blocks and "clean tags". |
|
| 1809 | + # |
|
| 1810 | + # We only want to do this for block-level HTML tags, such as headers, |
|
| 1811 | + # lists, and tables. That's because we still want to wrap <p>s around |
|
| 1812 | + # "paragraphs" that are wrapped in non-block-level tags, such as anchors, |
|
| 1813 | + # phrase emphasis, and spans. The list of tags we're looking for is |
|
| 1814 | + # hard-coded. |
|
| 1815 | + # |
|
| 1816 | + # This works by calling _HashHTMLBlocks_InMarkdown, which then calls |
|
| 1817 | + # _HashHTMLBlocks_InHTML when it encounter block tags. When the markdown="1" |
|
| 1818 | + # attribute is found within a tag, _HashHTMLBlocks_InHTML calls back |
|
| 1819 | + # _HashHTMLBlocks_InMarkdown to handle the Markdown syntax within the tag. |
|
| 1820 | + # These two functions are calling each other. It's recursive! |
|
| 1821 | + # |
|
| 1822 | + if ($this->no_markup) return $text; |
|
| 1823 | + |
|
| 1824 | + # |
|
| 1825 | + # Call the HTML-in-Markdown hasher. |
|
| 1826 | + # |
|
| 1827 | + list($text, ) = $this->_hashHTMLBlocks_inMarkdown($text); |
|
| 1828 | + |
|
| 1829 | + return $text; |
|
| 1830 | + } |
|
| 1831 | + protected function _hashHTMLBlocks_inMarkdown($text, $indent = 0, |
|
| 1832 | + $enclosing_tag_re = '', $span = false) |
|
| 1833 | + { |
|
| 1834 | + # |
|
| 1835 | + # Parse markdown text, calling _HashHTMLBlocks_InHTML for block tags. |
|
| 1836 | + # |
|
| 1837 | + # * $indent is the number of space to be ignored when checking for code |
|
| 1838 | + # blocks. This is important because if we don't take the indent into |
|
| 1839 | + # account, something like this (which looks right) won't work as expected: |
|
| 1840 | + # |
|
| 1841 | + # <div> |
|
| 1842 | + # <div markdown="1"> |
|
| 1843 | + # Hello World. <-- Is this a Markdown code block or text? |
|
| 1844 | + # </div> <-- Is this a Markdown code block or a real tag? |
|
| 1845 | + # <div> |
|
| 1846 | + # |
|
| 1847 | + # If you don't like this, just don't indent the tag on which |
|
| 1848 | + # you apply the markdown="1" attribute. |
|
| 1849 | + # |
|
| 1850 | + # * If $enclosing_tag_re is not empty, stops at the first unmatched closing |
|
| 1851 | + # tag with that name. Nested tags supported. |
|
| 1852 | + # |
|
| 1853 | + # * If $span is true, text inside must treated as span. So any double |
|
| 1854 | + # newline will be replaced by a single newline so that it does not create |
|
| 1855 | + # paragraphs. |
|
| 1856 | + # |
|
| 1857 | + # Returns an array of that form: ( processed text , remaining text ) |
|
| 1858 | + # |
|
| 1859 | + if ($text === '') return array('', ''); |
|
| 1860 | + |
|
| 1861 | + # Regex to check for the presense of newlines around a block tag. |
|
| 1862 | + $newline_before_re = '/(?:^\n?|\n\n)*$/'; |
|
| 1863 | + $newline_after_re = |
|
| 1864 | + '{ |
|
| 1865 | 1865 | ^ # Start of text following the tag. |
| 1866 | 1866 | (?>[ ]*<!--.*?-->)? # Optional comment. |
| 1867 | 1867 | [ ]*\n # Must be followed by newline. |
| 1868 | 1868 | }xs'; |
| 1869 | 1869 | |
| 1870 | - # Regex to match any tag. |
|
| 1871 | - $block_tag_re = |
|
| 1872 | - '{ |
|
| 1870 | + # Regex to match any tag. |
|
| 1871 | + $block_tag_re = |
|
| 1872 | + '{ |
|
| 1873 | 1873 | ( # $2: Capture whole tag. |
| 1874 | 1874 | </? # Any opening or closing tag. |
| 1875 | 1875 | (?> # Tag name. |
@@ -1921,166 +1921,166 @@ discard block |
||
| 1921 | 1921 | }xs'; |
| 1922 | 1922 | |
| 1923 | 1923 | |
| 1924 | - $depth = 0; # Current depth inside the tag tree. |
|
| 1925 | - $parsed = ""; # Parsed text that will be returned. |
|
| 1926 | - |
|
| 1927 | - # |
|
| 1928 | - # Loop through every tag until we find the closing tag of the parent |
|
| 1929 | - # or loop until reaching the end of text if no parent tag specified. |
|
| 1930 | - # |
|
| 1931 | - do { |
|
| 1932 | - # |
|
| 1933 | - # Split the text using the first $tag_match pattern found. |
|
| 1934 | - # Text before pattern will be first in the array, text after |
|
| 1935 | - # pattern will be at the end, and between will be any catches made |
|
| 1936 | - # by the pattern. |
|
| 1937 | - # |
|
| 1938 | - $parts = preg_split($block_tag_re, $text, 2, |
|
| 1939 | - PREG_SPLIT_DELIM_CAPTURE); |
|
| 1924 | + $depth = 0; # Current depth inside the tag tree. |
|
| 1925 | + $parsed = ""; # Parsed text that will be returned. |
|
| 1926 | + |
|
| 1927 | + # |
|
| 1928 | + # Loop through every tag until we find the closing tag of the parent |
|
| 1929 | + # or loop until reaching the end of text if no parent tag specified. |
|
| 1930 | + # |
|
| 1931 | + do { |
|
| 1932 | + # |
|
| 1933 | + # Split the text using the first $tag_match pattern found. |
|
| 1934 | + # Text before pattern will be first in the array, text after |
|
| 1935 | + # pattern will be at the end, and between will be any catches made |
|
| 1936 | + # by the pattern. |
|
| 1937 | + # |
|
| 1938 | + $parts = preg_split($block_tag_re, $text, 2, |
|
| 1939 | + PREG_SPLIT_DELIM_CAPTURE); |
|
| 1940 | 1940 | |
| 1941 | - # If in Markdown span mode, add a empty-string span-level hash |
|
| 1942 | - # after each newline to prevent triggering any block element. |
|
| 1943 | - if ($span) { |
|
| 1944 | - $void = $this->hashPart("", ':'); |
|
| 1945 | - $newline = "$void\n"; |
|
| 1946 | - $parts[0] = $void . str_replace("\n", $newline, $parts[0]) . $void; |
|
| 1947 | - } |
|
| 1941 | + # If in Markdown span mode, add a empty-string span-level hash |
|
| 1942 | + # after each newline to prevent triggering any block element. |
|
| 1943 | + if ($span) { |
|
| 1944 | + $void = $this->hashPart("", ':'); |
|
| 1945 | + $newline = "$void\n"; |
|
| 1946 | + $parts[0] = $void . str_replace("\n", $newline, $parts[0]) . $void; |
|
| 1947 | + } |
|
| 1948 | 1948 | |
| 1949 | - $parsed .= $parts[0]; # Text before current tag. |
|
| 1949 | + $parsed .= $parts[0]; # Text before current tag. |
|
| 1950 | 1950 | |
| 1951 | - # If end of $text has been reached. Stop loop. |
|
| 1952 | - if (count($parts) < 3) { |
|
| 1953 | - $text = ""; |
|
| 1954 | - break; |
|
| 1955 | - } |
|
| 1951 | + # If end of $text has been reached. Stop loop. |
|
| 1952 | + if (count($parts) < 3) { |
|
| 1953 | + $text = ""; |
|
| 1954 | + break; |
|
| 1955 | + } |
|
| 1956 | 1956 | |
| 1957 | - $tag = $parts[1]; # Tag to handle. |
|
| 1958 | - $text = $parts[2]; # Remaining text after current tag. |
|
| 1959 | - $tag_re = preg_quote($tag); # For use in a regular expression. |
|
| 1957 | + $tag = $parts[1]; # Tag to handle. |
|
| 1958 | + $text = $parts[2]; # Remaining text after current tag. |
|
| 1959 | + $tag_re = preg_quote($tag); # For use in a regular expression. |
|
| 1960 | 1960 | |
| 1961 | - # |
|
| 1962 | - # Check for: Code span marker |
|
| 1963 | - # |
|
| 1964 | - if ($tag{0} == "`") { |
|
| 1965 | - # Find corresponding end marker. |
|
| 1966 | - $tag_re = preg_quote($tag); |
|
| 1967 | - if (preg_match('{^(?>.+?|\n(?!\n))*?(?<!`)'.$tag_re.'(?!`)}', |
|
| 1968 | - $text, $matches)) |
|
| 1969 | - { |
|
| 1970 | - # End marker found: pass text unchanged until marker. |
|
| 1971 | - $parsed .= $tag . $matches[0]; |
|
| 1972 | - $text = substr($text, strlen($matches[0])); |
|
| 1973 | - } |
|
| 1974 | - else { |
|
| 1975 | - # Unmatched marker: just skip it. |
|
| 1976 | - $parsed .= $tag; |
|
| 1977 | - } |
|
| 1978 | - } |
|
| 1979 | - # |
|
| 1980 | - # Check for: Fenced code block marker. |
|
| 1981 | - # |
|
| 1982 | - else if (preg_match('{^\n?([ ]{0,'.($indent+3).'})(~+)}', $tag, $capture)) { |
|
| 1983 | - # Fenced code block marker: find matching end marker. |
|
| 1984 | - $fence_indent = strlen($capture[1]); # use captured indent in re |
|
| 1985 | - $fence_re = $capture[2]; # use captured fence in re |
|
| 1986 | - if (preg_match('{^(?>.*\n)*?[ ]{'.($fence_indent).'}'.$fence_re.'[ ]*(?:\n|$)}', $text, |
|
| 1987 | - $matches)) |
|
| 1988 | - { |
|
| 1989 | - # End marker found: pass text unchanged until marker. |
|
| 1990 | - $parsed .= $tag . $matches[0]; |
|
| 1991 | - $text = substr($text, strlen($matches[0])); |
|
| 1992 | - } |
|
| 1993 | - else { |
|
| 1994 | - # No end marker: just skip it. |
|
| 1995 | - $parsed .= $tag; |
|
| 1996 | - } |
|
| 1997 | - } |
|
| 1998 | - # |
|
| 1999 | - # Check for: Indented code block. |
|
| 2000 | - # |
|
| 2001 | - else if ($tag{0} == "\n" || $tag{0} == " ") { |
|
| 2002 | - # Indented code block: pass it unchanged, will be handled |
|
| 2003 | - # later. |
|
| 2004 | - $parsed .= $tag; |
|
| 2005 | - } |
|
| 2006 | - # |
|
| 2007 | - # Check for: Opening Block level tag or |
|
| 2008 | - # Opening Context Block tag (like ins and del) |
|
| 2009 | - # used as a block tag (tag is alone on it's line). |
|
| 2010 | - # |
|
| 2011 | - else if (preg_match('{^<(?:'.$this->block_tags_re.')\b}', $tag) || |
|
| 2012 | - ( preg_match('{^<(?:'.$this->context_block_tags_re.')\b}', $tag) && |
|
| 2013 | - preg_match($newline_before_re, $parsed) && |
|
| 2014 | - preg_match($newline_after_re, $text) ) |
|
| 2015 | - ) |
|
| 2016 | - { |
|
| 2017 | - # Need to parse tag and following text using the HTML parser. |
|
| 2018 | - list($block_text, $text) = |
|
| 2019 | - $this->_hashHTMLBlocks_inHTML($tag . $text, "hashBlock", true); |
|
| 1961 | + # |
|
| 1962 | + # Check for: Code span marker |
|
| 1963 | + # |
|
| 1964 | + if ($tag{0} == "`") { |
|
| 1965 | + # Find corresponding end marker. |
|
| 1966 | + $tag_re = preg_quote($tag); |
|
| 1967 | + if (preg_match('{^(?>.+?|\n(?!\n))*?(?<!`)'.$tag_re.'(?!`)}', |
|
| 1968 | + $text, $matches)) |
|
| 1969 | + { |
|
| 1970 | + # End marker found: pass text unchanged until marker. |
|
| 1971 | + $parsed .= $tag . $matches[0]; |
|
| 1972 | + $text = substr($text, strlen($matches[0])); |
|
| 1973 | + } |
|
| 1974 | + else { |
|
| 1975 | + # Unmatched marker: just skip it. |
|
| 1976 | + $parsed .= $tag; |
|
| 1977 | + } |
|
| 1978 | + } |
|
| 1979 | + # |
|
| 1980 | + # Check for: Fenced code block marker. |
|
| 1981 | + # |
|
| 1982 | + else if (preg_match('{^\n?([ ]{0,'.($indent+3).'})(~+)}', $tag, $capture)) { |
|
| 1983 | + # Fenced code block marker: find matching end marker. |
|
| 1984 | + $fence_indent = strlen($capture[1]); # use captured indent in re |
|
| 1985 | + $fence_re = $capture[2]; # use captured fence in re |
|
| 1986 | + if (preg_match('{^(?>.*\n)*?[ ]{'.($fence_indent).'}'.$fence_re.'[ ]*(?:\n|$)}', $text, |
|
| 1987 | + $matches)) |
|
| 1988 | + { |
|
| 1989 | + # End marker found: pass text unchanged until marker. |
|
| 1990 | + $parsed .= $tag . $matches[0]; |
|
| 1991 | + $text = substr($text, strlen($matches[0])); |
|
| 1992 | + } |
|
| 1993 | + else { |
|
| 1994 | + # No end marker: just skip it. |
|
| 1995 | + $parsed .= $tag; |
|
| 1996 | + } |
|
| 1997 | + } |
|
| 1998 | + # |
|
| 1999 | + # Check for: Indented code block. |
|
| 2000 | + # |
|
| 2001 | + else if ($tag{0} == "\n" || $tag{0} == " ") { |
|
| 2002 | + # Indented code block: pass it unchanged, will be handled |
|
| 2003 | + # later. |
|
| 2004 | + $parsed .= $tag; |
|
| 2005 | + } |
|
| 2006 | + # |
|
| 2007 | + # Check for: Opening Block level tag or |
|
| 2008 | + # Opening Context Block tag (like ins and del) |
|
| 2009 | + # used as a block tag (tag is alone on it's line). |
|
| 2010 | + # |
|
| 2011 | + else if (preg_match('{^<(?:'.$this->block_tags_re.')\b}', $tag) || |
|
| 2012 | + ( preg_match('{^<(?:'.$this->context_block_tags_re.')\b}', $tag) && |
|
| 2013 | + preg_match($newline_before_re, $parsed) && |
|
| 2014 | + preg_match($newline_after_re, $text) ) |
|
| 2015 | + ) |
|
| 2016 | + { |
|
| 2017 | + # Need to parse tag and following text using the HTML parser. |
|
| 2018 | + list($block_text, $text) = |
|
| 2019 | + $this->_hashHTMLBlocks_inHTML($tag . $text, "hashBlock", true); |
|
| 2020 | 2020 | |
| 2021 | - # Make sure it stays outside of any paragraph by adding newlines. |
|
| 2022 | - $parsed .= "\n\n$block_text\n\n"; |
|
| 2023 | - } |
|
| 2024 | - # |
|
| 2025 | - # Check for: Clean tag (like script, math) |
|
| 2026 | - # HTML Comments, processing instructions. |
|
| 2027 | - # |
|
| 2028 | - else if (preg_match('{^<(?:'.$this->clean_tags_re.')\b}', $tag) || |
|
| 2029 | - $tag{1} == '!' || $tag{1} == '?') |
|
| 2030 | - { |
|
| 2031 | - # Need to parse tag and following text using the HTML parser. |
|
| 2032 | - # (don't check for markdown attribute) |
|
| 2033 | - list($block_text, $text) = |
|
| 2034 | - $this->_hashHTMLBlocks_inHTML($tag . $text, "hashClean", false); |
|
| 2021 | + # Make sure it stays outside of any paragraph by adding newlines. |
|
| 2022 | + $parsed .= "\n\n$block_text\n\n"; |
|
| 2023 | + } |
|
| 2024 | + # |
|
| 2025 | + # Check for: Clean tag (like script, math) |
|
| 2026 | + # HTML Comments, processing instructions. |
|
| 2027 | + # |
|
| 2028 | + else if (preg_match('{^<(?:'.$this->clean_tags_re.')\b}', $tag) || |
|
| 2029 | + $tag{1} == '!' || $tag{1} == '?') |
|
| 2030 | + { |
|
| 2031 | + # Need to parse tag and following text using the HTML parser. |
|
| 2032 | + # (don't check for markdown attribute) |
|
| 2033 | + list($block_text, $text) = |
|
| 2034 | + $this->_hashHTMLBlocks_inHTML($tag . $text, "hashClean", false); |
|
| 2035 | 2035 | |
| 2036 | - $parsed .= $block_text; |
|
| 2037 | - } |
|
| 2038 | - # |
|
| 2039 | - # Check for: Tag with same name as enclosing tag. |
|
| 2040 | - # |
|
| 2041 | - else if ($enclosing_tag_re !== '' && |
|
| 2042 | - # Same name as enclosing tag. |
|
| 2043 | - preg_match('{^</?(?:'.$enclosing_tag_re.')\b}', $tag)) |
|
| 2044 | - { |
|
| 2045 | - # |
|
| 2046 | - # Increase/decrease nested tag count. |
|
| 2047 | - # |
|
| 2048 | - if ($tag{1} == '/') $depth--; |
|
| 2049 | - else if ($tag{strlen($tag)-2} != '/') $depth++; |
|
| 2050 | - |
|
| 2051 | - if ($depth < 0) { |
|
| 2052 | - # |
|
| 2053 | - # Going out of parent element. Clean up and break so we |
|
| 2054 | - # return to the calling function. |
|
| 2055 | - # |
|
| 2056 | - $text = $tag . $text; |
|
| 2057 | - break; |
|
| 2058 | - } |
|
| 2036 | + $parsed .= $block_text; |
|
| 2037 | + } |
|
| 2038 | + # |
|
| 2039 | + # Check for: Tag with same name as enclosing tag. |
|
| 2040 | + # |
|
| 2041 | + else if ($enclosing_tag_re !== '' && |
|
| 2042 | + # Same name as enclosing tag. |
|
| 2043 | + preg_match('{^</?(?:'.$enclosing_tag_re.')\b}', $tag)) |
|
| 2044 | + { |
|
| 2045 | + # |
|
| 2046 | + # Increase/decrease nested tag count. |
|
| 2047 | + # |
|
| 2048 | + if ($tag{1} == '/') $depth--; |
|
| 2049 | + else if ($tag{strlen($tag)-2} != '/') $depth++; |
|
| 2050 | + |
|
| 2051 | + if ($depth < 0) { |
|
| 2052 | + # |
|
| 2053 | + # Going out of parent element. Clean up and break so we |
|
| 2054 | + # return to the calling function. |
|
| 2055 | + # |
|
| 2056 | + $text = $tag . $text; |
|
| 2057 | + break; |
|
| 2058 | + } |
|
| 2059 | 2059 | |
| 2060 | - $parsed .= $tag; |
|
| 2061 | - } |
|
| 2062 | - else { |
|
| 2063 | - $parsed .= $tag; |
|
| 2064 | - } |
|
| 2065 | - } while ($depth >= 0); |
|
| 2066 | - |
|
| 2067 | - return array($parsed, $text); |
|
| 2068 | - } |
|
| 2069 | - protected function _hashHTMLBlocks_inHTML($text, $hash_method, $md_attr) { |
|
| 2070 | - # |
|
| 2071 | - # Parse HTML, calling _HashHTMLBlocks_InMarkdown for block tags. |
|
| 2072 | - # |
|
| 2073 | - # * Calls $hash_method to convert any blocks. |
|
| 2074 | - # * Stops when the first opening tag closes. |
|
| 2075 | - # * $md_attr indicate if the use of the `markdown="1"` attribute is allowed. |
|
| 2076 | - # (it is not inside clean tags) |
|
| 2077 | - # |
|
| 2078 | - # Returns an array of that form: ( processed text , remaining text ) |
|
| 2079 | - # |
|
| 2080 | - if ($text === '') return array('', ''); |
|
| 2081 | - |
|
| 2082 | - # Regex to match `markdown` attribute inside of a tag. |
|
| 2083 | - $markdown_attr_re = ' |
|
| 2060 | + $parsed .= $tag; |
|
| 2061 | + } |
|
| 2062 | + else { |
|
| 2063 | + $parsed .= $tag; |
|
| 2064 | + } |
|
| 2065 | + } while ($depth >= 0); |
|
| 2066 | + |
|
| 2067 | + return array($parsed, $text); |
|
| 2068 | + } |
|
| 2069 | + protected function _hashHTMLBlocks_inHTML($text, $hash_method, $md_attr) { |
|
| 2070 | + # |
|
| 2071 | + # Parse HTML, calling _HashHTMLBlocks_InMarkdown for block tags. |
|
| 2072 | + # |
|
| 2073 | + # * Calls $hash_method to convert any blocks. |
|
| 2074 | + # * Stops when the first opening tag closes. |
|
| 2075 | + # * $md_attr indicate if the use of the `markdown="1"` attribute is allowed. |
|
| 2076 | + # (it is not inside clean tags) |
|
| 2077 | + # |
|
| 2078 | + # Returns an array of that form: ( processed text , remaining text ) |
|
| 2079 | + # |
|
| 2080 | + if ($text === '') return array('', ''); |
|
| 2081 | + |
|
| 2082 | + # Regex to match `markdown` attribute inside of a tag. |
|
| 2083 | + $markdown_attr_re = ' |
|
| 2084 | 2084 | { |
| 2085 | 2085 | \s* # Eat whitespace before the `markdown` attribute |
| 2086 | 2086 | markdown |
@@ -2095,8 +2095,8 @@ discard block |
||
| 2095 | 2095 | () # $4: make $3 always defined (avoid warnings) |
| 2096 | 2096 | }xs'; |
| 2097 | 2097 | |
| 2098 | - # Regex to match any tag. |
|
| 2099 | - $tag_re = '{ |
|
| 2098 | + # Regex to match any tag. |
|
| 2099 | + $tag_re = '{ |
|
| 2100 | 2100 | ( # $2: Capture whole tag. |
| 2101 | 2101 | </? # Any opening or closing tag. |
| 2102 | 2102 | [\w:$]+ # Tag name. |
@@ -2118,150 +2118,150 @@ discard block |
||
| 2118 | 2118 | ) |
| 2119 | 2119 | }xs'; |
| 2120 | 2120 | |
| 2121 | - $original_text = $text; # Save original text in case of faliure. |
|
| 2122 | - |
|
| 2123 | - $depth = 0; # Current depth inside the tag tree. |
|
| 2124 | - $block_text = ""; # Temporary text holder for current text. |
|
| 2125 | - $parsed = ""; # Parsed text that will be returned. |
|
| 2126 | - |
|
| 2127 | - # |
|
| 2128 | - # Get the name of the starting tag. |
|
| 2129 | - # (This pattern makes $base_tag_name_re safe without quoting.) |
|
| 2130 | - # |
|
| 2131 | - if (preg_match('/^<([\w:$]*)\b/', $text, $matches)) |
|
| 2132 | - $base_tag_name_re = $matches[1]; |
|
| 2133 | - |
|
| 2134 | - # |
|
| 2135 | - # Loop through every tag until we find the corresponding closing tag. |
|
| 2136 | - # |
|
| 2137 | - do { |
|
| 2138 | - # |
|
| 2139 | - # Split the text using the first $tag_match pattern found. |
|
| 2140 | - # Text before pattern will be first in the array, text after |
|
| 2141 | - # pattern will be at the end, and between will be any catches made |
|
| 2142 | - # by the pattern. |
|
| 2143 | - # |
|
| 2144 | - $parts = preg_split($tag_re, $text, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 2121 | + $original_text = $text; # Save original text in case of faliure. |
|
| 2122 | + |
|
| 2123 | + $depth = 0; # Current depth inside the tag tree. |
|
| 2124 | + $block_text = ""; # Temporary text holder for current text. |
|
| 2125 | + $parsed = ""; # Parsed text that will be returned. |
|
| 2126 | + |
|
| 2127 | + # |
|
| 2128 | + # Get the name of the starting tag. |
|
| 2129 | + # (This pattern makes $base_tag_name_re safe without quoting.) |
|
| 2130 | + # |
|
| 2131 | + if (preg_match('/^<([\w:$]*)\b/', $text, $matches)) |
|
| 2132 | + $base_tag_name_re = $matches[1]; |
|
| 2133 | + |
|
| 2134 | + # |
|
| 2135 | + # Loop through every tag until we find the corresponding closing tag. |
|
| 2136 | + # |
|
| 2137 | + do { |
|
| 2138 | + # |
|
| 2139 | + # Split the text using the first $tag_match pattern found. |
|
| 2140 | + # Text before pattern will be first in the array, text after |
|
| 2141 | + # pattern will be at the end, and between will be any catches made |
|
| 2142 | + # by the pattern. |
|
| 2143 | + # |
|
| 2144 | + $parts = preg_split($tag_re, $text, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 2145 | 2145 | |
| 2146 | - if (count($parts) < 3) { |
|
| 2147 | - # |
|
| 2148 | - # End of $text reached with unbalenced tag(s). |
|
| 2149 | - # In that case, we return original text unchanged and pass the |
|
| 2150 | - # first character as filtered to prevent an infinite loop in the |
|
| 2151 | - # parent function. |
|
| 2152 | - # |
|
| 2153 | - return array($original_text{0}, substr($original_text, 1)); |
|
| 2154 | - } |
|
| 2146 | + if (count($parts) < 3) { |
|
| 2147 | + # |
|
| 2148 | + # End of $text reached with unbalenced tag(s). |
|
| 2149 | + # In that case, we return original text unchanged and pass the |
|
| 2150 | + # first character as filtered to prevent an infinite loop in the |
|
| 2151 | + # parent function. |
|
| 2152 | + # |
|
| 2153 | + return array($original_text{0}, substr($original_text, 1)); |
|
| 2154 | + } |
|
| 2155 | 2155 | |
| 2156 | - $block_text .= $parts[0]; # Text before current tag. |
|
| 2157 | - $tag = $parts[1]; # Tag to handle. |
|
| 2158 | - $text = $parts[2]; # Remaining text after current tag. |
|
| 2156 | + $block_text .= $parts[0]; # Text before current tag. |
|
| 2157 | + $tag = $parts[1]; # Tag to handle. |
|
| 2158 | + $text = $parts[2]; # Remaining text after current tag. |
|
| 2159 | 2159 | |
| 2160 | - # |
|
| 2161 | - # Check for: Auto-close tag (like <hr/>) |
|
| 2162 | - # Comments and Processing Instructions. |
|
| 2163 | - # |
|
| 2164 | - if (preg_match('{^</?(?:'.$this->auto_close_tags_re.')\b}', $tag) || |
|
| 2165 | - $tag{1} == '!' || $tag{1} == '?') |
|
| 2166 | - { |
|
| 2167 | - # Just add the tag to the block as if it was text. |
|
| 2168 | - $block_text .= $tag; |
|
| 2169 | - } |
|
| 2170 | - else { |
|
| 2171 | - # |
|
| 2172 | - # Increase/decrease nested tag count. Only do so if |
|
| 2173 | - # the tag's name match base tag's. |
|
| 2174 | - # |
|
| 2175 | - if (preg_match('{^</?'.$base_tag_name_re.'\b}', $tag)) { |
|
| 2176 | - if ($tag{1} == '/') $depth--; |
|
| 2177 | - else if ($tag{strlen($tag)-2} != '/') $depth++; |
|
| 2178 | - } |
|
| 2160 | + # |
|
| 2161 | + # Check for: Auto-close tag (like <hr/>) |
|
| 2162 | + # Comments and Processing Instructions. |
|
| 2163 | + # |
|
| 2164 | + if (preg_match('{^</?(?:'.$this->auto_close_tags_re.')\b}', $tag) || |
|
| 2165 | + $tag{1} == '!' || $tag{1} == '?') |
|
| 2166 | + { |
|
| 2167 | + # Just add the tag to the block as if it was text. |
|
| 2168 | + $block_text .= $tag; |
|
| 2169 | + } |
|
| 2170 | + else { |
|
| 2171 | + # |
|
| 2172 | + # Increase/decrease nested tag count. Only do so if |
|
| 2173 | + # the tag's name match base tag's. |
|
| 2174 | + # |
|
| 2175 | + if (preg_match('{^</?'.$base_tag_name_re.'\b}', $tag)) { |
|
| 2176 | + if ($tag{1} == '/') $depth--; |
|
| 2177 | + else if ($tag{strlen($tag)-2} != '/') $depth++; |
|
| 2178 | + } |
|
| 2179 | 2179 | |
| 2180 | - # |
|
| 2181 | - # Check for `markdown="1"` attribute and handle it. |
|
| 2182 | - # |
|
| 2183 | - if ($md_attr && |
|
| 2184 | - preg_match($markdown_attr_re, $tag, $attr_m) && |
|
| 2185 | - preg_match('/^1|block|span$/', $attr_m[2] . $attr_m[3])) |
|
| 2186 | - { |
|
| 2187 | - # Remove `markdown` attribute from opening tag. |
|
| 2188 | - $tag = preg_replace($markdown_attr_re, '', $tag); |
|
| 2180 | + # |
|
| 2181 | + # Check for `markdown="1"` attribute and handle it. |
|
| 2182 | + # |
|
| 2183 | + if ($md_attr && |
|
| 2184 | + preg_match($markdown_attr_re, $tag, $attr_m) && |
|
| 2185 | + preg_match('/^1|block|span$/', $attr_m[2] . $attr_m[3])) |
|
| 2186 | + { |
|
| 2187 | + # Remove `markdown` attribute from opening tag. |
|
| 2188 | + $tag = preg_replace($markdown_attr_re, '', $tag); |
|
| 2189 | 2189 | |
| 2190 | - # Check if text inside this tag must be parsed in span mode. |
|
| 2191 | - $this->mode = $attr_m[2] . $attr_m[3]; |
|
| 2192 | - $span_mode = $this->mode == 'span' || $this->mode != 'block' && |
|
| 2193 | - preg_match('{^<(?:'.$this->contain_span_tags_re.')\b}', $tag); |
|
| 2190 | + # Check if text inside this tag must be parsed in span mode. |
|
| 2191 | + $this->mode = $attr_m[2] . $attr_m[3]; |
|
| 2192 | + $span_mode = $this->mode == 'span' || $this->mode != 'block' && |
|
| 2193 | + preg_match('{^<(?:'.$this->contain_span_tags_re.')\b}', $tag); |
|
| 2194 | 2194 | |
| 2195 | - # Calculate indent before tag. |
|
| 2196 | - if (preg_match('/(?:^|\n)( *?)(?! ).*?$/', $block_text, $matches)) { |
|
| 2197 | - $strlen = $this->utf8_strlen; |
|
| 2198 | - $indent = call_user_func($strlen, $matches[1], 'UTF-8'); |
|
| 2199 | - } else { |
|
| 2200 | - $indent = 0; |
|
| 2201 | - } |
|
| 2195 | + # Calculate indent before tag. |
|
| 2196 | + if (preg_match('/(?:^|\n)( *?)(?! ).*?$/', $block_text, $matches)) { |
|
| 2197 | + $strlen = $this->utf8_strlen; |
|
| 2198 | + $indent = call_user_func($strlen, $matches[1], 'UTF-8'); |
|
| 2199 | + } else { |
|
| 2200 | + $indent = 0; |
|
| 2201 | + } |
|
| 2202 | 2202 | |
| 2203 | - # End preceding block with this tag. |
|
| 2204 | - $block_text .= $tag; |
|
| 2205 | - $parsed .= $this->$hash_method($block_text); |
|
| 2203 | + # End preceding block with this tag. |
|
| 2204 | + $block_text .= $tag; |
|
| 2205 | + $parsed .= $this->$hash_method($block_text); |
|
| 2206 | 2206 | |
| 2207 | - # Get enclosing tag name for the ParseMarkdown function. |
|
| 2208 | - # (This pattern makes $tag_name_re safe without quoting.) |
|
| 2209 | - preg_match('/^<([\w:$]*)\b/', $tag, $matches); |
|
| 2210 | - $tag_name_re = $matches[1]; |
|
| 2207 | + # Get enclosing tag name for the ParseMarkdown function. |
|
| 2208 | + # (This pattern makes $tag_name_re safe without quoting.) |
|
| 2209 | + preg_match('/^<([\w:$]*)\b/', $tag, $matches); |
|
| 2210 | + $tag_name_re = $matches[1]; |
|
| 2211 | 2211 | |
| 2212 | - # Parse the content using the HTML-in-Markdown parser. |
|
| 2213 | - list ($block_text, $text) |
|
| 2214 | - = $this->_hashHTMLBlocks_inMarkdown($text, $indent, |
|
| 2215 | - $tag_name_re, $span_mode); |
|
| 2212 | + # Parse the content using the HTML-in-Markdown parser. |
|
| 2213 | + list ($block_text, $text) |
|
| 2214 | + = $this->_hashHTMLBlocks_inMarkdown($text, $indent, |
|
| 2215 | + $tag_name_re, $span_mode); |
|
| 2216 | 2216 | |
| 2217 | - # Outdent markdown text. |
|
| 2218 | - if ($indent > 0) { |
|
| 2219 | - $block_text = preg_replace("/^[ ]{1,$indent}/m", "", |
|
| 2220 | - $block_text); |
|
| 2221 | - } |
|
| 2217 | + # Outdent markdown text. |
|
| 2218 | + if ($indent > 0) { |
|
| 2219 | + $block_text = preg_replace("/^[ ]{1,$indent}/m", "", |
|
| 2220 | + $block_text); |
|
| 2221 | + } |
|
| 2222 | 2222 | |
| 2223 | - # Append tag content to parsed text. |
|
| 2224 | - if (!$span_mode) $parsed .= "\n\n$block_text\n\n"; |
|
| 2225 | - else $parsed .= "$block_text"; |
|
| 2223 | + # Append tag content to parsed text. |
|
| 2224 | + if (!$span_mode) $parsed .= "\n\n$block_text\n\n"; |
|
| 2225 | + else $parsed .= "$block_text"; |
|
| 2226 | 2226 | |
| 2227 | - # Start over with a new block. |
|
| 2228 | - $block_text = ""; |
|
| 2229 | - } |
|
| 2230 | - else $block_text .= $tag; |
|
| 2231 | - } |
|
| 2227 | + # Start over with a new block. |
|
| 2228 | + $block_text = ""; |
|
| 2229 | + } |
|
| 2230 | + else $block_text .= $tag; |
|
| 2231 | + } |
|
| 2232 | 2232 | |
| 2233 | - } while ($depth > 0); |
|
| 2234 | - |
|
| 2235 | - # |
|
| 2236 | - # Hash last block text that wasn't processed inside the loop. |
|
| 2237 | - # |
|
| 2238 | - $parsed .= $this->$hash_method($block_text); |
|
| 2239 | - |
|
| 2240 | - return array($parsed, $text); |
|
| 2241 | - } |
|
| 2242 | - |
|
| 2243 | - |
|
| 2244 | - protected function hashClean($text) { |
|
| 2245 | - # |
|
| 2246 | - # Called whenever a tag must be hashed when a function inserts a "clean" tag |
|
| 2247 | - # in $text, it passes through this function and is automaticaly escaped, |
|
| 2248 | - # blocking invalid nested overlap. |
|
| 2249 | - # |
|
| 2250 | - return $this->hashPart($text, 'C'); |
|
| 2251 | - } |
|
| 2252 | - |
|
| 2253 | - |
|
| 2254 | - protected function doAnchors($text) { |
|
| 2255 | - # |
|
| 2256 | - # Turn Markdown link shortcuts into XHTML <a> tags. |
|
| 2257 | - # |
|
| 2258 | - if ($this->in_anchor) return $text; |
|
| 2259 | - $this->in_anchor = true; |
|
| 2260 | - |
|
| 2261 | - # |
|
| 2262 | - # First, handle reference-style links: [link text] [id] |
|
| 2263 | - # |
|
| 2264 | - $text = preg_replace_callback('{ |
|
| 2233 | + } while ($depth > 0); |
|
| 2234 | + |
|
| 2235 | + # |
|
| 2236 | + # Hash last block text that wasn't processed inside the loop. |
|
| 2237 | + # |
|
| 2238 | + $parsed .= $this->$hash_method($block_text); |
|
| 2239 | + |
|
| 2240 | + return array($parsed, $text); |
|
| 2241 | + } |
|
| 2242 | + |
|
| 2243 | + |
|
| 2244 | + protected function hashClean($text) { |
|
| 2245 | + # |
|
| 2246 | + # Called whenever a tag must be hashed when a function inserts a "clean" tag |
|
| 2247 | + # in $text, it passes through this function and is automaticaly escaped, |
|
| 2248 | + # blocking invalid nested overlap. |
|
| 2249 | + # |
|
| 2250 | + return $this->hashPart($text, 'C'); |
|
| 2251 | + } |
|
| 2252 | + |
|
| 2253 | + |
|
| 2254 | + protected function doAnchors($text) { |
|
| 2255 | + # |
|
| 2256 | + # Turn Markdown link shortcuts into XHTML <a> tags. |
|
| 2257 | + # |
|
| 2258 | + if ($this->in_anchor) return $text; |
|
| 2259 | + $this->in_anchor = true; |
|
| 2260 | + |
|
| 2261 | + # |
|
| 2262 | + # First, handle reference-style links: [link text] [id] |
|
| 2263 | + # |
|
| 2264 | + $text = preg_replace_callback('{ |
|
| 2265 | 2265 | ( # wrap whole match in $1 |
| 2266 | 2266 | \[ |
| 2267 | 2267 | ('.$this->nested_brackets_re.') # link text = $2 |
@@ -2275,12 +2275,12 @@ discard block |
||
| 2275 | 2275 | \] |
| 2276 | 2276 | ) |
| 2277 | 2277 | }xs', |
| 2278 | - array($this, '_doAnchors_reference_callback'), $text); |
|
| 2278 | + array($this, '_doAnchors_reference_callback'), $text); |
|
| 2279 | 2279 | |
| 2280 | - # |
|
| 2281 | - # Next, inline-style links: [link text](url "optional title") |
|
| 2282 | - # |
|
| 2283 | - $text = preg_replace_callback('{ |
|
| 2280 | + # |
|
| 2281 | + # Next, inline-style links: [link text](url "optional title") |
|
| 2282 | + # |
|
| 2283 | + $text = preg_replace_callback('{ |
|
| 2284 | 2284 | ( # wrap whole match in $1 |
| 2285 | 2285 | \[ |
| 2286 | 2286 | ('.$this->nested_brackets_re.') # link text = $2 |
@@ -2303,93 +2303,93 @@ discard block |
||
| 2303 | 2303 | (?:[ ]? '.$this->id_class_attr_catch_re.' )? # $8 = id/class attributes |
| 2304 | 2304 | ) |
| 2305 | 2305 | }xs', |
| 2306 | - array($this, '_doAnchors_inline_callback'), $text); |
|
| 2307 | - |
|
| 2308 | - # |
|
| 2309 | - # Last, handle reference-style shortcuts: [link text] |
|
| 2310 | - # These must come last in case you've also got [link text][1] |
|
| 2311 | - # or [link text](/foo) |
|
| 2312 | - # |
|
| 2313 | - $text = preg_replace_callback('{ |
|
| 2306 | + array($this, '_doAnchors_inline_callback'), $text); |
|
| 2307 | + |
|
| 2308 | + # |
|
| 2309 | + # Last, handle reference-style shortcuts: [link text] |
|
| 2310 | + # These must come last in case you've also got [link text][1] |
|
| 2311 | + # or [link text](/foo) |
|
| 2312 | + # |
|
| 2313 | + $text = preg_replace_callback('{ |
|
| 2314 | 2314 | ( # wrap whole match in $1 |
| 2315 | 2315 | \[ |
| 2316 | 2316 | ([^\[\]]+) # link text = $2; can\'t contain [ or ] |
| 2317 | 2317 | \] |
| 2318 | 2318 | ) |
| 2319 | 2319 | }xs', |
| 2320 | - array($this, '_doAnchors_reference_callback'), $text); |
|
| 2321 | - |
|
| 2322 | - $this->in_anchor = false; |
|
| 2323 | - return $text; |
|
| 2324 | - } |
|
| 2325 | - protected function _doAnchors_reference_callback($matches) { |
|
| 2326 | - $whole_match = $matches[1]; |
|
| 2327 | - $link_text = $matches[2]; |
|
| 2328 | - $link_id =& $matches[3]; |
|
| 2329 | - |
|
| 2330 | - if ($link_id == "") { |
|
| 2331 | - # for shortcut links like [this][] or [this]. |
|
| 2332 | - $link_id = $link_text; |
|
| 2333 | - } |
|
| 2334 | - |
|
| 2335 | - # lower-case and turn embedded newlines into spaces |
|
| 2336 | - $link_id = strtolower($link_id); |
|
| 2337 | - $link_id = preg_replace('{[ ]?\n}', ' ', $link_id); |
|
| 2338 | - |
|
| 2339 | - if (isset($this->urls[$link_id])) { |
|
| 2340 | - $url = $this->urls[$link_id]; |
|
| 2341 | - $url = $this->encodeAttribute($url); |
|
| 2320 | + array($this, '_doAnchors_reference_callback'), $text); |
|
| 2321 | + |
|
| 2322 | + $this->in_anchor = false; |
|
| 2323 | + return $text; |
|
| 2324 | + } |
|
| 2325 | + protected function _doAnchors_reference_callback($matches) { |
|
| 2326 | + $whole_match = $matches[1]; |
|
| 2327 | + $link_text = $matches[2]; |
|
| 2328 | + $link_id =& $matches[3]; |
|
| 2329 | + |
|
| 2330 | + if ($link_id == "") { |
|
| 2331 | + # for shortcut links like [this][] or [this]. |
|
| 2332 | + $link_id = $link_text; |
|
| 2333 | + } |
|
| 2334 | + |
|
| 2335 | + # lower-case and turn embedded newlines into spaces |
|
| 2336 | + $link_id = strtolower($link_id); |
|
| 2337 | + $link_id = preg_replace('{[ ]?\n}', ' ', $link_id); |
|
| 2338 | + |
|
| 2339 | + if (isset($this->urls[$link_id])) { |
|
| 2340 | + $url = $this->urls[$link_id]; |
|
| 2341 | + $url = $this->encodeAttribute($url); |
|
| 2342 | 2342 | |
| 2343 | - $result = "<a href=\"$url\""; |
|
| 2344 | - if ( isset( $this->titles[$link_id] ) ) { |
|
| 2345 | - $title = $this->titles[$link_id]; |
|
| 2346 | - $title = $this->encodeAttribute($title); |
|
| 2347 | - $result .= " title=\"$title\""; |
|
| 2348 | - } |
|
| 2349 | - if (isset($this->ref_attr[$link_id])) |
|
| 2350 | - $result .= $this->ref_attr[$link_id]; |
|
| 2351 | - |
|
| 2352 | - $link_text = $this->runSpanGamut($link_text); |
|
| 2353 | - $result .= ">$link_text</a>"; |
|
| 2354 | - $result = $this->hashPart($result); |
|
| 2355 | - } |
|
| 2356 | - else { |
|
| 2357 | - $result = $whole_match; |
|
| 2358 | - } |
|
| 2359 | - return $result; |
|
| 2360 | - } |
|
| 2361 | - protected function _doAnchors_inline_callback($matches) { |
|
| 2362 | - $whole_match = $matches[1]; |
|
| 2363 | - $link_text = $this->runSpanGamut($matches[2]); |
|
| 2364 | - $url = $matches[3] == '' ? $matches[4] : $matches[3]; |
|
| 2365 | - $title =& $matches[7]; |
|
| 2366 | - $attr = $this->doExtraAttributes("a", $dummy =& $matches[8]); |
|
| 2367 | - |
|
| 2368 | - |
|
| 2369 | - $url = $this->encodeAttribute($url); |
|
| 2370 | - |
|
| 2371 | - $result = "<a href=\"$url\""; |
|
| 2372 | - if (isset($title)) { |
|
| 2373 | - $title = $this->encodeAttribute($title); |
|
| 2374 | - $result .= " title=\"$title\""; |
|
| 2375 | - } |
|
| 2376 | - $result .= $attr; |
|
| 2377 | - |
|
| 2378 | - $link_text = $this->runSpanGamut($link_text); |
|
| 2379 | - $result .= ">$link_text</a>"; |
|
| 2380 | - |
|
| 2381 | - return $this->hashPart($result); |
|
| 2382 | - } |
|
| 2383 | - |
|
| 2384 | - |
|
| 2385 | - protected function doImages($text) { |
|
| 2386 | - # |
|
| 2387 | - # Turn Markdown image shortcuts into <img> tags. |
|
| 2388 | - # |
|
| 2389 | - # |
|
| 2390 | - # First, handle reference-style labeled images: ![alt text][id] |
|
| 2391 | - # |
|
| 2392 | - $text = preg_replace_callback('{ |
|
| 2343 | + $result = "<a href=\"$url\""; |
|
| 2344 | + if ( isset( $this->titles[$link_id] ) ) { |
|
| 2345 | + $title = $this->titles[$link_id]; |
|
| 2346 | + $title = $this->encodeAttribute($title); |
|
| 2347 | + $result .= " title=\"$title\""; |
|
| 2348 | + } |
|
| 2349 | + if (isset($this->ref_attr[$link_id])) |
|
| 2350 | + $result .= $this->ref_attr[$link_id]; |
|
| 2351 | + |
|
| 2352 | + $link_text = $this->runSpanGamut($link_text); |
|
| 2353 | + $result .= ">$link_text</a>"; |
|
| 2354 | + $result = $this->hashPart($result); |
|
| 2355 | + } |
|
| 2356 | + else { |
|
| 2357 | + $result = $whole_match; |
|
| 2358 | + } |
|
| 2359 | + return $result; |
|
| 2360 | + } |
|
| 2361 | + protected function _doAnchors_inline_callback($matches) { |
|
| 2362 | + $whole_match = $matches[1]; |
|
| 2363 | + $link_text = $this->runSpanGamut($matches[2]); |
|
| 2364 | + $url = $matches[3] == '' ? $matches[4] : $matches[3]; |
|
| 2365 | + $title =& $matches[7]; |
|
| 2366 | + $attr = $this->doExtraAttributes("a", $dummy =& $matches[8]); |
|
| 2367 | + |
|
| 2368 | + |
|
| 2369 | + $url = $this->encodeAttribute($url); |
|
| 2370 | + |
|
| 2371 | + $result = "<a href=\"$url\""; |
|
| 2372 | + if (isset($title)) { |
|
| 2373 | + $title = $this->encodeAttribute($title); |
|
| 2374 | + $result .= " title=\"$title\""; |
|
| 2375 | + } |
|
| 2376 | + $result .= $attr; |
|
| 2377 | + |
|
| 2378 | + $link_text = $this->runSpanGamut($link_text); |
|
| 2379 | + $result .= ">$link_text</a>"; |
|
| 2380 | + |
|
| 2381 | + return $this->hashPart($result); |
|
| 2382 | + } |
|
| 2383 | + |
|
| 2384 | + |
|
| 2385 | + protected function doImages($text) { |
|
| 2386 | + # |
|
| 2387 | + # Turn Markdown image shortcuts into <img> tags. |
|
| 2388 | + # |
|
| 2389 | + # |
|
| 2390 | + # First, handle reference-style labeled images: ![alt text][id] |
|
| 2391 | + # |
|
| 2392 | + $text = preg_replace_callback('{ |
|
| 2393 | 2393 | ( # wrap whole match in $1 |
| 2394 | 2394 | !\[ |
| 2395 | 2395 | ('.$this->nested_brackets_re.') # alt text = $2 |
@@ -2404,13 +2404,13 @@ discard block |
||
| 2404 | 2404 | |
| 2405 | 2405 | ) |
| 2406 | 2406 | }xs', |
| 2407 | - array($this, '_doImages_reference_callback'), $text); |
|
| 2407 | + array($this, '_doImages_reference_callback'), $text); |
|
| 2408 | 2408 | |
| 2409 | - # |
|
| 2410 | - # Next, handle inline images:  |
|
| 2411 | - # Don't forget: encode * and _ |
|
| 2412 | - # |
|
| 2413 | - $text = preg_replace_callback('{ |
|
| 2409 | + # |
|
| 2410 | + # Next, handle inline images:  |
|
| 2411 | + # Don't forget: encode * and _ |
|
| 2412 | + # |
|
| 2413 | + $text = preg_replace_callback('{ |
|
| 2414 | 2414 | ( # wrap whole match in $1 |
| 2415 | 2415 | !\[ |
| 2416 | 2416 | ('.$this->nested_brackets_re.') # alt text = $2 |
@@ -2434,88 +2434,88 @@ discard block |
||
| 2434 | 2434 | (?:[ ]? '.$this->id_class_attr_catch_re.' )? # $8 = id/class attributes |
| 2435 | 2435 | ) |
| 2436 | 2436 | }xs', |
| 2437 | - array($this, '_doImages_inline_callback'), $text); |
|
| 2438 | - |
|
| 2439 | - return $text; |
|
| 2440 | - } |
|
| 2441 | - protected function _doImages_reference_callback($matches) { |
|
| 2442 | - $whole_match = $matches[1]; |
|
| 2443 | - $alt_text = $matches[2]; |
|
| 2444 | - $link_id = strtolower($matches[3]); |
|
| 2445 | - |
|
| 2446 | - if ($link_id == "") { |
|
| 2447 | - $link_id = strtolower($alt_text); # for shortcut links like ![this][]. |
|
| 2448 | - } |
|
| 2449 | - |
|
| 2450 | - $alt_text = $this->encodeAttribute($alt_text); |
|
| 2451 | - if (isset($this->urls[$link_id])) { |
|
| 2452 | - $url = $this->encodeAttribute($this->urls[$link_id]); |
|
| 2453 | - $result = "<img src=\"$url\" alt=\"$alt_text\""; |
|
| 2454 | - if (isset($this->titles[$link_id])) { |
|
| 2455 | - $title = $this->titles[$link_id]; |
|
| 2456 | - $title = $this->encodeAttribute($title); |
|
| 2457 | - $result .= " title=\"$title\""; |
|
| 2458 | - } |
|
| 2459 | - if (isset($this->ref_attr[$link_id])) |
|
| 2460 | - $result .= $this->ref_attr[$link_id]; |
|
| 2461 | - $result .= $this->empty_element_suffix; |
|
| 2462 | - $result = $this->hashPart($result); |
|
| 2463 | - } |
|
| 2464 | - else { |
|
| 2465 | - # If there's no such link ID, leave intact: |
|
| 2466 | - $result = $whole_match; |
|
| 2467 | - } |
|
| 2468 | - |
|
| 2469 | - return $result; |
|
| 2470 | - } |
|
| 2471 | - protected function _doImages_inline_callback($matches) { |
|
| 2472 | - $whole_match = $matches[1]; |
|
| 2473 | - $alt_text = $matches[2]; |
|
| 2474 | - $url = $matches[3] == '' ? $matches[4] : $matches[3]; |
|
| 2475 | - $title =& $matches[7]; |
|
| 2476 | - $attr = $this->doExtraAttributes("img", $dummy =& $matches[8]); |
|
| 2477 | - |
|
| 2478 | - $alt_text = $this->encodeAttribute($alt_text); |
|
| 2479 | - $url = $this->encodeAttribute($url); |
|
| 2480 | - $result = "<img src=\"$url\" alt=\"$alt_text\""; |
|
| 2481 | - if (isset($title)) { |
|
| 2482 | - $title = $this->encodeAttribute($title); |
|
| 2483 | - $result .= " title=\"$title\""; # $title already quoted |
|
| 2484 | - } |
|
| 2485 | - $result .= $attr; |
|
| 2486 | - $result .= $this->empty_element_suffix; |
|
| 2487 | - |
|
| 2488 | - return $this->hashPart($result); |
|
| 2489 | - } |
|
| 2490 | - |
|
| 2491 | - |
|
| 2492 | - protected function doHeaders($text) { |
|
| 2493 | - # |
|
| 2494 | - # Redefined to add id and class attribute support. |
|
| 2495 | - # |
|
| 2496 | - # Setext-style headers: |
|
| 2497 | - # Header 1 {#header1} |
|
| 2498 | - # ======== |
|
| 2499 | - # |
|
| 2500 | - # Header 2 {#header2 .class1 .class2} |
|
| 2501 | - # -------- |
|
| 2502 | - # |
|
| 2503 | - $text = preg_replace_callback( |
|
| 2504 | - '{ |
|
| 2437 | + array($this, '_doImages_inline_callback'), $text); |
|
| 2438 | + |
|
| 2439 | + return $text; |
|
| 2440 | + } |
|
| 2441 | + protected function _doImages_reference_callback($matches) { |
|
| 2442 | + $whole_match = $matches[1]; |
|
| 2443 | + $alt_text = $matches[2]; |
|
| 2444 | + $link_id = strtolower($matches[3]); |
|
| 2445 | + |
|
| 2446 | + if ($link_id == "") { |
|
| 2447 | + $link_id = strtolower($alt_text); # for shortcut links like ![this][]. |
|
| 2448 | + } |
|
| 2449 | + |
|
| 2450 | + $alt_text = $this->encodeAttribute($alt_text); |
|
| 2451 | + if (isset($this->urls[$link_id])) { |
|
| 2452 | + $url = $this->encodeAttribute($this->urls[$link_id]); |
|
| 2453 | + $result = "<img src=\"$url\" alt=\"$alt_text\""; |
|
| 2454 | + if (isset($this->titles[$link_id])) { |
|
| 2455 | + $title = $this->titles[$link_id]; |
|
| 2456 | + $title = $this->encodeAttribute($title); |
|
| 2457 | + $result .= " title=\"$title\""; |
|
| 2458 | + } |
|
| 2459 | + if (isset($this->ref_attr[$link_id])) |
|
| 2460 | + $result .= $this->ref_attr[$link_id]; |
|
| 2461 | + $result .= $this->empty_element_suffix; |
|
| 2462 | + $result = $this->hashPart($result); |
|
| 2463 | + } |
|
| 2464 | + else { |
|
| 2465 | + # If there's no such link ID, leave intact: |
|
| 2466 | + $result = $whole_match; |
|
| 2467 | + } |
|
| 2468 | + |
|
| 2469 | + return $result; |
|
| 2470 | + } |
|
| 2471 | + protected function _doImages_inline_callback($matches) { |
|
| 2472 | + $whole_match = $matches[1]; |
|
| 2473 | + $alt_text = $matches[2]; |
|
| 2474 | + $url = $matches[3] == '' ? $matches[4] : $matches[3]; |
|
| 2475 | + $title =& $matches[7]; |
|
| 2476 | + $attr = $this->doExtraAttributes("img", $dummy =& $matches[8]); |
|
| 2477 | + |
|
| 2478 | + $alt_text = $this->encodeAttribute($alt_text); |
|
| 2479 | + $url = $this->encodeAttribute($url); |
|
| 2480 | + $result = "<img src=\"$url\" alt=\"$alt_text\""; |
|
| 2481 | + if (isset($title)) { |
|
| 2482 | + $title = $this->encodeAttribute($title); |
|
| 2483 | + $result .= " title=\"$title\""; # $title already quoted |
|
| 2484 | + } |
|
| 2485 | + $result .= $attr; |
|
| 2486 | + $result .= $this->empty_element_suffix; |
|
| 2487 | + |
|
| 2488 | + return $this->hashPart($result); |
|
| 2489 | + } |
|
| 2490 | + |
|
| 2491 | + |
|
| 2492 | + protected function doHeaders($text) { |
|
| 2493 | + # |
|
| 2494 | + # Redefined to add id and class attribute support. |
|
| 2495 | + # |
|
| 2496 | + # Setext-style headers: |
|
| 2497 | + # Header 1 {#header1} |
|
| 2498 | + # ======== |
|
| 2499 | + # |
|
| 2500 | + # Header 2 {#header2 .class1 .class2} |
|
| 2501 | + # -------- |
|
| 2502 | + # |
|
| 2503 | + $text = preg_replace_callback( |
|
| 2504 | + '{ |
|
| 2505 | 2505 | (^.+?) # $1: Header text |
| 2506 | 2506 | (?:[ ]+ '.$this->id_class_attr_catch_re.' )? # $3 = id/class attributes |
| 2507 | 2507 | [ ]*\n(=+|-+)[ ]*\n+ # $3: Header footer |
| 2508 | 2508 | }mx', |
| 2509 | - array($this, '_doHeaders_callback_setext'), $text); |
|
| 2510 | - |
|
| 2511 | - # atx-style headers: |
|
| 2512 | - # # Header 1 {#header1} |
|
| 2513 | - # ## Header 2 {#header2} |
|
| 2514 | - # ## Header 2 with closing hashes ## {#header3.class1.class2} |
|
| 2515 | - # ... |
|
| 2516 | - # ###### Header 6 {.class2} |
|
| 2517 | - # |
|
| 2518 | - $text = preg_replace_callback('{ |
|
| 2509 | + array($this, '_doHeaders_callback_setext'), $text); |
|
| 2510 | + |
|
| 2511 | + # atx-style headers: |
|
| 2512 | + # # Header 1 {#header1} |
|
| 2513 | + # ## Header 2 {#header2} |
|
| 2514 | + # ## Header 2 with closing hashes ## {#header3.class1.class2} |
|
| 2515 | + # ... |
|
| 2516 | + # ###### Header 6 {.class2} |
|
| 2517 | + # |
|
| 2518 | + $text = preg_replace_callback('{ |
|
| 2519 | 2519 | ^(\#{1,6}) # $1 = string of #\'s |
| 2520 | 2520 | [ ]* |
| 2521 | 2521 | (.+?) # $2 = Header text |
@@ -2525,40 +2525,40 @@ discard block |
||
| 2525 | 2525 | [ ]* |
| 2526 | 2526 | \n+ |
| 2527 | 2527 | }xm', |
| 2528 | - array($this, '_doHeaders_callback_atx'), $text); |
|
| 2529 | - |
|
| 2530 | - return $text; |
|
| 2531 | - } |
|
| 2532 | - protected function _doHeaders_callback_setext($matches) { |
|
| 2533 | - if ($matches[3] == '-' && preg_match('{^- }', $matches[1])) |
|
| 2534 | - return $matches[0]; |
|
| 2535 | - $level = $matches[3]{0} == '=' ? 1 : 2; |
|
| 2536 | - $attr = $this->doExtraAttributes("h$level", $dummy =& $matches[2]); |
|
| 2537 | - $block = "<h$level$attr>".$this->runSpanGamut($matches[1])."</h$level>"; |
|
| 2538 | - return "\n" . $this->hashBlock($block) . "\n\n"; |
|
| 2539 | - } |
|
| 2540 | - protected function _doHeaders_callback_atx($matches) { |
|
| 2541 | - $level = strlen($matches[1]); |
|
| 2542 | - $attr = $this->doExtraAttributes("h$level", $dummy =& $matches[3]); |
|
| 2543 | - $block = "<h$level$attr>".$this->runSpanGamut($matches[2])."</h$level>"; |
|
| 2544 | - return "\n" . $this->hashBlock($block) . "\n\n"; |
|
| 2545 | - } |
|
| 2546 | - |
|
| 2547 | - |
|
| 2548 | - protected function doTables($text) { |
|
| 2549 | - # |
|
| 2550 | - # Form HTML tables. |
|
| 2551 | - # |
|
| 2552 | - $less_than_tab = $this->tab_width - 1; |
|
| 2553 | - # |
|
| 2554 | - # Find tables with leading pipe. |
|
| 2555 | - # |
|
| 2556 | - # | Header 1 | Header 2 |
|
| 2557 | - # | -------- | -------- |
|
| 2558 | - # | Cell 1 | Cell 2 |
|
| 2559 | - # | Cell 3 | Cell 4 |
|
| 2560 | - # |
|
| 2561 | - $text = preg_replace_callback(' |
|
| 2528 | + array($this, '_doHeaders_callback_atx'), $text); |
|
| 2529 | + |
|
| 2530 | + return $text; |
|
| 2531 | + } |
|
| 2532 | + protected function _doHeaders_callback_setext($matches) { |
|
| 2533 | + if ($matches[3] == '-' && preg_match('{^- }', $matches[1])) |
|
| 2534 | + return $matches[0]; |
|
| 2535 | + $level = $matches[3]{0} == '=' ? 1 : 2; |
|
| 2536 | + $attr = $this->doExtraAttributes("h$level", $dummy =& $matches[2]); |
|
| 2537 | + $block = "<h$level$attr>".$this->runSpanGamut($matches[1])."</h$level>"; |
|
| 2538 | + return "\n" . $this->hashBlock($block) . "\n\n"; |
|
| 2539 | + } |
|
| 2540 | + protected function _doHeaders_callback_atx($matches) { |
|
| 2541 | + $level = strlen($matches[1]); |
|
| 2542 | + $attr = $this->doExtraAttributes("h$level", $dummy =& $matches[3]); |
|
| 2543 | + $block = "<h$level$attr>".$this->runSpanGamut($matches[2])."</h$level>"; |
|
| 2544 | + return "\n" . $this->hashBlock($block) . "\n\n"; |
|
| 2545 | + } |
|
| 2546 | + |
|
| 2547 | + |
|
| 2548 | + protected function doTables($text) { |
|
| 2549 | + # |
|
| 2550 | + # Form HTML tables. |
|
| 2551 | + # |
|
| 2552 | + $less_than_tab = $this->tab_width - 1; |
|
| 2553 | + # |
|
| 2554 | + # Find tables with leading pipe. |
|
| 2555 | + # |
|
| 2556 | + # | Header 1 | Header 2 |
|
| 2557 | + # | -------- | -------- |
|
| 2558 | + # | Cell 1 | Cell 2 |
|
| 2559 | + # | Cell 3 | Cell 4 |
|
| 2560 | + # |
|
| 2561 | + $text = preg_replace_callback(' |
|
| 2562 | 2562 | { |
| 2563 | 2563 | ^ # Start of a line |
| 2564 | 2564 | [ ]{0,'.$less_than_tab.'} # Allowed whitespace. |
@@ -2576,17 +2576,17 @@ discard block |
||
| 2576 | 2576 | ) |
| 2577 | 2577 | (?=\n|\Z) # Stop at final double newline. |
| 2578 | 2578 | }xm', |
| 2579 | - array($this, '_doTable_leadingPipe_callback'), $text); |
|
| 2580 | - |
|
| 2581 | - # |
|
| 2582 | - # Find tables without leading pipe. |
|
| 2583 | - # |
|
| 2584 | - # Header 1 | Header 2 |
|
| 2585 | - # -------- | -------- |
|
| 2586 | - # Cell 1 | Cell 2 |
|
| 2587 | - # Cell 3 | Cell 4 |
|
| 2588 | - # |
|
| 2589 | - $text = preg_replace_callback(' |
|
| 2579 | + array($this, '_doTable_leadingPipe_callback'), $text); |
|
| 2580 | + |
|
| 2581 | + # |
|
| 2582 | + # Find tables without leading pipe. |
|
| 2583 | + # |
|
| 2584 | + # Header 1 | Header 2 |
|
| 2585 | + # -------- | -------- |
|
| 2586 | + # Cell 1 | Cell 2 |
|
| 2587 | + # Cell 3 | Cell 4 |
|
| 2588 | + # |
|
| 2589 | + $text = preg_replace_callback(' |
|
| 2590 | 2590 | { |
| 2591 | 2591 | ^ # Start of a line |
| 2592 | 2592 | [ ]{0,'.$less_than_tab.'} # Allowed whitespace. |
@@ -2602,100 +2602,100 @@ discard block |
||
| 2602 | 2602 | ) |
| 2603 | 2603 | (?=\n|\Z) # Stop at final double newline. |
| 2604 | 2604 | }xm', |
| 2605 | - array($this, '_DoTable_callback'), $text); |
|
| 2606 | - |
|
| 2607 | - return $text; |
|
| 2608 | - } |
|
| 2609 | - protected function _doTable_leadingPipe_callback($matches) { |
|
| 2610 | - $head = $matches[1]; |
|
| 2611 | - $underline = $matches[2]; |
|
| 2612 | - $content = $matches[3]; |
|
| 2613 | - |
|
| 2614 | - # Remove leading pipe for each row. |
|
| 2615 | - $content = preg_replace('/^ *[|]/m', '', $content); |
|
| 2616 | - |
|
| 2617 | - return $this->_doTable_callback(array($matches[0], $head, $underline, $content)); |
|
| 2618 | - } |
|
| 2619 | - protected function _doTable_makeAlignAttr($alignname) |
|
| 2620 | - { |
|
| 2621 | - if (empty($this->table_align_class_tmpl)) |
|
| 2622 | - return " align=\"$alignname\""; |
|
| 2623 | - |
|
| 2624 | - $classname = str_replace('%%', $alignname, $this->table_align_class_tmpl); |
|
| 2625 | - return " class=\"$classname\""; |
|
| 2626 | - } |
|
| 2627 | - protected function _doTable_callback($matches) { |
|
| 2628 | - $head = $matches[1]; |
|
| 2629 | - $underline = $matches[2]; |
|
| 2630 | - $content = $matches[3]; |
|
| 2631 | - |
|
| 2632 | - # Remove any tailing pipes for each line. |
|
| 2633 | - $head = preg_replace('/[|] *$/m', '', $head); |
|
| 2634 | - $underline = preg_replace('/[|] *$/m', '', $underline); |
|
| 2635 | - $content = preg_replace('/[|] *$/m', '', $content); |
|
| 2636 | - |
|
| 2637 | - # Reading alignement from header underline. |
|
| 2638 | - $separators = preg_split('/ *[|] */', $underline); |
|
| 2639 | - foreach ($separators as $n => $s) { |
|
| 2640 | - if (preg_match('/^ *-+: *$/', $s)) |
|
| 2641 | - $attr[$n] = $this->_doTable_makeAlignAttr('right'); |
|
| 2642 | - else if (preg_match('/^ *:-+: *$/', $s)) |
|
| 2643 | - $attr[$n] = $this->_doTable_makeAlignAttr('center'); |
|
| 2644 | - else if (preg_match('/^ *:-+ *$/', $s)) |
|
| 2645 | - $attr[$n] = $this->_doTable_makeAlignAttr('left'); |
|
| 2646 | - else |
|
| 2647 | - $attr[$n] = ''; |
|
| 2648 | - } |
|
| 2649 | - |
|
| 2650 | - # Parsing span elements, including code spans, character escapes, |
|
| 2651 | - # and inline HTML tags, so that pipes inside those gets ignored. |
|
| 2652 | - $head = $this->parseSpan($head); |
|
| 2653 | - $headers = preg_split('/ *[|] */', $head); |
|
| 2654 | - $col_count = count($headers); |
|
| 2655 | - $attr = array_pad($attr, $col_count, ''); |
|
| 2656 | - |
|
| 2657 | - # Write column headers. |
|
| 2658 | - $text = "<table>\n"; |
|
| 2659 | - $text .= "<thead>\n"; |
|
| 2660 | - $text .= "<tr>\n"; |
|
| 2661 | - foreach ($headers as $n => $header) |
|
| 2662 | - $text .= " <th$attr[$n]>".$this->runSpanGamut(trim($header))."</th>\n"; |
|
| 2663 | - $text .= "</tr>\n"; |
|
| 2664 | - $text .= "</thead>\n"; |
|
| 2665 | - |
|
| 2666 | - # Split content by row. |
|
| 2667 | - $rows = explode("\n", trim($content, "\n")); |
|
| 2668 | - |
|
| 2669 | - $text .= "<tbody>\n"; |
|
| 2670 | - foreach ($rows as $row) { |
|
| 2671 | - # Parsing span elements, including code spans, character escapes, |
|
| 2672 | - # and inline HTML tags, so that pipes inside those gets ignored. |
|
| 2673 | - $row = $this->parseSpan($row); |
|
| 2605 | + array($this, '_DoTable_callback'), $text); |
|
| 2606 | + |
|
| 2607 | + return $text; |
|
| 2608 | + } |
|
| 2609 | + protected function _doTable_leadingPipe_callback($matches) { |
|
| 2610 | + $head = $matches[1]; |
|
| 2611 | + $underline = $matches[2]; |
|
| 2612 | + $content = $matches[3]; |
|
| 2613 | + |
|
| 2614 | + # Remove leading pipe for each row. |
|
| 2615 | + $content = preg_replace('/^ *[|]/m', '', $content); |
|
| 2616 | + |
|
| 2617 | + return $this->_doTable_callback(array($matches[0], $head, $underline, $content)); |
|
| 2618 | + } |
|
| 2619 | + protected function _doTable_makeAlignAttr($alignname) |
|
| 2620 | + { |
|
| 2621 | + if (empty($this->table_align_class_tmpl)) |
|
| 2622 | + return " align=\"$alignname\""; |
|
| 2623 | + |
|
| 2624 | + $classname = str_replace('%%', $alignname, $this->table_align_class_tmpl); |
|
| 2625 | + return " class=\"$classname\""; |
|
| 2626 | + } |
|
| 2627 | + protected function _doTable_callback($matches) { |
|
| 2628 | + $head = $matches[1]; |
|
| 2629 | + $underline = $matches[2]; |
|
| 2630 | + $content = $matches[3]; |
|
| 2631 | + |
|
| 2632 | + # Remove any tailing pipes for each line. |
|
| 2633 | + $head = preg_replace('/[|] *$/m', '', $head); |
|
| 2634 | + $underline = preg_replace('/[|] *$/m', '', $underline); |
|
| 2635 | + $content = preg_replace('/[|] *$/m', '', $content); |
|
| 2636 | + |
|
| 2637 | + # Reading alignement from header underline. |
|
| 2638 | + $separators = preg_split('/ *[|] */', $underline); |
|
| 2639 | + foreach ($separators as $n => $s) { |
|
| 2640 | + if (preg_match('/^ *-+: *$/', $s)) |
|
| 2641 | + $attr[$n] = $this->_doTable_makeAlignAttr('right'); |
|
| 2642 | + else if (preg_match('/^ *:-+: *$/', $s)) |
|
| 2643 | + $attr[$n] = $this->_doTable_makeAlignAttr('center'); |
|
| 2644 | + else if (preg_match('/^ *:-+ *$/', $s)) |
|
| 2645 | + $attr[$n] = $this->_doTable_makeAlignAttr('left'); |
|
| 2646 | + else |
|
| 2647 | + $attr[$n] = ''; |
|
| 2648 | + } |
|
| 2649 | + |
|
| 2650 | + # Parsing span elements, including code spans, character escapes, |
|
| 2651 | + # and inline HTML tags, so that pipes inside those gets ignored. |
|
| 2652 | + $head = $this->parseSpan($head); |
|
| 2653 | + $headers = preg_split('/ *[|] */', $head); |
|
| 2654 | + $col_count = count($headers); |
|
| 2655 | + $attr = array_pad($attr, $col_count, ''); |
|
| 2656 | + |
|
| 2657 | + # Write column headers. |
|
| 2658 | + $text = "<table>\n"; |
|
| 2659 | + $text .= "<thead>\n"; |
|
| 2660 | + $text .= "<tr>\n"; |
|
| 2661 | + foreach ($headers as $n => $header) |
|
| 2662 | + $text .= " <th$attr[$n]>".$this->runSpanGamut(trim($header))."</th>\n"; |
|
| 2663 | + $text .= "</tr>\n"; |
|
| 2664 | + $text .= "</thead>\n"; |
|
| 2665 | + |
|
| 2666 | + # Split content by row. |
|
| 2667 | + $rows = explode("\n", trim($content, "\n")); |
|
| 2668 | + |
|
| 2669 | + $text .= "<tbody>\n"; |
|
| 2670 | + foreach ($rows as $row) { |
|
| 2671 | + # Parsing span elements, including code spans, character escapes, |
|
| 2672 | + # and inline HTML tags, so that pipes inside those gets ignored. |
|
| 2673 | + $row = $this->parseSpan($row); |
|
| 2674 | 2674 | |
| 2675 | - # Split row by cell. |
|
| 2676 | - $row_cells = preg_split('/ *[|] */', $row, $col_count); |
|
| 2677 | - $row_cells = array_pad($row_cells, $col_count, ''); |
|
| 2675 | + # Split row by cell. |
|
| 2676 | + $row_cells = preg_split('/ *[|] */', $row, $col_count); |
|
| 2677 | + $row_cells = array_pad($row_cells, $col_count, ''); |
|
| 2678 | 2678 | |
| 2679 | - $text .= "<tr>\n"; |
|
| 2680 | - foreach ($row_cells as $n => $cell) |
|
| 2681 | - $text .= " <td$attr[$n]>".$this->runSpanGamut(trim($cell))."</td>\n"; |
|
| 2682 | - $text .= "</tr>\n"; |
|
| 2683 | - } |
|
| 2684 | - $text .= "</tbody>\n"; |
|
| 2685 | - $text .= "</table>"; |
|
| 2679 | + $text .= "<tr>\n"; |
|
| 2680 | + foreach ($row_cells as $n => $cell) |
|
| 2681 | + $text .= " <td$attr[$n]>".$this->runSpanGamut(trim($cell))."</td>\n"; |
|
| 2682 | + $text .= "</tr>\n"; |
|
| 2683 | + } |
|
| 2684 | + $text .= "</tbody>\n"; |
|
| 2685 | + $text .= "</table>"; |
|
| 2686 | 2686 | |
| 2687 | - return $this->hashBlock($text) . "\n"; |
|
| 2688 | - } |
|
| 2687 | + return $this->hashBlock($text) . "\n"; |
|
| 2688 | + } |
|
| 2689 | 2689 | |
| 2690 | 2690 | |
| 2691 | - protected function doDefLists($text) { |
|
| 2692 | - # |
|
| 2693 | - # Form HTML definition lists. |
|
| 2694 | - # |
|
| 2695 | - $less_than_tab = $this->tab_width - 1; |
|
| 2696 | - |
|
| 2697 | - # Re-usable pattern to match any entire dl list: |
|
| 2698 | - $whole_list_re = '(?> |
|
| 2691 | + protected function doDefLists($text) { |
|
| 2692 | + # |
|
| 2693 | + # Form HTML definition lists. |
|
| 2694 | + # |
|
| 2695 | + $less_than_tab = $this->tab_width - 1; |
|
| 2696 | + |
|
| 2697 | + # Re-usable pattern to match any entire dl list: |
|
| 2698 | + $whole_list_re = '(?> |
|
| 2699 | 2699 | ( # $1 = whole list |
| 2700 | 2700 | ( # $2 |
| 2701 | 2701 | [ ]{0,'.$less_than_tab.'} |
@@ -2722,38 +2722,38 @@ discard block |
||
| 2722 | 2722 | ) |
| 2723 | 2723 | )'; // mx |
| 2724 | 2724 | |
| 2725 | - $text = preg_replace_callback('{ |
|
| 2725 | + $text = preg_replace_callback('{ |
|
| 2726 | 2726 | (?>\A\n?|(?<=\n\n)) |
| 2727 | 2727 | '.$whole_list_re.' |
| 2728 | 2728 | }mx', |
| 2729 | - array($this, '_doDefLists_callback'), $text); |
|
| 2730 | - |
|
| 2731 | - return $text; |
|
| 2732 | - } |
|
| 2733 | - protected function _doDefLists_callback($matches) { |
|
| 2734 | - # Re-usable patterns to match list item bullets and number markers: |
|
| 2735 | - $list = $matches[1]; |
|
| 2736 | - |
|
| 2737 | - # Turn double returns into triple returns, so that we can make a |
|
| 2738 | - # paragraph for the last item in a list, if necessary: |
|
| 2739 | - $result = trim($this->processDefListItems($list)); |
|
| 2740 | - $result = "<dl>\n" . $result . "\n</dl>"; |
|
| 2741 | - return $this->hashBlock($result) . "\n\n"; |
|
| 2742 | - } |
|
| 2743 | - |
|
| 2744 | - |
|
| 2745 | - protected function processDefListItems($list_str) { |
|
| 2746 | - # |
|
| 2747 | - # Process the contents of a single definition list, splitting it |
|
| 2748 | - # into individual term and definition list items. |
|
| 2749 | - # |
|
| 2750 | - $less_than_tab = $this->tab_width - 1; |
|
| 2751 | - |
|
| 2752 | - # trim trailing blank lines: |
|
| 2753 | - $list_str = preg_replace("/\n{2,}\\z/", "\n", $list_str); |
|
| 2754 | - |
|
| 2755 | - # Process definition terms. |
|
| 2756 | - $list_str = preg_replace_callback('{ |
|
| 2729 | + array($this, '_doDefLists_callback'), $text); |
|
| 2730 | + |
|
| 2731 | + return $text; |
|
| 2732 | + } |
|
| 2733 | + protected function _doDefLists_callback($matches) { |
|
| 2734 | + # Re-usable patterns to match list item bullets and number markers: |
|
| 2735 | + $list = $matches[1]; |
|
| 2736 | + |
|
| 2737 | + # Turn double returns into triple returns, so that we can make a |
|
| 2738 | + # paragraph for the last item in a list, if necessary: |
|
| 2739 | + $result = trim($this->processDefListItems($list)); |
|
| 2740 | + $result = "<dl>\n" . $result . "\n</dl>"; |
|
| 2741 | + return $this->hashBlock($result) . "\n\n"; |
|
| 2742 | + } |
|
| 2743 | + |
|
| 2744 | + |
|
| 2745 | + protected function processDefListItems($list_str) { |
|
| 2746 | + # |
|
| 2747 | + # Process the contents of a single definition list, splitting it |
|
| 2748 | + # into individual term and definition list items. |
|
| 2749 | + # |
|
| 2750 | + $less_than_tab = $this->tab_width - 1; |
|
| 2751 | + |
|
| 2752 | + # trim trailing blank lines: |
|
| 2753 | + $list_str = preg_replace("/\n{2,}\\z/", "\n", $list_str); |
|
| 2754 | + |
|
| 2755 | + # Process definition terms. |
|
| 2756 | + $list_str = preg_replace_callback('{ |
|
| 2757 | 2757 | (?>\A\n?|\n\n+) # leading line |
| 2758 | 2758 | ( # definition terms = $1 |
| 2759 | 2759 | [ ]{0,'.$less_than_tab.'} # leading whitespace |
@@ -2764,10 +2764,10 @@ discard block |
||
| 2764 | 2764 | (?=\n?[ ]{0,3}:[ ]) # lookahead for following line feed |
| 2765 | 2765 | # with a definition mark. |
| 2766 | 2766 | }xm', |
| 2767 | - array($this, '_processDefListItems_callback_dt'), $list_str); |
|
| 2767 | + array($this, '_processDefListItems_callback_dt'), $list_str); |
|
| 2768 | 2768 | |
| 2769 | - # Process actual definitions. |
|
| 2770 | - $list_str = preg_replace_callback('{ |
|
| 2769 | + # Process actual definitions. |
|
| 2770 | + $list_str = preg_replace_callback('{ |
|
| 2771 | 2771 | \n(\n+)? # leading line = $1 |
| 2772 | 2772 | ( # marker space = $2 |
| 2773 | 2773 | [ ]{0,'.$less_than_tab.'} # whitespace before colon |
@@ -2781,50 +2781,50 @@ discard block |
||
| 2781 | 2781 | ) |
| 2782 | 2782 | ) |
| 2783 | 2783 | }xm', |
| 2784 | - array($this, '_processDefListItems_callback_dd'), $list_str); |
|
| 2785 | - |
|
| 2786 | - return $list_str; |
|
| 2787 | - } |
|
| 2788 | - protected function _processDefListItems_callback_dt($matches) { |
|
| 2789 | - $terms = explode("\n", trim($matches[1])); |
|
| 2790 | - $text = ''; |
|
| 2791 | - foreach ($terms as $term) { |
|
| 2792 | - $term = $this->runSpanGamut(trim($term)); |
|
| 2793 | - $text .= "\n<dt>" . $term . "</dt>"; |
|
| 2794 | - } |
|
| 2795 | - return $text . "\n"; |
|
| 2796 | - } |
|
| 2797 | - protected function _processDefListItems_callback_dd($matches) { |
|
| 2798 | - $leading_line = $matches[1]; |
|
| 2799 | - $marker_space = $matches[2]; |
|
| 2800 | - $def = $matches[3]; |
|
| 2801 | - |
|
| 2802 | - if ($leading_line || preg_match('/\n{2,}/', $def)) { |
|
| 2803 | - # Replace marker with the appropriate whitespace indentation |
|
| 2804 | - $def = str_repeat(' ', strlen($marker_space)) . $def; |
|
| 2805 | - $def = $this->runBlockGamut($this->outdent($def . "\n\n")); |
|
| 2806 | - $def = "\n". $def ."\n"; |
|
| 2807 | - } |
|
| 2808 | - else { |
|
| 2809 | - $def = rtrim($def); |
|
| 2810 | - $def = $this->runSpanGamut($this->outdent($def)); |
|
| 2811 | - } |
|
| 2812 | - |
|
| 2813 | - return "\n<dd>" . $def . "</dd>\n"; |
|
| 2814 | - } |
|
| 2815 | - |
|
| 2816 | - |
|
| 2817 | - protected function doFencedCodeBlocks($text) { |
|
| 2818 | - # |
|
| 2819 | - # Adding the fenced code block syntax to regular Markdown: |
|
| 2820 | - # |
|
| 2821 | - # ~~~ |
|
| 2822 | - # Code block |
|
| 2823 | - # ~~~ |
|
| 2824 | - # |
|
| 2825 | - $less_than_tab = $this->tab_width; |
|
| 2826 | - |
|
| 2827 | - $text = preg_replace_callback('{ |
|
| 2784 | + array($this, '_processDefListItems_callback_dd'), $list_str); |
|
| 2785 | + |
|
| 2786 | + return $list_str; |
|
| 2787 | + } |
|
| 2788 | + protected function _processDefListItems_callback_dt($matches) { |
|
| 2789 | + $terms = explode("\n", trim($matches[1])); |
|
| 2790 | + $text = ''; |
|
| 2791 | + foreach ($terms as $term) { |
|
| 2792 | + $term = $this->runSpanGamut(trim($term)); |
|
| 2793 | + $text .= "\n<dt>" . $term . "</dt>"; |
|
| 2794 | + } |
|
| 2795 | + return $text . "\n"; |
|
| 2796 | + } |
|
| 2797 | + protected function _processDefListItems_callback_dd($matches) { |
|
| 2798 | + $leading_line = $matches[1]; |
|
| 2799 | + $marker_space = $matches[2]; |
|
| 2800 | + $def = $matches[3]; |
|
| 2801 | + |
|
| 2802 | + if ($leading_line || preg_match('/\n{2,}/', $def)) { |
|
| 2803 | + # Replace marker with the appropriate whitespace indentation |
|
| 2804 | + $def = str_repeat(' ', strlen($marker_space)) . $def; |
|
| 2805 | + $def = $this->runBlockGamut($this->outdent($def . "\n\n")); |
|
| 2806 | + $def = "\n". $def ."\n"; |
|
| 2807 | + } |
|
| 2808 | + else { |
|
| 2809 | + $def = rtrim($def); |
|
| 2810 | + $def = $this->runSpanGamut($this->outdent($def)); |
|
| 2811 | + } |
|
| 2812 | + |
|
| 2813 | + return "\n<dd>" . $def . "</dd>\n"; |
|
| 2814 | + } |
|
| 2815 | + |
|
| 2816 | + |
|
| 2817 | + protected function doFencedCodeBlocks($text) { |
|
| 2818 | + # |
|
| 2819 | + # Adding the fenced code block syntax to regular Markdown: |
|
| 2820 | + # |
|
| 2821 | + # ~~~ |
|
| 2822 | + # Code block |
|
| 2823 | + # ~~~ |
|
| 2824 | + # |
|
| 2825 | + $less_than_tab = $this->tab_width; |
|
| 2826 | + |
|
| 2827 | + $text = preg_replace_callback('{ |
|
| 2828 | 2828 | (?:\n|\A) |
| 2829 | 2829 | # 1: Opening marker |
| 2830 | 2830 | ( |
@@ -2849,105 +2849,105 @@ discard block |
||
| 2849 | 2849 | # Closing marker. |
| 2850 | 2850 | \1 [ ]* \n |
| 2851 | 2851 | }xm', |
| 2852 | - array($this, '_doFencedCodeBlocks_callback'), $text); |
|
| 2853 | - |
|
| 2854 | - return $text; |
|
| 2855 | - } |
|
| 2856 | - protected function _doFencedCodeBlocks_callback($matches) { |
|
| 2857 | - $classname =& $matches[2]; |
|
| 2858 | - $attrs =& $matches[3]; |
|
| 2859 | - $codeblock = $matches[4]; |
|
| 2860 | - $codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES); |
|
| 2861 | - $codeblock = preg_replace_callback('/^\n+/', |
|
| 2862 | - array($this, '_doFencedCodeBlocks_newlines'), $codeblock); |
|
| 2863 | - |
|
| 2864 | - if ($classname != "") { |
|
| 2865 | - if ($classname{0} == '.') |
|
| 2866 | - $classname = substr($classname, 1); |
|
| 2867 | - $attr_str = ' class="'.$this->code_class_prefix.$classname.'"'; |
|
| 2868 | - } else { |
|
| 2869 | - $attr_str = $this->doExtraAttributes($this->code_attr_on_pre ? "pre" : "code", $attrs); |
|
| 2870 | - } |
|
| 2871 | - $pre_attr_str = $this->code_attr_on_pre ? $attr_str : ''; |
|
| 2872 | - $code_attr_str = $this->code_attr_on_pre ? '' : $attr_str; |
|
| 2873 | - $codeblock = "<pre$pre_attr_str><code$code_attr_str>$codeblock</code></pre>"; |
|
| 2874 | - |
|
| 2875 | - return "\n\n".$this->hashBlock($codeblock)."\n\n"; |
|
| 2876 | - } |
|
| 2877 | - protected function _doFencedCodeBlocks_newlines($matches) { |
|
| 2878 | - return str_repeat("<br$this->empty_element_suffix", |
|
| 2879 | - strlen($matches[0])); |
|
| 2880 | - } |
|
| 2881 | - |
|
| 2882 | - |
|
| 2883 | - # |
|
| 2884 | - # Redefining emphasis markers so that emphasis by underscore does not |
|
| 2885 | - # work in the middle of a word. |
|
| 2886 | - # |
|
| 2887 | - protected $em_relist = array( |
|
| 2888 | - '' => '(?:(?<!\*)\*(?!\*)|(?<![a-zA-Z0-9_])_(?!_))(?=\S|$)(?![\.,:;]\s)', |
|
| 2889 | - '*' => '(?<=\S|^)(?<!\*)\*(?!\*)', |
|
| 2890 | - '_' => '(?<=\S|^)(?<!_)_(?![a-zA-Z0-9_])', |
|
| 2891 | - ); |
|
| 2892 | - protected $strong_relist = array( |
|
| 2893 | - '' => '(?:(?<!\*)\*\*(?!\*)|(?<![a-zA-Z0-9_])__(?!_))(?=\S|$)(?![\.,:;]\s)', |
|
| 2894 | - '**' => '(?<=\S|^)(?<!\*)\*\*(?!\*)', |
|
| 2895 | - '__' => '(?<=\S|^)(?<!_)__(?![a-zA-Z0-9_])', |
|
| 2896 | - ); |
|
| 2897 | - protected $em_strong_relist = array( |
|
| 2898 | - '' => '(?:(?<!\*)\*\*\*(?!\*)|(?<![a-zA-Z0-9_])___(?!_))(?=\S|$)(?![\.,:;]\s)', |
|
| 2899 | - '***' => '(?<=\S|^)(?<!\*)\*\*\*(?!\*)', |
|
| 2900 | - '___' => '(?<=\S|^)(?<!_)___(?![a-zA-Z0-9_])', |
|
| 2901 | - ); |
|
| 2852 | + array($this, '_doFencedCodeBlocks_callback'), $text); |
|
| 2853 | + |
|
| 2854 | + return $text; |
|
| 2855 | + } |
|
| 2856 | + protected function _doFencedCodeBlocks_callback($matches) { |
|
| 2857 | + $classname =& $matches[2]; |
|
| 2858 | + $attrs =& $matches[3]; |
|
| 2859 | + $codeblock = $matches[4]; |
|
| 2860 | + $codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES); |
|
| 2861 | + $codeblock = preg_replace_callback('/^\n+/', |
|
| 2862 | + array($this, '_doFencedCodeBlocks_newlines'), $codeblock); |
|
| 2863 | + |
|
| 2864 | + if ($classname != "") { |
|
| 2865 | + if ($classname{0} == '.') |
|
| 2866 | + $classname = substr($classname, 1); |
|
| 2867 | + $attr_str = ' class="'.$this->code_class_prefix.$classname.'"'; |
|
| 2868 | + } else { |
|
| 2869 | + $attr_str = $this->doExtraAttributes($this->code_attr_on_pre ? "pre" : "code", $attrs); |
|
| 2870 | + } |
|
| 2871 | + $pre_attr_str = $this->code_attr_on_pre ? $attr_str : ''; |
|
| 2872 | + $code_attr_str = $this->code_attr_on_pre ? '' : $attr_str; |
|
| 2873 | + $codeblock = "<pre$pre_attr_str><code$code_attr_str>$codeblock</code></pre>"; |
|
| 2874 | + |
|
| 2875 | + return "\n\n".$this->hashBlock($codeblock)."\n\n"; |
|
| 2876 | + } |
|
| 2877 | + protected function _doFencedCodeBlocks_newlines($matches) { |
|
| 2878 | + return str_repeat("<br$this->empty_element_suffix", |
|
| 2879 | + strlen($matches[0])); |
|
| 2880 | + } |
|
| 2902 | 2881 | |
| 2903 | 2882 | |
| 2904 | - protected function formParagraphs($text) { |
|
| 2905 | - # |
|
| 2906 | - # Params: |
|
| 2907 | - # $text - string to process with html <p> tags |
|
| 2908 | - # |
|
| 2909 | - # Strip leading and trailing lines: |
|
| 2910 | - $text = preg_replace('/\A\n+|\n+\z/', '', $text); |
|
| 2883 | + # |
|
| 2884 | + # Redefining emphasis markers so that emphasis by underscore does not |
|
| 2885 | + # work in the middle of a word. |
|
| 2886 | + # |
|
| 2887 | + protected $em_relist = array( |
|
| 2888 | + '' => '(?:(?<!\*)\*(?!\*)|(?<![a-zA-Z0-9_])_(?!_))(?=\S|$)(?![\.,:;]\s)', |
|
| 2889 | + '*' => '(?<=\S|^)(?<!\*)\*(?!\*)', |
|
| 2890 | + '_' => '(?<=\S|^)(?<!_)_(?![a-zA-Z0-9_])', |
|
| 2891 | + ); |
|
| 2892 | + protected $strong_relist = array( |
|
| 2893 | + '' => '(?:(?<!\*)\*\*(?!\*)|(?<![a-zA-Z0-9_])__(?!_))(?=\S|$)(?![\.,:;]\s)', |
|
| 2894 | + '**' => '(?<=\S|^)(?<!\*)\*\*(?!\*)', |
|
| 2895 | + '__' => '(?<=\S|^)(?<!_)__(?![a-zA-Z0-9_])', |
|
| 2896 | + ); |
|
| 2897 | + protected $em_strong_relist = array( |
|
| 2898 | + '' => '(?:(?<!\*)\*\*\*(?!\*)|(?<![a-zA-Z0-9_])___(?!_))(?=\S|$)(?![\.,:;]\s)', |
|
| 2899 | + '***' => '(?<=\S|^)(?<!\*)\*\*\*(?!\*)', |
|
| 2900 | + '___' => '(?<=\S|^)(?<!_)___(?![a-zA-Z0-9_])', |
|
| 2901 | + ); |
|
| 2902 | + |
|
| 2903 | + |
|
| 2904 | + protected function formParagraphs($text) { |
|
| 2905 | + # |
|
| 2906 | + # Params: |
|
| 2907 | + # $text - string to process with html <p> tags |
|
| 2908 | + # |
|
| 2909 | + # Strip leading and trailing lines: |
|
| 2910 | + $text = preg_replace('/\A\n+|\n+\z/', '', $text); |
|
| 2911 | 2911 | |
| 2912 | - $grafs = preg_split('/\n{2,}/', $text, -1, PREG_SPLIT_NO_EMPTY); |
|
| 2912 | + $grafs = preg_split('/\n{2,}/', $text, -1, PREG_SPLIT_NO_EMPTY); |
|
| 2913 | 2913 | |
| 2914 | - # |
|
| 2915 | - # Wrap <p> tags and unhashify HTML blocks |
|
| 2916 | - # |
|
| 2917 | - foreach ($grafs as $key => $value) { |
|
| 2918 | - $value = trim($this->runSpanGamut($value)); |
|
| 2914 | + # |
|
| 2915 | + # Wrap <p> tags and unhashify HTML blocks |
|
| 2916 | + # |
|
| 2917 | + foreach ($grafs as $key => $value) { |
|
| 2918 | + $value = trim($this->runSpanGamut($value)); |
|
| 2919 | 2919 | |
| 2920 | - # Check if this should be enclosed in a paragraph. |
|
| 2921 | - # Clean tag hashes & block tag hashes are left alone. |
|
| 2922 | - $is_p = !preg_match('/^B\x1A[0-9]+B|^C\x1A[0-9]+C$/', $value); |
|
| 2920 | + # Check if this should be enclosed in a paragraph. |
|
| 2921 | + # Clean tag hashes & block tag hashes are left alone. |
|
| 2922 | + $is_p = !preg_match('/^B\x1A[0-9]+B|^C\x1A[0-9]+C$/', $value); |
|
| 2923 | 2923 | |
| 2924 | - if ($is_p) { |
|
| 2925 | - $value = "<p>$value</p>"; |
|
| 2926 | - } |
|
| 2927 | - $grafs[$key] = $value; |
|
| 2928 | - } |
|
| 2924 | + if ($is_p) { |
|
| 2925 | + $value = "<p>$value</p>"; |
|
| 2926 | + } |
|
| 2927 | + $grafs[$key] = $value; |
|
| 2928 | + } |
|
| 2929 | 2929 | |
| 2930 | - # Join grafs in one text, then unhash HTML tags. |
|
| 2931 | - $text = implode("\n\n", $grafs); |
|
| 2930 | + # Join grafs in one text, then unhash HTML tags. |
|
| 2931 | + $text = implode("\n\n", $grafs); |
|
| 2932 | 2932 | |
| 2933 | - # Finish by removing any tag hashes still present in $text. |
|
| 2934 | - $text = $this->unhash($text); |
|
| 2933 | + # Finish by removing any tag hashes still present in $text. |
|
| 2934 | + $text = $this->unhash($text); |
|
| 2935 | 2935 | |
| 2936 | - return $text; |
|
| 2937 | - } |
|
| 2936 | + return $text; |
|
| 2937 | + } |
|
| 2938 | 2938 | |
| 2939 | 2939 | |
| 2940 | - ### Footnotes |
|
| 2940 | + ### Footnotes |
|
| 2941 | 2941 | |
| 2942 | - protected function stripFootnotes($text) { |
|
| 2943 | - # |
|
| 2944 | - # Strips link definitions from text, stores the URLs and titles in |
|
| 2945 | - # hash references. |
|
| 2946 | - # |
|
| 2947 | - $less_than_tab = $this->tab_width - 1; |
|
| 2948 | - |
|
| 2949 | - # Link defs are in the form: [^id]: url "optional title" |
|
| 2950 | - $text = preg_replace_callback('{ |
|
| 2942 | + protected function stripFootnotes($text) { |
|
| 2943 | + # |
|
| 2944 | + # Strips link definitions from text, stores the URLs and titles in |
|
| 2945 | + # hash references. |
|
| 2946 | + # |
|
| 2947 | + $less_than_tab = $this->tab_width - 1; |
|
| 2948 | + |
|
| 2949 | + # Link defs are in the form: [^id]: url "optional title" |
|
| 2950 | + $text = preg_replace_callback('{ |
|
| 2951 | 2951 | ^[ ]{0,'.$less_than_tab.'}\[\^(.+?)\][ ]?: # note_id = $1 |
| 2952 | 2952 | [ ]* |
| 2953 | 2953 | \n? # maybe *one* newline |
@@ -2962,203 +2962,203 @@ discard block |
||
| 2962 | 2962 | )* |
| 2963 | 2963 | ) |
| 2964 | 2964 | }xm', |
| 2965 | - array($this, '_stripFootnotes_callback'), |
|
| 2966 | - $text); |
|
| 2967 | - return $text; |
|
| 2968 | - } |
|
| 2969 | - protected function _stripFootnotes_callback($matches) { |
|
| 2970 | - $note_id = $this->fn_id_prefix . $matches[1]; |
|
| 2971 | - $this->footnotes[$note_id] = $this->outdent($matches[2]); |
|
| 2972 | - return ''; # String that will replace the block |
|
| 2973 | - } |
|
| 2974 | - |
|
| 2975 | - |
|
| 2976 | - protected function doFootnotes($text) { |
|
| 2977 | - # |
|
| 2978 | - # Replace footnote references in $text [^id] with a special text-token |
|
| 2979 | - # which will be replaced by the actual footnote marker in appendFootnotes. |
|
| 2980 | - # |
|
| 2981 | - if (!$this->in_anchor) { |
|
| 2982 | - $text = preg_replace('{\[\^(.+?)\]}', "F\x1Afn:\\1\x1A:", $text); |
|
| 2983 | - } |
|
| 2984 | - return $text; |
|
| 2985 | - } |
|
| 2965 | + array($this, '_stripFootnotes_callback'), |
|
| 2966 | + $text); |
|
| 2967 | + return $text; |
|
| 2968 | + } |
|
| 2969 | + protected function _stripFootnotes_callback($matches) { |
|
| 2970 | + $note_id = $this->fn_id_prefix . $matches[1]; |
|
| 2971 | + $this->footnotes[$note_id] = $this->outdent($matches[2]); |
|
| 2972 | + return ''; # String that will replace the block |
|
| 2973 | + } |
|
| 2974 | + |
|
| 2975 | + |
|
| 2976 | + protected function doFootnotes($text) { |
|
| 2977 | + # |
|
| 2978 | + # Replace footnote references in $text [^id] with a special text-token |
|
| 2979 | + # which will be replaced by the actual footnote marker in appendFootnotes. |
|
| 2980 | + # |
|
| 2981 | + if (!$this->in_anchor) { |
|
| 2982 | + $text = preg_replace('{\[\^(.+?)\]}', "F\x1Afn:\\1\x1A:", $text); |
|
| 2983 | + } |
|
| 2984 | + return $text; |
|
| 2985 | + } |
|
| 2986 | 2986 | |
| 2987 | 2987 | |
| 2988 | - protected function appendFootnotes($text) { |
|
| 2989 | - # |
|
| 2990 | - # Append footnote list to text. |
|
| 2991 | - # |
|
| 2992 | - $text = preg_replace_callback('{F\x1Afn:(.*?)\x1A:}', |
|
| 2993 | - array($this, '_appendFootnotes_callback'), $text); |
|
| 2988 | + protected function appendFootnotes($text) { |
|
| 2989 | + # |
|
| 2990 | + # Append footnote list to text. |
|
| 2991 | + # |
|
| 2992 | + $text = preg_replace_callback('{F\x1Afn:(.*?)\x1A:}', |
|
| 2993 | + array($this, '_appendFootnotes_callback'), $text); |
|
| 2994 | 2994 | |
| 2995 | - if (!empty($this->footnotes_ordered)) { |
|
| 2996 | - $text .= "\n\n"; |
|
| 2997 | - $text .= "<div class=\"footnotes\">\n"; |
|
| 2998 | - $text .= "<hr". $this->empty_element_suffix ."\n"; |
|
| 2999 | - $text .= "<ol>\n\n"; |
|
| 2995 | + if (!empty($this->footnotes_ordered)) { |
|
| 2996 | + $text .= "\n\n"; |
|
| 2997 | + $text .= "<div class=\"footnotes\">\n"; |
|
| 2998 | + $text .= "<hr". $this->empty_element_suffix ."\n"; |
|
| 2999 | + $text .= "<ol>\n\n"; |
|
| 3000 | 3000 | |
| 3001 | - $attr = " rev=\"footnote\""; |
|
| 3002 | - if ($this->fn_backlink_class != "") { |
|
| 3003 | - $class = $this->fn_backlink_class; |
|
| 3004 | - $class = $this->encodeAttribute($class); |
|
| 3005 | - $attr .= " class=\"$class\""; |
|
| 3006 | - } |
|
| 3007 | - if ($this->fn_backlink_title != "") { |
|
| 3008 | - $title = $this->fn_backlink_title; |
|
| 3009 | - $title = $this->encodeAttribute($title); |
|
| 3010 | - $attr .= " title=\"$title\""; |
|
| 3011 | - } |
|
| 3012 | - $num = 0; |
|
| 3001 | + $attr = " rev=\"footnote\""; |
|
| 3002 | + if ($this->fn_backlink_class != "") { |
|
| 3003 | + $class = $this->fn_backlink_class; |
|
| 3004 | + $class = $this->encodeAttribute($class); |
|
| 3005 | + $attr .= " class=\"$class\""; |
|
| 3006 | + } |
|
| 3007 | + if ($this->fn_backlink_title != "") { |
|
| 3008 | + $title = $this->fn_backlink_title; |
|
| 3009 | + $title = $this->encodeAttribute($title); |
|
| 3010 | + $attr .= " title=\"$title\""; |
|
| 3011 | + } |
|
| 3012 | + $num = 0; |
|
| 3013 | 3013 | |
| 3014 | - while (!empty($this->footnotes_ordered)) { |
|
| 3015 | - $footnote = reset($this->footnotes_ordered); |
|
| 3016 | - $note_id = key($this->footnotes_ordered); |
|
| 3017 | - unset($this->footnotes_ordered[$note_id]); |
|
| 3018 | - $ref_count = $this->footnotes_ref_count[$note_id]; |
|
| 3019 | - unset($this->footnotes_ref_count[$note_id]); |
|
| 3020 | - unset($this->footnotes[$note_id]); |
|
| 3014 | + while (!empty($this->footnotes_ordered)) { |
|
| 3015 | + $footnote = reset($this->footnotes_ordered); |
|
| 3016 | + $note_id = key($this->footnotes_ordered); |
|
| 3017 | + unset($this->footnotes_ordered[$note_id]); |
|
| 3018 | + $ref_count = $this->footnotes_ref_count[$note_id]; |
|
| 3019 | + unset($this->footnotes_ref_count[$note_id]); |
|
| 3020 | + unset($this->footnotes[$note_id]); |
|
| 3021 | 3021 | |
| 3022 | - $footnote .= "\n"; # Need to append newline before parsing. |
|
| 3023 | - $footnote = $this->runBlockGamut("$footnote\n"); |
|
| 3024 | - $footnote = preg_replace_callback('{F\x1Afn:(.*?)\x1A:}', |
|
| 3025 | - array($this, '_appendFootnotes_callback'), $footnote); |
|
| 3022 | + $footnote .= "\n"; # Need to append newline before parsing. |
|
| 3023 | + $footnote = $this->runBlockGamut("$footnote\n"); |
|
| 3024 | + $footnote = preg_replace_callback('{F\x1Afn:(.*?)\x1A:}', |
|
| 3025 | + array($this, '_appendFootnotes_callback'), $footnote); |
|
| 3026 | 3026 | |
| 3027 | - $attr = str_replace("%%", ++$num, $attr); |
|
| 3028 | - $note_id = $this->encodeAttribute($note_id); |
|
| 3029 | - |
|
| 3030 | - # Prepare backlink, multiple backlinks if multiple references |
|
| 3031 | - $backlink = "<a href=\"#fnref:$note_id\"$attr>↩</a>"; |
|
| 3032 | - for ($ref_num = 2; $ref_num <= $ref_count; ++$ref_num) { |
|
| 3033 | - $backlink .= " <a href=\"#fnref$ref_num:$note_id\"$attr>↩</a>"; |
|
| 3034 | - } |
|
| 3035 | - # Add backlink to last paragraph; create new paragraph if needed. |
|
| 3036 | - if (preg_match('{</p>$}', $footnote)) { |
|
| 3037 | - $footnote = substr($footnote, 0, -4) . " $backlink</p>"; |
|
| 3038 | - } else { |
|
| 3039 | - $footnote .= "\n\n<p>$backlink</p>"; |
|
| 3040 | - } |
|
| 3027 | + $attr = str_replace("%%", ++$num, $attr); |
|
| 3028 | + $note_id = $this->encodeAttribute($note_id); |
|
| 3029 | + |
|
| 3030 | + # Prepare backlink, multiple backlinks if multiple references |
|
| 3031 | + $backlink = "<a href=\"#fnref:$note_id\"$attr>↩</a>"; |
|
| 3032 | + for ($ref_num = 2; $ref_num <= $ref_count; ++$ref_num) { |
|
| 3033 | + $backlink .= " <a href=\"#fnref$ref_num:$note_id\"$attr>↩</a>"; |
|
| 3034 | + } |
|
| 3035 | + # Add backlink to last paragraph; create new paragraph if needed. |
|
| 3036 | + if (preg_match('{</p>$}', $footnote)) { |
|
| 3037 | + $footnote = substr($footnote, 0, -4) . " $backlink</p>"; |
|
| 3038 | + } else { |
|
| 3039 | + $footnote .= "\n\n<p>$backlink</p>"; |
|
| 3040 | + } |
|
| 3041 | 3041 | |
| 3042 | - $text .= "<li id=\"fn:$note_id\">\n"; |
|
| 3043 | - $text .= $footnote . "\n"; |
|
| 3044 | - $text .= "</li>\n\n"; |
|
| 3045 | - } |
|
| 3042 | + $text .= "<li id=\"fn:$note_id\">\n"; |
|
| 3043 | + $text .= $footnote . "\n"; |
|
| 3044 | + $text .= "</li>\n\n"; |
|
| 3045 | + } |
|
| 3046 | 3046 | |
| 3047 | - $text .= "</ol>\n"; |
|
| 3048 | - $text .= "</div>"; |
|
| 3049 | - } |
|
| 3050 | - return $text; |
|
| 3051 | - } |
|
| 3052 | - protected function _appendFootnotes_callback($matches) { |
|
| 3053 | - $node_id = $this->fn_id_prefix . $matches[1]; |
|
| 3054 | - |
|
| 3055 | - # Create footnote marker only if it has a corresponding footnote *and* |
|
| 3056 | - # the footnote hasn't been used by another marker. |
|
| 3057 | - if (isset($this->footnotes[$node_id])) { |
|
| 3058 | - $num =& $this->footnotes_numbers[$node_id]; |
|
| 3059 | - if (!isset($num)) { |
|
| 3060 | - # Transfer footnote content to the ordered list and give it its |
|
| 3061 | - # number |
|
| 3062 | - $this->footnotes_ordered[$node_id] = $this->footnotes[$node_id]; |
|
| 3063 | - $this->footnotes_ref_count[$node_id] = 1; |
|
| 3064 | - $num = $this->footnote_counter++; |
|
| 3065 | - $ref_count_mark = ''; |
|
| 3066 | - } else { |
|
| 3067 | - $ref_count_mark = $this->footnotes_ref_count[$node_id] += 1; |
|
| 3068 | - } |
|
| 3069 | - |
|
| 3070 | - $attr = ""; |
|
| 3071 | - if ($this->fn_link_class != "") { |
|
| 3072 | - $class = $this->fn_link_class; |
|
| 3073 | - $class = $this->encodeAttribute($class); |
|
| 3074 | - $attr .= " class=\"$class\""; |
|
| 3075 | - } |
|
| 3076 | - if ($this->fn_link_title != "") { |
|
| 3077 | - $title = $this->fn_link_title; |
|
| 3078 | - $title = $this->encodeAttribute($title); |
|
| 3079 | - $attr .= " title=\"$title\""; |
|
| 3080 | - } |
|
| 3047 | + $text .= "</ol>\n"; |
|
| 3048 | + $text .= "</div>"; |
|
| 3049 | + } |
|
| 3050 | + return $text; |
|
| 3051 | + } |
|
| 3052 | + protected function _appendFootnotes_callback($matches) { |
|
| 3053 | + $node_id = $this->fn_id_prefix . $matches[1]; |
|
| 3054 | + |
|
| 3055 | + # Create footnote marker only if it has a corresponding footnote *and* |
|
| 3056 | + # the footnote hasn't been used by another marker. |
|
| 3057 | + if (isset($this->footnotes[$node_id])) { |
|
| 3058 | + $num =& $this->footnotes_numbers[$node_id]; |
|
| 3059 | + if (!isset($num)) { |
|
| 3060 | + # Transfer footnote content to the ordered list and give it its |
|
| 3061 | + # number |
|
| 3062 | + $this->footnotes_ordered[$node_id] = $this->footnotes[$node_id]; |
|
| 3063 | + $this->footnotes_ref_count[$node_id] = 1; |
|
| 3064 | + $num = $this->footnote_counter++; |
|
| 3065 | + $ref_count_mark = ''; |
|
| 3066 | + } else { |
|
| 3067 | + $ref_count_mark = $this->footnotes_ref_count[$node_id] += 1; |
|
| 3068 | + } |
|
| 3069 | + |
|
| 3070 | + $attr = ""; |
|
| 3071 | + if ($this->fn_link_class != "") { |
|
| 3072 | + $class = $this->fn_link_class; |
|
| 3073 | + $class = $this->encodeAttribute($class); |
|
| 3074 | + $attr .= " class=\"$class\""; |
|
| 3075 | + } |
|
| 3076 | + if ($this->fn_link_title != "") { |
|
| 3077 | + $title = $this->fn_link_title; |
|
| 3078 | + $title = $this->encodeAttribute($title); |
|
| 3079 | + $attr .= " title=\"$title\""; |
|
| 3080 | + } |
|
| 3081 | 3081 | |
| 3082 | - $attr = str_replace("%%", $num, $attr); |
|
| 3083 | - $node_id = $this->encodeAttribute($node_id); |
|
| 3082 | + $attr = str_replace("%%", $num, $attr); |
|
| 3083 | + $node_id = $this->encodeAttribute($node_id); |
|
| 3084 | 3084 | |
| 3085 | - return |
|
| 3086 | - "<sup id=\"fnref$ref_count_mark:$node_id\">". |
|
| 3087 | - "<a href=\"#fn:$node_id\"$attr>$num</a>". |
|
| 3088 | - "</sup>"; |
|
| 3089 | - } |
|
| 3085 | + return |
|
| 3086 | + "<sup id=\"fnref$ref_count_mark:$node_id\">". |
|
| 3087 | + "<a href=\"#fn:$node_id\"$attr>$num</a>". |
|
| 3088 | + "</sup>"; |
|
| 3089 | + } |
|
| 3090 | 3090 | |
| 3091 | - return "[^".$matches[1]."]"; |
|
| 3092 | - } |
|
| 3091 | + return "[^".$matches[1]."]"; |
|
| 3092 | + } |
|
| 3093 | 3093 | |
| 3094 | 3094 | |
| 3095 | - ### Abbreviations ### |
|
| 3095 | + ### Abbreviations ### |
|
| 3096 | 3096 | |
| 3097 | - protected function stripAbbreviations($text) { |
|
| 3098 | - # |
|
| 3099 | - # Strips abbreviations from text, stores titles in hash references. |
|
| 3100 | - # |
|
| 3101 | - $less_than_tab = $this->tab_width - 1; |
|
| 3102 | - |
|
| 3103 | - # Link defs are in the form: [id]*: url "optional title" |
|
| 3104 | - $text = preg_replace_callback('{ |
|
| 3097 | + protected function stripAbbreviations($text) { |
|
| 3098 | + # |
|
| 3099 | + # Strips abbreviations from text, stores titles in hash references. |
|
| 3100 | + # |
|
| 3101 | + $less_than_tab = $this->tab_width - 1; |
|
| 3102 | + |
|
| 3103 | + # Link defs are in the form: [id]*: url "optional title" |
|
| 3104 | + $text = preg_replace_callback('{ |
|
| 3105 | 3105 | ^[ ]{0,'.$less_than_tab.'}\*\[(.+?)\][ ]?: # abbr_id = $1 |
| 3106 | 3106 | (.*) # text = $2 (no blank lines allowed) |
| 3107 | 3107 | }xm', |
| 3108 | - array($this, '_stripAbbreviations_callback'), |
|
| 3109 | - $text); |
|
| 3110 | - return $text; |
|
| 3111 | - } |
|
| 3112 | - protected function _stripAbbreviations_callback($matches) { |
|
| 3113 | - $abbr_word = $matches[1]; |
|
| 3114 | - $abbr_desc = $matches[2]; |
|
| 3115 | - if ($this->abbr_word_re) |
|
| 3116 | - $this->abbr_word_re .= '|'; |
|
| 3117 | - $this->abbr_word_re .= preg_quote($abbr_word); |
|
| 3118 | - $this->abbr_desciptions[$abbr_word] = trim($abbr_desc); |
|
| 3119 | - return ''; # String that will replace the block |
|
| 3120 | - } |
|
| 3108 | + array($this, '_stripAbbreviations_callback'), |
|
| 3109 | + $text); |
|
| 3110 | + return $text; |
|
| 3111 | + } |
|
| 3112 | + protected function _stripAbbreviations_callback($matches) { |
|
| 3113 | + $abbr_word = $matches[1]; |
|
| 3114 | + $abbr_desc = $matches[2]; |
|
| 3115 | + if ($this->abbr_word_re) |
|
| 3116 | + $this->abbr_word_re .= '|'; |
|
| 3117 | + $this->abbr_word_re .= preg_quote($abbr_word); |
|
| 3118 | + $this->abbr_desciptions[$abbr_word] = trim($abbr_desc); |
|
| 3119 | + return ''; # String that will replace the block |
|
| 3120 | + } |
|
| 3121 | 3121 | |
| 3122 | 3122 | |
| 3123 | - protected function doAbbreviations($text) { |
|
| 3124 | - # |
|
| 3125 | - # Find defined abbreviations in text and wrap them in <abbr> elements. |
|
| 3126 | - # |
|
| 3127 | - if ($this->abbr_word_re) { |
|
| 3128 | - // cannot use the /x modifier because abbr_word_re may |
|
| 3129 | - // contain significant spaces: |
|
| 3130 | - $text = preg_replace_callback('{'. |
|
| 3131 | - '(?<![\w\x1A])'. |
|
| 3132 | - '(?:'.$this->abbr_word_re.')'. |
|
| 3133 | - '(?![\w\x1A])'. |
|
| 3134 | - '}', |
|
| 3135 | - array($this, '_doAbbreviations_callback'), $text); |
|
| 3136 | - } |
|
| 3137 | - return $text; |
|
| 3138 | - } |
|
| 3139 | - protected function _doAbbreviations_callback($matches) { |
|
| 3140 | - $abbr = $matches[0]; |
|
| 3141 | - if (isset($this->abbr_desciptions[$abbr])) { |
|
| 3142 | - $desc = $this->abbr_desciptions[$abbr]; |
|
| 3143 | - if (empty($desc)) { |
|
| 3144 | - return $this->hashPart("<abbr>$abbr</abbr>"); |
|
| 3145 | - } else { |
|
| 3146 | - $desc = $this->encodeAttribute($desc); |
|
| 3147 | - return $this->hashPart("<abbr title=\"$desc\">$abbr</abbr>"); |
|
| 3148 | - } |
|
| 3149 | - } else { |
|
| 3150 | - return $matches[0]; |
|
| 3151 | - } |
|
| 3152 | - } |
|
| 3123 | + protected function doAbbreviations($text) { |
|
| 3124 | + # |
|
| 3125 | + # Find defined abbreviations in text and wrap them in <abbr> elements. |
|
| 3126 | + # |
|
| 3127 | + if ($this->abbr_word_re) { |
|
| 3128 | + // cannot use the /x modifier because abbr_word_re may |
|
| 3129 | + // contain significant spaces: |
|
| 3130 | + $text = preg_replace_callback('{'. |
|
| 3131 | + '(?<![\w\x1A])'. |
|
| 3132 | + '(?:'.$this->abbr_word_re.')'. |
|
| 3133 | + '(?![\w\x1A])'. |
|
| 3134 | + '}', |
|
| 3135 | + array($this, '_doAbbreviations_callback'), $text); |
|
| 3136 | + } |
|
| 3137 | + return $text; |
|
| 3138 | + } |
|
| 3139 | + protected function _doAbbreviations_callback($matches) { |
|
| 3140 | + $abbr = $matches[0]; |
|
| 3141 | + if (isset($this->abbr_desciptions[$abbr])) { |
|
| 3142 | + $desc = $this->abbr_desciptions[$abbr]; |
|
| 3143 | + if (empty($desc)) { |
|
| 3144 | + return $this->hashPart("<abbr>$abbr</abbr>"); |
|
| 3145 | + } else { |
|
| 3146 | + $desc = $this->encodeAttribute($desc); |
|
| 3147 | + return $this->hashPart("<abbr title=\"$desc\">$abbr</abbr>"); |
|
| 3148 | + } |
|
| 3149 | + } else { |
|
| 3150 | + return $matches[0]; |
|
| 3151 | + } |
|
| 3152 | + } |
|
| 3153 | 3153 | |
| 3154 | 3154 | } |
| 3155 | 3155 | |
| 3156 | 3156 | // https://github.com/egil/php-markdown-extra-extended |
| 3157 | 3157 | class MarkdownExtraExtended extends MarkdownExtra { |
| 3158 | - # Tags that are always treated as block tags: |
|
| 3159 | - protected $block_tags_re = 'figure|figcaption|p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|address|form|fieldset|iframe|hr|legend'; |
|
| 3158 | + # Tags that are always treated as block tags: |
|
| 3159 | + protected $block_tags_re = 'figure|figcaption|p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|address|form|fieldset|iframe|hr|legend'; |
|
| 3160 | 3160 | |
| 3161 | - public function __construct() { |
|
| 3161 | + public function __construct() { |
|
| 3162 | 3162 | /* |
| 3163 | 3163 | $this->block_gamut += array( |
| 3164 | 3164 | "doFencedFigures" => 7 |
@@ -3169,29 +3169,29 @@ discard block |
||
| 3169 | 3169 | "doClearBreaks" => 100 |
| 3170 | 3170 | ); |
| 3171 | 3171 | |
| 3172 | - parent::__construct(); |
|
| 3173 | - } |
|
| 3172 | + parent::__construct(); |
|
| 3173 | + } |
|
| 3174 | 3174 | |
| 3175 | 3175 | public static function defaultTransform($text) { |
| 3176 | - # try to take parser from the static parser list |
|
| 3177 | - static $parser; |
|
| 3176 | + # try to take parser from the static parser list |
|
| 3177 | + static $parser; |
|
| 3178 | 3178 | |
| 3179 | - # create the parser it not already set |
|
| 3180 | - if (!$parser) { |
|
| 3181 | - $parser = new MarkdownExtraExtended(); |
|
| 3179 | + # create the parser it not already set |
|
| 3180 | + if (!$parser) { |
|
| 3181 | + $parser = new MarkdownExtraExtended(); |
|
| 3182 | 3182 | } |
| 3183 | 3183 | |
| 3184 | - # Transform text using parser. |
|
| 3185 | - return $parser->transform($text); |
|
| 3186 | - } |
|
| 3184 | + # Transform text using parser. |
|
| 3185 | + return $parser->transform($text); |
|
| 3186 | + } |
|
| 3187 | 3187 | |
| 3188 | - public function doHardBreaks($text) { |
|
| 3189 | - # Do hard breaks: |
|
| 3190 | - # EXTENDED: changed to allow breaks without two spaces and just one new line |
|
| 3191 | - # original code /* return preg_replace_callback('/ {2,}\n/', */ |
|
| 3192 | - return preg_replace_callback('/ *\n/', |
|
| 3193 | - array($this, '_doHardBreaks_callback'), $text); |
|
| 3194 | - } |
|
| 3188 | + public function doHardBreaks($text) { |
|
| 3189 | + # Do hard breaks: |
|
| 3190 | + # EXTENDED: changed to allow breaks without two spaces and just one new line |
|
| 3191 | + # original code /* return preg_replace_callback('/ {2,}\n/', */ |
|
| 3192 | + return preg_replace_callback('/ *\n/', |
|
| 3193 | + array($this, '_doHardBreaks_callback'), $text); |
|
| 3194 | + } |
|
| 3195 | 3195 | |
| 3196 | 3196 | public function doClearBreaks($text) { |
| 3197 | 3197 | return preg_replace("/\s*((?:<br \/>\n)+)\s*(<\/?(?:$this->block_tags_re|li|dd|dt)[^\d])/is", |
@@ -3199,41 +3199,41 @@ discard block |
||
| 3199 | 3199 | } |
| 3200 | 3200 | |
| 3201 | 3201 | |
| 3202 | - public function doBlockQuotes($text) { |
|
| 3203 | - $text = preg_replace_callback('/ |
|
| 3202 | + public function doBlockQuotes($text) { |
|
| 3203 | + $text = preg_replace_callback('/ |
|
| 3204 | 3204 | (?>^[ ]*>[ ]? |
| 3205 | 3205 | (?:\((.+?)\))? |
| 3206 | 3206 | [ ]*(.+\n(?:.+\n)*) |
| 3207 | 3207 | )+ |
| 3208 | 3208 | /xm', |
| 3209 | - array($this, '_doBlockQuotes_callback'), $text); |
|
| 3209 | + array($this, '_doBlockQuotes_callback'), $text); |
|
| 3210 | 3210 | |
| 3211 | - return $text; |
|
| 3212 | - } |
|
| 3211 | + return $text; |
|
| 3212 | + } |
|
| 3213 | 3213 | |
| 3214 | - public function _doBlockQuotes_callback($matches) { |
|
| 3215 | - $cite = $matches[1]; |
|
| 3216 | - $bq = '> ' . $matches[2]; |
|
| 3217 | - # trim one level of quoting - trim whitespace-only lines |
|
| 3218 | - $bq = preg_replace('/^[ ]*>[ ]?|^[ ]+$/m', '', $bq); |
|
| 3219 | - $bq = $this->runBlockGamut($bq); # recurse |
|
| 3220 | - |
|
| 3221 | - $bq = preg_replace('/^/m', " ", $bq); |
|
| 3222 | - # These leading spaces cause problem with <pre> content, |
|
| 3223 | - # so we need to fix that: |
|
| 3224 | - $bq = preg_replace_callback('{(\s*<pre>.+?</pre>)}sx', |
|
| 3225 | - array($this, '_doBlockQuotes_callback2'), $bq); |
|
| 3226 | - |
|
| 3227 | - $res = "<blockquote"; |
|
| 3228 | - $res .= empty($cite) ? ">" : " cite=\"$cite\">"; |
|
| 3229 | - $res .= "\n$bq\n</blockquote>"; |
|
| 3230 | - return "\n". $this->hashBlock($res)."\n\n"; |
|
| 3231 | - } |
|
| 3232 | - |
|
| 3233 | - public function doFencedCodeBlocks($text) { |
|
| 3234 | - $less_than_tab = $this->tab_width; |
|
| 3235 | - |
|
| 3236 | - $text = preg_replace_callback('{ |
|
| 3214 | + public function _doBlockQuotes_callback($matches) { |
|
| 3215 | + $cite = $matches[1]; |
|
| 3216 | + $bq = '> ' . $matches[2]; |
|
| 3217 | + # trim one level of quoting - trim whitespace-only lines |
|
| 3218 | + $bq = preg_replace('/^[ ]*>[ ]?|^[ ]+$/m', '', $bq); |
|
| 3219 | + $bq = $this->runBlockGamut($bq); # recurse |
|
| 3220 | + |
|
| 3221 | + $bq = preg_replace('/^/m', " ", $bq); |
|
| 3222 | + # These leading spaces cause problem with <pre> content, |
|
| 3223 | + # so we need to fix that: |
|
| 3224 | + $bq = preg_replace_callback('{(\s*<pre>.+?</pre>)}sx', |
|
| 3225 | + array($this, '_doBlockQuotes_callback2'), $bq); |
|
| 3226 | + |
|
| 3227 | + $res = "<blockquote"; |
|
| 3228 | + $res .= empty($cite) ? ">" : " cite=\"$cite\">"; |
|
| 3229 | + $res .= "\n$bq\n</blockquote>"; |
|
| 3230 | + return "\n". $this->hashBlock($res)."\n\n"; |
|
| 3231 | + } |
|
| 3232 | + |
|
| 3233 | + public function doFencedCodeBlocks($text) { |
|
| 3234 | + $less_than_tab = $this->tab_width; |
|
| 3235 | + |
|
| 3236 | + $text = preg_replace_callback('{ |
|
| 3237 | 3237 | (?:\n|\A) |
| 3238 | 3238 | # 1: Opening marker |
| 3239 | 3239 | ( |
@@ -3253,26 +3253,26 @@ discard block |
||
| 3253 | 3253 | # Closing marker. |
| 3254 | 3254 | \1 [ ]* \n |
| 3255 | 3255 | }xm', |
| 3256 | - array($this, '_doFencedCodeBlocks_callback'), $text); |
|
| 3256 | + array($this, '_doFencedCodeBlocks_callback'), $text); |
|
| 3257 | 3257 | |
| 3258 | - return $text; |
|
| 3259 | - } |
|
| 3258 | + return $text; |
|
| 3259 | + } |
|
| 3260 | 3260 | |
| 3261 | - public function _doFencedCodeBlocks_callback($matches) { |
|
| 3262 | - $codeblock = $this->unhash($matches[4]); |
|
| 3263 | - $codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES); |
|
| 3264 | - $codeblock = preg_replace_callback('/^\n+/', |
|
| 3265 | - array($this, '_doFencedCodeBlocks_newlines'), $codeblock); |
|
| 3266 | - //$codeblock = "<pre><code>$codeblock</code></pre>"; |
|
| 3267 | - //$cb = "<pre><code"; |
|
| 3268 | - $cb = empty($matches[3]) ? "<pre><code" : "<pre class=\"linenums:$matches[3]\"><code"; |
|
| 3269 | - $cb .= empty($matches[2]) ? ">" : " class=\"lang-$matches[2]\">"; |
|
| 3270 | - $cb .= "$codeblock</code></pre>"; |
|
| 3271 | - return "\n\n".$this->hashBlock($cb)."\n\n"; |
|
| 3272 | - } |
|
| 3273 | - |
|
| 3274 | - public function doFencedFigures($text){ |
|
| 3275 | - $text = preg_replace_callback('{ |
|
| 3261 | + public function _doFencedCodeBlocks_callback($matches) { |
|
| 3262 | + $codeblock = $this->unhash($matches[4]); |
|
| 3263 | + $codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES); |
|
| 3264 | + $codeblock = preg_replace_callback('/^\n+/', |
|
| 3265 | + array($this, '_doFencedCodeBlocks_newlines'), $codeblock); |
|
| 3266 | + //$codeblock = "<pre><code>$codeblock</code></pre>"; |
|
| 3267 | + //$cb = "<pre><code"; |
|
| 3268 | + $cb = empty($matches[3]) ? "<pre><code" : "<pre class=\"linenums:$matches[3]\"><code"; |
|
| 3269 | + $cb .= empty($matches[2]) ? ">" : " class=\"lang-$matches[2]\">"; |
|
| 3270 | + $cb .= "$codeblock</code></pre>"; |
|
| 3271 | + return "\n\n".$this->hashBlock($cb)."\n\n"; |
|
| 3272 | + } |
|
| 3273 | + |
|
| 3274 | + public function doFencedFigures($text){ |
|
| 3275 | + $text = preg_replace_callback('{ |
|
| 3276 | 3276 | (?:\n|\A) |
| 3277 | 3277 | # 1: Opening marker |
| 3278 | 3278 | ( |
@@ -3293,33 +3293,33 @@ discard block |
||
| 3293 | 3293 | \1 [ ]?(?:\[([^\]]+)\])?[ ]* \n |
| 3294 | 3294 | }xm', array($this, '_doFencedFigures_callback'), $text); |
| 3295 | 3295 | |
| 3296 | - return $text; |
|
| 3297 | - } |
|
| 3296 | + return $text; |
|
| 3297 | + } |
|
| 3298 | 3298 | |
| 3299 | - public function _doFencedFigures_callback($matches) { |
|
| 3300 | - # get figcaption |
|
| 3301 | - $topcaption = empty($matches[2]) ? null : $this->runBlockGamut($matches[2]); |
|
| 3302 | - $bottomcaption = empty($matches[5]) ? null : $this->runBlockGamut($matches[5]); |
|
| 3303 | - $figure = $matches[3]; |
|
| 3304 | - $figure = $this->runBlockGamut($figure); # recurse |
|
| 3305 | - |
|
| 3306 | - $figure = preg_replace('/^/m', " ", $figure); |
|
| 3307 | - # These leading spaces cause problem with <pre> content, |
|
| 3308 | - # so we need to fix that - reuse blockqoute code to handle this: |
|
| 3309 | - $figure = preg_replace_callback('{(\s*<pre>.+?</pre>)}sx', |
|
| 3310 | - array($this, '_doBlockQuotes_callback2'), $figure); |
|
| 3311 | - |
|
| 3312 | - $res = "<figure>"; |
|
| 3313 | - if(!empty($topcaption)){ |
|
| 3314 | - $res .= "\n<figcaption>$topcaption</figcaption>"; |
|
| 3315 | - } |
|
| 3316 | - $res .= "\n$figure\n"; |
|
| 3317 | - if(!empty($bottomcaption) && empty($topcaption)){ |
|
| 3318 | - $res .= "<figcaption>$bottomcaption</figcaption>"; |
|
| 3319 | - } |
|
| 3320 | - $res .= "</figure>"; |
|
| 3321 | - return "\n". $this->hashBlock($res)."\n\n"; |
|
| 3322 | - } |
|
| 3299 | + public function _doFencedFigures_callback($matches) { |
|
| 3300 | + # get figcaption |
|
| 3301 | + $topcaption = empty($matches[2]) ? null : $this->runBlockGamut($matches[2]); |
|
| 3302 | + $bottomcaption = empty($matches[5]) ? null : $this->runBlockGamut($matches[5]); |
|
| 3303 | + $figure = $matches[3]; |
|
| 3304 | + $figure = $this->runBlockGamut($figure); # recurse |
|
| 3305 | + |
|
| 3306 | + $figure = preg_replace('/^/m', " ", $figure); |
|
| 3307 | + # These leading spaces cause problem with <pre> content, |
|
| 3308 | + # so we need to fix that - reuse blockqoute code to handle this: |
|
| 3309 | + $figure = preg_replace_callback('{(\s*<pre>.+?</pre>)}sx', |
|
| 3310 | + array($this, '_doBlockQuotes_callback2'), $figure); |
|
| 3311 | + |
|
| 3312 | + $res = "<figure>"; |
|
| 3313 | + if(!empty($topcaption)){ |
|
| 3314 | + $res .= "\n<figcaption>$topcaption</figcaption>"; |
|
| 3315 | + } |
|
| 3316 | + $res .= "\n$figure\n"; |
|
| 3317 | + if(!empty($bottomcaption) && empty($topcaption)){ |
|
| 3318 | + $res .= "<figcaption>$bottomcaption</figcaption>"; |
|
| 3319 | + } |
|
| 3320 | + $res .= "</figure>"; |
|
| 3321 | + return "\n". $this->hashBlock($res)."\n\n"; |
|
| 3322 | + } |
|
| 3323 | 3323 | } |
| 3324 | 3324 | |
| 3325 | 3325 | |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | |
| 43 | 43 | ### Version ### |
| 44 | 44 | |
| 45 | - const MARKDOWNLIB_VERSION = "1.3"; |
|
| 45 | + const MARKDOWNLIB_VERSION = "1.3"; |
|
| 46 | 46 | |
| 47 | 47 | ### Configuration Variables ### |
| 48 | 48 | |
@@ -82,14 +82,14 @@ discard block |
||
| 82 | 82 | $this->prepareItalicsAndBold(); |
| 83 | 83 | |
| 84 | 84 | $this->nested_brackets_re = |
| 85 | - str_repeat('(?>[^\[\]]+|\[', $this->nested_brackets_depth). |
|
| 85 | + str_repeat('(?>[^\[\]]+|\[', $this->nested_brackets_depth) . |
|
| 86 | 86 | str_repeat('\])*', $this->nested_brackets_depth); |
| 87 | 87 | |
| 88 | 88 | $this->nested_url_parenthesis_re = |
| 89 | - str_repeat('(?>[^()\s]+|\(', $this->nested_url_parenthesis_depth). |
|
| 89 | + str_repeat('(?>[^()\s]+|\(', $this->nested_url_parenthesis_depth) . |
|
| 90 | 90 | str_repeat('(?>\)))*', $this->nested_url_parenthesis_depth); |
| 91 | 91 | |
| 92 | - $this->escape_chars_re = '['.preg_quote($this->escape_chars).']'; |
|
| 92 | + $this->escape_chars_re = '[' . preg_quote($this->escape_chars) . ']'; |
|
| 93 | 93 | |
| 94 | 94 | # Sort document, block, and span gamut in ascendent priority order. |
| 95 | 95 | asort($this->document_gamut); |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | |
| 202 | 202 | # Link defs are in the form: ^[id]: url "optional title" |
| 203 | 203 | $text = preg_replace_callback('{ |
| 204 | - ^[ ]{0,'.$less_than_tab.'}\[(.+)\][ ]?: # id = $1 |
|
| 204 | + ^[ ]{0,'.$less_than_tab . '}\[(.+)\][ ]?: # id = $1 |
|
| 205 | 205 | [ ]* |
| 206 | 206 | \n? # maybe *one* newline |
| 207 | 207 | [ ]* |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | $link_id = strtolower($matches[1]); |
| 231 | 231 | $url = $matches[2] == '' ? $matches[3] : $matches[2]; |
| 232 | 232 | $this->urls[$link_id] = $url; |
| 233 | - $this->titles[$link_id] =& $matches[4]; |
|
| 233 | + $this->titles[$link_id] = & $matches[4]; |
|
| 234 | 234 | return ''; # String that will replace the block |
| 235 | 235 | } |
| 236 | 236 | |
@@ -254,9 +254,9 @@ discard block |
||
| 254 | 254 | # * List "b" is made of tags which are always block-level; |
| 255 | 255 | # |
| 256 | 256 | $block_tags_a_re = 'ins|del'; |
| 257 | - $block_tags_b_re = 'p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|address|'. |
|
| 258 | - 'script|noscript|form|fieldset|iframe|math|svg|'. |
|
| 259 | - 'article|section|nav|aside|hgroup|header|footer|'. |
|
| 257 | + $block_tags_b_re = 'p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|address|' . |
|
| 258 | + 'script|noscript|form|fieldset|iframe|math|svg|' . |
|
| 259 | + 'article|section|nav|aside|hgroup|header|footer|' . |
|
| 260 | 260 | 'figure'; |
| 261 | 261 | |
| 262 | 262 | # Regular expression for the content of a block tag. |
@@ -281,12 +281,12 @@ discard block |
||
| 281 | 281 | [^<]+ # content without tag |
| 282 | 282 | | |
| 283 | 283 | <\2 # nested opening tag |
| 284 | - '.$attr.' # attributes |
|
| 284 | + '.$attr . ' # attributes |
|
| 285 | 285 | (?> |
| 286 | 286 | /> |
| 287 | 287 | | |
| 288 | - >', $nested_tags_level). # end of opening tag |
|
| 289 | - '.*?'. # last level nested tag content |
|
| 288 | + >', $nested_tags_level) . # end of opening tag |
|
| 289 | + '.*?' . # last level nested tag content |
|
| 290 | 290 | str_repeat(' |
| 291 | 291 | </\2\s*> # closing nested tag |
| 292 | 292 | ) |
@@ -319,20 +319,20 @@ discard block |
||
| 319 | 319 | # Match from `\n<tag>` to `</tag>\n`, handling nested tags |
| 320 | 320 | # in between. |
| 321 | 321 | |
| 322 | - [ ]{0,'.$less_than_tab.'} |
|
| 323 | - <('.$block_tags_b_re.')# start tag = $2 |
|
| 324 | - '.$attr.'> # attributes followed by > and \n |
|
| 325 | - '.$content.' # content, support nesting |
|
| 322 | + [ ]{0,'.$less_than_tab . '} |
|
| 323 | + <('.$block_tags_b_re . ')# start tag = $2 |
|
| 324 | + '.$attr . '> # attributes followed by > and \n |
|
| 325 | + '.$content . ' # content, support nesting |
|
| 326 | 326 | </\2> # the matching end tag |
| 327 | 327 | [ ]* # trailing spaces/tabs |
| 328 | 328 | (?=\n+|\Z) # followed by a newline or end of document |
| 329 | 329 | |
| 330 | 330 | | # Special version for tags of group a. |
| 331 | 331 | |
| 332 | - [ ]{0,'.$less_than_tab.'} |
|
| 333 | - <('.$block_tags_a_re.')# start tag = $3 |
|
| 334 | - '.$attr.'>[ ]*\n # attributes followed by > |
|
| 335 | - '.$content2.' # content, support nesting |
|
| 332 | + [ ]{0,'.$less_than_tab . '} |
|
| 333 | + <('.$block_tags_a_re . ')# start tag = $3 |
|
| 334 | + '.$attr . '>[ ]*\n # attributes followed by > |
|
| 335 | + '.$content2 . ' # content, support nesting |
|
| 336 | 336 | </\3> # the matching end tag |
| 337 | 337 | [ ]* # trailing spaces/tabs |
| 338 | 338 | (?=\n+|\Z) # followed by a newline or end of document |
@@ -340,16 +340,16 @@ discard block |
||
| 340 | 340 | | # Special case just for <hr />. It was easier to make a special |
| 341 | 341 | # case than to make the other regex more complicated. |
| 342 | 342 | |
| 343 | - [ ]{0,'.$less_than_tab.'} |
|
| 343 | + [ ]{0,'.$less_than_tab . '} |
|
| 344 | 344 | <(hr) # start tag = $2 |
| 345 | - '.$attr.' # attributes |
|
| 345 | + '.$attr . ' # attributes |
|
| 346 | 346 | /?> # the matching end tag |
| 347 | 347 | [ ]* |
| 348 | 348 | (?=\n{2,}|\Z) # followed by a blank line or end of document |
| 349 | 349 | |
| 350 | 350 | | # Special case for standalone HTML comments: |
| 351 | 351 | |
| 352 | - [ ]{0,'.$less_than_tab.'} |
|
| 352 | + [ ]{0,'.$less_than_tab . '} |
|
| 353 | 353 | (?s: |
| 354 | 354 | <!-- .*? --> |
| 355 | 355 | ) |
@@ -358,7 +358,7 @@ discard block |
||
| 358 | 358 | |
| 359 | 359 | | # PHP and ASP-style processor instructions (<? and <%) |
| 360 | 360 | |
| 361 | - [ ]{0,'.$less_than_tab.'} |
|
| 361 | + [ ]{0,'.$less_than_tab . '} |
|
| 362 | 362 | (?s: |
| 363 | 363 | <([?%]) # $2 |
| 364 | 364 | .*? |
@@ -469,7 +469,7 @@ discard block |
||
| 469 | 469 | [ ]* # Tailing spaces |
| 470 | 470 | $ # End of line. |
| 471 | 471 | }mx', |
| 472 | - "\n".$this->hashBlock("<hr$this->empty_element_suffix")."\n", |
|
| 472 | + "\n" . $this->hashBlock("<hr$this->empty_element_suffix") . "\n", |
|
| 473 | 473 | $text); |
| 474 | 474 | } |
| 475 | 475 | |
@@ -533,7 +533,7 @@ discard block |
||
| 533 | 533 | $text = preg_replace_callback('{ |
| 534 | 534 | ( # wrap whole match in $1 |
| 535 | 535 | \[ |
| 536 | - ('.$this->nested_brackets_re.') # link text = $2 |
|
| 536 | + ('.$this->nested_brackets_re . ') # link text = $2 |
|
| 537 | 537 | \] |
| 538 | 538 | |
| 539 | 539 | [ ]? # one optional space |
@@ -552,14 +552,14 @@ discard block |
||
| 552 | 552 | $text = preg_replace_callback('{ |
| 553 | 553 | ( # wrap whole match in $1 |
| 554 | 554 | \[ |
| 555 | - ('.$this->nested_brackets_re.') # link text = $2 |
|
| 555 | + ('.$this->nested_brackets_re . ') # link text = $2 |
|
| 556 | 556 | \] |
| 557 | 557 | \( # literal paren |
| 558 | 558 | [ \n]* |
| 559 | 559 | (?: |
| 560 | 560 | <(.+?)> # href = $3 |
| 561 | 561 | | |
| 562 | - ('.$this->nested_url_parenthesis_re.') # href = $4 |
|
| 562 | + ('.$this->nested_url_parenthesis_re . ') # href = $4 |
|
| 563 | 563 | ) |
| 564 | 564 | [ \n]* |
| 565 | 565 | ( # $5 |
@@ -591,9 +591,9 @@ discard block |
||
| 591 | 591 | return $text; |
| 592 | 592 | } |
| 593 | 593 | protected function _doAnchors_reference_callback($matches) { |
| 594 | - $whole_match = $matches[1]; |
|
| 595 | - $link_text = $matches[2]; |
|
| 596 | - $link_id =& $matches[3]; |
|
| 594 | + $whole_match = $matches[1]; |
|
| 595 | + $link_text = $matches[2]; |
|
| 596 | + $link_id = & $matches[3]; |
|
| 597 | 597 | |
| 598 | 598 | if ($link_id == "") { |
| 599 | 599 | # for shortcut links like [this][] or [this]. |
@@ -609,10 +609,10 @@ discard block |
||
| 609 | 609 | $url = $this->encodeAttribute($url); |
| 610 | 610 | |
| 611 | 611 | $result = "<a href=\"$url\""; |
| 612 | - if ( isset( $this->titles[$link_id] ) ) { |
|
| 612 | + if (isset($this->titles[$link_id])) { |
|
| 613 | 613 | $title = $this->titles[$link_id]; |
| 614 | 614 | $title = $this->encodeAttribute($title); |
| 615 | - $result .= " title=\"$title\""; |
|
| 615 | + $result .= " title=\"$title\""; |
|
| 616 | 616 | } |
| 617 | 617 | |
| 618 | 618 | $link_text = $this->runSpanGamut($link_text); |
@@ -625,17 +625,17 @@ discard block |
||
| 625 | 625 | return $result; |
| 626 | 626 | } |
| 627 | 627 | protected function _doAnchors_inline_callback($matches) { |
| 628 | - $whole_match = $matches[1]; |
|
| 629 | - $link_text = $this->runSpanGamut($matches[2]); |
|
| 630 | - $url = $matches[3] == '' ? $matches[4] : $matches[3]; |
|
| 631 | - $title =& $matches[7]; |
|
| 628 | + $whole_match = $matches[1]; |
|
| 629 | + $link_text = $this->runSpanGamut($matches[2]); |
|
| 630 | + $url = $matches[3] == '' ? $matches[4] : $matches[3]; |
|
| 631 | + $title = & $matches[7]; |
|
| 632 | 632 | |
| 633 | 633 | $url = $this->encodeAttribute($url); |
| 634 | 634 | |
| 635 | 635 | $result = "<a href=\"$url\""; |
| 636 | 636 | if (isset($title)) { |
| 637 | 637 | $title = $this->encodeAttribute($title); |
| 638 | - $result .= " title=\"$title\""; |
|
| 638 | + $result .= " title=\"$title\""; |
|
| 639 | 639 | } |
| 640 | 640 | |
| 641 | 641 | $link_text = $this->runSpanGamut($link_text); |
@@ -655,7 +655,7 @@ discard block |
||
| 655 | 655 | $text = preg_replace_callback('{ |
| 656 | 656 | ( # wrap whole match in $1 |
| 657 | 657 | !\[ |
| 658 | - ('.$this->nested_brackets_re.') # alt text = $2 |
|
| 658 | + ('.$this->nested_brackets_re . ') # alt text = $2 |
|
| 659 | 659 | \] |
| 660 | 660 | |
| 661 | 661 | [ ]? # one optional space |
@@ -676,7 +676,7 @@ discard block |
||
| 676 | 676 | $text = preg_replace_callback('{ |
| 677 | 677 | ( # wrap whole match in $1 |
| 678 | 678 | !\[ |
| 679 | - ('.$this->nested_brackets_re.') # alt text = $2 |
|
| 679 | + ('.$this->nested_brackets_re . ') # alt text = $2 |
|
| 680 | 680 | \] |
| 681 | 681 | \s? # One optional whitespace character |
| 682 | 682 | \( # literal paren |
@@ -684,7 +684,7 @@ discard block |
||
| 684 | 684 | (?: |
| 685 | 685 | <(\S*)> # src url = $3 |
| 686 | 686 | | |
| 687 | - ('.$this->nested_url_parenthesis_re.') # src url = $4 |
|
| 687 | + ('.$this->nested_url_parenthesis_re . ') # src url = $4 |
|
| 688 | 688 | ) |
| 689 | 689 | [ \n]* |
| 690 | 690 | ( # $5 |
@@ -716,7 +716,7 @@ discard block |
||
| 716 | 716 | if (isset($this->titles[$link_id])) { |
| 717 | 717 | $title = $this->titles[$link_id]; |
| 718 | 718 | $title = $this->encodeAttribute($title); |
| 719 | - $result .= " title=\"$title\""; |
|
| 719 | + $result .= " title=\"$title\""; |
|
| 720 | 720 | } |
| 721 | 721 | $result .= $this->empty_element_suffix; |
| 722 | 722 | $result = $this->hashPart($result); |
@@ -729,17 +729,17 @@ discard block |
||
| 729 | 729 | return $result; |
| 730 | 730 | } |
| 731 | 731 | protected function _doImages_inline_callback($matches) { |
| 732 | - $whole_match = $matches[1]; |
|
| 733 | - $alt_text = $matches[2]; |
|
| 734 | - $url = $matches[3] == '' ? $matches[4] : $matches[3]; |
|
| 735 | - $title =& $matches[7]; |
|
| 732 | + $whole_match = $matches[1]; |
|
| 733 | + $alt_text = $matches[2]; |
|
| 734 | + $url = $matches[3] == '' ? $matches[4] : $matches[3]; |
|
| 735 | + $title = & $matches[7]; |
|
| 736 | 736 | |
| 737 | 737 | $alt_text = $this->encodeAttribute($alt_text); |
| 738 | 738 | $url = $this->encodeAttribute($url); |
| 739 | 739 | $result = "<img src=\"$url\" alt=\"$alt_text\""; |
| 740 | 740 | if (isset($title)) { |
| 741 | 741 | $title = $this->encodeAttribute($title); |
| 742 | - $result .= " title=\"$title\""; # $title already quoted |
|
| 742 | + $result .= " title=\"$title\""; # $title already quoted |
|
| 743 | 743 | } |
| 744 | 744 | $result .= $this->empty_element_suffix; |
| 745 | 745 | |
@@ -783,12 +783,12 @@ discard block |
||
| 783 | 783 | return $matches[0]; |
| 784 | 784 | |
| 785 | 785 | $level = $matches[2]{0} == '=' ? 1 : 2; |
| 786 | - $block = "<h$level>".$this->runSpanGamut($matches[1])."</h$level>"; |
|
| 786 | + $block = "<h$level>" . $this->runSpanGamut($matches[1]) . "</h$level>"; |
|
| 787 | 787 | return "\n" . $this->hashBlock($block) . "\n\n"; |
| 788 | 788 | } |
| 789 | 789 | protected function _doHeaders_callback_atx($matches) { |
| 790 | 790 | $level = strlen($matches[1]); |
| 791 | - $block = "<h$level>".$this->runSpanGamut($matches[2])."</h$level>"; |
|
| 791 | + $block = "<h$level>" . $this->runSpanGamut($matches[2]) . "</h$level>"; |
|
| 792 | 792 | return "\n" . $this->hashBlock($block) . "\n\n"; |
| 793 | 793 | } |
| 794 | 794 | |
@@ -814,8 +814,8 @@ discard block |
||
| 814 | 814 | $whole_list_re = ' |
| 815 | 815 | ( # $1 = whole list |
| 816 | 816 | ( # $2 |
| 817 | - ([ ]{0,'.$less_than_tab.'}) # $3 = number of spaces |
|
| 818 | - ('.$marker_re.') # $4 = first list item marker |
|
| 817 | + ([ ]{0,'.$less_than_tab . '}) # $3 = number of spaces |
|
| 818 | + ('.$marker_re . ') # $4 = first list item marker |
|
| 819 | 819 | [ ]+ |
| 820 | 820 | ) |
| 821 | 821 | (?s:.+?) |
@@ -826,13 +826,13 @@ discard block |
||
| 826 | 826 | (?=\S) |
| 827 | 827 | (?! # Negative lookahead for another list item marker |
| 828 | 828 | [ ]* |
| 829 | - '.$marker_re.'[ ]+ |
|
| 829 | + '.$marker_re . '[ ]+ |
|
| 830 | 830 | ) |
| 831 | 831 | | |
| 832 | 832 | (?= # Lookahead for another kind of list |
| 833 | 833 | \n |
| 834 | 834 | \3 # Must have the same indentation |
| 835 | - '.$other_marker_re.'[ ]+ |
|
| 835 | + '.$other_marker_re . '[ ]+ |
|
| 836 | 836 | ) |
| 837 | 837 | ) |
| 838 | 838 | ) |
@@ -844,14 +844,14 @@ discard block |
||
| 844 | 844 | if ($this->list_level) { |
| 845 | 845 | $text = preg_replace_callback('{ |
| 846 | 846 | ^ |
| 847 | - '.$whole_list_re.' |
|
| 847 | + '.$whole_list_re . ' |
|
| 848 | 848 | }mx', |
| 849 | 849 | array($this, '_doLists_callback'), $text); |
| 850 | 850 | } |
| 851 | 851 | else { |
| 852 | 852 | $text = preg_replace_callback('{ |
| 853 | 853 | (?:(?<=\n)\n?|\A\n?) # Must eat the newline |
| 854 | - '.$whole_list_re.' |
|
| 854 | + '.$whole_list_re . ' |
|
| 855 | 855 | }mx', |
| 856 | 856 | array($this, '_doLists_callback'), $text); |
| 857 | 857 | } |
@@ -868,13 +868,13 @@ discard block |
||
| 868 | 868 | $list = $matches[1]; |
| 869 | 869 | $list_type = preg_match("/$marker_ul_re/", $matches[4]) ? "ul" : "ol"; |
| 870 | 870 | |
| 871 | - $marker_any_re = ( $list_type == "ul" ? $marker_ul_re : $marker_ol_re ); |
|
| 871 | + $marker_any_re = ($list_type == "ul" ? $marker_ul_re : $marker_ol_re); |
|
| 872 | 872 | |
| 873 | 873 | $list .= "\n"; |
| 874 | 874 | $result = $this->processListItems($list, $marker_any_re); |
| 875 | 875 | |
| 876 | 876 | $result = $this->hashBlock("<$list_type>\n" . $result . "</$list_type>"); |
| 877 | - return "\n". $result ."\n\n"; |
|
| 877 | + return "\n" . $result . "\n\n"; |
|
| 878 | 878 | } |
| 879 | 879 | |
| 880 | 880 | protected $list_level = 0; |
@@ -913,12 +913,12 @@ discard block |
||
| 913 | 913 | $list_str = preg_replace_callback('{ |
| 914 | 914 | (\n)? # leading line = $1 |
| 915 | 915 | (^[ ]*) # leading whitespace = $2 |
| 916 | - ('.$marker_any_re.' # list marker and space = $3 |
|
| 916 | + ('.$marker_any_re . ' # list marker and space = $3 |
|
| 917 | 917 | (?:[ ]+|(?=\n)) # space only required if item is not empty |
| 918 | 918 | ) |
| 919 | 919 | ((?s:.*?)) # list item text = $4 |
| 920 | 920 | (?:(\n+(?=\n))|\n) # tailing blank line = $5 |
| 921 | - (?= \n* (\z | \2 ('.$marker_any_re.') (?:[ ]+|(?=\n)))) |
|
| 921 | + (?= \n* (\z | \2 ('.$marker_any_re . ') (?:[ ]+|(?=\n)))) |
|
| 922 | 922 | }xm', |
| 923 | 923 | array($this, '_processListItems_callback'), $list_str); |
| 924 | 924 | |
@@ -927,17 +927,17 @@ discard block |
||
| 927 | 927 | } |
| 928 | 928 | protected function _processListItems_callback($matches) { |
| 929 | 929 | $item = $matches[4]; |
| 930 | - $leading_line =& $matches[1]; |
|
| 931 | - $leading_space =& $matches[2]; |
|
| 930 | + $leading_line = & $matches[1]; |
|
| 931 | + $leading_space = & $matches[2]; |
|
| 932 | 932 | $marker_space = $matches[3]; |
| 933 | - $tailing_blank_line =& $matches[5]; |
|
| 933 | + $tailing_blank_line = & $matches[5]; |
|
| 934 | 934 | |
| 935 | 935 | if ($leading_line || $tailing_blank_line || |
| 936 | 936 | preg_match('/\n{2,}/', $item)) |
| 937 | 937 | { |
| 938 | 938 | # Replace marker with the appropriate whitespace indentation |
| 939 | 939 | $item = $leading_space . str_repeat(' ', strlen($marker_space)) . $item; |
| 940 | - $item = $this->runBlockGamut($this->outdent($item)."\n"); |
|
| 940 | + $item = $this->runBlockGamut($this->outdent($item) . "\n"); |
|
| 941 | 941 | } |
| 942 | 942 | else { |
| 943 | 943 | # Recursion for sub-lists: |
@@ -958,11 +958,11 @@ discard block |
||
| 958 | 958 | (?:\n\n|\A\n?) |
| 959 | 959 | ( # $1 = the code block -- one or more lines, starting with a space/tab |
| 960 | 960 | (?> |
| 961 | - [ ]{'.$this->tab_width.'} # Lines must start with a tab or a tab-width of spaces |
|
| 961 | + [ ]{'.$this->tab_width . '} # Lines must start with a tab or a tab-width of spaces |
|
| 962 | 962 | .*\n+ |
| 963 | 963 | )+ |
| 964 | 964 | ) |
| 965 | - ((?=^[ ]{0,'.$this->tab_width.'}\S)|\Z) # Lookahead for non-space at line-start, or end of doc |
|
| 965 | + ((?=^[ ]{0,'.$this->tab_width . '}\S)|\Z) # Lookahead for non-space at line-start, or end of doc |
|
| 966 | 966 | }xm', |
| 967 | 967 | array($this, '_doCodeBlocks_callback'), $text); |
| 968 | 968 | |
@@ -978,7 +978,7 @@ discard block |
||
| 978 | 978 | $codeblock = preg_replace('/\A\n+|\n+\z/', '', $codeblock); |
| 979 | 979 | |
| 980 | 980 | $codeblock = "<pre><code>$codeblock\n</code></pre>"; |
| 981 | - return "\n\n".$this->hashBlock($codeblock)."\n\n"; |
|
| 981 | + return "\n\n" . $this->hashBlock($codeblock) . "\n\n"; |
|
| 982 | 982 | } |
| 983 | 983 | |
| 984 | 984 | |
@@ -1024,7 +1024,7 @@ discard block |
||
| 1024 | 1024 | $token_relist[] = $strong_re; |
| 1025 | 1025 | |
| 1026 | 1026 | # Construct master expression from list. |
| 1027 | - $token_re = '{('. implode('|', $token_relist) .')}'; |
|
| 1027 | + $token_re = '{(' . implode('|', $token_relist) . ')}'; |
|
| 1028 | 1028 | $this->em_strong_prepared_relist["$em$strong"] = $token_re; |
| 1029 | 1029 | } |
| 1030 | 1030 | } |
@@ -1050,8 +1050,8 @@ discard block |
||
| 1050 | 1050 | # |
| 1051 | 1051 | $parts = preg_split($token_re, $text, 2, PREG_SPLIT_DELIM_CAPTURE); |
| 1052 | 1052 | $text_stack[0] .= $parts[0]; |
| 1053 | - $token =& $parts[1]; |
|
| 1054 | - $text =& $parts[2]; |
|
| 1053 | + $token = & $parts[1]; |
|
| 1054 | + $text = & $parts[2]; |
|
| 1055 | 1055 | |
| 1056 | 1056 | if (empty($token)) { |
| 1057 | 1057 | # Reached end of text span: empty stack without emitting. |
@@ -1078,7 +1078,7 @@ discard block |
||
| 1078 | 1078 | } else { |
| 1079 | 1079 | # Other closing marker: close one em or strong and |
| 1080 | 1080 | # change current token state to match the other |
| 1081 | - $token_stack[0] = str_repeat($token{0}, 3-$token_len); |
|
| 1081 | + $token_stack[0] = str_repeat($token{0}, 3 - $token_len); |
|
| 1082 | 1082 | $tag = $token_len == 2 ? "strong" : "em"; |
| 1083 | 1083 | $span = $text_stack[0]; |
| 1084 | 1084 | $span = $this->runSpanGamut($span); |
@@ -1172,7 +1172,7 @@ discard block |
||
| 1172 | 1172 | $bq = $matches[1]; |
| 1173 | 1173 | # trim one level of quoting - trim whitespace-only lines |
| 1174 | 1174 | $bq = preg_replace('/^[ ]*>[ ]?|^[ ]+$/m', '', $bq); |
| 1175 | - $bq = $this->runBlockGamut($bq); # recurse |
|
| 1175 | + $bq = $this->runBlockGamut($bq); # recurse |
|
| 1176 | 1176 | |
| 1177 | 1177 | $bq = preg_replace('/^/m', " ", $bq); |
| 1178 | 1178 | # These leading spaces cause problem with <pre> content, |
@@ -1180,7 +1180,7 @@ discard block |
||
| 1180 | 1180 | $bq = preg_replace_callback('{(\s*<pre>.+?</pre>)}sx', |
| 1181 | 1181 | array($this, '_doBlockQuotes_callback2'), $bq); |
| 1182 | 1182 | |
| 1183 | - return "\n". $this->hashBlock("<blockquote>\n$bq\n</blockquote>")."\n\n"; |
|
| 1183 | + return "\n" . $this->hashBlock("<blockquote>\n$bq\n</blockquote>") . "\n\n"; |
|
| 1184 | 1184 | } |
| 1185 | 1185 | protected function _doBlockQuotes_callback2($matches) { |
| 1186 | 1186 | $pre = $matches[1]; |
@@ -1282,7 +1282,7 @@ discard block |
||
| 1282 | 1282 | # Ampersand-encoding based entirely on Nat Irons's Amputator |
| 1283 | 1283 | # MT plugin: <http://bumppo.net/projects/amputator/> |
| 1284 | 1284 | $text = preg_replace('/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/', |
| 1285 | - '&', $text);; |
|
| 1285 | + '&', $text); ; |
|
| 1286 | 1286 | } |
| 1287 | 1287 | # Encode remaining <'s |
| 1288 | 1288 | $text = str_replace('<', '<', $text); |
@@ -1346,17 +1346,17 @@ discard block |
||
| 1346 | 1346 | if ($level <= 0) { |
| 1347 | 1347 | $level = 1; |
| 1348 | 1348 | } else { |
| 1349 | - $level ++; |
|
| 1349 | + $level++; |
|
| 1350 | 1350 | } |
| 1351 | 1351 | } else { |
| 1352 | - $level --; |
|
| 1352 | + $level--; |
|
| 1353 | 1353 | } |
| 1354 | 1354 | } |
| 1355 | 1355 | } |
| 1356 | 1356 | |
| 1357 | 1357 | $this->tail = ''; |
| 1358 | 1358 | if ($level < 0) { |
| 1359 | - $link = preg_replace_callback("/\){1," . (- $level) . "}$/", |
|
| 1359 | + $link = preg_replace_callback("/\){1," . (-$level) . "}$/", |
|
| 1360 | 1360 | array($this, '_doAutoLinks_url_callback_callback'), $link); |
| 1361 | 1361 | } |
| 1362 | 1362 | |
@@ -1394,7 +1394,7 @@ discard block |
||
| 1394 | 1394 | # |
| 1395 | 1395 | $addr = "mailto:" . $addr; |
| 1396 | 1396 | $chars = preg_split('/(?<!^)(?!$)/', $addr); |
| 1397 | - $seed = (int)abs(crc32($addr) / strlen($addr)); # Deterministic seed. |
|
| 1397 | + $seed = (int) abs(crc32($addr) / strlen($addr)); # Deterministic seed. |
|
| 1398 | 1398 | |
| 1399 | 1399 | foreach ($chars as $key => $char) { |
| 1400 | 1400 | $ord = ord($char); |
@@ -1404,8 +1404,8 @@ discard block |
||
| 1404 | 1404 | # roughly 10% raw, 45% hex, 45% dec |
| 1405 | 1405 | # '@' *must* be encoded. I insist. |
| 1406 | 1406 | if ($r > 90 && $char != '@') /* do nothing */; |
| 1407 | - else if ($r < 45) $chars[$key] = '&#x'.dechex($ord).';'; |
|
| 1408 | - else $chars[$key] = '&#'.$ord.';'; |
|
| 1407 | + else if ($r < 45) $chars[$key] = '&#x' . dechex($ord) . ';'; |
|
| 1408 | + else $chars[$key] = '&#' . $ord . ';'; |
|
| 1409 | 1409 | } |
| 1410 | 1410 | } |
| 1411 | 1411 | |
@@ -1426,11 +1426,11 @@ discard block |
||
| 1426 | 1426 | |
| 1427 | 1427 | $span_re = '{ |
| 1428 | 1428 | ( |
| 1429 | - \\\\'.$this->escape_chars_re.' |
|
| 1429 | + \\\\'.$this->escape_chars_re . ' |
|
| 1430 | 1430 | | |
| 1431 | 1431 | (?<![`\\\\]) |
| 1432 | 1432 | `+ # code span marker |
| 1433 | - '.( $this->no_markup ? '' : ' |
|
| 1433 | + '.($this->no_markup ? '' : ' |
|
| 1434 | 1434 | | |
| 1435 | 1435 | <!-- .*? --> # comment |
| 1436 | 1436 | | |
@@ -1446,7 +1446,7 @@ discard block |
||
| 1446 | 1446 | <[-a-zA-Z0-9:_]+\s*/> # xml-style empty tag |
| 1447 | 1447 | | |
| 1448 | 1448 | </[-a-zA-Z0-9:_]+\s*> # closing tag |
| 1449 | - ').' |
|
| 1449 | + ') . ' |
|
| 1450 | 1450 | ) |
| 1451 | 1451 | }xs'; |
| 1452 | 1452 | |
@@ -1484,10 +1484,10 @@ discard block |
||
| 1484 | 1484 | # |
| 1485 | 1485 | switch ($token{0}) { |
| 1486 | 1486 | case "\\": |
| 1487 | - return $this->hashPart("&#". ord($token{1}). ";"); |
|
| 1487 | + return $this->hashPart("&#" . ord($token{1}) . ";"); |
|
| 1488 | 1488 | case "`": |
| 1489 | 1489 | # Search for end marker in remaining text. |
| 1490 | - if (preg_match('/^(.*?[^`])'.preg_quote($token).'(?!`)(.*)$/sm', |
|
| 1490 | + if (preg_match('/^(.*?[^`])' . preg_quote($token) . '(?!`)(.*)$/sm', |
|
| 1491 | 1491 | $str, $matches)) |
| 1492 | 1492 | { |
| 1493 | 1493 | $str = $matches[2]; |
@@ -1505,7 +1505,7 @@ discard block |
||
| 1505 | 1505 | # |
| 1506 | 1506 | # Remove one level of line-leading tabs or spaces |
| 1507 | 1507 | # |
| 1508 | - return preg_replace('/^(\t|[ ]{1,'.$this->tab_width.'})/m', '', $text); |
|
| 1508 | + return preg_replace('/^(\t|[ ]{1,' . $this->tab_width . '})/m', '', $text); |
|
| 1509 | 1509 | } |
| 1510 | 1510 | |
| 1511 | 1511 | |
@@ -1730,10 +1730,10 @@ discard block |
||
| 1730 | 1730 | # compose attributes as string |
| 1731 | 1731 | $attr_str = ""; |
| 1732 | 1732 | if (!empty($id)) { |
| 1733 | - $attr_str .= ' id="'.$id.'"'; |
|
| 1733 | + $attr_str .= ' id="' . $id . '"'; |
|
| 1734 | 1734 | } |
| 1735 | 1735 | if (!empty($classes)) { |
| 1736 | - $attr_str .= ' class="'.implode(" ", $classes).'"'; |
|
| 1736 | + $attr_str .= ' class="' . implode(" ", $classes) . '"'; |
|
| 1737 | 1737 | } |
| 1738 | 1738 | return $attr_str; |
| 1739 | 1739 | } |
@@ -1748,7 +1748,7 @@ discard block |
||
| 1748 | 1748 | |
| 1749 | 1749 | # Link defs are in the form: ^[id]: url "optional title" |
| 1750 | 1750 | $text = preg_replace_callback('{ |
| 1751 | - ^[ ]{0,'.$less_than_tab.'}\[(.+)\][ ]?: # id = $1 |
|
| 1751 | + ^[ ]{0,'.$less_than_tab . '}\[(.+)\][ ]?: # id = $1 |
|
| 1752 | 1752 | [ ]* |
| 1753 | 1753 | \n? # maybe *one* newline |
| 1754 | 1754 | [ ]* |
@@ -1767,7 +1767,7 @@ discard block |
||
| 1767 | 1767 | [")] |
| 1768 | 1768 | [ ]* |
| 1769 | 1769 | )? # title is optional |
| 1770 | - (?:[ ]* '.$this->id_class_attr_catch_re.' )? # $5 = extra id & class attr |
|
| 1770 | + (?:[ ]* '.$this->id_class_attr_catch_re . ' )? # $5 = extra id & class attr |
|
| 1771 | 1771 | (?:\n+|\Z) |
| 1772 | 1772 | }xm', |
| 1773 | 1773 | array($this, '_stripLinkDefinitions_callback'), |
@@ -1778,8 +1778,8 @@ discard block |
||
| 1778 | 1778 | $link_id = strtolower($matches[1]); |
| 1779 | 1779 | $url = $matches[2] == '' ? $matches[3] : $matches[2]; |
| 1780 | 1780 | $this->urls[$link_id] = $url; |
| 1781 | - $this->titles[$link_id] =& $matches[4]; |
|
| 1782 | - $this->ref_attr[$link_id] = $this->doExtraAttributes("", $dummy =& $matches[5]); |
|
| 1781 | + $this->titles[$link_id] = & $matches[4]; |
|
| 1782 | + $this->ref_attr[$link_id] = $this->doExtraAttributes("", $dummy = & $matches[5]); |
|
| 1783 | 1783 | return ''; # String that will replace the block |
| 1784 | 1784 | } |
| 1785 | 1785 | |
@@ -1824,7 +1824,7 @@ discard block |
||
| 1824 | 1824 | # |
| 1825 | 1825 | # Call the HTML-in-Markdown hasher. |
| 1826 | 1826 | # |
| 1827 | - list($text, ) = $this->_hashHTMLBlocks_inMarkdown($text); |
|
| 1827 | + list($text,) = $this->_hashHTMLBlocks_inMarkdown($text); |
|
| 1828 | 1828 | |
| 1829 | 1829 | return $text; |
| 1830 | 1830 | } |
@@ -1873,10 +1873,10 @@ discard block |
||
| 1873 | 1873 | ( # $2: Capture whole tag. |
| 1874 | 1874 | </? # Any opening or closing tag. |
| 1875 | 1875 | (?> # Tag name. |
| 1876 | - '.$this->block_tags_re.' | |
|
| 1877 | - '.$this->context_block_tags_re.' | |
|
| 1878 | - '.$this->clean_tags_re.' | |
|
| 1879 | - (?!\s)'.$enclosing_tag_re.' |
|
| 1876 | + '.$this->block_tags_re . ' | |
|
| 1877 | + '.$this->context_block_tags_re . ' | |
|
| 1878 | + '.$this->clean_tags_re . ' | |
|
| 1879 | + (?!\s)'.$enclosing_tag_re . ' |
|
| 1880 | 1880 | ) |
| 1881 | 1881 | (?: |
| 1882 | 1882 | (?=[\s"\'/a-zA-Z0-9]) # Allowed characters after tag name. |
@@ -1896,33 +1896,33 @@ discard block |
||
| 1896 | 1896 | | |
| 1897 | 1897 | # Code span marker |
| 1898 | 1898 | `+ |
| 1899 | - '. ( !$span ? ' # If not in span. |
|
| 1899 | + '. (!$span ? ' # If not in span. |
|
| 1900 | 1900 | | |
| 1901 | 1901 | # Indented code block |
| 1902 | 1902 | (?: ^[ ]*\n | ^ | \n[ ]*\n ) |
| 1903 | - [ ]{'.($indent+4).'}[^\n]* \n |
|
| 1903 | + [ ]{'.($indent + 4) . '}[^\n]* \n |
|
| 1904 | 1904 | (?> |
| 1905 | - (?: [ ]{'.($indent+4).'}[^\n]* | [ ]* ) \n |
|
| 1905 | + (?: [ ]{'.($indent + 4) . '}[^\n]* | [ ]* ) \n |
|
| 1906 | 1906 | )* |
| 1907 | 1907 | | |
| 1908 | 1908 | # Fenced code block marker |
| 1909 | 1909 | (?<= ^ | \n ) |
| 1910 | - [ ]{0,'.($indent+3).'}~{3,} |
|
| 1910 | + [ ]{0,'.($indent + 3) . '}~{3,} |
|
| 1911 | 1911 | [ ]* |
| 1912 | 1912 | (?: |
| 1913 | 1913 | \.?[-_:a-zA-Z0-9]+ # standalone class name |
| 1914 | 1914 | | |
| 1915 | - '.$this->id_class_attr_nocatch_re.' # extra attributes |
|
| 1915 | + '.$this->id_class_attr_nocatch_re . ' # extra attributes |
|
| 1916 | 1916 | )? |
| 1917 | 1917 | [ ]* |
| 1918 | 1918 | \n |
| 1919 | - ' : '' ). ' # End (if not is span). |
|
| 1919 | + ' : '') . ' # End (if not is span). |
|
| 1920 | 1920 | ) |
| 1921 | 1921 | }xs'; |
| 1922 | 1922 | |
| 1923 | 1923 | |
| 1924 | - $depth = 0; # Current depth inside the tag tree. |
|
| 1925 | - $parsed = ""; # Parsed text that will be returned. |
|
| 1924 | + $depth = 0; # Current depth inside the tag tree. |
|
| 1925 | + $parsed = ""; # Parsed text that will be returned. |
|
| 1926 | 1926 | |
| 1927 | 1927 | # |
| 1928 | 1928 | # Loop through every tag until we find the closing tag of the parent |
@@ -1964,7 +1964,7 @@ discard block |
||
| 1964 | 1964 | if ($tag{0} == "`") { |
| 1965 | 1965 | # Find corresponding end marker. |
| 1966 | 1966 | $tag_re = preg_quote($tag); |
| 1967 | - if (preg_match('{^(?>.+?|\n(?!\n))*?(?<!`)'.$tag_re.'(?!`)}', |
|
| 1967 | + if (preg_match('{^(?>.+?|\n(?!\n))*?(?<!`)' . $tag_re . '(?!`)}', |
|
| 1968 | 1968 | $text, $matches)) |
| 1969 | 1969 | { |
| 1970 | 1970 | # End marker found: pass text unchanged until marker. |
@@ -1979,11 +1979,11 @@ discard block |
||
| 1979 | 1979 | # |
| 1980 | 1980 | # Check for: Fenced code block marker. |
| 1981 | 1981 | # |
| 1982 | - else if (preg_match('{^\n?([ ]{0,'.($indent+3).'})(~+)}', $tag, $capture)) { |
|
| 1982 | + else if (preg_match('{^\n?([ ]{0,' . ($indent + 3) . '})(~+)}', $tag, $capture)) { |
|
| 1983 | 1983 | # Fenced code block marker: find matching end marker. |
| 1984 | 1984 | $fence_indent = strlen($capture[1]); # use captured indent in re |
| 1985 | 1985 | $fence_re = $capture[2]; # use captured fence in re |
| 1986 | - if (preg_match('{^(?>.*\n)*?[ ]{'.($fence_indent).'}'.$fence_re.'[ ]*(?:\n|$)}', $text, |
|
| 1986 | + if (preg_match('{^(?>.*\n)*?[ ]{' . ($fence_indent) . '}' . $fence_re . '[ ]*(?:\n|$)}', $text, |
|
| 1987 | 1987 | $matches)) |
| 1988 | 1988 | { |
| 1989 | 1989 | # End marker found: pass text unchanged until marker. |
@@ -2008,10 +2008,10 @@ discard block |
||
| 2008 | 2008 | # Opening Context Block tag (like ins and del) |
| 2009 | 2009 | # used as a block tag (tag is alone on it's line). |
| 2010 | 2010 | # |
| 2011 | - else if (preg_match('{^<(?:'.$this->block_tags_re.')\b}', $tag) || |
|
| 2012 | - ( preg_match('{^<(?:'.$this->context_block_tags_re.')\b}', $tag) && |
|
| 2011 | + else if (preg_match('{^<(?:' . $this->block_tags_re . ')\b}', $tag) || |
|
| 2012 | + (preg_match('{^<(?:' . $this->context_block_tags_re . ')\b}', $tag) && |
|
| 2013 | 2013 | preg_match($newline_before_re, $parsed) && |
| 2014 | - preg_match($newline_after_re, $text) ) |
|
| 2014 | + preg_match($newline_after_re, $text)) |
|
| 2015 | 2015 | ) |
| 2016 | 2016 | { |
| 2017 | 2017 | # Need to parse tag and following text using the HTML parser. |
@@ -2025,7 +2025,7 @@ discard block |
||
| 2025 | 2025 | # Check for: Clean tag (like script, math) |
| 2026 | 2026 | # HTML Comments, processing instructions. |
| 2027 | 2027 | # |
| 2028 | - else if (preg_match('{^<(?:'.$this->clean_tags_re.')\b}', $tag) || |
|
| 2028 | + else if (preg_match('{^<(?:' . $this->clean_tags_re . ')\b}', $tag) || |
|
| 2029 | 2029 | $tag{1} == '!' || $tag{1} == '?') |
| 2030 | 2030 | { |
| 2031 | 2031 | # Need to parse tag and following text using the HTML parser. |
@@ -2040,13 +2040,13 @@ discard block |
||
| 2040 | 2040 | # |
| 2041 | 2041 | else if ($enclosing_tag_re !== '' && |
| 2042 | 2042 | # Same name as enclosing tag. |
| 2043 | - preg_match('{^</?(?:'.$enclosing_tag_re.')\b}', $tag)) |
|
| 2043 | + preg_match('{^</?(?:' . $enclosing_tag_re . ')\b}', $tag)) |
|
| 2044 | 2044 | { |
| 2045 | 2045 | # |
| 2046 | 2046 | # Increase/decrease nested tag count. |
| 2047 | 2047 | # |
| 2048 | 2048 | if ($tag{1} == '/') $depth--; |
| 2049 | - else if ($tag{strlen($tag)-2} != '/') $depth++; |
|
| 2049 | + else if ($tag{strlen($tag) - 2} != '/') $depth++; |
|
| 2050 | 2050 | |
| 2051 | 2051 | if ($depth < 0) { |
| 2052 | 2052 | # |
@@ -2118,11 +2118,11 @@ discard block |
||
| 2118 | 2118 | ) |
| 2119 | 2119 | }xs'; |
| 2120 | 2120 | |
| 2121 | - $original_text = $text; # Save original text in case of faliure. |
|
| 2121 | + $original_text = $text; # Save original text in case of faliure. |
|
| 2122 | 2122 | |
| 2123 | - $depth = 0; # Current depth inside the tag tree. |
|
| 2124 | - $block_text = ""; # Temporary text holder for current text. |
|
| 2125 | - $parsed = ""; # Parsed text that will be returned. |
|
| 2123 | + $depth = 0; # Current depth inside the tag tree. |
|
| 2124 | + $block_text = ""; # Temporary text holder for current text. |
|
| 2125 | + $parsed = ""; # Parsed text that will be returned. |
|
| 2126 | 2126 | |
| 2127 | 2127 | # |
| 2128 | 2128 | # Get the name of the starting tag. |
@@ -2161,7 +2161,7 @@ discard block |
||
| 2161 | 2161 | # Check for: Auto-close tag (like <hr/>) |
| 2162 | 2162 | # Comments and Processing Instructions. |
| 2163 | 2163 | # |
| 2164 | - if (preg_match('{^</?(?:'.$this->auto_close_tags_re.')\b}', $tag) || |
|
| 2164 | + if (preg_match('{^</?(?:' . $this->auto_close_tags_re . ')\b}', $tag) || |
|
| 2165 | 2165 | $tag{1} == '!' || $tag{1} == '?') |
| 2166 | 2166 | { |
| 2167 | 2167 | # Just add the tag to the block as if it was text. |
@@ -2172,9 +2172,9 @@ discard block |
||
| 2172 | 2172 | # Increase/decrease nested tag count. Only do so if |
| 2173 | 2173 | # the tag's name match base tag's. |
| 2174 | 2174 | # |
| 2175 | - if (preg_match('{^</?'.$base_tag_name_re.'\b}', $tag)) { |
|
| 2175 | + if (preg_match('{^</?' . $base_tag_name_re . '\b}', $tag)) { |
|
| 2176 | 2176 | if ($tag{1} == '/') $depth--; |
| 2177 | - else if ($tag{strlen($tag)-2} != '/') $depth++; |
|
| 2177 | + else if ($tag{strlen($tag) - 2} != '/') $depth++; |
|
| 2178 | 2178 | } |
| 2179 | 2179 | |
| 2180 | 2180 | # |
@@ -2190,7 +2190,7 @@ discard block |
||
| 2190 | 2190 | # Check if text inside this tag must be parsed in span mode. |
| 2191 | 2191 | $this->mode = $attr_m[2] . $attr_m[3]; |
| 2192 | 2192 | $span_mode = $this->mode == 'span' || $this->mode != 'block' && |
| 2193 | - preg_match('{^<(?:'.$this->contain_span_tags_re.')\b}', $tag); |
|
| 2193 | + preg_match('{^<(?:' . $this->contain_span_tags_re . ')\b}', $tag); |
|
| 2194 | 2194 | |
| 2195 | 2195 | # Calculate indent before tag. |
| 2196 | 2196 | if (preg_match('/(?:^|\n)( *?)(?! ).*?$/', $block_text, $matches)) { |
@@ -2264,7 +2264,7 @@ discard block |
||
| 2264 | 2264 | $text = preg_replace_callback('{ |
| 2265 | 2265 | ( # wrap whole match in $1 |
| 2266 | 2266 | \[ |
| 2267 | - ('.$this->nested_brackets_re.') # link text = $2 |
|
| 2267 | + ('.$this->nested_brackets_re . ') # link text = $2 |
|
| 2268 | 2268 | \] |
| 2269 | 2269 | |
| 2270 | 2270 | [ ]? # one optional space |
@@ -2283,14 +2283,14 @@ discard block |
||
| 2283 | 2283 | $text = preg_replace_callback('{ |
| 2284 | 2284 | ( # wrap whole match in $1 |
| 2285 | 2285 | \[ |
| 2286 | - ('.$this->nested_brackets_re.') # link text = $2 |
|
| 2286 | + ('.$this->nested_brackets_re . ') # link text = $2 |
|
| 2287 | 2287 | \] |
| 2288 | 2288 | \( # literal paren |
| 2289 | 2289 | [ \n]* |
| 2290 | 2290 | (?: |
| 2291 | 2291 | <(.+?)> # href = $3 |
| 2292 | 2292 | | |
| 2293 | - ('.$this->nested_url_parenthesis_re.') # href = $4 |
|
| 2293 | + ('.$this->nested_url_parenthesis_re . ') # href = $4 |
|
| 2294 | 2294 | ) |
| 2295 | 2295 | [ \n]* |
| 2296 | 2296 | ( # $5 |
@@ -2300,7 +2300,7 @@ discard block |
||
| 2300 | 2300 | [ \n]* # ignore any spaces/tabs between closing quote and ) |
| 2301 | 2301 | )? # title is optional |
| 2302 | 2302 | \) |
| 2303 | - (?:[ ]? '.$this->id_class_attr_catch_re.' )? # $8 = id/class attributes |
|
| 2303 | + (?:[ ]? '.$this->id_class_attr_catch_re . ' )? # $8 = id/class attributes |
|
| 2304 | 2304 | ) |
| 2305 | 2305 | }xs', |
| 2306 | 2306 | array($this, '_doAnchors_inline_callback'), $text); |
@@ -2323,9 +2323,9 @@ discard block |
||
| 2323 | 2323 | return $text; |
| 2324 | 2324 | } |
| 2325 | 2325 | protected function _doAnchors_reference_callback($matches) { |
| 2326 | - $whole_match = $matches[1]; |
|
| 2327 | - $link_text = $matches[2]; |
|
| 2328 | - $link_id =& $matches[3]; |
|
| 2326 | + $whole_match = $matches[1]; |
|
| 2327 | + $link_text = $matches[2]; |
|
| 2328 | + $link_id = & $matches[3]; |
|
| 2329 | 2329 | |
| 2330 | 2330 | if ($link_id == "") { |
| 2331 | 2331 | # for shortcut links like [this][] or [this]. |
@@ -2341,10 +2341,10 @@ discard block |
||
| 2341 | 2341 | $url = $this->encodeAttribute($url); |
| 2342 | 2342 | |
| 2343 | 2343 | $result = "<a href=\"$url\""; |
| 2344 | - if ( isset( $this->titles[$link_id] ) ) { |
|
| 2344 | + if (isset($this->titles[$link_id])) { |
|
| 2345 | 2345 | $title = $this->titles[$link_id]; |
| 2346 | 2346 | $title = $this->encodeAttribute($title); |
| 2347 | - $result .= " title=\"$title\""; |
|
| 2347 | + $result .= " title=\"$title\""; |
|
| 2348 | 2348 | } |
| 2349 | 2349 | if (isset($this->ref_attr[$link_id])) |
| 2350 | 2350 | $result .= $this->ref_attr[$link_id]; |
@@ -2359,11 +2359,11 @@ discard block |
||
| 2359 | 2359 | return $result; |
| 2360 | 2360 | } |
| 2361 | 2361 | protected function _doAnchors_inline_callback($matches) { |
| 2362 | - $whole_match = $matches[1]; |
|
| 2363 | - $link_text = $this->runSpanGamut($matches[2]); |
|
| 2364 | - $url = $matches[3] == '' ? $matches[4] : $matches[3]; |
|
| 2365 | - $title =& $matches[7]; |
|
| 2366 | - $attr = $this->doExtraAttributes("a", $dummy =& $matches[8]); |
|
| 2362 | + $whole_match = $matches[1]; |
|
| 2363 | + $link_text = $this->runSpanGamut($matches[2]); |
|
| 2364 | + $url = $matches[3] == '' ? $matches[4] : $matches[3]; |
|
| 2365 | + $title = & $matches[7]; |
|
| 2366 | + $attr = $this->doExtraAttributes("a", $dummy = & $matches[8]); |
|
| 2367 | 2367 | |
| 2368 | 2368 | |
| 2369 | 2369 | $url = $this->encodeAttribute($url); |
@@ -2371,7 +2371,7 @@ discard block |
||
| 2371 | 2371 | $result = "<a href=\"$url\""; |
| 2372 | 2372 | if (isset($title)) { |
| 2373 | 2373 | $title = $this->encodeAttribute($title); |
| 2374 | - $result .= " title=\"$title\""; |
|
| 2374 | + $result .= " title=\"$title\""; |
|
| 2375 | 2375 | } |
| 2376 | 2376 | $result .= $attr; |
| 2377 | 2377 | |
@@ -2392,7 +2392,7 @@ discard block |
||
| 2392 | 2392 | $text = preg_replace_callback('{ |
| 2393 | 2393 | ( # wrap whole match in $1 |
| 2394 | 2394 | !\[ |
| 2395 | - ('.$this->nested_brackets_re.') # alt text = $2 |
|
| 2395 | + ('.$this->nested_brackets_re . ') # alt text = $2 |
|
| 2396 | 2396 | \] |
| 2397 | 2397 | |
| 2398 | 2398 | [ ]? # one optional space |
@@ -2413,7 +2413,7 @@ discard block |
||
| 2413 | 2413 | $text = preg_replace_callback('{ |
| 2414 | 2414 | ( # wrap whole match in $1 |
| 2415 | 2415 | !\[ |
| 2416 | - ('.$this->nested_brackets_re.') # alt text = $2 |
|
| 2416 | + ('.$this->nested_brackets_re . ') # alt text = $2 |
|
| 2417 | 2417 | \] |
| 2418 | 2418 | \s? # One optional whitespace character |
| 2419 | 2419 | \( # literal paren |
@@ -2421,7 +2421,7 @@ discard block |
||
| 2421 | 2421 | (?: |
| 2422 | 2422 | <(\S*)> # src url = $3 |
| 2423 | 2423 | | |
| 2424 | - ('.$this->nested_url_parenthesis_re.') # src url = $4 |
|
| 2424 | + ('.$this->nested_url_parenthesis_re . ') # src url = $4 |
|
| 2425 | 2425 | ) |
| 2426 | 2426 | [ \n]* |
| 2427 | 2427 | ( # $5 |
@@ -2431,7 +2431,7 @@ discard block |
||
| 2431 | 2431 | [ \n]* |
| 2432 | 2432 | )? # title is optional |
| 2433 | 2433 | \) |
| 2434 | - (?:[ ]? '.$this->id_class_attr_catch_re.' )? # $8 = id/class attributes |
|
| 2434 | + (?:[ ]? '.$this->id_class_attr_catch_re . ' )? # $8 = id/class attributes |
|
| 2435 | 2435 | ) |
| 2436 | 2436 | }xs', |
| 2437 | 2437 | array($this, '_doImages_inline_callback'), $text); |
@@ -2454,7 +2454,7 @@ discard block |
||
| 2454 | 2454 | if (isset($this->titles[$link_id])) { |
| 2455 | 2455 | $title = $this->titles[$link_id]; |
| 2456 | 2456 | $title = $this->encodeAttribute($title); |
| 2457 | - $result .= " title=\"$title\""; |
|
| 2457 | + $result .= " title=\"$title\""; |
|
| 2458 | 2458 | } |
| 2459 | 2459 | if (isset($this->ref_attr[$link_id])) |
| 2460 | 2460 | $result .= $this->ref_attr[$link_id]; |
@@ -2469,18 +2469,18 @@ discard block |
||
| 2469 | 2469 | return $result; |
| 2470 | 2470 | } |
| 2471 | 2471 | protected function _doImages_inline_callback($matches) { |
| 2472 | - $whole_match = $matches[1]; |
|
| 2473 | - $alt_text = $matches[2]; |
|
| 2472 | + $whole_match = $matches[1]; |
|
| 2473 | + $alt_text = $matches[2]; |
|
| 2474 | 2474 | $url = $matches[3] == '' ? $matches[4] : $matches[3]; |
| 2475 | - $title =& $matches[7]; |
|
| 2476 | - $attr = $this->doExtraAttributes("img", $dummy =& $matches[8]); |
|
| 2475 | + $title = & $matches[7]; |
|
| 2476 | + $attr = $this->doExtraAttributes("img", $dummy = & $matches[8]); |
|
| 2477 | 2477 | |
| 2478 | 2478 | $alt_text = $this->encodeAttribute($alt_text); |
| 2479 | 2479 | $url = $this->encodeAttribute($url); |
| 2480 | 2480 | $result = "<img src=\"$url\" alt=\"$alt_text\""; |
| 2481 | 2481 | if (isset($title)) { |
| 2482 | 2482 | $title = $this->encodeAttribute($title); |
| 2483 | - $result .= " title=\"$title\""; # $title already quoted |
|
| 2483 | + $result .= " title=\"$title\""; # $title already quoted |
|
| 2484 | 2484 | } |
| 2485 | 2485 | $result .= $attr; |
| 2486 | 2486 | $result .= $this->empty_element_suffix; |
@@ -2503,7 +2503,7 @@ discard block |
||
| 2503 | 2503 | $text = preg_replace_callback( |
| 2504 | 2504 | '{ |
| 2505 | 2505 | (^.+?) # $1: Header text |
| 2506 | - (?:[ ]+ '.$this->id_class_attr_catch_re.' )? # $3 = id/class attributes |
|
| 2506 | + (?:[ ]+ '.$this->id_class_attr_catch_re . ' )? # $3 = id/class attributes |
|
| 2507 | 2507 | [ ]*\n(=+|-+)[ ]*\n+ # $3: Header footer |
| 2508 | 2508 | }mx', |
| 2509 | 2509 | array($this, '_doHeaders_callback_setext'), $text); |
@@ -2521,7 +2521,7 @@ discard block |
||
| 2521 | 2521 | (.+?) # $2 = Header text |
| 2522 | 2522 | [ ]* |
| 2523 | 2523 | \#* # optional closing #\'s (not counted) |
| 2524 | - (?:[ ]+ '.$this->id_class_attr_catch_re.' )? # $3 = id/class attributes |
|
| 2524 | + (?:[ ]+ '.$this->id_class_attr_catch_re . ' )? # $3 = id/class attributes |
|
| 2525 | 2525 | [ ]* |
| 2526 | 2526 | \n+ |
| 2527 | 2527 | }xm', |
@@ -2533,14 +2533,14 @@ discard block |
||
| 2533 | 2533 | if ($matches[3] == '-' && preg_match('{^- }', $matches[1])) |
| 2534 | 2534 | return $matches[0]; |
| 2535 | 2535 | $level = $matches[3]{0} == '=' ? 1 : 2; |
| 2536 | - $attr = $this->doExtraAttributes("h$level", $dummy =& $matches[2]); |
|
| 2537 | - $block = "<h$level$attr>".$this->runSpanGamut($matches[1])."</h$level>"; |
|
| 2536 | + $attr = $this->doExtraAttributes("h$level", $dummy = & $matches[2]); |
|
| 2537 | + $block = "<h$level$attr>" . $this->runSpanGamut($matches[1]) . "</h$level>"; |
|
| 2538 | 2538 | return "\n" . $this->hashBlock($block) . "\n\n"; |
| 2539 | 2539 | } |
| 2540 | 2540 | protected function _doHeaders_callback_atx($matches) { |
| 2541 | 2541 | $level = strlen($matches[1]); |
| 2542 | - $attr = $this->doExtraAttributes("h$level", $dummy =& $matches[3]); |
|
| 2543 | - $block = "<h$level$attr>".$this->runSpanGamut($matches[2])."</h$level>"; |
|
| 2542 | + $attr = $this->doExtraAttributes("h$level", $dummy = & $matches[3]); |
|
| 2543 | + $block = "<h$level$attr>" . $this->runSpanGamut($matches[2]) . "</h$level>"; |
|
| 2544 | 2544 | return "\n" . $this->hashBlock($block) . "\n\n"; |
| 2545 | 2545 | } |
| 2546 | 2546 | |
@@ -2561,11 +2561,11 @@ discard block |
||
| 2561 | 2561 | $text = preg_replace_callback(' |
| 2562 | 2562 | { |
| 2563 | 2563 | ^ # Start of a line |
| 2564 | - [ ]{0,'.$less_than_tab.'} # Allowed whitespace. |
|
| 2564 | + [ ]{0,'.$less_than_tab . '} # Allowed whitespace. |
|
| 2565 | 2565 | [|] # Optional leading pipe (present) |
| 2566 | 2566 | (.+) \n # $1: Header row (at least one pipe) |
| 2567 | 2567 | |
| 2568 | - [ ]{0,'.$less_than_tab.'} # Allowed whitespace. |
|
| 2568 | + [ ]{0,'.$less_than_tab . '} # Allowed whitespace. |
|
| 2569 | 2569 | [|] ([ ]*[-:]+[-| :]*) \n # $2: Header underline |
| 2570 | 2570 | |
| 2571 | 2571 | ( # $3: Cells |
@@ -2589,10 +2589,10 @@ discard block |
||
| 2589 | 2589 | $text = preg_replace_callback(' |
| 2590 | 2590 | { |
| 2591 | 2591 | ^ # Start of a line |
| 2592 | - [ ]{0,'.$less_than_tab.'} # Allowed whitespace. |
|
| 2592 | + [ ]{0,'.$less_than_tab . '} # Allowed whitespace. |
|
| 2593 | 2593 | (\S.*[|].*) \n # $1: Header row (at least one pipe) |
| 2594 | 2594 | |
| 2595 | - [ ]{0,'.$less_than_tab.'} # Allowed whitespace. |
|
| 2595 | + [ ]{0,'.$less_than_tab . '} # Allowed whitespace. |
|
| 2596 | 2596 | ([-:]+[ ]*[|][-| :]*) \n # $2: Header underline |
| 2597 | 2597 | |
| 2598 | 2598 | ( # $3: Cells |
@@ -2607,8 +2607,8 @@ discard block |
||
| 2607 | 2607 | return $text; |
| 2608 | 2608 | } |
| 2609 | 2609 | protected function _doTable_leadingPipe_callback($matches) { |
| 2610 | - $head = $matches[1]; |
|
| 2611 | - $underline = $matches[2]; |
|
| 2610 | + $head = $matches[1]; |
|
| 2611 | + $underline = $matches[2]; |
|
| 2612 | 2612 | $content = $matches[3]; |
| 2613 | 2613 | |
| 2614 | 2614 | # Remove leading pipe for each row. |
@@ -2625,14 +2625,14 @@ discard block |
||
| 2625 | 2625 | return " class=\"$classname\""; |
| 2626 | 2626 | } |
| 2627 | 2627 | protected function _doTable_callback($matches) { |
| 2628 | - $head = $matches[1]; |
|
| 2629 | - $underline = $matches[2]; |
|
| 2630 | - $content = $matches[3]; |
|
| 2628 | + $head = $matches[1]; |
|
| 2629 | + $underline = $matches[2]; |
|
| 2630 | + $content = $matches[3]; |
|
| 2631 | 2631 | |
| 2632 | 2632 | # Remove any tailing pipes for each line. |
| 2633 | - $head = preg_replace('/[|] *$/m', '', $head); |
|
| 2634 | - $underline = preg_replace('/[|] *$/m', '', $underline); |
|
| 2635 | - $content = preg_replace('/[|] *$/m', '', $content); |
|
| 2633 | + $head = preg_replace('/[|] *$/m', '', $head); |
|
| 2634 | + $underline = preg_replace('/[|] *$/m', '', $underline); |
|
| 2635 | + $content = preg_replace('/[|] *$/m', '', $content); |
|
| 2636 | 2636 | |
| 2637 | 2637 | # Reading alignement from header underline. |
| 2638 | 2638 | $separators = preg_split('/ *[|] */', $underline); |
@@ -2649,17 +2649,17 @@ discard block |
||
| 2649 | 2649 | |
| 2650 | 2650 | # Parsing span elements, including code spans, character escapes, |
| 2651 | 2651 | # and inline HTML tags, so that pipes inside those gets ignored. |
| 2652 | - $head = $this->parseSpan($head); |
|
| 2653 | - $headers = preg_split('/ *[|] */', $head); |
|
| 2654 | - $col_count = count($headers); |
|
| 2655 | - $attr = array_pad($attr, $col_count, ''); |
|
| 2652 | + $head = $this->parseSpan($head); |
|
| 2653 | + $headers = preg_split('/ *[|] */', $head); |
|
| 2654 | + $col_count = count($headers); |
|
| 2655 | + $attr = array_pad($attr, $col_count, ''); |
|
| 2656 | 2656 | |
| 2657 | 2657 | # Write column headers. |
| 2658 | 2658 | $text = "<table>\n"; |
| 2659 | 2659 | $text .= "<thead>\n"; |
| 2660 | 2660 | $text .= "<tr>\n"; |
| 2661 | 2661 | foreach ($headers as $n => $header) |
| 2662 | - $text .= " <th$attr[$n]>".$this->runSpanGamut(trim($header))."</th>\n"; |
|
| 2662 | + $text .= " <th$attr[$n]>" . $this->runSpanGamut(trim($header)) . "</th>\n"; |
|
| 2663 | 2663 | $text .= "</tr>\n"; |
| 2664 | 2664 | $text .= "</thead>\n"; |
| 2665 | 2665 | |
@@ -2678,7 +2678,7 @@ discard block |
||
| 2678 | 2678 | |
| 2679 | 2679 | $text .= "<tr>\n"; |
| 2680 | 2680 | foreach ($row_cells as $n => $cell) |
| 2681 | - $text .= " <td$attr[$n]>".$this->runSpanGamut(trim($cell))."</td>\n"; |
|
| 2681 | + $text .= " <td$attr[$n]>" . $this->runSpanGamut(trim($cell)) . "</td>\n"; |
|
| 2682 | 2682 | $text .= "</tr>\n"; |
| 2683 | 2683 | } |
| 2684 | 2684 | $text .= "</tbody>\n"; |
@@ -2698,10 +2698,10 @@ discard block |
||
| 2698 | 2698 | $whole_list_re = '(?> |
| 2699 | 2699 | ( # $1 = whole list |
| 2700 | 2700 | ( # $2 |
| 2701 | - [ ]{0,'.$less_than_tab.'} |
|
| 2701 | + [ ]{0,'.$less_than_tab . '} |
|
| 2702 | 2702 | ((?>.*\S.*\n)+) # $3 = defined term |
| 2703 | 2703 | \n? |
| 2704 | - [ ]{0,'.$less_than_tab.'}:[ ]+ # colon starting definition |
|
| 2704 | + [ ]{0,'.$less_than_tab . '}:[ ]+ # colon starting definition |
|
| 2705 | 2705 | ) |
| 2706 | 2706 | (?s:.+?) |
| 2707 | 2707 | ( # $4 |
@@ -2710,13 +2710,13 @@ discard block |
||
| 2710 | 2710 | \n{2,} |
| 2711 | 2711 | (?=\S) |
| 2712 | 2712 | (?! # Negative lookahead for another term |
| 2713 | - [ ]{0,'.$less_than_tab.'} |
|
| 2713 | + [ ]{0,'.$less_than_tab . '} |
|
| 2714 | 2714 | (?: \S.*\n )+? # defined term |
| 2715 | 2715 | \n? |
| 2716 | - [ ]{0,'.$less_than_tab.'}:[ ]+ # colon starting definition |
|
| 2716 | + [ ]{0,'.$less_than_tab . '}:[ ]+ # colon starting definition |
|
| 2717 | 2717 | ) |
| 2718 | 2718 | (?! # Negative lookahead for another definition |
| 2719 | - [ ]{0,'.$less_than_tab.'}:[ ]+ # colon starting definition |
|
| 2719 | + [ ]{0,'.$less_than_tab . '}:[ ]+ # colon starting definition |
|
| 2720 | 2720 | ) |
| 2721 | 2721 | ) |
| 2722 | 2722 | ) |
@@ -2724,7 +2724,7 @@ discard block |
||
| 2724 | 2724 | |
| 2725 | 2725 | $text = preg_replace_callback('{ |
| 2726 | 2726 | (?>\A\n?|(?<=\n\n)) |
| 2727 | - '.$whole_list_re.' |
|
| 2727 | + '.$whole_list_re . ' |
|
| 2728 | 2728 | }mx', |
| 2729 | 2729 | array($this, '_doDefLists_callback'), $text); |
| 2730 | 2730 | |
@@ -2756,7 +2756,7 @@ discard block |
||
| 2756 | 2756 | $list_str = preg_replace_callback('{ |
| 2757 | 2757 | (?>\A\n?|\n\n+) # leading line |
| 2758 | 2758 | ( # definition terms = $1 |
| 2759 | - [ ]{0,'.$less_than_tab.'} # leading whitespace |
|
| 2759 | + [ ]{0,'.$less_than_tab . '} # leading whitespace |
|
| 2760 | 2760 | (?!\:[ ]|[ ]) # negative lookahead for a definition |
| 2761 | 2761 | # mark (colon) or more whitespace. |
| 2762 | 2762 | (?> \S.* \n)+? # actual term (not whitespace). |
@@ -2770,13 +2770,13 @@ discard block |
||
| 2770 | 2770 | $list_str = preg_replace_callback('{ |
| 2771 | 2771 | \n(\n+)? # leading line = $1 |
| 2772 | 2772 | ( # marker space = $2 |
| 2773 | - [ ]{0,'.$less_than_tab.'} # whitespace before colon |
|
| 2773 | + [ ]{0,'.$less_than_tab . '} # whitespace before colon |
|
| 2774 | 2774 | \:[ ]+ # definition mark (colon) |
| 2775 | 2775 | ) |
| 2776 | 2776 | ((?s:.+?)) # definition text = $3 |
| 2777 | 2777 | (?= \n+ # stop at next definition mark, |
| 2778 | 2778 | (?: # next term or end of text |
| 2779 | - [ ]{0,'.$less_than_tab.'} \:[ ] | |
|
| 2779 | + [ ]{0,'.$less_than_tab . '} \:[ ] | |
|
| 2780 | 2780 | <dt> | \z |
| 2781 | 2781 | ) |
| 2782 | 2782 | ) |
@@ -2797,13 +2797,13 @@ discard block |
||
| 2797 | 2797 | protected function _processDefListItems_callback_dd($matches) { |
| 2798 | 2798 | $leading_line = $matches[1]; |
| 2799 | 2799 | $marker_space = $matches[2]; |
| 2800 | - $def = $matches[3]; |
|
| 2800 | + $def = $matches[3]; |
|
| 2801 | 2801 | |
| 2802 | 2802 | if ($leading_line || preg_match('/\n{2,}/', $def)) { |
| 2803 | 2803 | # Replace marker with the appropriate whitespace indentation |
| 2804 | 2804 | $def = str_repeat(' ', strlen($marker_space)) . $def; |
| 2805 | 2805 | $def = $this->runBlockGamut($this->outdent($def . "\n\n")); |
| 2806 | - $def = "\n". $def ."\n"; |
|
| 2806 | + $def = "\n" . $def . "\n"; |
|
| 2807 | 2807 | } |
| 2808 | 2808 | else { |
| 2809 | 2809 | $def = rtrim($def); |
@@ -2834,7 +2834,7 @@ discard block |
||
| 2834 | 2834 | (?: |
| 2835 | 2835 | \.?([-_:a-zA-Z0-9]+) # 2: standalone class name |
| 2836 | 2836 | | |
| 2837 | - '.$this->id_class_attr_catch_re.' # 3: Extra attributes |
|
| 2837 | + '.$this->id_class_attr_catch_re . ' # 3: Extra attributes |
|
| 2838 | 2838 | )? |
| 2839 | 2839 | [ ]* \n # Whitespace and newline following marker. |
| 2840 | 2840 | |
@@ -2854,8 +2854,8 @@ discard block |
||
| 2854 | 2854 | return $text; |
| 2855 | 2855 | } |
| 2856 | 2856 | protected function _doFencedCodeBlocks_callback($matches) { |
| 2857 | - $classname =& $matches[2]; |
|
| 2858 | - $attrs =& $matches[3]; |
|
| 2857 | + $classname = & $matches[2]; |
|
| 2858 | + $attrs = & $matches[3]; |
|
| 2859 | 2859 | $codeblock = $matches[4]; |
| 2860 | 2860 | $codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES); |
| 2861 | 2861 | $codeblock = preg_replace_callback('/^\n+/', |
@@ -2864,15 +2864,15 @@ discard block |
||
| 2864 | 2864 | if ($classname != "") { |
| 2865 | 2865 | if ($classname{0} == '.') |
| 2866 | 2866 | $classname = substr($classname, 1); |
| 2867 | - $attr_str = ' class="'.$this->code_class_prefix.$classname.'"'; |
|
| 2867 | + $attr_str = ' class="' . $this->code_class_prefix . $classname . '"'; |
|
| 2868 | 2868 | } else { |
| 2869 | 2869 | $attr_str = $this->doExtraAttributes($this->code_attr_on_pre ? "pre" : "code", $attrs); |
| 2870 | 2870 | } |
| 2871 | 2871 | $pre_attr_str = $this->code_attr_on_pre ? $attr_str : ''; |
| 2872 | 2872 | $code_attr_str = $this->code_attr_on_pre ? '' : $attr_str; |
| 2873 | - $codeblock = "<pre$pre_attr_str><code$code_attr_str>$codeblock</code></pre>"; |
|
| 2873 | + $codeblock = "<pre$pre_attr_str><code$code_attr_str>$codeblock</code></pre>"; |
|
| 2874 | 2874 | |
| 2875 | - return "\n\n".$this->hashBlock($codeblock)."\n\n"; |
|
| 2875 | + return "\n\n" . $this->hashBlock($codeblock) . "\n\n"; |
|
| 2876 | 2876 | } |
| 2877 | 2877 | protected function _doFencedCodeBlocks_newlines($matches) { |
| 2878 | 2878 | return str_repeat("<br$this->empty_element_suffix", |
@@ -2948,7 +2948,7 @@ discard block |
||
| 2948 | 2948 | |
| 2949 | 2949 | # Link defs are in the form: [^id]: url "optional title" |
| 2950 | 2950 | $text = preg_replace_callback('{ |
| 2951 | - ^[ ]{0,'.$less_than_tab.'}\[\^(.+?)\][ ]?: # note_id = $1 |
|
| 2951 | + ^[ ]{0,'.$less_than_tab . '}\[\^(.+?)\][ ]?: # note_id = $1 |
|
| 2952 | 2952 | [ ]* |
| 2953 | 2953 | \n? # maybe *one* newline |
| 2954 | 2954 | ( # text = $2 (no blank lines allowed) |
@@ -2995,7 +2995,7 @@ discard block |
||
| 2995 | 2995 | if (!empty($this->footnotes_ordered)) { |
| 2996 | 2996 | $text .= "\n\n"; |
| 2997 | 2997 | $text .= "<div class=\"footnotes\">\n"; |
| 2998 | - $text .= "<hr". $this->empty_element_suffix ."\n"; |
|
| 2998 | + $text .= "<hr" . $this->empty_element_suffix . "\n"; |
|
| 2999 | 2999 | $text .= "<ol>\n\n"; |
| 3000 | 3000 | |
| 3001 | 3001 | $attr = " rev=\"footnote\""; |
@@ -3055,7 +3055,7 @@ discard block |
||
| 3055 | 3055 | # Create footnote marker only if it has a corresponding footnote *and* |
| 3056 | 3056 | # the footnote hasn't been used by another marker. |
| 3057 | 3057 | if (isset($this->footnotes[$node_id])) { |
| 3058 | - $num =& $this->footnotes_numbers[$node_id]; |
|
| 3058 | + $num = & $this->footnotes_numbers[$node_id]; |
|
| 3059 | 3059 | if (!isset($num)) { |
| 3060 | 3060 | # Transfer footnote content to the ordered list and give it its |
| 3061 | 3061 | # number |
@@ -3083,12 +3083,12 @@ discard block |
||
| 3083 | 3083 | $node_id = $this->encodeAttribute($node_id); |
| 3084 | 3084 | |
| 3085 | 3085 | return |
| 3086 | - "<sup id=\"fnref$ref_count_mark:$node_id\">". |
|
| 3087 | - "<a href=\"#fn:$node_id\"$attr>$num</a>". |
|
| 3086 | + "<sup id=\"fnref$ref_count_mark:$node_id\">" . |
|
| 3087 | + "<a href=\"#fn:$node_id\"$attr>$num</a>" . |
|
| 3088 | 3088 | "</sup>"; |
| 3089 | 3089 | } |
| 3090 | 3090 | |
| 3091 | - return "[^".$matches[1]."]"; |
|
| 3091 | + return "[^" . $matches[1] . "]"; |
|
| 3092 | 3092 | } |
| 3093 | 3093 | |
| 3094 | 3094 | |
@@ -3102,7 +3102,7 @@ discard block |
||
| 3102 | 3102 | |
| 3103 | 3103 | # Link defs are in the form: [id]*: url "optional title" |
| 3104 | 3104 | $text = preg_replace_callback('{ |
| 3105 | - ^[ ]{0,'.$less_than_tab.'}\*\[(.+?)\][ ]?: # abbr_id = $1 |
|
| 3105 | + ^[ ]{0,'.$less_than_tab . '}\*\[(.+?)\][ ]?: # abbr_id = $1 |
|
| 3106 | 3106 | (.*) # text = $2 (no blank lines allowed) |
| 3107 | 3107 | }xm', |
| 3108 | 3108 | array($this, '_stripAbbreviations_callback'), |
@@ -3127,10 +3127,10 @@ discard block |
||
| 3127 | 3127 | if ($this->abbr_word_re) { |
| 3128 | 3128 | // cannot use the /x modifier because abbr_word_re may |
| 3129 | 3129 | // contain significant spaces: |
| 3130 | - $text = preg_replace_callback('{'. |
|
| 3131 | - '(?<![\w\x1A])'. |
|
| 3132 | - '(?:'.$this->abbr_word_re.')'. |
|
| 3133 | - '(?![\w\x1A])'. |
|
| 3130 | + $text = preg_replace_callback('{' . |
|
| 3131 | + '(?<![\w\x1A])' . |
|
| 3132 | + '(?:' . $this->abbr_word_re . ')' . |
|
| 3133 | + '(?![\w\x1A])' . |
|
| 3134 | 3134 | '}', |
| 3135 | 3135 | array($this, '_doAbbreviations_callback'), $text); |
| 3136 | 3136 | } |
@@ -3216,7 +3216,7 @@ discard block |
||
| 3216 | 3216 | $bq = '> ' . $matches[2]; |
| 3217 | 3217 | # trim one level of quoting - trim whitespace-only lines |
| 3218 | 3218 | $bq = preg_replace('/^[ ]*>[ ]?|^[ ]+$/m', '', $bq); |
| 3219 | - $bq = $this->runBlockGamut($bq); # recurse |
|
| 3219 | + $bq = $this->runBlockGamut($bq); # recurse |
|
| 3220 | 3220 | |
| 3221 | 3221 | $bq = preg_replace('/^/m', " ", $bq); |
| 3222 | 3222 | # These leading spaces cause problem with <pre> content, |
@@ -3227,7 +3227,7 @@ discard block |
||
| 3227 | 3227 | $res = "<blockquote"; |
| 3228 | 3228 | $res .= empty($cite) ? ">" : " cite=\"$cite\">"; |
| 3229 | 3229 | $res .= "\n$bq\n</blockquote>"; |
| 3230 | - return "\n". $this->hashBlock($res)."\n\n"; |
|
| 3230 | + return "\n" . $this->hashBlock($res) . "\n\n"; |
|
| 3231 | 3231 | } |
| 3232 | 3232 | |
| 3233 | 3233 | public function doFencedCodeBlocks($text) { |
@@ -3268,10 +3268,10 @@ discard block |
||
| 3268 | 3268 | $cb = empty($matches[3]) ? "<pre><code" : "<pre class=\"linenums:$matches[3]\"><code"; |
| 3269 | 3269 | $cb .= empty($matches[2]) ? ">" : " class=\"lang-$matches[2]\">"; |
| 3270 | 3270 | $cb .= "$codeblock</code></pre>"; |
| 3271 | - return "\n\n".$this->hashBlock($cb)."\n\n"; |
|
| 3271 | + return "\n\n" . $this->hashBlock($cb) . "\n\n"; |
|
| 3272 | 3272 | } |
| 3273 | 3273 | |
| 3274 | - public function doFencedFigures($text){ |
|
| 3274 | + public function doFencedFigures($text) { |
|
| 3275 | 3275 | $text = preg_replace_callback('{ |
| 3276 | 3276 | (?:\n|\A) |
| 3277 | 3277 | # 1: Opening marker |
@@ -3310,15 +3310,15 @@ discard block |
||
| 3310 | 3310 | array($this, '_doBlockQuotes_callback2'), $figure); |
| 3311 | 3311 | |
| 3312 | 3312 | $res = "<figure>"; |
| 3313 | - if(!empty($topcaption)){ |
|
| 3313 | + if (!empty($topcaption)) { |
|
| 3314 | 3314 | $res .= "\n<figcaption>$topcaption</figcaption>"; |
| 3315 | 3315 | } |
| 3316 | 3316 | $res .= "\n$figure\n"; |
| 3317 | - if(!empty($bottomcaption) && empty($topcaption)){ |
|
| 3317 | + if (!empty($bottomcaption) && empty($topcaption)) { |
|
| 3318 | 3318 | $res .= "<figcaption>$bottomcaption</figcaption>"; |
| 3319 | 3319 | } |
| 3320 | 3320 | $res .= "</figure>"; |
| 3321 | - return "\n". $this->hashBlock($res)."\n\n"; |
|
| 3321 | + return "\n" . $this->hashBlock($res) . "\n\n"; |
|
| 3322 | 3322 | } |
| 3323 | 3323 | } |
| 3324 | 3324 | |
@@ -236,7 +236,9 @@ discard block |
||
| 236 | 236 | |
| 237 | 237 | |
| 238 | 238 | protected function hashHTMLBlocks($text) { |
| 239 | - if ($this->no_markup) return $text; |
|
| 239 | + if ($this->no_markup) { |
|
| 240 | + return $text; |
|
| 241 | + } |
|
| 240 | 242 | |
| 241 | 243 | $less_than_tab = $this->tab_width - 1; |
| 242 | 244 | |
@@ -524,7 +526,9 @@ discard block |
||
| 524 | 526 | # |
| 525 | 527 | # Turn Markdown link shortcuts into XHTML <a> tags. |
| 526 | 528 | # |
| 527 | - if ($this->in_anchor) return $text; |
|
| 529 | + if ($this->in_anchor) { |
|
| 530 | + return $text; |
|
| 531 | + } |
|
| 528 | 532 | $this->in_anchor = true; |
| 529 | 533 | |
| 530 | 534 | # |
@@ -618,8 +622,7 @@ discard block |
||
| 618 | 622 | $link_text = $this->runSpanGamut($link_text); |
| 619 | 623 | $result .= ">$link_text</a>"; |
| 620 | 624 | $result = $this->hashPart($result); |
| 621 | - } |
|
| 622 | - else { |
|
| 625 | + } else { |
|
| 623 | 626 | $result = $whole_match; |
| 624 | 627 | } |
| 625 | 628 | return $result; |
@@ -720,8 +723,7 @@ discard block |
||
| 720 | 723 | } |
| 721 | 724 | $result .= $this->empty_element_suffix; |
| 722 | 725 | $result = $this->hashPart($result); |
| 723 | - } |
|
| 724 | - else { |
|
| 726 | + } else { |
|
| 725 | 727 | # If there's no such link ID, leave intact: |
| 726 | 728 | $result = $whole_match; |
| 727 | 729 | } |
@@ -779,8 +781,9 @@ discard block |
||
| 779 | 781 | } |
| 780 | 782 | protected function _doHeaders_callback_setext($matches) { |
| 781 | 783 | # Terrible hack to check we haven't found an empty list item. |
| 782 | - if ($matches[2] == '-' && preg_match('{^-(?: |$)}', $matches[1])) |
|
| 783 | - return $matches[0]; |
|
| 784 | + if ($matches[2] == '-' && preg_match('{^-(?: |$)}', $matches[1])) { |
|
| 785 | + return $matches[0]; |
|
| 786 | + } |
|
| 784 | 787 | |
| 785 | 788 | $level = $matches[2]{0} == '=' ? 1 : 2; |
| 786 | 789 | $block = "<h$level>".$this->runSpanGamut($matches[1])."</h$level>"; |
@@ -847,8 +850,7 @@ discard block |
||
| 847 | 850 | '.$whole_list_re.' |
| 848 | 851 | }mx', |
| 849 | 852 | array($this, '_doLists_callback'), $text); |
| 850 | - } |
|
| 851 | - else { |
|
| 853 | + } else { |
|
| 852 | 854 | $text = preg_replace_callback('{ |
| 853 | 855 | (?:(?<=\n)\n?|\A\n?) # Must eat the newline |
| 854 | 856 | '.$whole_list_re.' |
@@ -938,8 +940,7 @@ discard block |
||
| 938 | 940 | # Replace marker with the appropriate whitespace indentation |
| 939 | 941 | $item = $leading_space . str_repeat(' ', strlen($marker_space)) . $item; |
| 940 | 942 | $item = $this->runBlockGamut($this->outdent($item)."\n"); |
| 941 | - } |
|
| 942 | - else { |
|
| 943 | + } else { |
|
| 943 | 944 | # Recursion for sub-lists: |
| 944 | 945 | $item = $this->doLists($this->outdent($item)); |
| 945 | 946 | $item = preg_replace('/\n+$/', '', $item); |
@@ -1209,8 +1210,7 @@ discard block |
||
| 1209 | 1210 | $value = preg_replace('/^([ ]*)/', "<p>", $value); |
| 1210 | 1211 | $value .= "</p>"; |
| 1211 | 1212 | $grafs[$key] = $this->unhash($value); |
| 1212 | - } |
|
| 1213 | - else { |
|
| 1213 | + } else { |
|
| 1214 | 1214 | # Is a block. |
| 1215 | 1215 | # Modify elements of @grafs in-place... |
| 1216 | 1216 | $graf = $value; |
@@ -1404,8 +1404,11 @@ discard block |
||
| 1404 | 1404 | # roughly 10% raw, 45% hex, 45% dec |
| 1405 | 1405 | # '@' *must* be encoded. I insist. |
| 1406 | 1406 | if ($r > 90 && $char != '@') /* do nothing */; |
| 1407 | - else if ($r < 45) $chars[$key] = '&#x'.dechex($ord).';'; |
|
| 1408 | - else $chars[$key] = '&#'.$ord.';'; |
|
| 1407 | + else if ($r < 45) { |
|
| 1408 | + $chars[$key] = '&#x'.dechex($ord).';'; |
|
| 1409 | + } else { |
|
| 1410 | + $chars[$key] = '&#'.$ord.';'; |
|
| 1411 | + } |
|
| 1409 | 1412 | } |
| 1410 | 1413 | } |
| 1411 | 1414 | |
@@ -1467,8 +1470,7 @@ discard block |
||
| 1467 | 1470 | if (isset($parts[1])) { |
| 1468 | 1471 | $output .= $this->handleSpanToken($parts[1], $parts[2]); |
| 1469 | 1472 | $str = $parts[2]; |
| 1470 | - } |
|
| 1471 | - else { |
|
| 1473 | + } else { |
|
| 1472 | 1474 | break; |
| 1473 | 1475 | } |
| 1474 | 1476 | } |
@@ -1550,7 +1552,9 @@ discard block |
||
| 1550 | 1552 | # function that will loosely count the number of UTF-8 characters with a |
| 1551 | 1553 | # regular expression. |
| 1552 | 1554 | # |
| 1553 | - if (function_exists($this->utf8_strlen)) return; |
|
| 1555 | + if (function_exists($this->utf8_strlen)) { |
|
| 1556 | + return; |
|
| 1557 | + } |
|
| 1554 | 1558 | $this->utf8_strlen = array($this, '_utf8_strlen'); |
| 1555 | 1559 | } |
| 1556 | 1560 | |
@@ -1674,8 +1678,9 @@ discard block |
||
| 1674 | 1678 | $this->footnote_counter = 1; |
| 1675 | 1679 | |
| 1676 | 1680 | foreach ($this->predef_abbr as $abbr_word => $abbr_desc) { |
| 1677 | - if ($this->abbr_word_re) |
|
| 1678 | - $this->abbr_word_re .= '|'; |
|
| 1681 | + if ($this->abbr_word_re) { |
|
| 1682 | + $this->abbr_word_re .= '|'; |
|
| 1683 | + } |
|
| 1679 | 1684 | $this->abbr_word_re .= preg_quote($abbr_word); |
| 1680 | 1685 | $this->abbr_desciptions[$abbr_word] = trim($abbr_desc); |
| 1681 | 1686 | } |
@@ -1710,7 +1715,9 @@ discard block |
||
| 1710 | 1715 | # |
| 1711 | 1716 | # Currently supported attributes are .class and #id. |
| 1712 | 1717 | # |
| 1713 | - if (empty($attr)) return ""; |
|
| 1718 | + if (empty($attr)) { |
|
| 1719 | + return ""; |
|
| 1720 | + } |
|
| 1714 | 1721 | |
| 1715 | 1722 | # Split on components |
| 1716 | 1723 | preg_match_all('/[#.][-_:a-zA-Z0-9]+/', $attr, $matches); |
@@ -1723,7 +1730,9 @@ discard block |
||
| 1723 | 1730 | if ($element{0} == '.') { |
| 1724 | 1731 | $classes[] = substr($element, 1); |
| 1725 | 1732 | } else if ($element{0} == '#') { |
| 1726 | - if ($id === false) $id = substr($element, 1); |
|
| 1733 | + if ($id === false) { |
|
| 1734 | + $id = substr($element, 1); |
|
| 1735 | + } |
|
| 1727 | 1736 | } |
| 1728 | 1737 | } |
| 1729 | 1738 | |
@@ -1819,7 +1828,9 @@ discard block |
||
| 1819 | 1828 | # _HashHTMLBlocks_InMarkdown to handle the Markdown syntax within the tag. |
| 1820 | 1829 | # These two functions are calling each other. It's recursive! |
| 1821 | 1830 | # |
| 1822 | - if ($this->no_markup) return $text; |
|
| 1831 | + if ($this->no_markup) { |
|
| 1832 | + return $text; |
|
| 1833 | + } |
|
| 1823 | 1834 | |
| 1824 | 1835 | # |
| 1825 | 1836 | # Call the HTML-in-Markdown hasher. |
@@ -1856,7 +1867,9 @@ discard block |
||
| 1856 | 1867 | # |
| 1857 | 1868 | # Returns an array of that form: ( processed text , remaining text ) |
| 1858 | 1869 | # |
| 1859 | - if ($text === '') return array('', ''); |
|
| 1870 | + if ($text === '') { |
|
| 1871 | + return array('', ''); |
|
| 1872 | + } |
|
| 1860 | 1873 | |
| 1861 | 1874 | # Regex to check for the presense of newlines around a block tag. |
| 1862 | 1875 | $newline_before_re = '/(?:^\n?|\n\n)*$/'; |
@@ -1970,8 +1983,7 @@ discard block |
||
| 1970 | 1983 | # End marker found: pass text unchanged until marker. |
| 1971 | 1984 | $parsed .= $tag . $matches[0]; |
| 1972 | 1985 | $text = substr($text, strlen($matches[0])); |
| 1973 | - } |
|
| 1974 | - else { |
|
| 1986 | + } else { |
|
| 1975 | 1987 | # Unmatched marker: just skip it. |
| 1976 | 1988 | $parsed .= $tag; |
| 1977 | 1989 | } |
@@ -1989,8 +2001,7 @@ discard block |
||
| 1989 | 2001 | # End marker found: pass text unchanged until marker. |
| 1990 | 2002 | $parsed .= $tag . $matches[0]; |
| 1991 | 2003 | $text = substr($text, strlen($matches[0])); |
| 1992 | - } |
|
| 1993 | - else { |
|
| 2004 | + } else { |
|
| 1994 | 2005 | # No end marker: just skip it. |
| 1995 | 2006 | $parsed .= $tag; |
| 1996 | 2007 | } |
@@ -2045,8 +2056,11 @@ discard block |
||
| 2045 | 2056 | # |
| 2046 | 2057 | # Increase/decrease nested tag count. |
| 2047 | 2058 | # |
| 2048 | - if ($tag{1} == '/') $depth--; |
|
| 2049 | - else if ($tag{strlen($tag)-2} != '/') $depth++; |
|
| 2059 | + if ($tag{1} == '/') { |
|
| 2060 | + $depth--; |
|
| 2061 | + } else if ($tag{strlen($tag)-2} != '/') { |
|
| 2062 | + $depth++; |
|
| 2063 | + } |
|
| 2050 | 2064 | |
| 2051 | 2065 | if ($depth < 0) { |
| 2052 | 2066 | # |
@@ -2058,8 +2072,7 @@ discard block |
||
| 2058 | 2072 | } |
| 2059 | 2073 | |
| 2060 | 2074 | $parsed .= $tag; |
| 2061 | - } |
|
| 2062 | - else { |
|
| 2075 | + } else { |
|
| 2063 | 2076 | $parsed .= $tag; |
| 2064 | 2077 | } |
| 2065 | 2078 | } while ($depth >= 0); |
@@ -2077,7 +2090,9 @@ discard block |
||
| 2077 | 2090 | # |
| 2078 | 2091 | # Returns an array of that form: ( processed text , remaining text ) |
| 2079 | 2092 | # |
| 2080 | - if ($text === '') return array('', ''); |
|
| 2093 | + if ($text === '') { |
|
| 2094 | + return array('', ''); |
|
| 2095 | + } |
|
| 2081 | 2096 | |
| 2082 | 2097 | # Regex to match `markdown` attribute inside of a tag. |
| 2083 | 2098 | $markdown_attr_re = ' |
@@ -2128,8 +2143,9 @@ discard block |
||
| 2128 | 2143 | # Get the name of the starting tag. |
| 2129 | 2144 | # (This pattern makes $base_tag_name_re safe without quoting.) |
| 2130 | 2145 | # |
| 2131 | - if (preg_match('/^<([\w:$]*)\b/', $text, $matches)) |
|
| 2132 | - $base_tag_name_re = $matches[1]; |
|
| 2146 | + if (preg_match('/^<([\w:$]*)\b/', $text, $matches)) { |
|
| 2147 | + $base_tag_name_re = $matches[1]; |
|
| 2148 | + } |
|
| 2133 | 2149 | |
| 2134 | 2150 | # |
| 2135 | 2151 | # Loop through every tag until we find the corresponding closing tag. |
@@ -2166,15 +2182,17 @@ discard block |
||
| 2166 | 2182 | { |
| 2167 | 2183 | # Just add the tag to the block as if it was text. |
| 2168 | 2184 | $block_text .= $tag; |
| 2169 | - } |
|
| 2170 | - else { |
|
| 2185 | + } else { |
|
| 2171 | 2186 | # |
| 2172 | 2187 | # Increase/decrease nested tag count. Only do so if |
| 2173 | 2188 | # the tag's name match base tag's. |
| 2174 | 2189 | # |
| 2175 | 2190 | if (preg_match('{^</?'.$base_tag_name_re.'\b}', $tag)) { |
| 2176 | - if ($tag{1} == '/') $depth--; |
|
| 2177 | - else if ($tag{strlen($tag)-2} != '/') $depth++; |
|
| 2191 | + if ($tag{1} == '/') { |
|
| 2192 | + $depth--; |
|
| 2193 | + } else if ($tag{strlen($tag)-2} != '/') { |
|
| 2194 | + $depth++; |
|
| 2195 | + } |
|
| 2178 | 2196 | } |
| 2179 | 2197 | |
| 2180 | 2198 | # |
@@ -2221,13 +2239,17 @@ discard block |
||
| 2221 | 2239 | } |
| 2222 | 2240 | |
| 2223 | 2241 | # Append tag content to parsed text. |
| 2224 | - if (!$span_mode) $parsed .= "\n\n$block_text\n\n"; |
|
| 2225 | - else $parsed .= "$block_text"; |
|
| 2242 | + if (!$span_mode) { |
|
| 2243 | + $parsed .= "\n\n$block_text\n\n"; |
|
| 2244 | + } else { |
|
| 2245 | + $parsed .= "$block_text"; |
|
| 2246 | + } |
|
| 2226 | 2247 | |
| 2227 | 2248 | # Start over with a new block. |
| 2228 | 2249 | $block_text = ""; |
| 2250 | + } else { |
|
| 2251 | + $block_text .= $tag; |
|
| 2229 | 2252 | } |
| 2230 | - else $block_text .= $tag; |
|
| 2231 | 2253 | } |
| 2232 | 2254 | |
| 2233 | 2255 | } while ($depth > 0); |
@@ -2255,7 +2277,9 @@ discard block |
||
| 2255 | 2277 | # |
| 2256 | 2278 | # Turn Markdown link shortcuts into XHTML <a> tags. |
| 2257 | 2279 | # |
| 2258 | - if ($this->in_anchor) return $text; |
|
| 2280 | + if ($this->in_anchor) { |
|
| 2281 | + return $text; |
|
| 2282 | + } |
|
| 2259 | 2283 | $this->in_anchor = true; |
| 2260 | 2284 | |
| 2261 | 2285 | # |
@@ -2346,14 +2370,14 @@ discard block |
||
| 2346 | 2370 | $title = $this->encodeAttribute($title); |
| 2347 | 2371 | $result .= " title=\"$title\""; |
| 2348 | 2372 | } |
| 2349 | - if (isset($this->ref_attr[$link_id])) |
|
| 2350 | - $result .= $this->ref_attr[$link_id]; |
|
| 2373 | + if (isset($this->ref_attr[$link_id])) { |
|
| 2374 | + $result .= $this->ref_attr[$link_id]; |
|
| 2375 | + } |
|
| 2351 | 2376 | |
| 2352 | 2377 | $link_text = $this->runSpanGamut($link_text); |
| 2353 | 2378 | $result .= ">$link_text</a>"; |
| 2354 | 2379 | $result = $this->hashPart($result); |
| 2355 | - } |
|
| 2356 | - else { |
|
| 2380 | + } else { |
|
| 2357 | 2381 | $result = $whole_match; |
| 2358 | 2382 | } |
| 2359 | 2383 | return $result; |
@@ -2456,12 +2480,12 @@ discard block |
||
| 2456 | 2480 | $title = $this->encodeAttribute($title); |
| 2457 | 2481 | $result .= " title=\"$title\""; |
| 2458 | 2482 | } |
| 2459 | - if (isset($this->ref_attr[$link_id])) |
|
| 2460 | - $result .= $this->ref_attr[$link_id]; |
|
| 2483 | + if (isset($this->ref_attr[$link_id])) { |
|
| 2484 | + $result .= $this->ref_attr[$link_id]; |
|
| 2485 | + } |
|
| 2461 | 2486 | $result .= $this->empty_element_suffix; |
| 2462 | 2487 | $result = $this->hashPart($result); |
| 2463 | - } |
|
| 2464 | - else { |
|
| 2488 | + } else { |
|
| 2465 | 2489 | # If there's no such link ID, leave intact: |
| 2466 | 2490 | $result = $whole_match; |
| 2467 | 2491 | } |
@@ -2530,8 +2554,9 @@ discard block |
||
| 2530 | 2554 | return $text; |
| 2531 | 2555 | } |
| 2532 | 2556 | protected function _doHeaders_callback_setext($matches) { |
| 2533 | - if ($matches[3] == '-' && preg_match('{^- }', $matches[1])) |
|
| 2534 | - return $matches[0]; |
|
| 2557 | + if ($matches[3] == '-' && preg_match('{^- }', $matches[1])) { |
|
| 2558 | + return $matches[0]; |
|
| 2559 | + } |
|
| 2535 | 2560 | $level = $matches[3]{0} == '=' ? 1 : 2; |
| 2536 | 2561 | $attr = $this->doExtraAttributes("h$level", $dummy =& $matches[2]); |
| 2537 | 2562 | $block = "<h$level$attr>".$this->runSpanGamut($matches[1])."</h$level>"; |
@@ -2618,8 +2643,9 @@ discard block |
||
| 2618 | 2643 | } |
| 2619 | 2644 | protected function _doTable_makeAlignAttr($alignname) |
| 2620 | 2645 | { |
| 2621 | - if (empty($this->table_align_class_tmpl)) |
|
| 2622 | - return " align=\"$alignname\""; |
|
| 2646 | + if (empty($this->table_align_class_tmpl)) { |
|
| 2647 | + return " align=\"$alignname\""; |
|
| 2648 | + } |
|
| 2623 | 2649 | |
| 2624 | 2650 | $classname = str_replace('%%', $alignname, $this->table_align_class_tmpl); |
| 2625 | 2651 | return " class=\"$classname\""; |
@@ -2637,14 +2663,15 @@ discard block |
||
| 2637 | 2663 | # Reading alignement from header underline. |
| 2638 | 2664 | $separators = preg_split('/ *[|] */', $underline); |
| 2639 | 2665 | foreach ($separators as $n => $s) { |
| 2640 | - if (preg_match('/^ *-+: *$/', $s)) |
|
| 2641 | - $attr[$n] = $this->_doTable_makeAlignAttr('right'); |
|
| 2642 | - else if (preg_match('/^ *:-+: *$/', $s)) |
|
| 2643 | - $attr[$n] = $this->_doTable_makeAlignAttr('center'); |
|
| 2644 | - else if (preg_match('/^ *:-+ *$/', $s)) |
|
| 2645 | - $attr[$n] = $this->_doTable_makeAlignAttr('left'); |
|
| 2646 | - else |
|
| 2647 | - $attr[$n] = ''; |
|
| 2666 | + if (preg_match('/^ *-+: *$/', $s)) { |
|
| 2667 | + $attr[$n] = $this->_doTable_makeAlignAttr('right'); |
|
| 2668 | + } else if (preg_match('/^ *:-+: *$/', $s)) { |
|
| 2669 | + $attr[$n] = $this->_doTable_makeAlignAttr('center'); |
|
| 2670 | + } else if (preg_match('/^ *:-+ *$/', $s)) { |
|
| 2671 | + $attr[$n] = $this->_doTable_makeAlignAttr('left'); |
|
| 2672 | + } else { |
|
| 2673 | + $attr[$n] = ''; |
|
| 2674 | + } |
|
| 2648 | 2675 | } |
| 2649 | 2676 | |
| 2650 | 2677 | # Parsing span elements, including code spans, character escapes, |
@@ -2658,8 +2685,9 @@ discard block |
||
| 2658 | 2685 | $text = "<table>\n"; |
| 2659 | 2686 | $text .= "<thead>\n"; |
| 2660 | 2687 | $text .= "<tr>\n"; |
| 2661 | - foreach ($headers as $n => $header) |
|
| 2662 | - $text .= " <th$attr[$n]>".$this->runSpanGamut(trim($header))."</th>\n"; |
|
| 2688 | + foreach ($headers as $n => $header) { |
|
| 2689 | + $text .= " <th$attr[$n]>".$this->runSpanGamut(trim($header))."</th>\n"; |
|
| 2690 | + } |
|
| 2663 | 2691 | $text .= "</tr>\n"; |
| 2664 | 2692 | $text .= "</thead>\n"; |
| 2665 | 2693 | |
@@ -2677,8 +2705,9 @@ discard block |
||
| 2677 | 2705 | $row_cells = array_pad($row_cells, $col_count, ''); |
| 2678 | 2706 | |
| 2679 | 2707 | $text .= "<tr>\n"; |
| 2680 | - foreach ($row_cells as $n => $cell) |
|
| 2681 | - $text .= " <td$attr[$n]>".$this->runSpanGamut(trim($cell))."</td>\n"; |
|
| 2708 | + foreach ($row_cells as $n => $cell) { |
|
| 2709 | + $text .= " <td$attr[$n]>".$this->runSpanGamut(trim($cell))."</td>\n"; |
|
| 2710 | + } |
|
| 2682 | 2711 | $text .= "</tr>\n"; |
| 2683 | 2712 | } |
| 2684 | 2713 | $text .= "</tbody>\n"; |
@@ -2804,8 +2833,7 @@ discard block |
||
| 2804 | 2833 | $def = str_repeat(' ', strlen($marker_space)) . $def; |
| 2805 | 2834 | $def = $this->runBlockGamut($this->outdent($def . "\n\n")); |
| 2806 | 2835 | $def = "\n". $def ."\n"; |
| 2807 | - } |
|
| 2808 | - else { |
|
| 2836 | + } else { |
|
| 2809 | 2837 | $def = rtrim($def); |
| 2810 | 2838 | $def = $this->runSpanGamut($this->outdent($def)); |
| 2811 | 2839 | } |
@@ -2862,8 +2890,9 @@ discard block |
||
| 2862 | 2890 | array($this, '_doFencedCodeBlocks_newlines'), $codeblock); |
| 2863 | 2891 | |
| 2864 | 2892 | if ($classname != "") { |
| 2865 | - if ($classname{0} == '.') |
|
| 2866 | - $classname = substr($classname, 1); |
|
| 2893 | + if ($classname{0} == '.') { |
|
| 2894 | + $classname = substr($classname, 1); |
|
| 2895 | + } |
|
| 2867 | 2896 | $attr_str = ' class="'.$this->code_class_prefix.$classname.'"'; |
| 2868 | 2897 | } else { |
| 2869 | 2898 | $attr_str = $this->doExtraAttributes($this->code_attr_on_pre ? "pre" : "code", $attrs); |
@@ -3112,8 +3141,9 @@ discard block |
||
| 3112 | 3141 | protected function _stripAbbreviations_callback($matches) { |
| 3113 | 3142 | $abbr_word = $matches[1]; |
| 3114 | 3143 | $abbr_desc = $matches[2]; |
| 3115 | - if ($this->abbr_word_re) |
|
| 3116 | - $this->abbr_word_re .= '|'; |
|
| 3144 | + if ($this->abbr_word_re) { |
|
| 3145 | + $this->abbr_word_re .= '|'; |
|
| 3146 | + } |
|
| 3117 | 3147 | $this->abbr_word_re .= preg_quote($abbr_word); |
| 3118 | 3148 | $this->abbr_desciptions[$abbr_word] = trim($abbr_desc); |
| 3119 | 3149 | return ''; # String that will replace the block |
@@ -38,7 +38,7 @@ |
||
| 38 | 38 | /** |
| 39 | 39 | * 架构函数 |
| 40 | 40 | * @param array $totalRows 总的记录数 |
| 41 | - * @param array $listRows 每页显示记录数 |
|
| 41 | + * @param integer $listRows 每页显示记录数 |
|
| 42 | 42 | * @param array $parameter 分页跳转的参数 |
| 43 | 43 | */ |
| 44 | 44 | public function __construct($totalRows, $listRows = 20, $parameter = array()) |
@@ -131,12 +131,10 @@ discard block |
||
| 131 | 131 | if (($this->nowPage - $now_cool_page) <= 0) |
| 132 | 132 | { |
| 133 | 133 | $page = $i; |
| 134 | - } |
|
| 135 | - elseif (($this->nowPage + $now_cool_page - 1) >= $this->totalPages) |
|
| 134 | + } elseif (($this->nowPage + $now_cool_page - 1) >= $this->totalPages) |
|
| 136 | 135 | { |
| 137 | 136 | $page = $this->totalPages - $this->rollPage + $i; |
| 138 | - } |
|
| 139 | - else |
|
| 137 | + } else |
|
| 140 | 138 | { |
| 141 | 139 | $page = $this->nowPage - $now_cool_page_ceil + $i; |
| 142 | 140 | } |
@@ -146,13 +144,11 @@ discard block |
||
| 146 | 144 | if ($page <= $this->totalPages) |
| 147 | 145 | { |
| 148 | 146 | $link_page .= '<a class="num" href="' . $this->url($page) . '">' . $page . '</a>'; |
| 149 | - } |
|
| 150 | - else |
|
| 147 | + } else |
|
| 151 | 148 | { |
| 152 | 149 | break; |
| 153 | 150 | } |
| 154 | - } |
|
| 155 | - else |
|
| 151 | + } else |
|
| 156 | 152 | { |
| 157 | 153 | if ($page > 0 && $this->totalPages != 1) |
| 158 | 154 | { |
@@ -33,7 +33,6 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | namespace Kotori; |
| 35 | 35 | |
| 36 | -use Kotori\Core\Build; |
|
| 37 | 36 | use Kotori\Core\Config; |
| 38 | 37 | use Kotori\Core\Helper; |
| 39 | 38 | use Kotori\Http\Route; |
@@ -188,7 +188,6 @@ |
||
| 188 | 188 | /** |
| 189 | 189 | * Is the requested driver supported in this environment? |
| 190 | 190 | * |
| 191 | - * @param string $key The driver to test |
|
| 192 | 191 | * @return array |
| 193 | 192 | */ |
| 194 | 193 | public function isSupported($driver) |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | * |
| 93 | 93 | * @param string $id Cache ID |
| 94 | 94 | * @param int $offset Step/value to add |
| 95 | - * @return mixed New value on success or FALSE on failure |
|
| 95 | + * @return boolean New value on success or FALSE on failure |
|
| 96 | 96 | */ |
| 97 | 97 | public function increment($id, $offset = 1) |
| 98 | 98 | { |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | * |
| 105 | 105 | * @param string $id Cache ID |
| 106 | 106 | * @param int $offset Step/value to reduce by |
| 107 | - * @return mixed New value on success or FALSE on failure |
|
| 107 | + * @return boolean New value on success or FALSE on failure |
|
| 108 | 108 | */ |
| 109 | 109 | public function decrement($id, $offset = 1) |
| 110 | 110 | { |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | * @param string $type Error type |
| 253 | 253 | * @param int $message Error string |
| 254 | 254 | * @param string $file Error filepath |
| 255 | - * @param int $errline Error line |
|
| 255 | + * @param int $line Error line |
|
| 256 | 256 | * @return string |
| 257 | 257 | */ |
| 258 | 258 | protected static function renderHaltBody($type, $message, $line, $file) |
@@ -347,6 +347,13 @@ discard block |
||
| 347 | 347 | * @return string |
| 348 | 348 | */ |
| 349 | 349 | // @codingStandardsIgnoreStart |
| 350 | + |
|
| 351 | + /** |
|
| 352 | + * @param string $type |
|
| 353 | + * @param integer $message |
|
| 354 | + * @param integer $line |
|
| 355 | + * @param string $file |
|
| 356 | + */ |
|
| 350 | 357 | protected static function renderErrorText($type, $message, $line, $file) |
| 351 | 358 | { |
| 352 | 359 | return $message . ' in ' . $file . ' on line ' . $line; |
@@ -112,7 +112,6 @@ |
||
| 112 | 112 | /** |
| 113 | 113 | * Set variables for Template |
| 114 | 114 | * |
| 115 | - * @param string $name key |
|
| 116 | 115 | * @param mixed $value value |
| 117 | 116 | * @return View |
| 118 | 117 | */ |
@@ -120,6 +120,7 @@ |
||
| 120 | 120 | /** |
| 121 | 121 | * Set current charset |
| 122 | 122 | * |
| 123 | + * @param string $charset |
|
| 123 | 124 | * @return void |
| 124 | 125 | */ |
| 125 | 126 | public function setCharset($charset = null) |
@@ -331,7 +331,7 @@ |
||
| 331 | 331 | { |
| 332 | 332 | $possibleHostSources = ['HTTP_X_FORWARDED_HOST', 'HTTP_HOST', 'SERVER_NAME', 'SERVER_ADDR']; |
| 333 | 333 | $sourceTransformations = [ |
| 334 | - "HTTP_X_FORWARDED_HOST" => function ($value) { |
|
| 334 | + "HTTP_X_FORWARDED_HOST" => function($value) { |
|
| 335 | 335 | $elements = explode(',', $value); |
| 336 | 336 | return trim(end($elements)); |
| 337 | 337 | }, |