@@ -15,1802 +15,1802 @@ |
||
| 15 | 15 | |
| 16 | 16 | class Parsedown { |
| 17 | 17 | |
| 18 | - // ~ |
|
| 18 | + // ~ |
|
| 19 | 19 | |
| 20 | - const version = '1.8.0'; |
|
| 20 | + const version = '1.8.0'; |
|
| 21 | 21 | |
| 22 | - // ~ |
|
| 22 | + // ~ |
|
| 23 | 23 | |
| 24 | - function text( $text ) { |
|
| 25 | - $Elements = $this->textElements( $text ); |
|
| 24 | + function text( $text ) { |
|
| 25 | + $Elements = $this->textElements( $text ); |
|
| 26 | 26 | |
| 27 | - // convert to markup |
|
| 28 | - $markup = $this->elements( $Elements ); |
|
| 27 | + // convert to markup |
|
| 28 | + $markup = $this->elements( $Elements ); |
|
| 29 | 29 | |
| 30 | - // trim line breaks |
|
| 31 | - $markup = trim( $markup, "\n" ); |
|
| 30 | + // trim line breaks |
|
| 31 | + $markup = trim( $markup, "\n" ); |
|
| 32 | 32 | |
| 33 | - return $markup; |
|
| 34 | - } |
|
| 33 | + return $markup; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - protected function textElements( $text ) { |
|
| 37 | - // make sure no definitions are set |
|
| 38 | - $this->DefinitionData = array(); |
|
| 36 | + protected function textElements( $text ) { |
|
| 37 | + // make sure no definitions are set |
|
| 38 | + $this->DefinitionData = array(); |
|
| 39 | 39 | |
| 40 | - // standardize line breaks |
|
| 41 | - $text = str_replace( array( "\r\n", "\r" ), "\n", $text ); |
|
| 42 | - |
|
| 43 | - // remove surrounding line breaks |
|
| 44 | - $text = trim( $text, "\n" ); |
|
| 45 | - |
|
| 46 | - // split text into lines |
|
| 47 | - $lines = explode( "\n", $text ); |
|
| 40 | + // standardize line breaks |
|
| 41 | + $text = str_replace( array( "\r\n", "\r" ), "\n", $text ); |
|
| 42 | + |
|
| 43 | + // remove surrounding line breaks |
|
| 44 | + $text = trim( $text, "\n" ); |
|
| 45 | + |
|
| 46 | + // split text into lines |
|
| 47 | + $lines = explode( "\n", $text ); |
|
| 48 | 48 | |
| 49 | - // iterate through lines to identify blocks |
|
| 50 | - return $this->linesElements( $lines ); |
|
| 51 | - } |
|
| 49 | + // iterate through lines to identify blocks |
|
| 50 | + return $this->linesElements( $lines ); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - // |
|
| 54 | - // Setters |
|
| 55 | - // |
|
| 53 | + // |
|
| 54 | + // Setters |
|
| 55 | + // |
|
| 56 | 56 | |
| 57 | - function setBreaksEnabled( $breaksEnabled ) { |
|
| 58 | - $this->breaksEnabled = $breaksEnabled; |
|
| 57 | + function setBreaksEnabled( $breaksEnabled ) { |
|
| 58 | + $this->breaksEnabled = $breaksEnabled; |
|
| 59 | 59 | |
| 60 | - return $this; |
|
| 61 | - } |
|
| 60 | + return $this; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - protected $breaksEnabled; |
|
| 63 | + protected $breaksEnabled; |
|
| 64 | 64 | |
| 65 | - function setMarkupEscaped( $markupEscaped ) { |
|
| 66 | - $this->markupEscaped = $markupEscaped; |
|
| 67 | - |
|
| 68 | - return $this; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - protected $markupEscaped; |
|
| 72 | - |
|
| 73 | - function setUrlsLinked( $urlsLinked ) { |
|
| 74 | - $this->urlsLinked = $urlsLinked; |
|
| 75 | - |
|
| 76 | - return $this; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - protected $urlsLinked = true; |
|
| 80 | - |
|
| 81 | - function setSafeMode( $safeMode ) { |
|
| 82 | - $this->safeMode = (bool) $safeMode; |
|
| 65 | + function setMarkupEscaped( $markupEscaped ) { |
|
| 66 | + $this->markupEscaped = $markupEscaped; |
|
| 67 | + |
|
| 68 | + return $this; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + protected $markupEscaped; |
|
| 72 | + |
|
| 73 | + function setUrlsLinked( $urlsLinked ) { |
|
| 74 | + $this->urlsLinked = $urlsLinked; |
|
| 75 | + |
|
| 76 | + return $this; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + protected $urlsLinked = true; |
|
| 80 | + |
|
| 81 | + function setSafeMode( $safeMode ) { |
|
| 82 | + $this->safeMode = (bool) $safeMode; |
|
| 83 | 83 | |
| 84 | - return $this; |
|
| 85 | - } |
|
| 84 | + return $this; |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - protected $safeMode; |
|
| 87 | + protected $safeMode; |
|
| 88 | 88 | |
| 89 | - function setStrictMode( $strictMode ) { |
|
| 90 | - $this->strictMode = (bool) $strictMode; |
|
| 89 | + function setStrictMode( $strictMode ) { |
|
| 90 | + $this->strictMode = (bool) $strictMode; |
|
| 91 | 91 | |
| 92 | - return $this; |
|
| 93 | - } |
|
| 92 | + return $this; |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - protected $strictMode; |
|
| 95 | + protected $strictMode; |
|
| 96 | 96 | |
| 97 | - protected $safeLinksWhitelist = array( |
|
| 98 | - 'http://', |
|
| 99 | - 'https://', |
|
| 100 | - 'ftp://', |
|
| 101 | - 'ftps://', |
|
| 102 | - 'mailto:', |
|
| 103 | - 'tel:', |
|
| 104 | - 'data:image/png;base64,', |
|
| 105 | - 'data:image/gif;base64,', |
|
| 106 | - 'data:image/jpeg;base64,', |
|
| 107 | - 'irc:', |
|
| 108 | - 'ircs:', |
|
| 109 | - 'git:', |
|
| 110 | - 'ssh:', |
|
| 111 | - 'news:', |
|
| 112 | - 'steam:', |
|
| 113 | - ); |
|
| 97 | + protected $safeLinksWhitelist = array( |
|
| 98 | + 'http://', |
|
| 99 | + 'https://', |
|
| 100 | + 'ftp://', |
|
| 101 | + 'ftps://', |
|
| 102 | + 'mailto:', |
|
| 103 | + 'tel:', |
|
| 104 | + 'data:image/png;base64,', |
|
| 105 | + 'data:image/gif;base64,', |
|
| 106 | + 'data:image/jpeg;base64,', |
|
| 107 | + 'irc:', |
|
| 108 | + 'ircs:', |
|
| 109 | + 'git:', |
|
| 110 | + 'ssh:', |
|
| 111 | + 'news:', |
|
| 112 | + 'steam:', |
|
| 113 | + ); |
|
| 114 | 114 | |
| 115 | - // |
|
| 116 | - // Lines |
|
| 117 | - // |
|
| 115 | + // |
|
| 116 | + // Lines |
|
| 117 | + // |
|
| 118 | 118 | |
| 119 | - protected $BlockTypes = array( |
|
| 120 | - '#' => array( 'Header' ), |
|
| 121 | - '*' => array( 'Rule', 'List' ), |
|
| 122 | - '+' => array( 'List' ), |
|
| 123 | - '-' => array( 'SetextHeader', 'Table', 'Rule', 'List' ), |
|
| 124 | - '0' => array( 'List' ), |
|
| 125 | - '1' => array( 'List' ), |
|
| 126 | - '2' => array( 'List' ), |
|
| 127 | - '3' => array( 'List' ), |
|
| 128 | - '4' => array( 'List' ), |
|
| 129 | - '5' => array( 'List' ), |
|
| 130 | - '6' => array( 'List' ), |
|
| 131 | - '7' => array( 'List' ), |
|
| 132 | - '8' => array( 'List' ), |
|
| 133 | - '9' => array( 'List' ), |
|
| 134 | - ':' => array( 'Table' ), |
|
| 135 | - '<' => array( 'Comment', 'Markup' ), |
|
| 136 | - '=' => array( 'SetextHeader' ), |
|
| 137 | - '>' => array( 'Quote' ), |
|
| 138 | - '[' => array( 'Reference' ), |
|
| 139 | - '_' => array( 'Rule' ), |
|
| 140 | - '`' => array( 'FencedCode' ), |
|
| 141 | - '|' => array( 'Table' ), |
|
| 142 | - '~' => array( 'FencedCode' ), |
|
| 143 | - ); |
|
| 119 | + protected $BlockTypes = array( |
|
| 120 | + '#' => array( 'Header' ), |
|
| 121 | + '*' => array( 'Rule', 'List' ), |
|
| 122 | + '+' => array( 'List' ), |
|
| 123 | + '-' => array( 'SetextHeader', 'Table', 'Rule', 'List' ), |
|
| 124 | + '0' => array( 'List' ), |
|
| 125 | + '1' => array( 'List' ), |
|
| 126 | + '2' => array( 'List' ), |
|
| 127 | + '3' => array( 'List' ), |
|
| 128 | + '4' => array( 'List' ), |
|
| 129 | + '5' => array( 'List' ), |
|
| 130 | + '6' => array( 'List' ), |
|
| 131 | + '7' => array( 'List' ), |
|
| 132 | + '8' => array( 'List' ), |
|
| 133 | + '9' => array( 'List' ), |
|
| 134 | + ':' => array( 'Table' ), |
|
| 135 | + '<' => array( 'Comment', 'Markup' ), |
|
| 136 | + '=' => array( 'SetextHeader' ), |
|
| 137 | + '>' => array( 'Quote' ), |
|
| 138 | + '[' => array( 'Reference' ), |
|
| 139 | + '_' => array( 'Rule' ), |
|
| 140 | + '`' => array( 'FencedCode' ), |
|
| 141 | + '|' => array( 'Table' ), |
|
| 142 | + '~' => array( 'FencedCode' ), |
|
| 143 | + ); |
|
| 144 | 144 | |
| 145 | - // ~ |
|
| 145 | + // ~ |
|
| 146 | 146 | |
| 147 | - protected $unmarkedBlockTypes = array( |
|
| 148 | - 'Code', |
|
| 149 | - ); |
|
| 147 | + protected $unmarkedBlockTypes = array( |
|
| 148 | + 'Code', |
|
| 149 | + ); |
|
| 150 | 150 | |
| 151 | - // |
|
| 152 | - // Blocks |
|
| 153 | - // |
|
| 151 | + // |
|
| 152 | + // Blocks |
|
| 153 | + // |
|
| 154 | 154 | |
| 155 | - protected function lines( array $lines ) { |
|
| 156 | - return $this->elements( $this->linesElements( $lines ) ); |
|
| 157 | - } |
|
| 155 | + protected function lines( array $lines ) { |
|
| 156 | + return $this->elements( $this->linesElements( $lines ) ); |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - protected function linesElements( array $lines ) { |
|
| 160 | - $Elements = array(); |
|
| 161 | - $CurrentBlock = null; |
|
| 162 | - |
|
| 163 | - foreach ( $lines as $line ) { |
|
| 164 | - if ( chop( $line ) === '' ) { |
|
| 165 | - if ( isset( $CurrentBlock ) ) { |
|
| 166 | - $CurrentBlock['interrupted'] = ( isset( $CurrentBlock['interrupted'] ) |
|
| 167 | - ? $CurrentBlock['interrupted'] + 1 : 1 |
|
| 168 | - ); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - continue; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - while ( ( $beforeTab = strstr( $line, "\t", true ) ) !== false ) { |
|
| 175 | - $shortage = 4 - mb_strlen( $beforeTab, 'utf-8' ) % 4; |
|
| 176 | - |
|
| 177 | - $line = $beforeTab |
|
| 178 | - . str_repeat( ' ', $shortage ) |
|
| 179 | - . substr( $line, strlen( $beforeTab ) + 1 ); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - $indent = strspn( $line, ' ' ); |
|
| 183 | - |
|
| 184 | - $text = $indent > 0 ? substr( $line, $indent ) : $line; |
|
| 185 | - |
|
| 186 | - // ~ |
|
| 187 | - |
|
| 188 | - $Line = array( |
|
| 189 | - 'body' => $line, |
|
| 190 | - 'indent' => $indent, |
|
| 191 | - 'text' => $text, |
|
| 192 | - ); |
|
| 193 | - |
|
| 194 | - // ~ |
|
| 195 | - |
|
| 196 | - if ( isset( $CurrentBlock['continuable'] ) ) { |
|
| 197 | - $methodName = 'block' . $CurrentBlock['type'] . 'Continue'; |
|
| 198 | - $Block = $this->$methodName( $Line, $CurrentBlock ); |
|
| 199 | - |
|
| 200 | - if ( isset( $Block ) ) { |
|
| 201 | - $CurrentBlock = $Block; |
|
| 202 | - |
|
| 203 | - continue; |
|
| 204 | - } elseif ( $this->isBlockCompletable( $CurrentBlock['type'] ) ) { |
|
| 205 | - $methodName = 'block' . $CurrentBlock['type'] . 'Complete'; |
|
| 206 | - $CurrentBlock = $this->$methodName( $CurrentBlock ); |
|
| 207 | - } |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - // ~ |
|
| 211 | - |
|
| 212 | - $marker = $text[0]; |
|
| 213 | - |
|
| 214 | - // ~ |
|
| 215 | - |
|
| 216 | - $blockTypes = $this->unmarkedBlockTypes; |
|
| 217 | - |
|
| 218 | - if ( isset( $this->BlockTypes[ $marker ] ) ) { |
|
| 219 | - foreach ( $this->BlockTypes[ $marker ] as $blockType ) { |
|
| 220 | - $blockTypes [] = $blockType; |
|
| 221 | - } |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - // |
|
| 225 | - // ~ |
|
| 226 | - |
|
| 227 | - foreach ( $blockTypes as $blockType ) { |
|
| 228 | - $Block = $this->{"block$blockType"}( $Line, $CurrentBlock ); |
|
| 159 | + protected function linesElements( array $lines ) { |
|
| 160 | + $Elements = array(); |
|
| 161 | + $CurrentBlock = null; |
|
| 162 | + |
|
| 163 | + foreach ( $lines as $line ) { |
|
| 164 | + if ( chop( $line ) === '' ) { |
|
| 165 | + if ( isset( $CurrentBlock ) ) { |
|
| 166 | + $CurrentBlock['interrupted'] = ( isset( $CurrentBlock['interrupted'] ) |
|
| 167 | + ? $CurrentBlock['interrupted'] + 1 : 1 |
|
| 168 | + ); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + continue; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + while ( ( $beforeTab = strstr( $line, "\t", true ) ) !== false ) { |
|
| 175 | + $shortage = 4 - mb_strlen( $beforeTab, 'utf-8' ) % 4; |
|
| 176 | + |
|
| 177 | + $line = $beforeTab |
|
| 178 | + . str_repeat( ' ', $shortage ) |
|
| 179 | + . substr( $line, strlen( $beforeTab ) + 1 ); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + $indent = strspn( $line, ' ' ); |
|
| 183 | + |
|
| 184 | + $text = $indent > 0 ? substr( $line, $indent ) : $line; |
|
| 185 | + |
|
| 186 | + // ~ |
|
| 187 | + |
|
| 188 | + $Line = array( |
|
| 189 | + 'body' => $line, |
|
| 190 | + 'indent' => $indent, |
|
| 191 | + 'text' => $text, |
|
| 192 | + ); |
|
| 193 | + |
|
| 194 | + // ~ |
|
| 195 | + |
|
| 196 | + if ( isset( $CurrentBlock['continuable'] ) ) { |
|
| 197 | + $methodName = 'block' . $CurrentBlock['type'] . 'Continue'; |
|
| 198 | + $Block = $this->$methodName( $Line, $CurrentBlock ); |
|
| 199 | + |
|
| 200 | + if ( isset( $Block ) ) { |
|
| 201 | + $CurrentBlock = $Block; |
|
| 202 | + |
|
| 203 | + continue; |
|
| 204 | + } elseif ( $this->isBlockCompletable( $CurrentBlock['type'] ) ) { |
|
| 205 | + $methodName = 'block' . $CurrentBlock['type'] . 'Complete'; |
|
| 206 | + $CurrentBlock = $this->$methodName( $CurrentBlock ); |
|
| 207 | + } |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + // ~ |
|
| 211 | + |
|
| 212 | + $marker = $text[0]; |
|
| 213 | + |
|
| 214 | + // ~ |
|
| 215 | + |
|
| 216 | + $blockTypes = $this->unmarkedBlockTypes; |
|
| 217 | + |
|
| 218 | + if ( isset( $this->BlockTypes[ $marker ] ) ) { |
|
| 219 | + foreach ( $this->BlockTypes[ $marker ] as $blockType ) { |
|
| 220 | + $blockTypes [] = $blockType; |
|
| 221 | + } |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + // |
|
| 225 | + // ~ |
|
| 226 | + |
|
| 227 | + foreach ( $blockTypes as $blockType ) { |
|
| 228 | + $Block = $this->{"block$blockType"}( $Line, $CurrentBlock ); |
|
| 229 | 229 | |
| 230 | - if ( isset( $Block ) ) { |
|
| 231 | - $Block['type'] = $blockType; |
|
| 230 | + if ( isset( $Block ) ) { |
|
| 231 | + $Block['type'] = $blockType; |
|
| 232 | 232 | |
| 233 | - if ( ! isset( $Block['identified'] ) ) { |
|
| 234 | - if ( isset( $CurrentBlock ) ) { |
|
| 235 | - $Elements[] = $this->extractElement( $CurrentBlock ); |
|
| 236 | - } |
|
| 233 | + if ( ! isset( $Block['identified'] ) ) { |
|
| 234 | + if ( isset( $CurrentBlock ) ) { |
|
| 235 | + $Elements[] = $this->extractElement( $CurrentBlock ); |
|
| 236 | + } |
|
| 237 | 237 | |
| 238 | - $Block['identified'] = true; |
|
| 239 | - } |
|
| 238 | + $Block['identified'] = true; |
|
| 239 | + } |
|
| 240 | 240 | |
| 241 | - if ( $this->isBlockContinuable( $blockType ) ) { |
|
| 242 | - $Block['continuable'] = true; |
|
| 243 | - } |
|
| 241 | + if ( $this->isBlockContinuable( $blockType ) ) { |
|
| 242 | + $Block['continuable'] = true; |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | - $CurrentBlock = $Block; |
|
| 245 | + $CurrentBlock = $Block; |
|
| 246 | 246 | |
| 247 | - continue 2; |
|
| 248 | - } |
|
| 249 | - } |
|
| 247 | + continue 2; |
|
| 248 | + } |
|
| 249 | + } |
|
| 250 | 250 | |
| 251 | - // ~ |
|
| 251 | + // ~ |
|
| 252 | 252 | |
| 253 | - if ( isset( $CurrentBlock ) and $CurrentBlock['type'] === 'Paragraph' ) { |
|
| 254 | - $Block = $this->paragraphContinue( $Line, $CurrentBlock ); |
|
| 255 | - } |
|
| 253 | + if ( isset( $CurrentBlock ) and $CurrentBlock['type'] === 'Paragraph' ) { |
|
| 254 | + $Block = $this->paragraphContinue( $Line, $CurrentBlock ); |
|
| 255 | + } |
|
| 256 | 256 | |
| 257 | - if ( isset( $Block ) ) { |
|
| 258 | - $CurrentBlock = $Block; |
|
| 259 | - } else { |
|
| 260 | - if ( isset( $CurrentBlock ) ) { |
|
| 261 | - $Elements[] = $this->extractElement( $CurrentBlock ); |
|
| 262 | - } |
|
| 257 | + if ( isset( $Block ) ) { |
|
| 258 | + $CurrentBlock = $Block; |
|
| 259 | + } else { |
|
| 260 | + if ( isset( $CurrentBlock ) ) { |
|
| 261 | + $Elements[] = $this->extractElement( $CurrentBlock ); |
|
| 262 | + } |
|
| 263 | 263 | |
| 264 | - $CurrentBlock = $this->paragraph( $Line ); |
|
| 264 | + $CurrentBlock = $this->paragraph( $Line ); |
|
| 265 | 265 | |
| 266 | - $CurrentBlock['identified'] = true; |
|
| 267 | - } |
|
| 268 | - } |
|
| 266 | + $CurrentBlock['identified'] = true; |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | 269 | |
| 270 | - // ~ |
|
| 270 | + // ~ |
|
| 271 | 271 | |
| 272 | - if ( isset( $CurrentBlock['continuable'] ) and $this->isBlockCompletable( $CurrentBlock['type'] ) ) { |
|
| 273 | - $methodName = 'block' . $CurrentBlock['type'] . 'Complete'; |
|
| 274 | - $CurrentBlock = $this->$methodName( $CurrentBlock ); |
|
| 275 | - } |
|
| 272 | + if ( isset( $CurrentBlock['continuable'] ) and $this->isBlockCompletable( $CurrentBlock['type'] ) ) { |
|
| 273 | + $methodName = 'block' . $CurrentBlock['type'] . 'Complete'; |
|
| 274 | + $CurrentBlock = $this->$methodName( $CurrentBlock ); |
|
| 275 | + } |
|
| 276 | 276 | |
| 277 | - // ~ |
|
| 277 | + // ~ |
|
| 278 | 278 | |
| 279 | - if ( isset( $CurrentBlock ) ) { |
|
| 280 | - $Elements[] = $this->extractElement( $CurrentBlock ); |
|
| 281 | - } |
|
| 279 | + if ( isset( $CurrentBlock ) ) { |
|
| 280 | + $Elements[] = $this->extractElement( $CurrentBlock ); |
|
| 281 | + } |
|
| 282 | 282 | |
| 283 | - // ~ |
|
| 283 | + // ~ |
|
| 284 | 284 | |
| 285 | - return $Elements; |
|
| 286 | - } |
|
| 285 | + return $Elements; |
|
| 286 | + } |
|
| 287 | 287 | |
| 288 | - protected function extractElement( array $Component ) { |
|
| 289 | - if ( ! isset( $Component['element'] ) ) { |
|
| 290 | - if ( isset( $Component['markup'] ) ) { |
|
| 291 | - $Component['element'] = array( 'rawHtml' => $Component['markup'] ); |
|
| 292 | - } elseif ( isset( $Component['hidden'] ) ) { |
|
| 293 | - $Component['element'] = array(); |
|
| 294 | - } |
|
| 295 | - } |
|
| 288 | + protected function extractElement( array $Component ) { |
|
| 289 | + if ( ! isset( $Component['element'] ) ) { |
|
| 290 | + if ( isset( $Component['markup'] ) ) { |
|
| 291 | + $Component['element'] = array( 'rawHtml' => $Component['markup'] ); |
|
| 292 | + } elseif ( isset( $Component['hidden'] ) ) { |
|
| 293 | + $Component['element'] = array(); |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | 296 | |
| 297 | - return $Component['element']; |
|
| 298 | - } |
|
| 297 | + return $Component['element']; |
|
| 298 | + } |
|
| 299 | 299 | |
| 300 | - protected function isBlockContinuable( $Type ) { |
|
| 301 | - return method_exists( $this, 'block' . $Type . 'Continue' ); |
|
| 302 | - } |
|
| 300 | + protected function isBlockContinuable( $Type ) { |
|
| 301 | + return method_exists( $this, 'block' . $Type . 'Continue' ); |
|
| 302 | + } |
|
| 303 | 303 | |
| 304 | - protected function isBlockCompletable( $Type ) { |
|
| 305 | - return method_exists( $this, 'block' . $Type . 'Complete' ); |
|
| 306 | - } |
|
| 304 | + protected function isBlockCompletable( $Type ) { |
|
| 305 | + return method_exists( $this, 'block' . $Type . 'Complete' ); |
|
| 306 | + } |
|
| 307 | 307 | |
| 308 | - // |
|
| 309 | - // Code |
|
| 308 | + // |
|
| 309 | + // Code |
|
| 310 | 310 | |
| 311 | - protected function blockCode( $Line, $Block = null ) { |
|
| 312 | - if ( isset( $Block ) and $Block['type'] === 'Paragraph' and ! isset( $Block['interrupted'] ) ) { |
|
| 313 | - return; |
|
| 314 | - } |
|
| 311 | + protected function blockCode( $Line, $Block = null ) { |
|
| 312 | + if ( isset( $Block ) and $Block['type'] === 'Paragraph' and ! isset( $Block['interrupted'] ) ) { |
|
| 313 | + return; |
|
| 314 | + } |
|
| 315 | 315 | |
| 316 | - if ( $Line['indent'] >= 4 ) { |
|
| 317 | - $text = substr( $Line['body'], 4 ); |
|
| 316 | + if ( $Line['indent'] >= 4 ) { |
|
| 317 | + $text = substr( $Line['body'], 4 ); |
|
| 318 | 318 | |
| 319 | - $Block = array( |
|
| 320 | - 'element' => array( |
|
| 321 | - 'name' => 'pre', |
|
| 322 | - 'element' => array( |
|
| 323 | - 'name' => 'code', |
|
| 324 | - 'text' => $text, |
|
| 325 | - ), |
|
| 326 | - ), |
|
| 327 | - ); |
|
| 319 | + $Block = array( |
|
| 320 | + 'element' => array( |
|
| 321 | + 'name' => 'pre', |
|
| 322 | + 'element' => array( |
|
| 323 | + 'name' => 'code', |
|
| 324 | + 'text' => $text, |
|
| 325 | + ), |
|
| 326 | + ), |
|
| 327 | + ); |
|
| 328 | 328 | |
| 329 | - return $Block; |
|
| 330 | - } |
|
| 331 | - } |
|
| 329 | + return $Block; |
|
| 330 | + } |
|
| 331 | + } |
|
| 332 | 332 | |
| 333 | - protected function blockCodeContinue( $Line, $Block ) { |
|
| 334 | - if ( $Line['indent'] >= 4 ) { |
|
| 335 | - if ( isset( $Block['interrupted'] ) ) { |
|
| 336 | - $Block['element']['element']['text'] .= str_repeat( "\n", $Block['interrupted'] ); |
|
| 333 | + protected function blockCodeContinue( $Line, $Block ) { |
|
| 334 | + if ( $Line['indent'] >= 4 ) { |
|
| 335 | + if ( isset( $Block['interrupted'] ) ) { |
|
| 336 | + $Block['element']['element']['text'] .= str_repeat( "\n", $Block['interrupted'] ); |
|
| 337 | 337 | |
| 338 | - unset( $Block['interrupted'] ); |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - $Block['element']['element']['text'] .= "\n"; |
|
| 342 | - |
|
| 343 | - $text = substr( $Line['body'], 4 ); |
|
| 344 | - |
|
| 345 | - $Block['element']['element']['text'] .= $text; |
|
| 346 | - |
|
| 347 | - return $Block; |
|
| 348 | - } |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - protected function blockCodeComplete( $Block ) { |
|
| 352 | - return $Block; |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - // |
|
| 356 | - // Comment |
|
| 357 | - |
|
| 358 | - protected function blockComment( $Line ) { |
|
| 359 | - if ( $this->markupEscaped or $this->safeMode ) { |
|
| 360 | - return; |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - if ( strpos( $Line['text'], '<!--' ) === 0 ) { |
|
| 364 | - $Block = array( |
|
| 365 | - 'element' => array( |
|
| 366 | - 'rawHtml' => $Line['body'], |
|
| 367 | - 'autobreak' => true, |
|
| 368 | - ), |
|
| 369 | - ); |
|
| 370 | - |
|
| 371 | - if ( strpos( $Line['text'], '-->' ) !== false ) { |
|
| 372 | - $Block['closed'] = true; |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - return $Block; |
|
| 376 | - } |
|
| 377 | - } |
|
| 338 | + unset( $Block['interrupted'] ); |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + $Block['element']['element']['text'] .= "\n"; |
|
| 342 | + |
|
| 343 | + $text = substr( $Line['body'], 4 ); |
|
| 344 | + |
|
| 345 | + $Block['element']['element']['text'] .= $text; |
|
| 346 | + |
|
| 347 | + return $Block; |
|
| 348 | + } |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + protected function blockCodeComplete( $Block ) { |
|
| 352 | + return $Block; |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + // |
|
| 356 | + // Comment |
|
| 357 | + |
|
| 358 | + protected function blockComment( $Line ) { |
|
| 359 | + if ( $this->markupEscaped or $this->safeMode ) { |
|
| 360 | + return; |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + if ( strpos( $Line['text'], '<!--' ) === 0 ) { |
|
| 364 | + $Block = array( |
|
| 365 | + 'element' => array( |
|
| 366 | + 'rawHtml' => $Line['body'], |
|
| 367 | + 'autobreak' => true, |
|
| 368 | + ), |
|
| 369 | + ); |
|
| 370 | + |
|
| 371 | + if ( strpos( $Line['text'], '-->' ) !== false ) { |
|
| 372 | + $Block['closed'] = true; |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + return $Block; |
|
| 376 | + } |
|
| 377 | + } |
|
| 378 | 378 | |
| 379 | - protected function blockCommentContinue( $Line, array $Block ) { |
|
| 380 | - if ( isset( $Block['closed'] ) ) { |
|
| 381 | - return; |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - $Block['element']['rawHtml'] .= "\n" . $Line['body']; |
|
| 385 | - |
|
| 386 | - if ( strpos( $Line['text'], '-->' ) !== false ) { |
|
| 387 | - $Block['closed'] = true; |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - return $Block; |
|
| 391 | - } |
|
| 379 | + protected function blockCommentContinue( $Line, array $Block ) { |
|
| 380 | + if ( isset( $Block['closed'] ) ) { |
|
| 381 | + return; |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + $Block['element']['rawHtml'] .= "\n" . $Line['body']; |
|
| 385 | + |
|
| 386 | + if ( strpos( $Line['text'], '-->' ) !== false ) { |
|
| 387 | + $Block['closed'] = true; |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + return $Block; |
|
| 391 | + } |
|
| 392 | 392 | |
| 393 | - // |
|
| 394 | - // Fenced Code |
|
| 393 | + // |
|
| 394 | + // Fenced Code |
|
| 395 | 395 | |
| 396 | - protected function blockFencedCode( $Line ) { |
|
| 397 | - $marker = $Line['text'][0]; |
|
| 396 | + protected function blockFencedCode( $Line ) { |
|
| 397 | + $marker = $Line['text'][0]; |
|
| 398 | 398 | |
| 399 | - $openerLength = strspn( $Line['text'], $marker ); |
|
| 400 | - |
|
| 401 | - if ( $openerLength < 3 ) { |
|
| 402 | - return; |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - $infostring = trim( substr( $Line['text'], $openerLength ), "\t " ); |
|
| 406 | - |
|
| 407 | - if ( strpos( $infostring, '`' ) !== false ) { |
|
| 408 | - return; |
|
| 409 | - } |
|
| 399 | + $openerLength = strspn( $Line['text'], $marker ); |
|
| 400 | + |
|
| 401 | + if ( $openerLength < 3 ) { |
|
| 402 | + return; |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + $infostring = trim( substr( $Line['text'], $openerLength ), "\t " ); |
|
| 406 | + |
|
| 407 | + if ( strpos( $infostring, '`' ) !== false ) { |
|
| 408 | + return; |
|
| 409 | + } |
|
| 410 | 410 | |
| 411 | - $Element = array( |
|
| 412 | - 'name' => 'code', |
|
| 413 | - 'text' => '', |
|
| 414 | - ); |
|
| 411 | + $Element = array( |
|
| 412 | + 'name' => 'code', |
|
| 413 | + 'text' => '', |
|
| 414 | + ); |
|
| 415 | 415 | |
| 416 | - if ( $infostring !== '' ) { |
|
| 417 | - /** |
|
| 418 | - * https://www.w3.org/TR/2011/WD-html5-20110525/elements.html#classes |
|
| 419 | - * Every HTML element may have a class attribute specified. |
|
| 420 | - * The attribute, if specified, must have a value that is a set |
|
| 421 | - * of space-separated tokens representing the various classes |
|
| 422 | - * that the element belongs to. |
|
| 423 | - * [...] |
|
| 424 | - * The space characters, for the purposes of this specification, |
|
| 425 | - * are U+0020 SPACE, U+0009 CHARACTER TABULATION (tab), |
|
| 426 | - * U+000A LINE FEED (LF), U+000C FORM FEED (FF), and |
|
| 427 | - * U+000D CARRIAGE RETURN (CR). |
|
| 428 | - */ |
|
| 429 | - $language = substr( $infostring, 0, strcspn( $infostring, " \t\n\f\r" ) ); |
|
| 416 | + if ( $infostring !== '' ) { |
|
| 417 | + /** |
|
| 418 | + * https://www.w3.org/TR/2011/WD-html5-20110525/elements.html#classes |
|
| 419 | + * Every HTML element may have a class attribute specified. |
|
| 420 | + * The attribute, if specified, must have a value that is a set |
|
| 421 | + * of space-separated tokens representing the various classes |
|
| 422 | + * that the element belongs to. |
|
| 423 | + * [...] |
|
| 424 | + * The space characters, for the purposes of this specification, |
|
| 425 | + * are U+0020 SPACE, U+0009 CHARACTER TABULATION (tab), |
|
| 426 | + * U+000A LINE FEED (LF), U+000C FORM FEED (FF), and |
|
| 427 | + * U+000D CARRIAGE RETURN (CR). |
|
| 428 | + */ |
|
| 429 | + $language = substr( $infostring, 0, strcspn( $infostring, " \t\n\f\r" ) ); |
|
| 430 | 430 | |
| 431 | - $Element['attributes'] = array( 'class' => "language-$language" ); |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - $Block = array( |
|
| 435 | - 'char' => $marker, |
|
| 436 | - 'openerLength' => $openerLength, |
|
| 437 | - 'element' => array( |
|
| 438 | - 'name' => 'pre', |
|
| 439 | - 'element' => $Element, |
|
| 440 | - ), |
|
| 441 | - ); |
|
| 442 | - |
|
| 443 | - return $Block; |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - protected function blockFencedCodeContinue( $Line, $Block ) { |
|
| 447 | - if ( isset( $Block['complete'] ) ) { |
|
| 448 | - return; |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - if ( isset( $Block['interrupted'] ) ) { |
|
| 452 | - $Block['element']['element']['text'] .= str_repeat( "\n", $Block['interrupted'] ); |
|
| 453 | - |
|
| 454 | - unset( $Block['interrupted'] ); |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - if ( ( $len = strspn( $Line['text'], $Block['char'] ) ) >= $Block['openerLength'] |
|
| 458 | - and chop( substr( $Line['text'], $len ), ' ' ) === '' |
|
| 459 | - ) { |
|
| 460 | - $Block['element']['element']['text'] = substr( $Block['element']['element']['text'], 1 ); |
|
| 461 | - |
|
| 462 | - $Block['complete'] = true; |
|
| 463 | - |
|
| 464 | - return $Block; |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - $Block['element']['element']['text'] .= "\n" . $Line['body']; |
|
| 468 | - |
|
| 469 | - return $Block; |
|
| 470 | - } |
|
| 471 | - |
|
| 472 | - protected function blockFencedCodeComplete( $Block ) { |
|
| 473 | - return $Block; |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - // |
|
| 477 | - // Header |
|
| 478 | - |
|
| 479 | - protected function blockHeader( $Line ) { |
|
| 480 | - $level = strspn( $Line['text'], '#' ); |
|
| 481 | - |
|
| 482 | - if ( $level > 6 ) { |
|
| 483 | - return; |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - $text = trim( $Line['text'], '#' ); |
|
| 487 | - |
|
| 488 | - if ( $this->strictMode and isset( $text[0] ) and $text[0] !== ' ' ) { |
|
| 489 | - return; |
|
| 490 | - } |
|
| 491 | - |
|
| 492 | - $text = trim( $text, ' ' ); |
|
| 493 | - |
|
| 494 | - $Block = array( |
|
| 495 | - 'element' => array( |
|
| 496 | - 'name' => 'h' . $level, |
|
| 497 | - 'handler' => array( |
|
| 498 | - 'function' => 'lineElements', |
|
| 499 | - 'argument' => $text, |
|
| 500 | - 'destination' => 'elements', |
|
| 501 | - ), |
|
| 502 | - ), |
|
| 503 | - ); |
|
| 504 | - |
|
| 505 | - return $Block; |
|
| 506 | - } |
|
| 507 | - |
|
| 508 | - // |
|
| 509 | - // List |
|
| 510 | - |
|
| 511 | - protected function blockList( $Line, ?array $CurrentBlock = null ) { |
|
| 512 | - list($name, $pattern) = $Line['text'][0] <= '-' ? array( 'ul', '[*+-]' ) : array( 'ol', '[0-9]{1,9}+[.\)]' ); |
|
| 513 | - |
|
| 514 | - if ( preg_match( '/^(' . $pattern . '([ ]++|$))(.*+)/', $Line['text'], $matches ) ) { |
|
| 515 | - $contentIndent = strlen( $matches[2] ); |
|
| 516 | - |
|
| 517 | - if ( $contentIndent >= 5 ) { |
|
| 518 | - $contentIndent -= 1; |
|
| 519 | - $matches[1] = substr( $matches[1], 0, -$contentIndent ); |
|
| 520 | - $matches[3] = str_repeat( ' ', $contentIndent ) . $matches[3]; |
|
| 521 | - } elseif ( $contentIndent === 0 ) { |
|
| 522 | - $matches[1] .= ' '; |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - $markerWithoutWhitespace = strstr( $matches[1], ' ', true ); |
|
| 526 | - |
|
| 527 | - $Block = array( |
|
| 528 | - 'indent' => $Line['indent'], |
|
| 529 | - 'pattern' => $pattern, |
|
| 530 | - 'data' => array( |
|
| 531 | - 'type' => $name, |
|
| 532 | - 'marker' => $matches[1], |
|
| 533 | - 'markerType' => ( $name === 'ul' ? $markerWithoutWhitespace : substr( $markerWithoutWhitespace, -1 ) ), |
|
| 534 | - ), |
|
| 535 | - 'element' => array( |
|
| 536 | - 'name' => $name, |
|
| 537 | - 'elements' => array(), |
|
| 538 | - ), |
|
| 539 | - ); |
|
| 540 | - $Block['data']['markerTypeRegex'] = preg_quote( $Block['data']['markerType'], '/' ); |
|
| 541 | - |
|
| 542 | - if ( $name === 'ol' ) { |
|
| 543 | - $listStart = ltrim( strstr( $matches[1], $Block['data']['markerType'], true ), '0' ) ?: '0'; |
|
| 544 | - |
|
| 545 | - if ( $listStart !== '1' ) { |
|
| 546 | - if ( |
|
| 547 | - isset( $CurrentBlock ) |
|
| 548 | - and $CurrentBlock['type'] === 'Paragraph' |
|
| 549 | - and ! isset( $CurrentBlock['interrupted'] ) |
|
| 550 | - ) { |
|
| 551 | - return; |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - $Block['element']['attributes'] = array( 'start' => $listStart ); |
|
| 555 | - } |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - $Block['li'] = array( |
|
| 559 | - 'name' => 'li', |
|
| 560 | - 'handler' => array( |
|
| 561 | - 'function' => 'li', |
|
| 562 | - 'argument' => ! empty( $matches[3] ) ? array( $matches[3] ) : array(), |
|
| 563 | - 'destination' => 'elements', |
|
| 564 | - ), |
|
| 565 | - ); |
|
| 566 | - |
|
| 567 | - $Block['element']['elements'] [] = & $Block['li']; |
|
| 568 | - |
|
| 569 | - return $Block; |
|
| 570 | - } |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - protected function blockListContinue( $Line, array $Block ) { |
|
| 574 | - if ( isset( $Block['interrupted'] ) and empty( $Block['li']['handler']['argument'] ) ) { |
|
| 575 | - return null; |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - $requiredIndent = ( $Block['indent'] + strlen( $Block['data']['marker'] ) ); |
|
| 579 | - |
|
| 580 | - if ( $Line['indent'] < $requiredIndent |
|
| 581 | - and ( |
|
| 582 | - ( |
|
| 583 | - $Block['data']['type'] === 'ol' |
|
| 584 | - and preg_match( '/^[0-9]++' . $Block['data']['markerTypeRegex'] . '(?:[ ]++(.*)|$)/', $Line['text'], $matches ) |
|
| 585 | - ) or ( |
|
| 586 | - $Block['data']['type'] === 'ul' |
|
| 587 | - and preg_match( '/^' . $Block['data']['markerTypeRegex'] . '(?:[ ]++(.*)|$)/', $Line['text'], $matches ) |
|
| 588 | - ) |
|
| 589 | - ) |
|
| 590 | - ) { |
|
| 591 | - if ( isset( $Block['interrupted'] ) ) { |
|
| 592 | - $Block['li']['handler']['argument'] [] = ''; |
|
| 593 | - |
|
| 594 | - $Block['loose'] = true; |
|
| 595 | - |
|
| 596 | - unset( $Block['interrupted'] ); |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - unset( $Block['li'] ); |
|
| 600 | - |
|
| 601 | - $text = isset( $matches[1] ) ? $matches[1] : ''; |
|
| 602 | - |
|
| 603 | - $Block['indent'] = $Line['indent']; |
|
| 604 | - |
|
| 605 | - $Block['li'] = array( |
|
| 606 | - 'name' => 'li', |
|
| 607 | - 'handler' => array( |
|
| 608 | - 'function' => 'li', |
|
| 609 | - 'argument' => array( $text ), |
|
| 610 | - 'destination' => 'elements', |
|
| 611 | - ), |
|
| 612 | - ); |
|
| 613 | - |
|
| 614 | - $Block['element']['elements'] [] = & $Block['li']; |
|
| 615 | - |
|
| 616 | - return $Block; |
|
| 617 | - } elseif ( $Line['indent'] < $requiredIndent and $this->blockList( $Line ) ) { |
|
| 618 | - return null; |
|
| 619 | - } |
|
| 620 | - |
|
| 621 | - if ( $Line['text'][0] === '[' and $this->blockReference( $Line ) ) { |
|
| 622 | - return $Block; |
|
| 623 | - } |
|
| 624 | - |
|
| 625 | - if ( $Line['indent'] >= $requiredIndent ) { |
|
| 626 | - if ( isset( $Block['interrupted'] ) ) { |
|
| 627 | - $Block['li']['handler']['argument'] [] = ''; |
|
| 628 | - |
|
| 629 | - $Block['loose'] = true; |
|
| 630 | - |
|
| 631 | - unset( $Block['interrupted'] ); |
|
| 632 | - } |
|
| 633 | - |
|
| 634 | - $text = substr( $Line['body'], $requiredIndent ); |
|
| 635 | - |
|
| 636 | - $Block['li']['handler']['argument'] [] = $text; |
|
| 637 | - |
|
| 638 | - return $Block; |
|
| 639 | - } |
|
| 640 | - |
|
| 641 | - if ( ! isset( $Block['interrupted'] ) ) { |
|
| 642 | - $text = preg_replace( '/^[ ]{0,' . $requiredIndent . '}+/', '', $Line['body'] ); |
|
| 643 | - |
|
| 644 | - $Block['li']['handler']['argument'] [] = $text; |
|
| 645 | - |
|
| 646 | - return $Block; |
|
| 647 | - } |
|
| 648 | - } |
|
| 649 | - |
|
| 650 | - protected function blockListComplete( array $Block ) { |
|
| 651 | - if ( isset( $Block['loose'] ) ) { |
|
| 652 | - foreach ( $Block['element']['elements'] as &$li ) { |
|
| 653 | - if ( end( $li['handler']['argument'] ) !== '' ) { |
|
| 654 | - $li['handler']['argument'] [] = ''; |
|
| 655 | - } |
|
| 656 | - } |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - return $Block; |
|
| 660 | - } |
|
| 661 | - |
|
| 662 | - // |
|
| 663 | - // Quote |
|
| 664 | - |
|
| 665 | - protected function blockQuote( $Line ) { |
|
| 666 | - if ( preg_match( '/^>[ ]?+(.*+)/', $Line['text'], $matches ) ) { |
|
| 667 | - $Block = array( |
|
| 668 | - 'element' => array( |
|
| 669 | - 'name' => 'blockquote', |
|
| 670 | - 'handler' => array( |
|
| 671 | - 'function' => 'linesElements', |
|
| 672 | - 'argument' => (array) $matches[1], |
|
| 673 | - 'destination' => 'elements', |
|
| 674 | - ), |
|
| 675 | - ), |
|
| 676 | - ); |
|
| 431 | + $Element['attributes'] = array( 'class' => "language-$language" ); |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + $Block = array( |
|
| 435 | + 'char' => $marker, |
|
| 436 | + 'openerLength' => $openerLength, |
|
| 437 | + 'element' => array( |
|
| 438 | + 'name' => 'pre', |
|
| 439 | + 'element' => $Element, |
|
| 440 | + ), |
|
| 441 | + ); |
|
| 442 | + |
|
| 443 | + return $Block; |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + protected function blockFencedCodeContinue( $Line, $Block ) { |
|
| 447 | + if ( isset( $Block['complete'] ) ) { |
|
| 448 | + return; |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + if ( isset( $Block['interrupted'] ) ) { |
|
| 452 | + $Block['element']['element']['text'] .= str_repeat( "\n", $Block['interrupted'] ); |
|
| 453 | + |
|
| 454 | + unset( $Block['interrupted'] ); |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + if ( ( $len = strspn( $Line['text'], $Block['char'] ) ) >= $Block['openerLength'] |
|
| 458 | + and chop( substr( $Line['text'], $len ), ' ' ) === '' |
|
| 459 | + ) { |
|
| 460 | + $Block['element']['element']['text'] = substr( $Block['element']['element']['text'], 1 ); |
|
| 461 | + |
|
| 462 | + $Block['complete'] = true; |
|
| 463 | + |
|
| 464 | + return $Block; |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + $Block['element']['element']['text'] .= "\n" . $Line['body']; |
|
| 468 | + |
|
| 469 | + return $Block; |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + protected function blockFencedCodeComplete( $Block ) { |
|
| 473 | + return $Block; |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + // |
|
| 477 | + // Header |
|
| 478 | + |
|
| 479 | + protected function blockHeader( $Line ) { |
|
| 480 | + $level = strspn( $Line['text'], '#' ); |
|
| 481 | + |
|
| 482 | + if ( $level > 6 ) { |
|
| 483 | + return; |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + $text = trim( $Line['text'], '#' ); |
|
| 487 | + |
|
| 488 | + if ( $this->strictMode and isset( $text[0] ) and $text[0] !== ' ' ) { |
|
| 489 | + return; |
|
| 490 | + } |
|
| 491 | + |
|
| 492 | + $text = trim( $text, ' ' ); |
|
| 493 | + |
|
| 494 | + $Block = array( |
|
| 495 | + 'element' => array( |
|
| 496 | + 'name' => 'h' . $level, |
|
| 497 | + 'handler' => array( |
|
| 498 | + 'function' => 'lineElements', |
|
| 499 | + 'argument' => $text, |
|
| 500 | + 'destination' => 'elements', |
|
| 501 | + ), |
|
| 502 | + ), |
|
| 503 | + ); |
|
| 504 | + |
|
| 505 | + return $Block; |
|
| 506 | + } |
|
| 507 | + |
|
| 508 | + // |
|
| 509 | + // List |
|
| 510 | + |
|
| 511 | + protected function blockList( $Line, ?array $CurrentBlock = null ) { |
|
| 512 | + list($name, $pattern) = $Line['text'][0] <= '-' ? array( 'ul', '[*+-]' ) : array( 'ol', '[0-9]{1,9}+[.\)]' ); |
|
| 513 | + |
|
| 514 | + if ( preg_match( '/^(' . $pattern . '([ ]++|$))(.*+)/', $Line['text'], $matches ) ) { |
|
| 515 | + $contentIndent = strlen( $matches[2] ); |
|
| 516 | + |
|
| 517 | + if ( $contentIndent >= 5 ) { |
|
| 518 | + $contentIndent -= 1; |
|
| 519 | + $matches[1] = substr( $matches[1], 0, -$contentIndent ); |
|
| 520 | + $matches[3] = str_repeat( ' ', $contentIndent ) . $matches[3]; |
|
| 521 | + } elseif ( $contentIndent === 0 ) { |
|
| 522 | + $matches[1] .= ' '; |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + $markerWithoutWhitespace = strstr( $matches[1], ' ', true ); |
|
| 526 | + |
|
| 527 | + $Block = array( |
|
| 528 | + 'indent' => $Line['indent'], |
|
| 529 | + 'pattern' => $pattern, |
|
| 530 | + 'data' => array( |
|
| 531 | + 'type' => $name, |
|
| 532 | + 'marker' => $matches[1], |
|
| 533 | + 'markerType' => ( $name === 'ul' ? $markerWithoutWhitespace : substr( $markerWithoutWhitespace, -1 ) ), |
|
| 534 | + ), |
|
| 535 | + 'element' => array( |
|
| 536 | + 'name' => $name, |
|
| 537 | + 'elements' => array(), |
|
| 538 | + ), |
|
| 539 | + ); |
|
| 540 | + $Block['data']['markerTypeRegex'] = preg_quote( $Block['data']['markerType'], '/' ); |
|
| 541 | + |
|
| 542 | + if ( $name === 'ol' ) { |
|
| 543 | + $listStart = ltrim( strstr( $matches[1], $Block['data']['markerType'], true ), '0' ) ?: '0'; |
|
| 544 | + |
|
| 545 | + if ( $listStart !== '1' ) { |
|
| 546 | + if ( |
|
| 547 | + isset( $CurrentBlock ) |
|
| 548 | + and $CurrentBlock['type'] === 'Paragraph' |
|
| 549 | + and ! isset( $CurrentBlock['interrupted'] ) |
|
| 550 | + ) { |
|
| 551 | + return; |
|
| 552 | + } |
|
| 553 | + |
|
| 554 | + $Block['element']['attributes'] = array( 'start' => $listStart ); |
|
| 555 | + } |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + $Block['li'] = array( |
|
| 559 | + 'name' => 'li', |
|
| 560 | + 'handler' => array( |
|
| 561 | + 'function' => 'li', |
|
| 562 | + 'argument' => ! empty( $matches[3] ) ? array( $matches[3] ) : array(), |
|
| 563 | + 'destination' => 'elements', |
|
| 564 | + ), |
|
| 565 | + ); |
|
| 566 | + |
|
| 567 | + $Block['element']['elements'] [] = & $Block['li']; |
|
| 568 | + |
|
| 569 | + return $Block; |
|
| 570 | + } |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + protected function blockListContinue( $Line, array $Block ) { |
|
| 574 | + if ( isset( $Block['interrupted'] ) and empty( $Block['li']['handler']['argument'] ) ) { |
|
| 575 | + return null; |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + $requiredIndent = ( $Block['indent'] + strlen( $Block['data']['marker'] ) ); |
|
| 579 | + |
|
| 580 | + if ( $Line['indent'] < $requiredIndent |
|
| 581 | + and ( |
|
| 582 | + ( |
|
| 583 | + $Block['data']['type'] === 'ol' |
|
| 584 | + and preg_match( '/^[0-9]++' . $Block['data']['markerTypeRegex'] . '(?:[ ]++(.*)|$)/', $Line['text'], $matches ) |
|
| 585 | + ) or ( |
|
| 586 | + $Block['data']['type'] === 'ul' |
|
| 587 | + and preg_match( '/^' . $Block['data']['markerTypeRegex'] . '(?:[ ]++(.*)|$)/', $Line['text'], $matches ) |
|
| 588 | + ) |
|
| 589 | + ) |
|
| 590 | + ) { |
|
| 591 | + if ( isset( $Block['interrupted'] ) ) { |
|
| 592 | + $Block['li']['handler']['argument'] [] = ''; |
|
| 593 | + |
|
| 594 | + $Block['loose'] = true; |
|
| 595 | + |
|
| 596 | + unset( $Block['interrupted'] ); |
|
| 597 | + } |
|
| 598 | + |
|
| 599 | + unset( $Block['li'] ); |
|
| 600 | + |
|
| 601 | + $text = isset( $matches[1] ) ? $matches[1] : ''; |
|
| 602 | + |
|
| 603 | + $Block['indent'] = $Line['indent']; |
|
| 604 | + |
|
| 605 | + $Block['li'] = array( |
|
| 606 | + 'name' => 'li', |
|
| 607 | + 'handler' => array( |
|
| 608 | + 'function' => 'li', |
|
| 609 | + 'argument' => array( $text ), |
|
| 610 | + 'destination' => 'elements', |
|
| 611 | + ), |
|
| 612 | + ); |
|
| 613 | + |
|
| 614 | + $Block['element']['elements'] [] = & $Block['li']; |
|
| 615 | + |
|
| 616 | + return $Block; |
|
| 617 | + } elseif ( $Line['indent'] < $requiredIndent and $this->blockList( $Line ) ) { |
|
| 618 | + return null; |
|
| 619 | + } |
|
| 620 | + |
|
| 621 | + if ( $Line['text'][0] === '[' and $this->blockReference( $Line ) ) { |
|
| 622 | + return $Block; |
|
| 623 | + } |
|
| 624 | + |
|
| 625 | + if ( $Line['indent'] >= $requiredIndent ) { |
|
| 626 | + if ( isset( $Block['interrupted'] ) ) { |
|
| 627 | + $Block['li']['handler']['argument'] [] = ''; |
|
| 628 | + |
|
| 629 | + $Block['loose'] = true; |
|
| 630 | + |
|
| 631 | + unset( $Block['interrupted'] ); |
|
| 632 | + } |
|
| 633 | + |
|
| 634 | + $text = substr( $Line['body'], $requiredIndent ); |
|
| 635 | + |
|
| 636 | + $Block['li']['handler']['argument'] [] = $text; |
|
| 637 | + |
|
| 638 | + return $Block; |
|
| 639 | + } |
|
| 640 | + |
|
| 641 | + if ( ! isset( $Block['interrupted'] ) ) { |
|
| 642 | + $text = preg_replace( '/^[ ]{0,' . $requiredIndent . '}+/', '', $Line['body'] ); |
|
| 643 | + |
|
| 644 | + $Block['li']['handler']['argument'] [] = $text; |
|
| 645 | + |
|
| 646 | + return $Block; |
|
| 647 | + } |
|
| 648 | + } |
|
| 649 | + |
|
| 650 | + protected function blockListComplete( array $Block ) { |
|
| 651 | + if ( isset( $Block['loose'] ) ) { |
|
| 652 | + foreach ( $Block['element']['elements'] as &$li ) { |
|
| 653 | + if ( end( $li['handler']['argument'] ) !== '' ) { |
|
| 654 | + $li['handler']['argument'] [] = ''; |
|
| 655 | + } |
|
| 656 | + } |
|
| 657 | + } |
|
| 658 | + |
|
| 659 | + return $Block; |
|
| 660 | + } |
|
| 661 | + |
|
| 662 | + // |
|
| 663 | + // Quote |
|
| 664 | + |
|
| 665 | + protected function blockQuote( $Line ) { |
|
| 666 | + if ( preg_match( '/^>[ ]?+(.*+)/', $Line['text'], $matches ) ) { |
|
| 667 | + $Block = array( |
|
| 668 | + 'element' => array( |
|
| 669 | + 'name' => 'blockquote', |
|
| 670 | + 'handler' => array( |
|
| 671 | + 'function' => 'linesElements', |
|
| 672 | + 'argument' => (array) $matches[1], |
|
| 673 | + 'destination' => 'elements', |
|
| 674 | + ), |
|
| 675 | + ), |
|
| 676 | + ); |
|
| 677 | 677 | |
| 678 | - return $Block; |
|
| 679 | - } |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - protected function blockQuoteContinue( $Line, array $Block ) { |
|
| 683 | - if ( isset( $Block['interrupted'] ) ) { |
|
| 684 | - return; |
|
| 685 | - } |
|
| 678 | + return $Block; |
|
| 679 | + } |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + protected function blockQuoteContinue( $Line, array $Block ) { |
|
| 683 | + if ( isset( $Block['interrupted'] ) ) { |
|
| 684 | + return; |
|
| 685 | + } |
|
| 686 | 686 | |
| 687 | - if ( $Line['text'][0] === '>' and preg_match( '/^>[ ]?+(.*+)/', $Line['text'], $matches ) ) { |
|
| 688 | - $Block['element']['handler']['argument'] [] = $matches[1]; |
|
| 687 | + if ( $Line['text'][0] === '>' and preg_match( '/^>[ ]?+(.*+)/', $Line['text'], $matches ) ) { |
|
| 688 | + $Block['element']['handler']['argument'] [] = $matches[1]; |
|
| 689 | 689 | |
| 690 | - return $Block; |
|
| 691 | - } |
|
| 690 | + return $Block; |
|
| 691 | + } |
|
| 692 | 692 | |
| 693 | - if ( ! isset( $Block['interrupted'] ) ) { |
|
| 694 | - $Block['element']['handler']['argument'] [] = $Line['text']; |
|
| 693 | + if ( ! isset( $Block['interrupted'] ) ) { |
|
| 694 | + $Block['element']['handler']['argument'] [] = $Line['text']; |
|
| 695 | 695 | |
| 696 | - return $Block; |
|
| 697 | - } |
|
| 698 | - } |
|
| 696 | + return $Block; |
|
| 697 | + } |
|
| 698 | + } |
|
| 699 | 699 | |
| 700 | - // |
|
| 701 | - // Rule |
|
| 700 | + // |
|
| 701 | + // Rule |
|
| 702 | 702 | |
| 703 | - protected function blockRule( $Line ) { |
|
| 704 | - $marker = $Line['text'][0]; |
|
| 705 | - |
|
| 706 | - if ( substr_count( $Line['text'], $marker ) >= 3 and chop( $Line['text'], " $marker" ) === '' ) { |
|
| 707 | - $Block = array( |
|
| 708 | - 'element' => array( |
|
| 709 | - 'name' => 'hr', |
|
| 710 | - ), |
|
| 711 | - ); |
|
| 712 | - |
|
| 713 | - return $Block; |
|
| 714 | - } |
|
| 715 | - } |
|
| 716 | - |
|
| 717 | - // |
|
| 718 | - // Setext |
|
| 703 | + protected function blockRule( $Line ) { |
|
| 704 | + $marker = $Line['text'][0]; |
|
| 705 | + |
|
| 706 | + if ( substr_count( $Line['text'], $marker ) >= 3 and chop( $Line['text'], " $marker" ) === '' ) { |
|
| 707 | + $Block = array( |
|
| 708 | + 'element' => array( |
|
| 709 | + 'name' => 'hr', |
|
| 710 | + ), |
|
| 711 | + ); |
|
| 712 | + |
|
| 713 | + return $Block; |
|
| 714 | + } |
|
| 715 | + } |
|
| 716 | + |
|
| 717 | + // |
|
| 718 | + // Setext |
|
| 719 | 719 | |
| 720 | - protected function blockSetextHeader( $Line, ?array $Block = null ) { |
|
| 721 | - if ( ! isset( $Block ) or $Block['type'] !== 'Paragraph' or isset( $Block['interrupted'] ) ) { |
|
| 722 | - return; |
|
| 723 | - } |
|
| 720 | + protected function blockSetextHeader( $Line, ?array $Block = null ) { |
|
| 721 | + if ( ! isset( $Block ) or $Block['type'] !== 'Paragraph' or isset( $Block['interrupted'] ) ) { |
|
| 722 | + return; |
|
| 723 | + } |
|
| 724 | 724 | |
| 725 | - if ( $Line['indent'] < 4 and chop( chop( $Line['text'], ' ' ), $Line['text'][0] ) === '' ) { |
|
| 726 | - $Block['element']['name'] = $Line['text'][0] === '=' ? 'h1' : 'h2'; |
|
| 725 | + if ( $Line['indent'] < 4 and chop( chop( $Line['text'], ' ' ), $Line['text'][0] ) === '' ) { |
|
| 726 | + $Block['element']['name'] = $Line['text'][0] === '=' ? 'h1' : 'h2'; |
|
| 727 | 727 | |
| 728 | - return $Block; |
|
| 729 | - } |
|
| 730 | - } |
|
| 728 | + return $Block; |
|
| 729 | + } |
|
| 730 | + } |
|
| 731 | 731 | |
| 732 | - // |
|
| 733 | - // Markup |
|
| 732 | + // |
|
| 733 | + // Markup |
|
| 734 | 734 | |
| 735 | - protected function blockMarkup( $Line ) { |
|
| 736 | - if ( $this->markupEscaped or $this->safeMode ) { |
|
| 737 | - return; |
|
| 738 | - } |
|
| 735 | + protected function blockMarkup( $Line ) { |
|
| 736 | + if ( $this->markupEscaped or $this->safeMode ) { |
|
| 737 | + return; |
|
| 738 | + } |
|
| 739 | 739 | |
| 740 | - if ( preg_match( '/^<[\/]?+(\w*)(?:[ ]*+' . $this->regexHtmlAttribute . ')*+[ ]*+(\/)?>/', $Line['text'], $matches ) ) { |
|
| 741 | - $element = strtolower( $matches[1] ); |
|
| 740 | + if ( preg_match( '/^<[\/]?+(\w*)(?:[ ]*+' . $this->regexHtmlAttribute . ')*+[ ]*+(\/)?>/', $Line['text'], $matches ) ) { |
|
| 741 | + $element = strtolower( $matches[1] ); |
|
| 742 | 742 | |
| 743 | - if ( in_array( $element, $this->textLevelElements ) ) { |
|
| 744 | - return; |
|
| 745 | - } |
|
| 743 | + if ( in_array( $element, $this->textLevelElements ) ) { |
|
| 744 | + return; |
|
| 745 | + } |
|
| 746 | 746 | |
| 747 | - $Block = array( |
|
| 748 | - 'name' => $matches[1], |
|
| 749 | - 'element' => array( |
|
| 750 | - 'rawHtml' => $Line['text'], |
|
| 751 | - 'autobreak' => true, |
|
| 752 | - ), |
|
| 753 | - ); |
|
| 747 | + $Block = array( |
|
| 748 | + 'name' => $matches[1], |
|
| 749 | + 'element' => array( |
|
| 750 | + 'rawHtml' => $Line['text'], |
|
| 751 | + 'autobreak' => true, |
|
| 752 | + ), |
|
| 753 | + ); |
|
| 754 | 754 | |
| 755 | - return $Block; |
|
| 756 | - } |
|
| 757 | - } |
|
| 755 | + return $Block; |
|
| 756 | + } |
|
| 757 | + } |
|
| 758 | 758 | |
| 759 | - protected function blockMarkupContinue( $Line, array $Block ) { |
|
| 760 | - if ( isset( $Block['closed'] ) or isset( $Block['interrupted'] ) ) { |
|
| 761 | - return; |
|
| 762 | - } |
|
| 759 | + protected function blockMarkupContinue( $Line, array $Block ) { |
|
| 760 | + if ( isset( $Block['closed'] ) or isset( $Block['interrupted'] ) ) { |
|
| 761 | + return; |
|
| 762 | + } |
|
| 763 | 763 | |
| 764 | - $Block['element']['rawHtml'] .= "\n" . $Line['body']; |
|
| 764 | + $Block['element']['rawHtml'] .= "\n" . $Line['body']; |
|
| 765 | 765 | |
| 766 | - return $Block; |
|
| 767 | - } |
|
| 766 | + return $Block; |
|
| 767 | + } |
|
| 768 | 768 | |
| 769 | - // |
|
| 770 | - // Reference |
|
| 769 | + // |
|
| 770 | + // Reference |
|
| 771 | 771 | |
| 772 | - protected function blockReference( $Line ) { |
|
| 773 | - if ( strpos( $Line['text'], ']' ) !== false |
|
| 774 | - and preg_match( '/^\[(.+?)\]:[ ]*+<?(\S+?)>?(?:[ ]+["\'(](.+)["\')])?[ ]*+$/', $Line['text'], $matches ) |
|
| 775 | - ) { |
|
| 776 | - $id = strtolower( $matches[1] ); |
|
| 772 | + protected function blockReference( $Line ) { |
|
| 773 | + if ( strpos( $Line['text'], ']' ) !== false |
|
| 774 | + and preg_match( '/^\[(.+?)\]:[ ]*+<?(\S+?)>?(?:[ ]+["\'(](.+)["\')])?[ ]*+$/', $Line['text'], $matches ) |
|
| 775 | + ) { |
|
| 776 | + $id = strtolower( $matches[1] ); |
|
| 777 | 777 | |
| 778 | - $Data = array( |
|
| 779 | - 'url' => $matches[2], |
|
| 780 | - 'title' => isset( $matches[3] ) ? $matches[3] : null, |
|
| 781 | - ); |
|
| 778 | + $Data = array( |
|
| 779 | + 'url' => $matches[2], |
|
| 780 | + 'title' => isset( $matches[3] ) ? $matches[3] : null, |
|
| 781 | + ); |
|
| 782 | 782 | |
| 783 | - $this->DefinitionData['Reference'][ $id ] = $Data; |
|
| 783 | + $this->DefinitionData['Reference'][ $id ] = $Data; |
|
| 784 | 784 | |
| 785 | - $Block = array( |
|
| 786 | - 'element' => array(), |
|
| 787 | - ); |
|
| 785 | + $Block = array( |
|
| 786 | + 'element' => array(), |
|
| 787 | + ); |
|
| 788 | 788 | |
| 789 | - return $Block; |
|
| 790 | - } |
|
| 791 | - } |
|
| 789 | + return $Block; |
|
| 790 | + } |
|
| 791 | + } |
|
| 792 | 792 | |
| 793 | - // |
|
| 794 | - // Table |
|
| 793 | + // |
|
| 794 | + // Table |
|
| 795 | 795 | |
| 796 | - protected function blockTable( $Line, ?array $Block = null ) { |
|
| 797 | - if ( ! isset( $Block ) or $Block['type'] !== 'Paragraph' or isset( $Block['interrupted'] ) ) { |
|
| 798 | - return; |
|
| 799 | - } |
|
| 796 | + protected function blockTable( $Line, ?array $Block = null ) { |
|
| 797 | + if ( ! isset( $Block ) or $Block['type'] !== 'Paragraph' or isset( $Block['interrupted'] ) ) { |
|
| 798 | + return; |
|
| 799 | + } |
|
| 800 | 800 | |
| 801 | - if ( |
|
| 802 | - strpos( $Block['element']['handler']['argument'], '|' ) === false |
|
| 803 | - and strpos( $Line['text'], '|' ) === false |
|
| 804 | - and strpos( $Line['text'], ':' ) === false |
|
| 805 | - or strpos( $Block['element']['handler']['argument'], "\n" ) !== false |
|
| 806 | - ) { |
|
| 807 | - return; |
|
| 808 | - } |
|
| 801 | + if ( |
|
| 802 | + strpos( $Block['element']['handler']['argument'], '|' ) === false |
|
| 803 | + and strpos( $Line['text'], '|' ) === false |
|
| 804 | + and strpos( $Line['text'], ':' ) === false |
|
| 805 | + or strpos( $Block['element']['handler']['argument'], "\n" ) !== false |
|
| 806 | + ) { |
|
| 807 | + return; |
|
| 808 | + } |
|
| 809 | 809 | |
| 810 | - if ( chop( $Line['text'], ' -:|' ) !== '' ) { |
|
| 811 | - return; |
|
| 812 | - } |
|
| 810 | + if ( chop( $Line['text'], ' -:|' ) !== '' ) { |
|
| 811 | + return; |
|
| 812 | + } |
|
| 813 | 813 | |
| 814 | - $alignments = array(); |
|
| 814 | + $alignments = array(); |
|
| 815 | 815 | |
| 816 | - $divider = $Line['text']; |
|
| 816 | + $divider = $Line['text']; |
|
| 817 | 817 | |
| 818 | - $divider = trim( $divider ); |
|
| 819 | - $divider = trim( $divider, '|' ); |
|
| 818 | + $divider = trim( $divider ); |
|
| 819 | + $divider = trim( $divider, '|' ); |
|
| 820 | 820 | |
| 821 | - $dividerCells = explode( '|', $divider ); |
|
| 821 | + $dividerCells = explode( '|', $divider ); |
|
| 822 | 822 | |
| 823 | - foreach ( $dividerCells as $dividerCell ) { |
|
| 824 | - $dividerCell = trim( $dividerCell ); |
|
| 823 | + foreach ( $dividerCells as $dividerCell ) { |
|
| 824 | + $dividerCell = trim( $dividerCell ); |
|
| 825 | 825 | |
| 826 | - if ( $dividerCell === '' ) { |
|
| 827 | - return; |
|
| 828 | - } |
|
| 826 | + if ( $dividerCell === '' ) { |
|
| 827 | + return; |
|
| 828 | + } |
|
| 829 | 829 | |
| 830 | - $alignment = null; |
|
| 830 | + $alignment = null; |
|
| 831 | 831 | |
| 832 | - if ( $dividerCell[0] === ':' ) { |
|
| 833 | - $alignment = 'left'; |
|
| 834 | - } |
|
| 832 | + if ( $dividerCell[0] === ':' ) { |
|
| 833 | + $alignment = 'left'; |
|
| 834 | + } |
|
| 835 | 835 | |
| 836 | - if ( substr( $dividerCell, - 1 ) === ':' ) { |
|
| 837 | - $alignment = $alignment === 'left' ? 'center' : 'right'; |
|
| 838 | - } |
|
| 836 | + if ( substr( $dividerCell, - 1 ) === ':' ) { |
|
| 837 | + $alignment = $alignment === 'left' ? 'center' : 'right'; |
|
| 838 | + } |
|
| 839 | 839 | |
| 840 | - $alignments [] = $alignment; |
|
| 841 | - } |
|
| 840 | + $alignments [] = $alignment; |
|
| 841 | + } |
|
| 842 | 842 | |
| 843 | - // ~ |
|
| 843 | + // ~ |
|
| 844 | 844 | |
| 845 | - $HeaderElements = array(); |
|
| 845 | + $HeaderElements = array(); |
|
| 846 | 846 | |
| 847 | - $header = $Block['element']['handler']['argument']; |
|
| 847 | + $header = $Block['element']['handler']['argument']; |
|
| 848 | 848 | |
| 849 | - $header = trim( $header ); |
|
| 850 | - $header = trim( $header, '|' ); |
|
| 849 | + $header = trim( $header ); |
|
| 850 | + $header = trim( $header, '|' ); |
|
| 851 | 851 | |
| 852 | - $headerCells = explode( '|', $header ); |
|
| 852 | + $headerCells = explode( '|', $header ); |
|
| 853 | 853 | |
| 854 | - if ( count( $headerCells ) !== count( $alignments ) ) { |
|
| 855 | - return; |
|
| 856 | - } |
|
| 854 | + if ( count( $headerCells ) !== count( $alignments ) ) { |
|
| 855 | + return; |
|
| 856 | + } |
|
| 857 | 857 | |
| 858 | - foreach ( $headerCells as $index => $headerCell ) { |
|
| 859 | - $headerCell = trim( $headerCell ); |
|
| 858 | + foreach ( $headerCells as $index => $headerCell ) { |
|
| 859 | + $headerCell = trim( $headerCell ); |
|
| 860 | 860 | |
| 861 | - $HeaderElement = array( |
|
| 862 | - 'name' => 'th', |
|
| 863 | - 'handler' => array( |
|
| 864 | - 'function' => 'lineElements', |
|
| 865 | - 'argument' => $headerCell, |
|
| 866 | - 'destination' => 'elements', |
|
| 867 | - ), |
|
| 868 | - ); |
|
| 861 | + $HeaderElement = array( |
|
| 862 | + 'name' => 'th', |
|
| 863 | + 'handler' => array( |
|
| 864 | + 'function' => 'lineElements', |
|
| 865 | + 'argument' => $headerCell, |
|
| 866 | + 'destination' => 'elements', |
|
| 867 | + ), |
|
| 868 | + ); |
|
| 869 | 869 | |
| 870 | - if ( isset( $alignments[ $index ] ) ) { |
|
| 871 | - $alignment = $alignments[ $index ]; |
|
| 870 | + if ( isset( $alignments[ $index ] ) ) { |
|
| 871 | + $alignment = $alignments[ $index ]; |
|
| 872 | 872 | |
| 873 | - $HeaderElement['attributes'] = array( |
|
| 874 | - 'style' => "text-align: $alignment;", |
|
| 875 | - ); |
|
| 876 | - } |
|
| 873 | + $HeaderElement['attributes'] = array( |
|
| 874 | + 'style' => "text-align: $alignment;", |
|
| 875 | + ); |
|
| 876 | + } |
|
| 877 | 877 | |
| 878 | - $HeaderElements [] = $HeaderElement; |
|
| 879 | - } |
|
| 878 | + $HeaderElements [] = $HeaderElement; |
|
| 879 | + } |
|
| 880 | 880 | |
| 881 | - // ~ |
|
| 881 | + // ~ |
|
| 882 | 882 | |
| 883 | - $Block = array( |
|
| 884 | - 'alignments' => $alignments, |
|
| 885 | - 'identified' => true, |
|
| 886 | - 'element' => array( |
|
| 887 | - 'name' => 'table', |
|
| 888 | - 'elements' => array(), |
|
| 889 | - ), |
|
| 890 | - ); |
|
| 883 | + $Block = array( |
|
| 884 | + 'alignments' => $alignments, |
|
| 885 | + 'identified' => true, |
|
| 886 | + 'element' => array( |
|
| 887 | + 'name' => 'table', |
|
| 888 | + 'elements' => array(), |
|
| 889 | + ), |
|
| 890 | + ); |
|
| 891 | 891 | |
| 892 | - $Block['element']['elements'] [] = array( |
|
| 893 | - 'name' => 'thead', |
|
| 894 | - ); |
|
| 892 | + $Block['element']['elements'] [] = array( |
|
| 893 | + 'name' => 'thead', |
|
| 894 | + ); |
|
| 895 | 895 | |
| 896 | - $Block['element']['elements'] [] = array( |
|
| 897 | - 'name' => 'tbody', |
|
| 898 | - 'elements' => array(), |
|
| 899 | - ); |
|
| 900 | - |
|
| 901 | - $Block['element']['elements'][0]['elements'] [] = array( |
|
| 902 | - 'name' => 'tr', |
|
| 903 | - 'elements' => $HeaderElements, |
|
| 904 | - ); |
|
| 896 | + $Block['element']['elements'] [] = array( |
|
| 897 | + 'name' => 'tbody', |
|
| 898 | + 'elements' => array(), |
|
| 899 | + ); |
|
| 900 | + |
|
| 901 | + $Block['element']['elements'][0]['elements'] [] = array( |
|
| 902 | + 'name' => 'tr', |
|
| 903 | + 'elements' => $HeaderElements, |
|
| 904 | + ); |
|
| 905 | 905 | |
| 906 | - return $Block; |
|
| 907 | - } |
|
| 906 | + return $Block; |
|
| 907 | + } |
|
| 908 | 908 | |
| 909 | - protected function blockTableContinue( $Line, array $Block ) { |
|
| 910 | - if ( isset( $Block['interrupted'] ) ) { |
|
| 911 | - return; |
|
| 912 | - } |
|
| 909 | + protected function blockTableContinue( $Line, array $Block ) { |
|
| 910 | + if ( isset( $Block['interrupted'] ) ) { |
|
| 911 | + return; |
|
| 912 | + } |
|
| 913 | 913 | |
| 914 | - if ( count( $Block['alignments'] ) === 1 or $Line['text'][0] === '|' or strpos( $Line['text'], '|' ) ) { |
|
| 915 | - $Elements = array(); |
|
| 914 | + if ( count( $Block['alignments'] ) === 1 or $Line['text'][0] === '|' or strpos( $Line['text'], '|' ) ) { |
|
| 915 | + $Elements = array(); |
|
| 916 | 916 | |
| 917 | - $row = $Line['text']; |
|
| 917 | + $row = $Line['text']; |
|
| 918 | 918 | |
| 919 | - $row = trim( $row ); |
|
| 920 | - $row = trim( $row, '|' ); |
|
| 919 | + $row = trim( $row ); |
|
| 920 | + $row = trim( $row, '|' ); |
|
| 921 | 921 | |
| 922 | - preg_match_all( '/(?:(\\\\[|])|[^|`]|`[^`]++`|`)++/', $row, $matches ); |
|
| 923 | - |
|
| 924 | - $cells = array_slice( $matches[0], 0, count( $Block['alignments'] ) ); |
|
| 922 | + preg_match_all( '/(?:(\\\\[|])|[^|`]|`[^`]++`|`)++/', $row, $matches ); |
|
| 923 | + |
|
| 924 | + $cells = array_slice( $matches[0], 0, count( $Block['alignments'] ) ); |
|
| 925 | 925 | |
| 926 | - foreach ( $cells as $index => $cell ) { |
|
| 927 | - $cell = trim( $cell ); |
|
| 926 | + foreach ( $cells as $index => $cell ) { |
|
| 927 | + $cell = trim( $cell ); |
|
| 928 | 928 | |
| 929 | - $Element = array( |
|
| 930 | - 'name' => 'td', |
|
| 931 | - 'handler' => array( |
|
| 932 | - 'function' => 'lineElements', |
|
| 933 | - 'argument' => $cell, |
|
| 934 | - 'destination' => 'elements', |
|
| 935 | - ), |
|
| 936 | - ); |
|
| 929 | + $Element = array( |
|
| 930 | + 'name' => 'td', |
|
| 931 | + 'handler' => array( |
|
| 932 | + 'function' => 'lineElements', |
|
| 933 | + 'argument' => $cell, |
|
| 934 | + 'destination' => 'elements', |
|
| 935 | + ), |
|
| 936 | + ); |
|
| 937 | 937 | |
| 938 | - if ( isset( $Block['alignments'][ $index ] ) ) { |
|
| 939 | - $Element['attributes'] = array( |
|
| 940 | - 'style' => 'text-align: ' . $Block['alignments'][ $index ] . ';', |
|
| 941 | - ); |
|
| 942 | - } |
|
| 943 | - |
|
| 944 | - $Elements [] = $Element; |
|
| 945 | - } |
|
| 938 | + if ( isset( $Block['alignments'][ $index ] ) ) { |
|
| 939 | + $Element['attributes'] = array( |
|
| 940 | + 'style' => 'text-align: ' . $Block['alignments'][ $index ] . ';', |
|
| 941 | + ); |
|
| 942 | + } |
|
| 943 | + |
|
| 944 | + $Elements [] = $Element; |
|
| 945 | + } |
|
| 946 | 946 | |
| 947 | - $Element = array( |
|
| 948 | - 'name' => 'tr', |
|
| 949 | - 'elements' => $Elements, |
|
| 950 | - ); |
|
| 951 | - |
|
| 952 | - $Block['element']['elements'][1]['elements'] [] = $Element; |
|
| 953 | - |
|
| 954 | - return $Block; |
|
| 955 | - } |
|
| 956 | - } |
|
| 957 | - |
|
| 958 | - // |
|
| 959 | - // ~ |
|
| 960 | - // |
|
| 961 | - |
|
| 962 | - protected function paragraph( $Line ) { |
|
| 963 | - return array( |
|
| 964 | - 'type' => 'Paragraph', |
|
| 965 | - 'element' => array( |
|
| 966 | - 'name' => 'p', |
|
| 967 | - 'handler' => array( |
|
| 968 | - 'function' => 'lineElements', |
|
| 969 | - 'argument' => $Line['text'], |
|
| 970 | - 'destination' => 'elements', |
|
| 971 | - ), |
|
| 972 | - ), |
|
| 973 | - ); |
|
| 974 | - } |
|
| 947 | + $Element = array( |
|
| 948 | + 'name' => 'tr', |
|
| 949 | + 'elements' => $Elements, |
|
| 950 | + ); |
|
| 951 | + |
|
| 952 | + $Block['element']['elements'][1]['elements'] [] = $Element; |
|
| 953 | + |
|
| 954 | + return $Block; |
|
| 955 | + } |
|
| 956 | + } |
|
| 957 | + |
|
| 958 | + // |
|
| 959 | + // ~ |
|
| 960 | + // |
|
| 961 | + |
|
| 962 | + protected function paragraph( $Line ) { |
|
| 963 | + return array( |
|
| 964 | + 'type' => 'Paragraph', |
|
| 965 | + 'element' => array( |
|
| 966 | + 'name' => 'p', |
|
| 967 | + 'handler' => array( |
|
| 968 | + 'function' => 'lineElements', |
|
| 969 | + 'argument' => $Line['text'], |
|
| 970 | + 'destination' => 'elements', |
|
| 971 | + ), |
|
| 972 | + ), |
|
| 973 | + ); |
|
| 974 | + } |
|
| 975 | 975 | |
| 976 | - protected function paragraphContinue( $Line, array $Block ) { |
|
| 977 | - if ( isset( $Block['interrupted'] ) ) { |
|
| 978 | - return; |
|
| 979 | - } |
|
| 976 | + protected function paragraphContinue( $Line, array $Block ) { |
|
| 977 | + if ( isset( $Block['interrupted'] ) ) { |
|
| 978 | + return; |
|
| 979 | + } |
|
| 980 | 980 | |
| 981 | - $Block['element']['handler']['argument'] .= "\n" . $Line['text']; |
|
| 981 | + $Block['element']['handler']['argument'] .= "\n" . $Line['text']; |
|
| 982 | 982 | |
| 983 | - return $Block; |
|
| 984 | - } |
|
| 983 | + return $Block; |
|
| 984 | + } |
|
| 985 | 985 | |
| 986 | - // |
|
| 987 | - // Inline Elements |
|
| 988 | - // |
|
| 986 | + // |
|
| 987 | + // Inline Elements |
|
| 988 | + // |
|
| 989 | 989 | |
| 990 | - protected $InlineTypes = array( |
|
| 991 | - '!' => array( 'Image' ), |
|
| 992 | - '&' => array( 'SpecialCharacter' ), |
|
| 993 | - '*' => array( 'Emphasis' ), |
|
| 994 | - ':' => array( 'Url' ), |
|
| 995 | - '<' => array( 'UrlTag', 'EmailTag', 'Markup' ), |
|
| 996 | - '[' => array( 'Link' ), |
|
| 997 | - '_' => array( 'Emphasis' ), |
|
| 998 | - '`' => array( 'Code' ), |
|
| 999 | - '~' => array( 'Strikethrough' ), |
|
| 1000 | - '\\' => array( 'EscapeSequence' ), |
|
| 1001 | - ); |
|
| 990 | + protected $InlineTypes = array( |
|
| 991 | + '!' => array( 'Image' ), |
|
| 992 | + '&' => array( 'SpecialCharacter' ), |
|
| 993 | + '*' => array( 'Emphasis' ), |
|
| 994 | + ':' => array( 'Url' ), |
|
| 995 | + '<' => array( 'UrlTag', 'EmailTag', 'Markup' ), |
|
| 996 | + '[' => array( 'Link' ), |
|
| 997 | + '_' => array( 'Emphasis' ), |
|
| 998 | + '`' => array( 'Code' ), |
|
| 999 | + '~' => array( 'Strikethrough' ), |
|
| 1000 | + '\\' => array( 'EscapeSequence' ), |
|
| 1001 | + ); |
|
| 1002 | 1002 | |
| 1003 | - // ~ |
|
| 1003 | + // ~ |
|
| 1004 | 1004 | |
| 1005 | - protected $inlineMarkerList = '!*_&[:<`~\\'; |
|
| 1005 | + protected $inlineMarkerList = '!*_&[:<`~\\'; |
|
| 1006 | 1006 | |
| 1007 | - // |
|
| 1008 | - // ~ |
|
| 1009 | - // |
|
| 1007 | + // |
|
| 1008 | + // ~ |
|
| 1009 | + // |
|
| 1010 | 1010 | |
| 1011 | - public function line( $text, $nonNestables = array() ) { |
|
| 1012 | - return $this->elements( $this->lineElements( $text, $nonNestables ) ); |
|
| 1013 | - } |
|
| 1011 | + public function line( $text, $nonNestables = array() ) { |
|
| 1012 | + return $this->elements( $this->lineElements( $text, $nonNestables ) ); |
|
| 1013 | + } |
|
| 1014 | 1014 | |
| 1015 | - protected function lineElements( $text, $nonNestables = array() ) { |
|
| 1016 | - // standardize line breaks |
|
| 1017 | - $text = str_replace( array( "\r\n", "\r" ), "\n", $text ); |
|
| 1015 | + protected function lineElements( $text, $nonNestables = array() ) { |
|
| 1016 | + // standardize line breaks |
|
| 1017 | + $text = str_replace( array( "\r\n", "\r" ), "\n", $text ); |
|
| 1018 | 1018 | |
| 1019 | - $Elements = array(); |
|
| 1019 | + $Elements = array(); |
|
| 1020 | 1020 | |
| 1021 | - $nonNestables = ( empty( $nonNestables ) |
|
| 1022 | - ? array() |
|
| 1023 | - : array_combine( $nonNestables, $nonNestables ) |
|
| 1024 | - ); |
|
| 1021 | + $nonNestables = ( empty( $nonNestables ) |
|
| 1022 | + ? array() |
|
| 1023 | + : array_combine( $nonNestables, $nonNestables ) |
|
| 1024 | + ); |
|
| 1025 | 1025 | |
| 1026 | - // $excerpt is based on the first occurrence of a marker |
|
| 1026 | + // $excerpt is based on the first occurrence of a marker |
|
| 1027 | 1027 | |
| 1028 | - while ( $excerpt = strpbrk( $text, $this->inlineMarkerList ) ) { |
|
| 1029 | - $marker = $excerpt[0]; |
|
| 1028 | + while ( $excerpt = strpbrk( $text, $this->inlineMarkerList ) ) { |
|
| 1029 | + $marker = $excerpt[0]; |
|
| 1030 | 1030 | |
| 1031 | - $markerPosition = strlen( $text ) - strlen( $excerpt ); |
|
| 1031 | + $markerPosition = strlen( $text ) - strlen( $excerpt ); |
|
| 1032 | 1032 | |
| 1033 | - $Excerpt = array( |
|
| 1034 | - 'text' => $excerpt, |
|
| 1035 | - 'context' => $text, |
|
| 1036 | - ); |
|
| 1033 | + $Excerpt = array( |
|
| 1034 | + 'text' => $excerpt, |
|
| 1035 | + 'context' => $text, |
|
| 1036 | + ); |
|
| 1037 | 1037 | |
| 1038 | - foreach ( $this->InlineTypes[ $marker ] as $inlineType ) { |
|
| 1039 | - // check to see if the current inline type is nestable in the current context |
|
| 1038 | + foreach ( $this->InlineTypes[ $marker ] as $inlineType ) { |
|
| 1039 | + // check to see if the current inline type is nestable in the current context |
|
| 1040 | 1040 | |
| 1041 | - if ( isset( $nonNestables[ $inlineType ] ) ) { |
|
| 1042 | - continue; |
|
| 1043 | - } |
|
| 1041 | + if ( isset( $nonNestables[ $inlineType ] ) ) { |
|
| 1042 | + continue; |
|
| 1043 | + } |
|
| 1044 | 1044 | |
| 1045 | - $Inline = $this->{"inline$inlineType"}( $Excerpt ); |
|
| 1045 | + $Inline = $this->{"inline$inlineType"}( $Excerpt ); |
|
| 1046 | 1046 | |
| 1047 | - if ( ! isset( $Inline ) ) { |
|
| 1048 | - continue; |
|
| 1049 | - } |
|
| 1047 | + if ( ! isset( $Inline ) ) { |
|
| 1048 | + continue; |
|
| 1049 | + } |
|
| 1050 | 1050 | |
| 1051 | - // makes sure that the inline belongs to "our" marker |
|
| 1051 | + // makes sure that the inline belongs to "our" marker |
|
| 1052 | 1052 | |
| 1053 | - if ( isset( $Inline['position'] ) and $Inline['position'] > $markerPosition ) { |
|
| 1054 | - continue; |
|
| 1055 | - } |
|
| 1053 | + if ( isset( $Inline['position'] ) and $Inline['position'] > $markerPosition ) { |
|
| 1054 | + continue; |
|
| 1055 | + } |
|
| 1056 | 1056 | |
| 1057 | - // sets a default inline position |
|
| 1057 | + // sets a default inline position |
|
| 1058 | 1058 | |
| 1059 | - if ( ! isset( $Inline['position'] ) ) { |
|
| 1060 | - $Inline['position'] = $markerPosition; |
|
| 1061 | - } |
|
| 1059 | + if ( ! isset( $Inline['position'] ) ) { |
|
| 1060 | + $Inline['position'] = $markerPosition; |
|
| 1061 | + } |
|
| 1062 | 1062 | |
| 1063 | - // cause the new element to 'inherit' our non nestables |
|
| 1063 | + // cause the new element to 'inherit' our non nestables |
|
| 1064 | 1064 | |
| 1065 | - $Inline['element']['nonNestables'] = isset( $Inline['element']['nonNestables'] ) |
|
| 1066 | - ? array_merge( $Inline['element']['nonNestables'], $nonNestables ) |
|
| 1067 | - : $nonNestables; |
|
| 1065 | + $Inline['element']['nonNestables'] = isset( $Inline['element']['nonNestables'] ) |
|
| 1066 | + ? array_merge( $Inline['element']['nonNestables'], $nonNestables ) |
|
| 1067 | + : $nonNestables; |
|
| 1068 | 1068 | |
| 1069 | - // the text that comes before the inline |
|
| 1070 | - $unmarkedText = substr( $text, 0, $Inline['position'] ); |
|
| 1069 | + // the text that comes before the inline |
|
| 1070 | + $unmarkedText = substr( $text, 0, $Inline['position'] ); |
|
| 1071 | 1071 | |
| 1072 | - // compile the unmarked text |
|
| 1073 | - $InlineText = $this->inlineText( $unmarkedText ); |
|
| 1074 | - $Elements[] = $InlineText['element']; |
|
| 1072 | + // compile the unmarked text |
|
| 1073 | + $InlineText = $this->inlineText( $unmarkedText ); |
|
| 1074 | + $Elements[] = $InlineText['element']; |
|
| 1075 | 1075 | |
| 1076 | - // compile the inline |
|
| 1077 | - $Elements[] = $this->extractElement( $Inline ); |
|
| 1076 | + // compile the inline |
|
| 1077 | + $Elements[] = $this->extractElement( $Inline ); |
|
| 1078 | 1078 | |
| 1079 | - // remove the examined text |
|
| 1080 | - $text = substr( $text, $Inline['position'] + $Inline['extent'] ); |
|
| 1079 | + // remove the examined text |
|
| 1080 | + $text = substr( $text, $Inline['position'] + $Inline['extent'] ); |
|
| 1081 | 1081 | |
| 1082 | - continue 2; |
|
| 1083 | - } |
|
| 1082 | + continue 2; |
|
| 1083 | + } |
|
| 1084 | 1084 | |
| 1085 | - // the marker does not belong to an inline |
|
| 1086 | - |
|
| 1087 | - $unmarkedText = substr( $text, 0, $markerPosition + 1 ); |
|
| 1085 | + // the marker does not belong to an inline |
|
| 1086 | + |
|
| 1087 | + $unmarkedText = substr( $text, 0, $markerPosition + 1 ); |
|
| 1088 | 1088 | |
| 1089 | - $InlineText = $this->inlineText( $unmarkedText ); |
|
| 1090 | - $Elements[] = $InlineText['element']; |
|
| 1091 | - |
|
| 1092 | - $text = substr( $text, $markerPosition + 1 ); |
|
| 1093 | - } |
|
| 1094 | - |
|
| 1095 | - $InlineText = $this->inlineText( $text ); |
|
| 1096 | - $Elements[] = $InlineText['element']; |
|
| 1097 | - |
|
| 1098 | - foreach ( $Elements as &$Element ) { |
|
| 1099 | - if ( ! isset( $Element['autobreak'] ) ) { |
|
| 1100 | - $Element['autobreak'] = false; |
|
| 1101 | - } |
|
| 1102 | - } |
|
| 1103 | - |
|
| 1104 | - return $Elements; |
|
| 1105 | - } |
|
| 1106 | - |
|
| 1107 | - // |
|
| 1108 | - // ~ |
|
| 1109 | - // |
|
| 1110 | - |
|
| 1111 | - protected function inlineText( $text ) { |
|
| 1112 | - $Inline = array( |
|
| 1113 | - 'extent' => strlen( $text ), |
|
| 1114 | - 'element' => array(), |
|
| 1115 | - ); |
|
| 1116 | - |
|
| 1117 | - $Inline['element']['elements'] = self::pregReplaceElements( |
|
| 1118 | - $this->breaksEnabled ? '/[ ]*+\n/' : '/(?:[ ]*+\\\\|[ ]{2,}+)\n/', |
|
| 1119 | - array( |
|
| 1120 | - array( 'name' => 'br' ), |
|
| 1121 | - array( 'text' => "\n" ), |
|
| 1122 | - ), |
|
| 1123 | - $text |
|
| 1124 | - ); |
|
| 1125 | - |
|
| 1126 | - return $Inline; |
|
| 1127 | - } |
|
| 1128 | - |
|
| 1129 | - protected function inlineCode( $Excerpt ) { |
|
| 1130 | - $marker = $Excerpt['text'][0]; |
|
| 1131 | - |
|
| 1132 | - if ( preg_match( '/^([' . $marker . ']++)[ ]*+(.+?)[ ]*+(?<![' . $marker . '])\1(?!' . $marker . ')/s', $Excerpt['text'], $matches ) ) { |
|
| 1133 | - $text = $matches[2]; |
|
| 1134 | - $text = preg_replace( '/[ ]*+\n/', ' ', $text ); |
|
| 1135 | - |
|
| 1136 | - return array( |
|
| 1137 | - 'extent' => strlen( $matches[0] ), |
|
| 1138 | - 'element' => array( |
|
| 1139 | - 'name' => 'code', |
|
| 1140 | - 'text' => $text, |
|
| 1141 | - ), |
|
| 1142 | - ); |
|
| 1143 | - } |
|
| 1144 | - } |
|
| 1145 | - |
|
| 1146 | - protected function inlineEmailTag( $Excerpt ) { |
|
| 1147 | - $hostnameLabel = '[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?'; |
|
| 1148 | - |
|
| 1149 | - $commonMarkEmail = '[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]++@' |
|
| 1150 | - . $hostnameLabel . '(?:\.' . $hostnameLabel . ')*'; |
|
| 1151 | - |
|
| 1152 | - if ( strpos( $Excerpt['text'], '>' ) !== false |
|
| 1153 | - and preg_match( "/^<((mailto:)?$commonMarkEmail)>/i", $Excerpt['text'], $matches ) |
|
| 1154 | - ) { |
|
| 1155 | - $url = $matches[1]; |
|
| 1156 | - |
|
| 1157 | - if ( ! isset( $matches[2] ) ) { |
|
| 1158 | - $url = "mailto:$url"; |
|
| 1159 | - } |
|
| 1160 | - |
|
| 1161 | - return array( |
|
| 1162 | - 'extent' => strlen( $matches[0] ), |
|
| 1163 | - 'element' => array( |
|
| 1164 | - 'name' => 'a', |
|
| 1165 | - 'text' => $matches[1], |
|
| 1166 | - 'attributes' => array( |
|
| 1167 | - 'href' => $url, |
|
| 1168 | - ), |
|
| 1169 | - ), |
|
| 1170 | - ); |
|
| 1171 | - } |
|
| 1172 | - } |
|
| 1173 | - |
|
| 1174 | - protected function inlineEmphasis( $Excerpt ) { |
|
| 1175 | - if ( ! isset( $Excerpt['text'][1] ) ) { |
|
| 1176 | - return; |
|
| 1177 | - } |
|
| 1178 | - |
|
| 1179 | - $marker = $Excerpt['text'][0]; |
|
| 1180 | - |
|
| 1181 | - if ( $Excerpt['text'][1] === $marker and preg_match( $this->StrongRegex[ $marker ], $Excerpt['text'], $matches ) ) { |
|
| 1182 | - $emphasis = 'strong'; |
|
| 1183 | - } elseif ( preg_match( $this->EmRegex[ $marker ], $Excerpt['text'], $matches ) ) { |
|
| 1184 | - $emphasis = 'em'; |
|
| 1185 | - } else { |
|
| 1186 | - return; |
|
| 1187 | - } |
|
| 1188 | - |
|
| 1189 | - return array( |
|
| 1190 | - 'extent' => strlen( $matches[0] ), |
|
| 1191 | - 'element' => array( |
|
| 1192 | - 'name' => $emphasis, |
|
| 1193 | - 'handler' => array( |
|
| 1194 | - 'function' => 'lineElements', |
|
| 1195 | - 'argument' => $matches[1], |
|
| 1196 | - 'destination' => 'elements', |
|
| 1197 | - ), |
|
| 1198 | - ), |
|
| 1199 | - ); |
|
| 1200 | - } |
|
| 1201 | - |
|
| 1202 | - protected function inlineEscapeSequence( $Excerpt ) { |
|
| 1203 | - if ( isset( $Excerpt['text'][1] ) and in_array( $Excerpt['text'][1], $this->specialCharacters ) ) { |
|
| 1204 | - return array( |
|
| 1205 | - 'element' => array( 'rawHtml' => $Excerpt['text'][1] ), |
|
| 1206 | - 'extent' => 2, |
|
| 1207 | - ); |
|
| 1208 | - } |
|
| 1209 | - } |
|
| 1210 | - |
|
| 1211 | - protected function inlineImage( $Excerpt ) { |
|
| 1212 | - if ( ! isset( $Excerpt['text'][1] ) or $Excerpt['text'][1] !== '[' ) { |
|
| 1213 | - return; |
|
| 1214 | - } |
|
| 1215 | - |
|
| 1216 | - $Excerpt['text'] = substr( $Excerpt['text'], 1 ); |
|
| 1217 | - |
|
| 1218 | - $Link = $this->inlineLink( $Excerpt ); |
|
| 1219 | - |
|
| 1220 | - if ( $Link === null ) { |
|
| 1221 | - return; |
|
| 1222 | - } |
|
| 1223 | - |
|
| 1224 | - $Inline = array( |
|
| 1225 | - 'extent' => $Link['extent'] + 1, |
|
| 1226 | - 'element' => array( |
|
| 1227 | - 'name' => 'img', |
|
| 1228 | - 'attributes' => array( |
|
| 1229 | - 'src' => $Link['element']['attributes']['href'], |
|
| 1230 | - 'alt' => $Link['element']['handler']['argument'], |
|
| 1231 | - ), |
|
| 1232 | - 'autobreak' => true, |
|
| 1233 | - ), |
|
| 1234 | - ); |
|
| 1235 | - |
|
| 1236 | - $Inline['element']['attributes'] += $Link['element']['attributes']; |
|
| 1237 | - |
|
| 1238 | - unset( $Inline['element']['attributes']['href'] ); |
|
| 1239 | - |
|
| 1240 | - return $Inline; |
|
| 1241 | - } |
|
| 1242 | - |
|
| 1243 | - protected function inlineLink( $Excerpt ) { |
|
| 1244 | - $Element = array( |
|
| 1245 | - 'name' => 'a', |
|
| 1246 | - 'handler' => array( |
|
| 1247 | - 'function' => 'lineElements', |
|
| 1248 | - 'argument' => null, |
|
| 1249 | - 'destination' => 'elements', |
|
| 1250 | - ), |
|
| 1251 | - 'nonNestables' => array( 'Url', 'Link' ), |
|
| 1252 | - 'attributes' => array( |
|
| 1253 | - 'href' => null, |
|
| 1254 | - 'title' => null, |
|
| 1255 | - ), |
|
| 1256 | - ); |
|
| 1257 | - |
|
| 1258 | - $extent = 0; |
|
| 1259 | - |
|
| 1260 | - $remainder = $Excerpt['text']; |
|
| 1261 | - |
|
| 1262 | - if ( preg_match( '/\[((?:[^][]++|(?R))*+)\]/', $remainder, $matches ) ) { |
|
| 1263 | - $Element['handler']['argument'] = $matches[1]; |
|
| 1264 | - |
|
| 1265 | - $extent += strlen( $matches[0] ); |
|
| 1266 | - |
|
| 1267 | - $remainder = substr( $remainder, $extent ); |
|
| 1268 | - } else { |
|
| 1269 | - return; |
|
| 1270 | - } |
|
| 1271 | - |
|
| 1272 | - if ( preg_match( '/^[(]\s*+((?:[^ ()]++|[(][^ )]+[)])++)(?:[ ]+("[^"]*+"|\'[^\']*+\'))?\s*+[)]/', $remainder, $matches ) ) { |
|
| 1273 | - $Element['attributes']['href'] = $matches[1]; |
|
| 1274 | - |
|
| 1275 | - if ( isset( $matches[2] ) ) { |
|
| 1276 | - $Element['attributes']['title'] = substr( $matches[2], 1, - 1 ); |
|
| 1277 | - } |
|
| 1278 | - |
|
| 1279 | - $extent += strlen( $matches[0] ); |
|
| 1280 | - } else { |
|
| 1281 | - if ( preg_match( '/^\s*\[(.*?)\]/', $remainder, $matches ) ) { |
|
| 1282 | - $definition = strlen( $matches[1] ) ? $matches[1] : $Element['handler']['argument']; |
|
| 1283 | - $definition = strtolower( $definition ); |
|
| 1284 | - |
|
| 1285 | - $extent += strlen( $matches[0] ); |
|
| 1286 | - } else { |
|
| 1287 | - $definition = strtolower( $Element['handler']['argument'] ); |
|
| 1288 | - } |
|
| 1289 | - |
|
| 1290 | - if ( ! isset( $this->DefinitionData['Reference'][ $definition ] ) ) { |
|
| 1291 | - return; |
|
| 1292 | - } |
|
| 1293 | - |
|
| 1294 | - $Definition = $this->DefinitionData['Reference'][ $definition ]; |
|
| 1295 | - |
|
| 1296 | - $Element['attributes']['href'] = $Definition['url']; |
|
| 1297 | - $Element['attributes']['title'] = $Definition['title']; |
|
| 1298 | - } |
|
| 1299 | - |
|
| 1300 | - return array( |
|
| 1301 | - 'extent' => $extent, |
|
| 1302 | - 'element' => $Element, |
|
| 1303 | - ); |
|
| 1304 | - } |
|
| 1305 | - |
|
| 1306 | - protected function inlineMarkup( $Excerpt ) { |
|
| 1307 | - if ( $this->markupEscaped or $this->safeMode or strpos( $Excerpt['text'], '>' ) === false ) { |
|
| 1308 | - return; |
|
| 1309 | - } |
|
| 1310 | - |
|
| 1311 | - if ( $Excerpt['text'][1] === '/' and preg_match( '/^<\/\w[\w-]*+[ ]*+>/s', $Excerpt['text'], $matches ) ) { |
|
| 1312 | - return array( |
|
| 1313 | - 'element' => array( 'rawHtml' => $matches[0] ), |
|
| 1314 | - 'extent' => strlen( $matches[0] ), |
|
| 1315 | - ); |
|
| 1316 | - } |
|
| 1317 | - |
|
| 1318 | - if ( $Excerpt['text'][1] === '!' and preg_match( '/^<!---?[^>-](?:-?+[^-])*-->/s', $Excerpt['text'], $matches ) ) { |
|
| 1319 | - return array( |
|
| 1320 | - 'element' => array( 'rawHtml' => $matches[0] ), |
|
| 1321 | - 'extent' => strlen( $matches[0] ), |
|
| 1322 | - ); |
|
| 1323 | - } |
|
| 1324 | - |
|
| 1325 | - if ( $Excerpt['text'][1] !== ' ' and preg_match( '/^<\w[\w-]*+(?:[ ]*+' . $this->regexHtmlAttribute . ')*+[ ]*+\/?>/s', $Excerpt['text'], $matches ) ) { |
|
| 1326 | - return array( |
|
| 1327 | - 'element' => array( 'rawHtml' => $matches[0] ), |
|
| 1328 | - 'extent' => strlen( $matches[0] ), |
|
| 1329 | - ); |
|
| 1330 | - } |
|
| 1331 | - } |
|
| 1332 | - |
|
| 1333 | - protected function inlineSpecialCharacter( $Excerpt ) { |
|
| 1334 | - if ( substr( $Excerpt['text'], 1, 1 ) !== ' ' and strpos( $Excerpt['text'], ';' ) !== false |
|
| 1335 | - and preg_match( '/^&(#?+[0-9a-zA-Z]++);/', $Excerpt['text'], $matches ) |
|
| 1336 | - ) { |
|
| 1337 | - return array( |
|
| 1338 | - 'element' => array( 'rawHtml' => '&' . $matches[1] . ';' ), |
|
| 1339 | - 'extent' => strlen( $matches[0] ), |
|
| 1340 | - ); |
|
| 1341 | - } |
|
| 1342 | - |
|
| 1343 | - return; |
|
| 1344 | - } |
|
| 1345 | - |
|
| 1346 | - protected function inlineStrikethrough( $Excerpt ) { |
|
| 1347 | - if ( ! isset( $Excerpt['text'][1] ) ) { |
|
| 1348 | - return; |
|
| 1349 | - } |
|
| 1350 | - |
|
| 1351 | - if ( $Excerpt['text'][1] === '~' and preg_match( '/^~~(?=\S)(.+?)(?<=\S)~~/', $Excerpt['text'], $matches ) ) { |
|
| 1352 | - return array( |
|
| 1353 | - 'extent' => strlen( $matches[0] ), |
|
| 1354 | - 'element' => array( |
|
| 1355 | - 'name' => 'del', |
|
| 1356 | - 'handler' => array( |
|
| 1357 | - 'function' => 'lineElements', |
|
| 1358 | - 'argument' => $matches[1], |
|
| 1359 | - 'destination' => 'elements', |
|
| 1360 | - ), |
|
| 1361 | - ), |
|
| 1362 | - ); |
|
| 1363 | - } |
|
| 1364 | - } |
|
| 1365 | - |
|
| 1366 | - protected function inlineUrl( $Excerpt ) { |
|
| 1367 | - if ( $this->urlsLinked !== true or ! isset( $Excerpt['text'][2] ) or $Excerpt['text'][2] !== '/' ) { |
|
| 1368 | - return; |
|
| 1369 | - } |
|
| 1370 | - |
|
| 1371 | - if ( strpos( $Excerpt['context'], 'http' ) !== false |
|
| 1372 | - and preg_match( '/\bhttps?+:[\/]{2}[^\s<]+\b\/*+/ui', $Excerpt['context'], $matches, PREG_OFFSET_CAPTURE ) |
|
| 1373 | - ) { |
|
| 1374 | - $url = $matches[0][0]; |
|
| 1375 | - |
|
| 1376 | - $Inline = array( |
|
| 1377 | - 'extent' => strlen( $matches[0][0] ), |
|
| 1378 | - 'position' => $matches[0][1], |
|
| 1379 | - 'element' => array( |
|
| 1380 | - 'name' => 'a', |
|
| 1381 | - 'text' => $url, |
|
| 1382 | - 'attributes' => array( |
|
| 1383 | - 'href' => $url, |
|
| 1384 | - ), |
|
| 1385 | - ), |
|
| 1386 | - ); |
|
| 1387 | - |
|
| 1388 | - return $Inline; |
|
| 1389 | - } |
|
| 1390 | - } |
|
| 1391 | - |
|
| 1392 | - protected function inlineUrlTag( $Excerpt ) { |
|
| 1393 | - if ( strpos( $Excerpt['text'], '>' ) !== false and preg_match( '/^<(\w++:\/{2}[^ >]++)>/i', $Excerpt['text'], $matches ) ) { |
|
| 1394 | - $url = $matches[1]; |
|
| 1395 | - |
|
| 1396 | - return array( |
|
| 1397 | - 'extent' => strlen( $matches[0] ), |
|
| 1398 | - 'element' => array( |
|
| 1399 | - 'name' => 'a', |
|
| 1400 | - 'text' => $url, |
|
| 1401 | - 'attributes' => array( |
|
| 1402 | - 'href' => $url, |
|
| 1403 | - ), |
|
| 1404 | - ), |
|
| 1405 | - ); |
|
| 1406 | - } |
|
| 1407 | - } |
|
| 1408 | - |
|
| 1409 | - // ~ |
|
| 1410 | - |
|
| 1411 | - protected function unmarkedText( $text ) { |
|
| 1412 | - $Inline = $this->inlineText( $text ); |
|
| 1413 | - return $this->element( $Inline['element'] ); |
|
| 1414 | - } |
|
| 1415 | - |
|
| 1416 | - // |
|
| 1417 | - // Handlers |
|
| 1418 | - // |
|
| 1419 | - |
|
| 1420 | - protected function handle( array $Element ) { |
|
| 1421 | - if ( isset( $Element['handler'] ) ) { |
|
| 1422 | - if ( ! isset( $Element['nonNestables'] ) ) { |
|
| 1423 | - $Element['nonNestables'] = array(); |
|
| 1424 | - } |
|
| 1425 | - |
|
| 1426 | - if ( is_string( $Element['handler'] ) ) { |
|
| 1427 | - $function = $Element['handler']; |
|
| 1428 | - $argument = $Element['text']; |
|
| 1429 | - unset( $Element['text'] ); |
|
| 1430 | - $destination = 'rawHtml'; |
|
| 1431 | - } else { |
|
| 1432 | - $function = $Element['handler']['function']; |
|
| 1433 | - $argument = $Element['handler']['argument']; |
|
| 1434 | - $destination = $Element['handler']['destination']; |
|
| 1435 | - } |
|
| 1436 | - |
|
| 1437 | - $Element[ $destination ] = $this->{$function}( $argument, $Element['nonNestables'] ); |
|
| 1438 | - |
|
| 1439 | - if ( $destination === 'handler' ) { |
|
| 1440 | - $Element = $this->handle( $Element ); |
|
| 1441 | - } |
|
| 1442 | - |
|
| 1443 | - unset( $Element['handler'] ); |
|
| 1444 | - } |
|
| 1445 | - |
|
| 1446 | - return $Element; |
|
| 1447 | - } |
|
| 1448 | - |
|
| 1449 | - protected function handleElementRecursive( array $Element ) { |
|
| 1450 | - return $this->elementApplyRecursive( array( $this, 'handle' ), $Element ); |
|
| 1451 | - } |
|
| 1452 | - |
|
| 1453 | - protected function handleElementsRecursive( array $Elements ) { |
|
| 1454 | - return $this->elementsApplyRecursive( array( $this, 'handle' ), $Elements ); |
|
| 1455 | - } |
|
| 1456 | - |
|
| 1457 | - protected function elementApplyRecursive( $closure, array $Element ) { |
|
| 1458 | - $Element = call_user_func( $closure, $Element ); |
|
| 1459 | - |
|
| 1460 | - if ( isset( $Element['elements'] ) ) { |
|
| 1461 | - $Element['elements'] = $this->elementsApplyRecursive( $closure, $Element['elements'] ); |
|
| 1462 | - } elseif ( isset( $Element['element'] ) ) { |
|
| 1463 | - $Element['element'] = $this->elementApplyRecursive( $closure, $Element['element'] ); |
|
| 1464 | - } |
|
| 1465 | - |
|
| 1466 | - return $Element; |
|
| 1467 | - } |
|
| 1468 | - |
|
| 1469 | - protected function elementApplyRecursiveDepthFirst( $closure, array $Element ) { |
|
| 1470 | - if ( isset( $Element['elements'] ) ) { |
|
| 1471 | - $Element['elements'] = $this->elementsApplyRecursiveDepthFirst( $closure, $Element['elements'] ); |
|
| 1472 | - } elseif ( isset( $Element['element'] ) ) { |
|
| 1473 | - $Element['element'] = $this->elementsApplyRecursiveDepthFirst( $closure, $Element['element'] ); |
|
| 1474 | - } |
|
| 1475 | - |
|
| 1476 | - $Element = call_user_func( $closure, $Element ); |
|
| 1477 | - |
|
| 1478 | - return $Element; |
|
| 1479 | - } |
|
| 1480 | - |
|
| 1481 | - protected function elementsApplyRecursive( $closure, array $Elements ) { |
|
| 1482 | - foreach ( $Elements as &$Element ) { |
|
| 1483 | - $Element = $this->elementApplyRecursive( $closure, $Element ); |
|
| 1484 | - } |
|
| 1485 | - |
|
| 1486 | - return $Elements; |
|
| 1487 | - } |
|
| 1488 | - |
|
| 1489 | - protected function elementsApplyRecursiveDepthFirst( $closure, array $Elements ) { |
|
| 1490 | - foreach ( $Elements as &$Element ) { |
|
| 1491 | - $Element = $this->elementApplyRecursiveDepthFirst( $closure, $Element ); |
|
| 1492 | - } |
|
| 1493 | - |
|
| 1494 | - return $Elements; |
|
| 1495 | - } |
|
| 1496 | - |
|
| 1497 | - protected function element( array $Element ) { |
|
| 1498 | - if ( $this->safeMode ) { |
|
| 1499 | - $Element = $this->sanitiseElement( $Element ); |
|
| 1500 | - } |
|
| 1501 | - |
|
| 1502 | - // identity map if element has no handler |
|
| 1503 | - $Element = $this->handle( $Element ); |
|
| 1504 | - |
|
| 1505 | - $hasName = isset( $Element['name'] ); |
|
| 1506 | - |
|
| 1507 | - $markup = ''; |
|
| 1508 | - |
|
| 1509 | - if ( $hasName ) { |
|
| 1510 | - $markup .= '<' . $Element['name']; |
|
| 1511 | - |
|
| 1512 | - if ( isset( $Element['attributes'] ) ) { |
|
| 1513 | - foreach ( $Element['attributes'] as $name => $value ) { |
|
| 1514 | - if ( $value === null ) { |
|
| 1515 | - continue; |
|
| 1516 | - } |
|
| 1517 | - |
|
| 1518 | - $markup .= " $name=\"" . self::escape( $value ) . '"'; |
|
| 1519 | - } |
|
| 1520 | - } |
|
| 1521 | - } |
|
| 1522 | - |
|
| 1523 | - $permitRawHtml = false; |
|
| 1089 | + $InlineText = $this->inlineText( $unmarkedText ); |
|
| 1090 | + $Elements[] = $InlineText['element']; |
|
| 1091 | + |
|
| 1092 | + $text = substr( $text, $markerPosition + 1 ); |
|
| 1093 | + } |
|
| 1094 | + |
|
| 1095 | + $InlineText = $this->inlineText( $text ); |
|
| 1096 | + $Elements[] = $InlineText['element']; |
|
| 1097 | + |
|
| 1098 | + foreach ( $Elements as &$Element ) { |
|
| 1099 | + if ( ! isset( $Element['autobreak'] ) ) { |
|
| 1100 | + $Element['autobreak'] = false; |
|
| 1101 | + } |
|
| 1102 | + } |
|
| 1103 | + |
|
| 1104 | + return $Elements; |
|
| 1105 | + } |
|
| 1106 | + |
|
| 1107 | + // |
|
| 1108 | + // ~ |
|
| 1109 | + // |
|
| 1110 | + |
|
| 1111 | + protected function inlineText( $text ) { |
|
| 1112 | + $Inline = array( |
|
| 1113 | + 'extent' => strlen( $text ), |
|
| 1114 | + 'element' => array(), |
|
| 1115 | + ); |
|
| 1116 | + |
|
| 1117 | + $Inline['element']['elements'] = self::pregReplaceElements( |
|
| 1118 | + $this->breaksEnabled ? '/[ ]*+\n/' : '/(?:[ ]*+\\\\|[ ]{2,}+)\n/', |
|
| 1119 | + array( |
|
| 1120 | + array( 'name' => 'br' ), |
|
| 1121 | + array( 'text' => "\n" ), |
|
| 1122 | + ), |
|
| 1123 | + $text |
|
| 1124 | + ); |
|
| 1125 | + |
|
| 1126 | + return $Inline; |
|
| 1127 | + } |
|
| 1128 | + |
|
| 1129 | + protected function inlineCode( $Excerpt ) { |
|
| 1130 | + $marker = $Excerpt['text'][0]; |
|
| 1131 | + |
|
| 1132 | + if ( preg_match( '/^([' . $marker . ']++)[ ]*+(.+?)[ ]*+(?<![' . $marker . '])\1(?!' . $marker . ')/s', $Excerpt['text'], $matches ) ) { |
|
| 1133 | + $text = $matches[2]; |
|
| 1134 | + $text = preg_replace( '/[ ]*+\n/', ' ', $text ); |
|
| 1135 | + |
|
| 1136 | + return array( |
|
| 1137 | + 'extent' => strlen( $matches[0] ), |
|
| 1138 | + 'element' => array( |
|
| 1139 | + 'name' => 'code', |
|
| 1140 | + 'text' => $text, |
|
| 1141 | + ), |
|
| 1142 | + ); |
|
| 1143 | + } |
|
| 1144 | + } |
|
| 1145 | + |
|
| 1146 | + protected function inlineEmailTag( $Excerpt ) { |
|
| 1147 | + $hostnameLabel = '[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?'; |
|
| 1148 | + |
|
| 1149 | + $commonMarkEmail = '[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]++@' |
|
| 1150 | + . $hostnameLabel . '(?:\.' . $hostnameLabel . ')*'; |
|
| 1151 | + |
|
| 1152 | + if ( strpos( $Excerpt['text'], '>' ) !== false |
|
| 1153 | + and preg_match( "/^<((mailto:)?$commonMarkEmail)>/i", $Excerpt['text'], $matches ) |
|
| 1154 | + ) { |
|
| 1155 | + $url = $matches[1]; |
|
| 1156 | + |
|
| 1157 | + if ( ! isset( $matches[2] ) ) { |
|
| 1158 | + $url = "mailto:$url"; |
|
| 1159 | + } |
|
| 1160 | + |
|
| 1161 | + return array( |
|
| 1162 | + 'extent' => strlen( $matches[0] ), |
|
| 1163 | + 'element' => array( |
|
| 1164 | + 'name' => 'a', |
|
| 1165 | + 'text' => $matches[1], |
|
| 1166 | + 'attributes' => array( |
|
| 1167 | + 'href' => $url, |
|
| 1168 | + ), |
|
| 1169 | + ), |
|
| 1170 | + ); |
|
| 1171 | + } |
|
| 1172 | + } |
|
| 1173 | + |
|
| 1174 | + protected function inlineEmphasis( $Excerpt ) { |
|
| 1175 | + if ( ! isset( $Excerpt['text'][1] ) ) { |
|
| 1176 | + return; |
|
| 1177 | + } |
|
| 1178 | + |
|
| 1179 | + $marker = $Excerpt['text'][0]; |
|
| 1180 | + |
|
| 1181 | + if ( $Excerpt['text'][1] === $marker and preg_match( $this->StrongRegex[ $marker ], $Excerpt['text'], $matches ) ) { |
|
| 1182 | + $emphasis = 'strong'; |
|
| 1183 | + } elseif ( preg_match( $this->EmRegex[ $marker ], $Excerpt['text'], $matches ) ) { |
|
| 1184 | + $emphasis = 'em'; |
|
| 1185 | + } else { |
|
| 1186 | + return; |
|
| 1187 | + } |
|
| 1188 | + |
|
| 1189 | + return array( |
|
| 1190 | + 'extent' => strlen( $matches[0] ), |
|
| 1191 | + 'element' => array( |
|
| 1192 | + 'name' => $emphasis, |
|
| 1193 | + 'handler' => array( |
|
| 1194 | + 'function' => 'lineElements', |
|
| 1195 | + 'argument' => $matches[1], |
|
| 1196 | + 'destination' => 'elements', |
|
| 1197 | + ), |
|
| 1198 | + ), |
|
| 1199 | + ); |
|
| 1200 | + } |
|
| 1201 | + |
|
| 1202 | + protected function inlineEscapeSequence( $Excerpt ) { |
|
| 1203 | + if ( isset( $Excerpt['text'][1] ) and in_array( $Excerpt['text'][1], $this->specialCharacters ) ) { |
|
| 1204 | + return array( |
|
| 1205 | + 'element' => array( 'rawHtml' => $Excerpt['text'][1] ), |
|
| 1206 | + 'extent' => 2, |
|
| 1207 | + ); |
|
| 1208 | + } |
|
| 1209 | + } |
|
| 1210 | + |
|
| 1211 | + protected function inlineImage( $Excerpt ) { |
|
| 1212 | + if ( ! isset( $Excerpt['text'][1] ) or $Excerpt['text'][1] !== '[' ) { |
|
| 1213 | + return; |
|
| 1214 | + } |
|
| 1215 | + |
|
| 1216 | + $Excerpt['text'] = substr( $Excerpt['text'], 1 ); |
|
| 1217 | + |
|
| 1218 | + $Link = $this->inlineLink( $Excerpt ); |
|
| 1219 | + |
|
| 1220 | + if ( $Link === null ) { |
|
| 1221 | + return; |
|
| 1222 | + } |
|
| 1223 | + |
|
| 1224 | + $Inline = array( |
|
| 1225 | + 'extent' => $Link['extent'] + 1, |
|
| 1226 | + 'element' => array( |
|
| 1227 | + 'name' => 'img', |
|
| 1228 | + 'attributes' => array( |
|
| 1229 | + 'src' => $Link['element']['attributes']['href'], |
|
| 1230 | + 'alt' => $Link['element']['handler']['argument'], |
|
| 1231 | + ), |
|
| 1232 | + 'autobreak' => true, |
|
| 1233 | + ), |
|
| 1234 | + ); |
|
| 1235 | + |
|
| 1236 | + $Inline['element']['attributes'] += $Link['element']['attributes']; |
|
| 1237 | + |
|
| 1238 | + unset( $Inline['element']['attributes']['href'] ); |
|
| 1239 | + |
|
| 1240 | + return $Inline; |
|
| 1241 | + } |
|
| 1242 | + |
|
| 1243 | + protected function inlineLink( $Excerpt ) { |
|
| 1244 | + $Element = array( |
|
| 1245 | + 'name' => 'a', |
|
| 1246 | + 'handler' => array( |
|
| 1247 | + 'function' => 'lineElements', |
|
| 1248 | + 'argument' => null, |
|
| 1249 | + 'destination' => 'elements', |
|
| 1250 | + ), |
|
| 1251 | + 'nonNestables' => array( 'Url', 'Link' ), |
|
| 1252 | + 'attributes' => array( |
|
| 1253 | + 'href' => null, |
|
| 1254 | + 'title' => null, |
|
| 1255 | + ), |
|
| 1256 | + ); |
|
| 1257 | + |
|
| 1258 | + $extent = 0; |
|
| 1259 | + |
|
| 1260 | + $remainder = $Excerpt['text']; |
|
| 1261 | + |
|
| 1262 | + if ( preg_match( '/\[((?:[^][]++|(?R))*+)\]/', $remainder, $matches ) ) { |
|
| 1263 | + $Element['handler']['argument'] = $matches[1]; |
|
| 1264 | + |
|
| 1265 | + $extent += strlen( $matches[0] ); |
|
| 1266 | + |
|
| 1267 | + $remainder = substr( $remainder, $extent ); |
|
| 1268 | + } else { |
|
| 1269 | + return; |
|
| 1270 | + } |
|
| 1271 | + |
|
| 1272 | + if ( preg_match( '/^[(]\s*+((?:[^ ()]++|[(][^ )]+[)])++)(?:[ ]+("[^"]*+"|\'[^\']*+\'))?\s*+[)]/', $remainder, $matches ) ) { |
|
| 1273 | + $Element['attributes']['href'] = $matches[1]; |
|
| 1274 | + |
|
| 1275 | + if ( isset( $matches[2] ) ) { |
|
| 1276 | + $Element['attributes']['title'] = substr( $matches[2], 1, - 1 ); |
|
| 1277 | + } |
|
| 1278 | + |
|
| 1279 | + $extent += strlen( $matches[0] ); |
|
| 1280 | + } else { |
|
| 1281 | + if ( preg_match( '/^\s*\[(.*?)\]/', $remainder, $matches ) ) { |
|
| 1282 | + $definition = strlen( $matches[1] ) ? $matches[1] : $Element['handler']['argument']; |
|
| 1283 | + $definition = strtolower( $definition ); |
|
| 1284 | + |
|
| 1285 | + $extent += strlen( $matches[0] ); |
|
| 1286 | + } else { |
|
| 1287 | + $definition = strtolower( $Element['handler']['argument'] ); |
|
| 1288 | + } |
|
| 1289 | + |
|
| 1290 | + if ( ! isset( $this->DefinitionData['Reference'][ $definition ] ) ) { |
|
| 1291 | + return; |
|
| 1292 | + } |
|
| 1293 | + |
|
| 1294 | + $Definition = $this->DefinitionData['Reference'][ $definition ]; |
|
| 1295 | + |
|
| 1296 | + $Element['attributes']['href'] = $Definition['url']; |
|
| 1297 | + $Element['attributes']['title'] = $Definition['title']; |
|
| 1298 | + } |
|
| 1299 | + |
|
| 1300 | + return array( |
|
| 1301 | + 'extent' => $extent, |
|
| 1302 | + 'element' => $Element, |
|
| 1303 | + ); |
|
| 1304 | + } |
|
| 1305 | + |
|
| 1306 | + protected function inlineMarkup( $Excerpt ) { |
|
| 1307 | + if ( $this->markupEscaped or $this->safeMode or strpos( $Excerpt['text'], '>' ) === false ) { |
|
| 1308 | + return; |
|
| 1309 | + } |
|
| 1310 | + |
|
| 1311 | + if ( $Excerpt['text'][1] === '/' and preg_match( '/^<\/\w[\w-]*+[ ]*+>/s', $Excerpt['text'], $matches ) ) { |
|
| 1312 | + return array( |
|
| 1313 | + 'element' => array( 'rawHtml' => $matches[0] ), |
|
| 1314 | + 'extent' => strlen( $matches[0] ), |
|
| 1315 | + ); |
|
| 1316 | + } |
|
| 1317 | + |
|
| 1318 | + if ( $Excerpt['text'][1] === '!' and preg_match( '/^<!---?[^>-](?:-?+[^-])*-->/s', $Excerpt['text'], $matches ) ) { |
|
| 1319 | + return array( |
|
| 1320 | + 'element' => array( 'rawHtml' => $matches[0] ), |
|
| 1321 | + 'extent' => strlen( $matches[0] ), |
|
| 1322 | + ); |
|
| 1323 | + } |
|
| 1324 | + |
|
| 1325 | + if ( $Excerpt['text'][1] !== ' ' and preg_match( '/^<\w[\w-]*+(?:[ ]*+' . $this->regexHtmlAttribute . ')*+[ ]*+\/?>/s', $Excerpt['text'], $matches ) ) { |
|
| 1326 | + return array( |
|
| 1327 | + 'element' => array( 'rawHtml' => $matches[0] ), |
|
| 1328 | + 'extent' => strlen( $matches[0] ), |
|
| 1329 | + ); |
|
| 1330 | + } |
|
| 1331 | + } |
|
| 1332 | + |
|
| 1333 | + protected function inlineSpecialCharacter( $Excerpt ) { |
|
| 1334 | + if ( substr( $Excerpt['text'], 1, 1 ) !== ' ' and strpos( $Excerpt['text'], ';' ) !== false |
|
| 1335 | + and preg_match( '/^&(#?+[0-9a-zA-Z]++);/', $Excerpt['text'], $matches ) |
|
| 1336 | + ) { |
|
| 1337 | + return array( |
|
| 1338 | + 'element' => array( 'rawHtml' => '&' . $matches[1] . ';' ), |
|
| 1339 | + 'extent' => strlen( $matches[0] ), |
|
| 1340 | + ); |
|
| 1341 | + } |
|
| 1342 | + |
|
| 1343 | + return; |
|
| 1344 | + } |
|
| 1345 | + |
|
| 1346 | + protected function inlineStrikethrough( $Excerpt ) { |
|
| 1347 | + if ( ! isset( $Excerpt['text'][1] ) ) { |
|
| 1348 | + return; |
|
| 1349 | + } |
|
| 1350 | + |
|
| 1351 | + if ( $Excerpt['text'][1] === '~' and preg_match( '/^~~(?=\S)(.+?)(?<=\S)~~/', $Excerpt['text'], $matches ) ) { |
|
| 1352 | + return array( |
|
| 1353 | + 'extent' => strlen( $matches[0] ), |
|
| 1354 | + 'element' => array( |
|
| 1355 | + 'name' => 'del', |
|
| 1356 | + 'handler' => array( |
|
| 1357 | + 'function' => 'lineElements', |
|
| 1358 | + 'argument' => $matches[1], |
|
| 1359 | + 'destination' => 'elements', |
|
| 1360 | + ), |
|
| 1361 | + ), |
|
| 1362 | + ); |
|
| 1363 | + } |
|
| 1364 | + } |
|
| 1365 | + |
|
| 1366 | + protected function inlineUrl( $Excerpt ) { |
|
| 1367 | + if ( $this->urlsLinked !== true or ! isset( $Excerpt['text'][2] ) or $Excerpt['text'][2] !== '/' ) { |
|
| 1368 | + return; |
|
| 1369 | + } |
|
| 1370 | + |
|
| 1371 | + if ( strpos( $Excerpt['context'], 'http' ) !== false |
|
| 1372 | + and preg_match( '/\bhttps?+:[\/]{2}[^\s<]+\b\/*+/ui', $Excerpt['context'], $matches, PREG_OFFSET_CAPTURE ) |
|
| 1373 | + ) { |
|
| 1374 | + $url = $matches[0][0]; |
|
| 1375 | + |
|
| 1376 | + $Inline = array( |
|
| 1377 | + 'extent' => strlen( $matches[0][0] ), |
|
| 1378 | + 'position' => $matches[0][1], |
|
| 1379 | + 'element' => array( |
|
| 1380 | + 'name' => 'a', |
|
| 1381 | + 'text' => $url, |
|
| 1382 | + 'attributes' => array( |
|
| 1383 | + 'href' => $url, |
|
| 1384 | + ), |
|
| 1385 | + ), |
|
| 1386 | + ); |
|
| 1387 | + |
|
| 1388 | + return $Inline; |
|
| 1389 | + } |
|
| 1390 | + } |
|
| 1391 | + |
|
| 1392 | + protected function inlineUrlTag( $Excerpt ) { |
|
| 1393 | + if ( strpos( $Excerpt['text'], '>' ) !== false and preg_match( '/^<(\w++:\/{2}[^ >]++)>/i', $Excerpt['text'], $matches ) ) { |
|
| 1394 | + $url = $matches[1]; |
|
| 1395 | + |
|
| 1396 | + return array( |
|
| 1397 | + 'extent' => strlen( $matches[0] ), |
|
| 1398 | + 'element' => array( |
|
| 1399 | + 'name' => 'a', |
|
| 1400 | + 'text' => $url, |
|
| 1401 | + 'attributes' => array( |
|
| 1402 | + 'href' => $url, |
|
| 1403 | + ), |
|
| 1404 | + ), |
|
| 1405 | + ); |
|
| 1406 | + } |
|
| 1407 | + } |
|
| 1408 | + |
|
| 1409 | + // ~ |
|
| 1410 | + |
|
| 1411 | + protected function unmarkedText( $text ) { |
|
| 1412 | + $Inline = $this->inlineText( $text ); |
|
| 1413 | + return $this->element( $Inline['element'] ); |
|
| 1414 | + } |
|
| 1415 | + |
|
| 1416 | + // |
|
| 1417 | + // Handlers |
|
| 1418 | + // |
|
| 1419 | + |
|
| 1420 | + protected function handle( array $Element ) { |
|
| 1421 | + if ( isset( $Element['handler'] ) ) { |
|
| 1422 | + if ( ! isset( $Element['nonNestables'] ) ) { |
|
| 1423 | + $Element['nonNestables'] = array(); |
|
| 1424 | + } |
|
| 1425 | + |
|
| 1426 | + if ( is_string( $Element['handler'] ) ) { |
|
| 1427 | + $function = $Element['handler']; |
|
| 1428 | + $argument = $Element['text']; |
|
| 1429 | + unset( $Element['text'] ); |
|
| 1430 | + $destination = 'rawHtml'; |
|
| 1431 | + } else { |
|
| 1432 | + $function = $Element['handler']['function']; |
|
| 1433 | + $argument = $Element['handler']['argument']; |
|
| 1434 | + $destination = $Element['handler']['destination']; |
|
| 1435 | + } |
|
| 1436 | + |
|
| 1437 | + $Element[ $destination ] = $this->{$function}( $argument, $Element['nonNestables'] ); |
|
| 1438 | + |
|
| 1439 | + if ( $destination === 'handler' ) { |
|
| 1440 | + $Element = $this->handle( $Element ); |
|
| 1441 | + } |
|
| 1442 | + |
|
| 1443 | + unset( $Element['handler'] ); |
|
| 1444 | + } |
|
| 1445 | + |
|
| 1446 | + return $Element; |
|
| 1447 | + } |
|
| 1448 | + |
|
| 1449 | + protected function handleElementRecursive( array $Element ) { |
|
| 1450 | + return $this->elementApplyRecursive( array( $this, 'handle' ), $Element ); |
|
| 1451 | + } |
|
| 1452 | + |
|
| 1453 | + protected function handleElementsRecursive( array $Elements ) { |
|
| 1454 | + return $this->elementsApplyRecursive( array( $this, 'handle' ), $Elements ); |
|
| 1455 | + } |
|
| 1456 | + |
|
| 1457 | + protected function elementApplyRecursive( $closure, array $Element ) { |
|
| 1458 | + $Element = call_user_func( $closure, $Element ); |
|
| 1459 | + |
|
| 1460 | + if ( isset( $Element['elements'] ) ) { |
|
| 1461 | + $Element['elements'] = $this->elementsApplyRecursive( $closure, $Element['elements'] ); |
|
| 1462 | + } elseif ( isset( $Element['element'] ) ) { |
|
| 1463 | + $Element['element'] = $this->elementApplyRecursive( $closure, $Element['element'] ); |
|
| 1464 | + } |
|
| 1465 | + |
|
| 1466 | + return $Element; |
|
| 1467 | + } |
|
| 1468 | + |
|
| 1469 | + protected function elementApplyRecursiveDepthFirst( $closure, array $Element ) { |
|
| 1470 | + if ( isset( $Element['elements'] ) ) { |
|
| 1471 | + $Element['elements'] = $this->elementsApplyRecursiveDepthFirst( $closure, $Element['elements'] ); |
|
| 1472 | + } elseif ( isset( $Element['element'] ) ) { |
|
| 1473 | + $Element['element'] = $this->elementsApplyRecursiveDepthFirst( $closure, $Element['element'] ); |
|
| 1474 | + } |
|
| 1475 | + |
|
| 1476 | + $Element = call_user_func( $closure, $Element ); |
|
| 1477 | + |
|
| 1478 | + return $Element; |
|
| 1479 | + } |
|
| 1480 | + |
|
| 1481 | + protected function elementsApplyRecursive( $closure, array $Elements ) { |
|
| 1482 | + foreach ( $Elements as &$Element ) { |
|
| 1483 | + $Element = $this->elementApplyRecursive( $closure, $Element ); |
|
| 1484 | + } |
|
| 1485 | + |
|
| 1486 | + return $Elements; |
|
| 1487 | + } |
|
| 1488 | + |
|
| 1489 | + protected function elementsApplyRecursiveDepthFirst( $closure, array $Elements ) { |
|
| 1490 | + foreach ( $Elements as &$Element ) { |
|
| 1491 | + $Element = $this->elementApplyRecursiveDepthFirst( $closure, $Element ); |
|
| 1492 | + } |
|
| 1493 | + |
|
| 1494 | + return $Elements; |
|
| 1495 | + } |
|
| 1496 | + |
|
| 1497 | + protected function element( array $Element ) { |
|
| 1498 | + if ( $this->safeMode ) { |
|
| 1499 | + $Element = $this->sanitiseElement( $Element ); |
|
| 1500 | + } |
|
| 1501 | + |
|
| 1502 | + // identity map if element has no handler |
|
| 1503 | + $Element = $this->handle( $Element ); |
|
| 1504 | + |
|
| 1505 | + $hasName = isset( $Element['name'] ); |
|
| 1506 | + |
|
| 1507 | + $markup = ''; |
|
| 1508 | + |
|
| 1509 | + if ( $hasName ) { |
|
| 1510 | + $markup .= '<' . $Element['name']; |
|
| 1511 | + |
|
| 1512 | + if ( isset( $Element['attributes'] ) ) { |
|
| 1513 | + foreach ( $Element['attributes'] as $name => $value ) { |
|
| 1514 | + if ( $value === null ) { |
|
| 1515 | + continue; |
|
| 1516 | + } |
|
| 1517 | + |
|
| 1518 | + $markup .= " $name=\"" . self::escape( $value ) . '"'; |
|
| 1519 | + } |
|
| 1520 | + } |
|
| 1521 | + } |
|
| 1522 | + |
|
| 1523 | + $permitRawHtml = false; |
|
| 1524 | 1524 | |
| 1525 | - if ( isset( $Element['text'] ) ) { |
|
| 1526 | - $text = $Element['text']; |
|
| 1527 | - } |
|
| 1528 | - // very strongly consider an alternative if you're writing an |
|
| 1529 | - // extension |
|
| 1530 | - elseif ( isset( $Element['rawHtml'] ) ) { |
|
| 1531 | - $text = $Element['rawHtml']; |
|
| 1525 | + if ( isset( $Element['text'] ) ) { |
|
| 1526 | + $text = $Element['text']; |
|
| 1527 | + } |
|
| 1528 | + // very strongly consider an alternative if you're writing an |
|
| 1529 | + // extension |
|
| 1530 | + elseif ( isset( $Element['rawHtml'] ) ) { |
|
| 1531 | + $text = $Element['rawHtml']; |
|
| 1532 | 1532 | |
| 1533 | - $allowRawHtmlInSafeMode = isset( $Element['allowRawHtmlInSafeMode'] ) && $Element['allowRawHtmlInSafeMode']; |
|
| 1534 | - $permitRawHtml = ! $this->safeMode || $allowRawHtmlInSafeMode; |
|
| 1535 | - } |
|
| 1533 | + $allowRawHtmlInSafeMode = isset( $Element['allowRawHtmlInSafeMode'] ) && $Element['allowRawHtmlInSafeMode']; |
|
| 1534 | + $permitRawHtml = ! $this->safeMode || $allowRawHtmlInSafeMode; |
|
| 1535 | + } |
|
| 1536 | 1536 | |
| 1537 | - $hasContent = isset( $text ) || isset( $Element['element'] ) || isset( $Element['elements'] ); |
|
| 1537 | + $hasContent = isset( $text ) || isset( $Element['element'] ) || isset( $Element['elements'] ); |
|
| 1538 | 1538 | |
| 1539 | - if ( $hasContent ) { |
|
| 1540 | - $markup .= $hasName ? '>' : ''; |
|
| 1539 | + if ( $hasContent ) { |
|
| 1540 | + $markup .= $hasName ? '>' : ''; |
|
| 1541 | 1541 | |
| 1542 | - if ( isset( $Element['elements'] ) ) { |
|
| 1543 | - $markup .= $this->elements( $Element['elements'] ); |
|
| 1544 | - } elseif ( isset( $Element['element'] ) ) { |
|
| 1545 | - $markup .= $this->element( $Element['element'] ); |
|
| 1546 | - } elseif ( ! $permitRawHtml ) { |
|
| 1547 | - $markup .= self::escape( $text, true ); |
|
| 1548 | - } else { |
|
| 1549 | - $markup .= $text; |
|
| 1550 | - } |
|
| 1542 | + if ( isset( $Element['elements'] ) ) { |
|
| 1543 | + $markup .= $this->elements( $Element['elements'] ); |
|
| 1544 | + } elseif ( isset( $Element['element'] ) ) { |
|
| 1545 | + $markup .= $this->element( $Element['element'] ); |
|
| 1546 | + } elseif ( ! $permitRawHtml ) { |
|
| 1547 | + $markup .= self::escape( $text, true ); |
|
| 1548 | + } else { |
|
| 1549 | + $markup .= $text; |
|
| 1550 | + } |
|
| 1551 | 1551 | |
| 1552 | - $markup .= $hasName ? '</' . $Element['name'] . '>' : ''; |
|
| 1553 | - } elseif ( $hasName ) { |
|
| 1554 | - $markup .= ' />'; |
|
| 1555 | - } |
|
| 1552 | + $markup .= $hasName ? '</' . $Element['name'] . '>' : ''; |
|
| 1553 | + } elseif ( $hasName ) { |
|
| 1554 | + $markup .= ' />'; |
|
| 1555 | + } |
|
| 1556 | 1556 | |
| 1557 | - return $markup; |
|
| 1558 | - } |
|
| 1557 | + return $markup; |
|
| 1558 | + } |
|
| 1559 | 1559 | |
| 1560 | - protected function elements( array $Elements ) { |
|
| 1561 | - $markup = ''; |
|
| 1562 | - |
|
| 1563 | - $autoBreak = true; |
|
| 1564 | - |
|
| 1565 | - foreach ( $Elements as $Element ) { |
|
| 1566 | - if ( empty( $Element ) ) { |
|
| 1567 | - continue; |
|
| 1568 | - } |
|
| 1569 | - |
|
| 1570 | - $autoBreakNext = ( isset( $Element['autobreak'] ) |
|
| 1571 | - ? $Element['autobreak'] : isset( $Element['name'] ) |
|
| 1572 | - ); |
|
| 1573 | - // (autobreak === false) covers both sides of an element |
|
| 1574 | - $autoBreak = ! $autoBreak ? $autoBreak : $autoBreakNext; |
|
| 1575 | - |
|
| 1576 | - $markup .= ( $autoBreak ? "\n" : '' ) . $this->element( $Element ); |
|
| 1577 | - $autoBreak = $autoBreakNext; |
|
| 1578 | - } |
|
| 1579 | - |
|
| 1580 | - $markup .= $autoBreak ? "\n" : ''; |
|
| 1581 | - |
|
| 1582 | - return $markup; |
|
| 1583 | - } |
|
| 1584 | - |
|
| 1585 | - // ~ |
|
| 1586 | - |
|
| 1587 | - protected function li( $lines ) { |
|
| 1588 | - $Elements = $this->linesElements( $lines ); |
|
| 1589 | - |
|
| 1590 | - if ( ! in_array( '', $lines ) |
|
| 1591 | - and isset( $Elements[0] ) and isset( $Elements[0]['name'] ) |
|
| 1592 | - and $Elements[0]['name'] === 'p' |
|
| 1593 | - ) { |
|
| 1594 | - unset( $Elements[0]['name'] ); |
|
| 1595 | - } |
|
| 1596 | - |
|
| 1597 | - return $Elements; |
|
| 1598 | - } |
|
| 1599 | - |
|
| 1600 | - // |
|
| 1601 | - // AST Convenience |
|
| 1602 | - // |
|
| 1603 | - |
|
| 1604 | - /** |
|
| 1605 | - * Replace occurrences $regexp with $Elements in $text. Return an array of |
|
| 1606 | - * elements representing the replacement. |
|
| 1607 | - */ |
|
| 1608 | - protected static function pregReplaceElements( $regexp, $Elements, $text ) { |
|
| 1609 | - $newElements = array(); |
|
| 1610 | - |
|
| 1611 | - while ( preg_match( $regexp, $text, $matches, PREG_OFFSET_CAPTURE ) ) { |
|
| 1612 | - $offset = $matches[0][1]; |
|
| 1613 | - $before = substr( $text, 0, $offset ); |
|
| 1614 | - $after = substr( $text, $offset + strlen( $matches[0][0] ) ); |
|
| 1615 | - |
|
| 1616 | - $newElements[] = array( 'text' => $before ); |
|
| 1617 | - |
|
| 1618 | - foreach ( $Elements as $Element ) { |
|
| 1619 | - $newElements[] = $Element; |
|
| 1620 | - } |
|
| 1560 | + protected function elements( array $Elements ) { |
|
| 1561 | + $markup = ''; |
|
| 1562 | + |
|
| 1563 | + $autoBreak = true; |
|
| 1564 | + |
|
| 1565 | + foreach ( $Elements as $Element ) { |
|
| 1566 | + if ( empty( $Element ) ) { |
|
| 1567 | + continue; |
|
| 1568 | + } |
|
| 1569 | + |
|
| 1570 | + $autoBreakNext = ( isset( $Element['autobreak'] ) |
|
| 1571 | + ? $Element['autobreak'] : isset( $Element['name'] ) |
|
| 1572 | + ); |
|
| 1573 | + // (autobreak === false) covers both sides of an element |
|
| 1574 | + $autoBreak = ! $autoBreak ? $autoBreak : $autoBreakNext; |
|
| 1575 | + |
|
| 1576 | + $markup .= ( $autoBreak ? "\n" : '' ) . $this->element( $Element ); |
|
| 1577 | + $autoBreak = $autoBreakNext; |
|
| 1578 | + } |
|
| 1579 | + |
|
| 1580 | + $markup .= $autoBreak ? "\n" : ''; |
|
| 1581 | + |
|
| 1582 | + return $markup; |
|
| 1583 | + } |
|
| 1584 | + |
|
| 1585 | + // ~ |
|
| 1586 | + |
|
| 1587 | + protected function li( $lines ) { |
|
| 1588 | + $Elements = $this->linesElements( $lines ); |
|
| 1589 | + |
|
| 1590 | + if ( ! in_array( '', $lines ) |
|
| 1591 | + and isset( $Elements[0] ) and isset( $Elements[0]['name'] ) |
|
| 1592 | + and $Elements[0]['name'] === 'p' |
|
| 1593 | + ) { |
|
| 1594 | + unset( $Elements[0]['name'] ); |
|
| 1595 | + } |
|
| 1596 | + |
|
| 1597 | + return $Elements; |
|
| 1598 | + } |
|
| 1599 | + |
|
| 1600 | + // |
|
| 1601 | + // AST Convenience |
|
| 1602 | + // |
|
| 1603 | + |
|
| 1604 | + /** |
|
| 1605 | + * Replace occurrences $regexp with $Elements in $text. Return an array of |
|
| 1606 | + * elements representing the replacement. |
|
| 1607 | + */ |
|
| 1608 | + protected static function pregReplaceElements( $regexp, $Elements, $text ) { |
|
| 1609 | + $newElements = array(); |
|
| 1610 | + |
|
| 1611 | + while ( preg_match( $regexp, $text, $matches, PREG_OFFSET_CAPTURE ) ) { |
|
| 1612 | + $offset = $matches[0][1]; |
|
| 1613 | + $before = substr( $text, 0, $offset ); |
|
| 1614 | + $after = substr( $text, $offset + strlen( $matches[0][0] ) ); |
|
| 1615 | + |
|
| 1616 | + $newElements[] = array( 'text' => $before ); |
|
| 1617 | + |
|
| 1618 | + foreach ( $Elements as $Element ) { |
|
| 1619 | + $newElements[] = $Element; |
|
| 1620 | + } |
|
| 1621 | 1621 | |
| 1622 | - $text = $after; |
|
| 1623 | - } |
|
| 1622 | + $text = $after; |
|
| 1623 | + } |
|
| 1624 | 1624 | |
| 1625 | - $newElements[] = array( 'text' => $text ); |
|
| 1626 | - |
|
| 1627 | - return $newElements; |
|
| 1628 | - } |
|
| 1629 | - |
|
| 1630 | - // |
|
| 1631 | - // Deprecated Methods |
|
| 1632 | - // |
|
| 1633 | - |
|
| 1634 | - function parse( $text ) { |
|
| 1635 | - $markup = $this->text( $text ); |
|
| 1636 | - |
|
| 1637 | - return $markup; |
|
| 1638 | - } |
|
| 1639 | - |
|
| 1640 | - protected function sanitiseElement( array $Element ) { |
|
| 1641 | - static $goodAttribute = '/^[a-zA-Z0-9][a-zA-Z0-9-_]*+$/'; |
|
| 1642 | - static $safeUrlNameToAtt = array( |
|
| 1643 | - 'a' => 'href', |
|
| 1644 | - 'img' => 'src', |
|
| 1645 | - ); |
|
| 1646 | - |
|
| 1647 | - if ( ! isset( $Element['name'] ) ) { |
|
| 1648 | - unset( $Element['attributes'] ); |
|
| 1649 | - return $Element; |
|
| 1650 | - } |
|
| 1651 | - |
|
| 1652 | - if ( isset( $safeUrlNameToAtt[ $Element['name'] ] ) ) { |
|
| 1653 | - $Element = $this->filterUnsafeUrlInAttribute( $Element, $safeUrlNameToAtt[ $Element['name'] ] ); |
|
| 1654 | - } |
|
| 1655 | - |
|
| 1656 | - if ( ! empty( $Element['attributes'] ) ) { |
|
| 1657 | - foreach ( $Element['attributes'] as $att => $val ) { |
|
| 1658 | - // filter out badly parsed attribute |
|
| 1659 | - if ( ! preg_match( $goodAttribute, $att ) ) { |
|
| 1660 | - unset( $Element['attributes'][ $att ] ); |
|
| 1661 | - } |
|
| 1662 | - // dump onevent attribute |
|
| 1663 | - elseif ( self::striAtStart( $att, 'on' ) ) { |
|
| 1664 | - unset( $Element['attributes'][ $att ] ); |
|
| 1665 | - } |
|
| 1666 | - } |
|
| 1667 | - } |
|
| 1668 | - |
|
| 1669 | - return $Element; |
|
| 1670 | - } |
|
| 1671 | - |
|
| 1672 | - protected function filterUnsafeUrlInAttribute( array $Element, $attribute ) { |
|
| 1673 | - foreach ( $this->safeLinksWhitelist as $scheme ) { |
|
| 1674 | - if ( self::striAtStart( $Element['attributes'][ $attribute ], $scheme ) ) { |
|
| 1675 | - return $Element; |
|
| 1676 | - } |
|
| 1677 | - } |
|
| 1678 | - |
|
| 1679 | - $Element['attributes'][ $attribute ] = str_replace( ':', '%3A', $Element['attributes'][ $attribute ] ); |
|
| 1680 | - |
|
| 1681 | - return $Element; |
|
| 1682 | - } |
|
| 1683 | - |
|
| 1684 | - // |
|
| 1685 | - // Static Methods |
|
| 1686 | - // |
|
| 1687 | - |
|
| 1688 | - protected static function escape( $text, $allowQuotes = false ) { |
|
| 1689 | - return htmlspecialchars( $text, $allowQuotes ? ENT_NOQUOTES : ENT_QUOTES, 'UTF-8' ); |
|
| 1690 | - } |
|
| 1691 | - |
|
| 1692 | - protected static function striAtStart( $string, $needle ) { |
|
| 1693 | - $len = strlen( $needle ); |
|
| 1694 | - |
|
| 1695 | - if ( $len > strlen( $string ) ) { |
|
| 1696 | - return false; |
|
| 1697 | - } else { |
|
| 1698 | - return strtolower( substr( $string, 0, $len ) ) === strtolower( $needle ); |
|
| 1699 | - } |
|
| 1700 | - } |
|
| 1701 | - |
|
| 1702 | - static function instance( $name = 'default' ) { |
|
| 1703 | - if ( isset( self::$instances[ $name ] ) ) { |
|
| 1704 | - return self::$instances[ $name ]; |
|
| 1705 | - } |
|
| 1706 | - |
|
| 1707 | - $instance = new static(); |
|
| 1708 | - |
|
| 1709 | - self::$instances[ $name ] = $instance; |
|
| 1710 | - |
|
| 1711 | - return $instance; |
|
| 1712 | - } |
|
| 1713 | - |
|
| 1714 | - private static $instances = array(); |
|
| 1715 | - |
|
| 1716 | - // |
|
| 1717 | - // Fields |
|
| 1718 | - // |
|
| 1719 | - |
|
| 1720 | - protected $DefinitionData; |
|
| 1721 | - |
|
| 1722 | - // |
|
| 1723 | - // Read-Only |
|
| 1724 | - |
|
| 1725 | - protected $specialCharacters = array( |
|
| 1726 | - '\\', |
|
| 1727 | - '`', |
|
| 1728 | - '*', |
|
| 1729 | - '_', |
|
| 1730 | - '{', |
|
| 1731 | - '}', |
|
| 1732 | - '[', |
|
| 1733 | - ']', |
|
| 1734 | - '(', |
|
| 1735 | - ')', |
|
| 1736 | - '>', |
|
| 1737 | - '#', |
|
| 1738 | - '+', |
|
| 1739 | - '-', |
|
| 1740 | - '.', |
|
| 1741 | - '!', |
|
| 1742 | - '|', |
|
| 1743 | - '~', |
|
| 1744 | - ); |
|
| 1745 | - |
|
| 1746 | - protected $StrongRegex = array( |
|
| 1747 | - '*' => '/^[*]{2}((?:\\\\\*|[^*]|[*][^*]*+[*])+?)[*]{2}(?![*])/s', |
|
| 1748 | - '_' => '/^__((?:\\\\_|[^_]|_[^_]*+_)+?)__(?!_)/us', |
|
| 1749 | - ); |
|
| 1750 | - |
|
| 1751 | - protected $EmRegex = array( |
|
| 1752 | - '*' => '/^[*]((?:\\\\\*|[^*]|[*][*][^*]+?[*][*])+?)[*](?![*])/s', |
|
| 1753 | - '_' => '/^_((?:\\\\_|[^_]|__[^_]*__)+?)_(?!_)\b/us', |
|
| 1754 | - ); |
|
| 1755 | - |
|
| 1756 | - protected $regexHtmlAttribute = '[a-zA-Z_:][\w:.-]*+(?:\s*+=\s*+(?:[^"\'=<>`\s]+|"[^"]*+"|\'[^\']*+\'))?+'; |
|
| 1757 | - |
|
| 1758 | - protected $voidElements = array( |
|
| 1759 | - 'area', |
|
| 1760 | - 'base', |
|
| 1761 | - 'br', |
|
| 1762 | - 'col', |
|
| 1763 | - 'command', |
|
| 1764 | - 'embed', |
|
| 1765 | - 'hr', |
|
| 1766 | - 'img', |
|
| 1767 | - 'input', |
|
| 1768 | - 'link', |
|
| 1769 | - 'meta', |
|
| 1770 | - 'param', |
|
| 1771 | - 'source', |
|
| 1772 | - ); |
|
| 1773 | - |
|
| 1774 | - protected $textLevelElements = array( |
|
| 1775 | - 'a', |
|
| 1776 | - 'br', |
|
| 1777 | - 'bdo', |
|
| 1778 | - 'abbr', |
|
| 1779 | - 'blink', |
|
| 1780 | - 'nextid', |
|
| 1781 | - 'acronym', |
|
| 1782 | - 'basefont', |
|
| 1783 | - 'b', |
|
| 1784 | - 'em', |
|
| 1785 | - 'big', |
|
| 1786 | - 'cite', |
|
| 1787 | - 'small', |
|
| 1788 | - 'spacer', |
|
| 1789 | - 'listing', |
|
| 1790 | - 'i', |
|
| 1791 | - 'rp', |
|
| 1792 | - 'del', |
|
| 1793 | - 'code', |
|
| 1794 | - 'strike', |
|
| 1795 | - 'marquee', |
|
| 1796 | - 'q', |
|
| 1797 | - 'rt', |
|
| 1798 | - 'ins', |
|
| 1799 | - 'font', |
|
| 1800 | - 'strong', |
|
| 1801 | - 's', |
|
| 1802 | - 'tt', |
|
| 1803 | - 'kbd', |
|
| 1804 | - 'mark', |
|
| 1805 | - 'u', |
|
| 1806 | - 'xm', |
|
| 1807 | - 'sub', |
|
| 1808 | - 'nobr', |
|
| 1809 | - 'sup', |
|
| 1810 | - 'ruby', |
|
| 1811 | - 'var', |
|
| 1812 | - 'span', |
|
| 1813 | - 'wbr', |
|
| 1814 | - 'time', |
|
| 1815 | - ); |
|
| 1625 | + $newElements[] = array( 'text' => $text ); |
|
| 1626 | + |
|
| 1627 | + return $newElements; |
|
| 1628 | + } |
|
| 1629 | + |
|
| 1630 | + // |
|
| 1631 | + // Deprecated Methods |
|
| 1632 | + // |
|
| 1633 | + |
|
| 1634 | + function parse( $text ) { |
|
| 1635 | + $markup = $this->text( $text ); |
|
| 1636 | + |
|
| 1637 | + return $markup; |
|
| 1638 | + } |
|
| 1639 | + |
|
| 1640 | + protected function sanitiseElement( array $Element ) { |
|
| 1641 | + static $goodAttribute = '/^[a-zA-Z0-9][a-zA-Z0-9-_]*+$/'; |
|
| 1642 | + static $safeUrlNameToAtt = array( |
|
| 1643 | + 'a' => 'href', |
|
| 1644 | + 'img' => 'src', |
|
| 1645 | + ); |
|
| 1646 | + |
|
| 1647 | + if ( ! isset( $Element['name'] ) ) { |
|
| 1648 | + unset( $Element['attributes'] ); |
|
| 1649 | + return $Element; |
|
| 1650 | + } |
|
| 1651 | + |
|
| 1652 | + if ( isset( $safeUrlNameToAtt[ $Element['name'] ] ) ) { |
|
| 1653 | + $Element = $this->filterUnsafeUrlInAttribute( $Element, $safeUrlNameToAtt[ $Element['name'] ] ); |
|
| 1654 | + } |
|
| 1655 | + |
|
| 1656 | + if ( ! empty( $Element['attributes'] ) ) { |
|
| 1657 | + foreach ( $Element['attributes'] as $att => $val ) { |
|
| 1658 | + // filter out badly parsed attribute |
|
| 1659 | + if ( ! preg_match( $goodAttribute, $att ) ) { |
|
| 1660 | + unset( $Element['attributes'][ $att ] ); |
|
| 1661 | + } |
|
| 1662 | + // dump onevent attribute |
|
| 1663 | + elseif ( self::striAtStart( $att, 'on' ) ) { |
|
| 1664 | + unset( $Element['attributes'][ $att ] ); |
|
| 1665 | + } |
|
| 1666 | + } |
|
| 1667 | + } |
|
| 1668 | + |
|
| 1669 | + return $Element; |
|
| 1670 | + } |
|
| 1671 | + |
|
| 1672 | + protected function filterUnsafeUrlInAttribute( array $Element, $attribute ) { |
|
| 1673 | + foreach ( $this->safeLinksWhitelist as $scheme ) { |
|
| 1674 | + if ( self::striAtStart( $Element['attributes'][ $attribute ], $scheme ) ) { |
|
| 1675 | + return $Element; |
|
| 1676 | + } |
|
| 1677 | + } |
|
| 1678 | + |
|
| 1679 | + $Element['attributes'][ $attribute ] = str_replace( ':', '%3A', $Element['attributes'][ $attribute ] ); |
|
| 1680 | + |
|
| 1681 | + return $Element; |
|
| 1682 | + } |
|
| 1683 | + |
|
| 1684 | + // |
|
| 1685 | + // Static Methods |
|
| 1686 | + // |
|
| 1687 | + |
|
| 1688 | + protected static function escape( $text, $allowQuotes = false ) { |
|
| 1689 | + return htmlspecialchars( $text, $allowQuotes ? ENT_NOQUOTES : ENT_QUOTES, 'UTF-8' ); |
|
| 1690 | + } |
|
| 1691 | + |
|
| 1692 | + protected static function striAtStart( $string, $needle ) { |
|
| 1693 | + $len = strlen( $needle ); |
|
| 1694 | + |
|
| 1695 | + if ( $len > strlen( $string ) ) { |
|
| 1696 | + return false; |
|
| 1697 | + } else { |
|
| 1698 | + return strtolower( substr( $string, 0, $len ) ) === strtolower( $needle ); |
|
| 1699 | + } |
|
| 1700 | + } |
|
| 1701 | + |
|
| 1702 | + static function instance( $name = 'default' ) { |
|
| 1703 | + if ( isset( self::$instances[ $name ] ) ) { |
|
| 1704 | + return self::$instances[ $name ]; |
|
| 1705 | + } |
|
| 1706 | + |
|
| 1707 | + $instance = new static(); |
|
| 1708 | + |
|
| 1709 | + self::$instances[ $name ] = $instance; |
|
| 1710 | + |
|
| 1711 | + return $instance; |
|
| 1712 | + } |
|
| 1713 | + |
|
| 1714 | + private static $instances = array(); |
|
| 1715 | + |
|
| 1716 | + // |
|
| 1717 | + // Fields |
|
| 1718 | + // |
|
| 1719 | + |
|
| 1720 | + protected $DefinitionData; |
|
| 1721 | + |
|
| 1722 | + // |
|
| 1723 | + // Read-Only |
|
| 1724 | + |
|
| 1725 | + protected $specialCharacters = array( |
|
| 1726 | + '\\', |
|
| 1727 | + '`', |
|
| 1728 | + '*', |
|
| 1729 | + '_', |
|
| 1730 | + '{', |
|
| 1731 | + '}', |
|
| 1732 | + '[', |
|
| 1733 | + ']', |
|
| 1734 | + '(', |
|
| 1735 | + ')', |
|
| 1736 | + '>', |
|
| 1737 | + '#', |
|
| 1738 | + '+', |
|
| 1739 | + '-', |
|
| 1740 | + '.', |
|
| 1741 | + '!', |
|
| 1742 | + '|', |
|
| 1743 | + '~', |
|
| 1744 | + ); |
|
| 1745 | + |
|
| 1746 | + protected $StrongRegex = array( |
|
| 1747 | + '*' => '/^[*]{2}((?:\\\\\*|[^*]|[*][^*]*+[*])+?)[*]{2}(?![*])/s', |
|
| 1748 | + '_' => '/^__((?:\\\\_|[^_]|_[^_]*+_)+?)__(?!_)/us', |
|
| 1749 | + ); |
|
| 1750 | + |
|
| 1751 | + protected $EmRegex = array( |
|
| 1752 | + '*' => '/^[*]((?:\\\\\*|[^*]|[*][*][^*]+?[*][*])+?)[*](?![*])/s', |
|
| 1753 | + '_' => '/^_((?:\\\\_|[^_]|__[^_]*__)+?)_(?!_)\b/us', |
|
| 1754 | + ); |
|
| 1755 | + |
|
| 1756 | + protected $regexHtmlAttribute = '[a-zA-Z_:][\w:.-]*+(?:\s*+=\s*+(?:[^"\'=<>`\s]+|"[^"]*+"|\'[^\']*+\'))?+'; |
|
| 1757 | + |
|
| 1758 | + protected $voidElements = array( |
|
| 1759 | + 'area', |
|
| 1760 | + 'base', |
|
| 1761 | + 'br', |
|
| 1762 | + 'col', |
|
| 1763 | + 'command', |
|
| 1764 | + 'embed', |
|
| 1765 | + 'hr', |
|
| 1766 | + 'img', |
|
| 1767 | + 'input', |
|
| 1768 | + 'link', |
|
| 1769 | + 'meta', |
|
| 1770 | + 'param', |
|
| 1771 | + 'source', |
|
| 1772 | + ); |
|
| 1773 | + |
|
| 1774 | + protected $textLevelElements = array( |
|
| 1775 | + 'a', |
|
| 1776 | + 'br', |
|
| 1777 | + 'bdo', |
|
| 1778 | + 'abbr', |
|
| 1779 | + 'blink', |
|
| 1780 | + 'nextid', |
|
| 1781 | + 'acronym', |
|
| 1782 | + 'basefont', |
|
| 1783 | + 'b', |
|
| 1784 | + 'em', |
|
| 1785 | + 'big', |
|
| 1786 | + 'cite', |
|
| 1787 | + 'small', |
|
| 1788 | + 'spacer', |
|
| 1789 | + 'listing', |
|
| 1790 | + 'i', |
|
| 1791 | + 'rp', |
|
| 1792 | + 'del', |
|
| 1793 | + 'code', |
|
| 1794 | + 'strike', |
|
| 1795 | + 'marquee', |
|
| 1796 | + 'q', |
|
| 1797 | + 'rt', |
|
| 1798 | + 'ins', |
|
| 1799 | + 'font', |
|
| 1800 | + 'strong', |
|
| 1801 | + 's', |
|
| 1802 | + 'tt', |
|
| 1803 | + 'kbd', |
|
| 1804 | + 'mark', |
|
| 1805 | + 'u', |
|
| 1806 | + 'xm', |
|
| 1807 | + 'sub', |
|
| 1808 | + 'nobr', |
|
| 1809 | + 'sup', |
|
| 1810 | + 'ruby', |
|
| 1811 | + 'var', |
|
| 1812 | + 'span', |
|
| 1813 | + 'wbr', |
|
| 1814 | + 'time', |
|
| 1815 | + ); |
|
| 1816 | 1816 | } |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | protected $urlsLinked = true; |
| 80 | 80 | |
| 81 | 81 | function setSafeMode( $safeMode ) { |
| 82 | - $this->safeMode = (bool) $safeMode; |
|
| 82 | + $this->safeMode = ( bool ) $safeMode; |
|
| 83 | 83 | |
| 84 | 84 | return $this; |
| 85 | 85 | } |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | protected $safeMode; |
| 88 | 88 | |
| 89 | 89 | function setStrictMode( $strictMode ) { |
| 90 | - $this->strictMode = (bool) $strictMode; |
|
| 90 | + $this->strictMode = ( bool ) $strictMode; |
|
| 91 | 91 | |
| 92 | 92 | return $this; |
| 93 | 93 | } |
@@ -215,8 +215,8 @@ discard block |
||
| 215 | 215 | |
| 216 | 216 | $blockTypes = $this->unmarkedBlockTypes; |
| 217 | 217 | |
| 218 | - if ( isset( $this->BlockTypes[ $marker ] ) ) { |
|
| 219 | - foreach ( $this->BlockTypes[ $marker ] as $blockType ) { |
|
| 218 | + if ( isset( $this->BlockTypes[$marker] ) ) { |
|
| 219 | + foreach ( $this->BlockTypes[$marker] as $blockType ) { |
|
| 220 | 220 | $blockTypes [] = $blockType; |
| 221 | 221 | } |
| 222 | 222 | } |
@@ -509,7 +509,7 @@ discard block |
||
| 509 | 509 | // List |
| 510 | 510 | |
| 511 | 511 | protected function blockList( $Line, ?array $CurrentBlock = null ) { |
| 512 | - list($name, $pattern) = $Line['text'][0] <= '-' ? array( 'ul', '[*+-]' ) : array( 'ol', '[0-9]{1,9}+[.\)]' ); |
|
| 512 | + list( $name, $pattern ) = $Line['text'][0] <= '-' ? array( 'ul', '[*+-]' ) : array( 'ol', '[0-9]{1,9}+[.\)]' ); |
|
| 513 | 513 | |
| 514 | 514 | if ( preg_match( '/^(' . $pattern . '([ ]++|$))(.*+)/', $Line['text'], $matches ) ) { |
| 515 | 515 | $contentIndent = strlen( $matches[2] ); |
@@ -524,7 +524,7 @@ discard block |
||
| 524 | 524 | |
| 525 | 525 | $markerWithoutWhitespace = strstr( $matches[1], ' ', true ); |
| 526 | 526 | |
| 527 | - $Block = array( |
|
| 527 | + $Block = array( |
|
| 528 | 528 | 'indent' => $Line['indent'], |
| 529 | 529 | 'pattern' => $pattern, |
| 530 | 530 | 'data' => array( |
@@ -669,7 +669,7 @@ discard block |
||
| 669 | 669 | 'name' => 'blockquote', |
| 670 | 670 | 'handler' => array( |
| 671 | 671 | 'function' => 'linesElements', |
| 672 | - 'argument' => (array) $matches[1], |
|
| 672 | + 'argument' => ( array ) $matches[1], |
|
| 673 | 673 | 'destination' => 'elements', |
| 674 | 674 | ), |
| 675 | 675 | ), |
@@ -780,7 +780,7 @@ discard block |
||
| 780 | 780 | 'title' => isset( $matches[3] ) ? $matches[3] : null, |
| 781 | 781 | ); |
| 782 | 782 | |
| 783 | - $this->DefinitionData['Reference'][ $id ] = $Data; |
|
| 783 | + $this->DefinitionData['Reference'][$id] = $Data; |
|
| 784 | 784 | |
| 785 | 785 | $Block = array( |
| 786 | 786 | 'element' => array(), |
@@ -867,8 +867,8 @@ discard block |
||
| 867 | 867 | ), |
| 868 | 868 | ); |
| 869 | 869 | |
| 870 | - if ( isset( $alignments[ $index ] ) ) { |
|
| 871 | - $alignment = $alignments[ $index ]; |
|
| 870 | + if ( isset( $alignments[$index] ) ) { |
|
| 871 | + $alignment = $alignments[$index]; |
|
| 872 | 872 | |
| 873 | 873 | $HeaderElement['attributes'] = array( |
| 874 | 874 | 'style' => "text-align: $alignment;", |
@@ -935,9 +935,9 @@ discard block |
||
| 935 | 935 | ), |
| 936 | 936 | ); |
| 937 | 937 | |
| 938 | - if ( isset( $Block['alignments'][ $index ] ) ) { |
|
| 938 | + if ( isset( $Block['alignments'][$index] ) ) { |
|
| 939 | 939 | $Element['attributes'] = array( |
| 940 | - 'style' => 'text-align: ' . $Block['alignments'][ $index ] . ';', |
|
| 940 | + 'style' => 'text-align: ' . $Block['alignments'][$index] . ';', |
|
| 941 | 941 | ); |
| 942 | 942 | } |
| 943 | 943 | |
@@ -1035,10 +1035,10 @@ discard block |
||
| 1035 | 1035 | 'context' => $text, |
| 1036 | 1036 | ); |
| 1037 | 1037 | |
| 1038 | - foreach ( $this->InlineTypes[ $marker ] as $inlineType ) { |
|
| 1038 | + foreach ( $this->InlineTypes[$marker] as $inlineType ) { |
|
| 1039 | 1039 | // check to see if the current inline type is nestable in the current context |
| 1040 | 1040 | |
| 1041 | - if ( isset( $nonNestables[ $inlineType ] ) ) { |
|
| 1041 | + if ( isset( $nonNestables[$inlineType] ) ) { |
|
| 1042 | 1042 | continue; |
| 1043 | 1043 | } |
| 1044 | 1044 | |
@@ -1178,9 +1178,9 @@ discard block |
||
| 1178 | 1178 | |
| 1179 | 1179 | $marker = $Excerpt['text'][0]; |
| 1180 | 1180 | |
| 1181 | - if ( $Excerpt['text'][1] === $marker and preg_match( $this->StrongRegex[ $marker ], $Excerpt['text'], $matches ) ) { |
|
| 1181 | + if ( $Excerpt['text'][1] === $marker and preg_match( $this->StrongRegex[$marker], $Excerpt['text'], $matches ) ) { |
|
| 1182 | 1182 | $emphasis = 'strong'; |
| 1183 | - } elseif ( preg_match( $this->EmRegex[ $marker ], $Excerpt['text'], $matches ) ) { |
|
| 1183 | + } elseif ( preg_match( $this->EmRegex[$marker], $Excerpt['text'], $matches ) ) { |
|
| 1184 | 1184 | $emphasis = 'em'; |
| 1185 | 1185 | } else { |
| 1186 | 1186 | return; |
@@ -1287,11 +1287,11 @@ discard block |
||
| 1287 | 1287 | $definition = strtolower( $Element['handler']['argument'] ); |
| 1288 | 1288 | } |
| 1289 | 1289 | |
| 1290 | - if ( ! isset( $this->DefinitionData['Reference'][ $definition ] ) ) { |
|
| 1290 | + if ( ! isset( $this->DefinitionData['Reference'][$definition] ) ) { |
|
| 1291 | 1291 | return; |
| 1292 | 1292 | } |
| 1293 | 1293 | |
| 1294 | - $Definition = $this->DefinitionData['Reference'][ $definition ]; |
|
| 1294 | + $Definition = $this->DefinitionData['Reference'][$definition]; |
|
| 1295 | 1295 | |
| 1296 | 1296 | $Element['attributes']['href'] = $Definition['url']; |
| 1297 | 1297 | $Element['attributes']['title'] = $Definition['title']; |
@@ -1434,7 +1434,7 @@ discard block |
||
| 1434 | 1434 | $destination = $Element['handler']['destination']; |
| 1435 | 1435 | } |
| 1436 | 1436 | |
| 1437 | - $Element[ $destination ] = $this->{$function}( $argument, $Element['nonNestables'] ); |
|
| 1437 | + $Element[$destination] = $this->{$function}( $argument, $Element['nonNestables'] ); |
|
| 1438 | 1438 | |
| 1439 | 1439 | if ( $destination === 'handler' ) { |
| 1440 | 1440 | $Element = $this->handle( $Element ); |
@@ -1649,19 +1649,19 @@ discard block |
||
| 1649 | 1649 | return $Element; |
| 1650 | 1650 | } |
| 1651 | 1651 | |
| 1652 | - if ( isset( $safeUrlNameToAtt[ $Element['name'] ] ) ) { |
|
| 1653 | - $Element = $this->filterUnsafeUrlInAttribute( $Element, $safeUrlNameToAtt[ $Element['name'] ] ); |
|
| 1652 | + if ( isset( $safeUrlNameToAtt[$Element['name']] ) ) { |
|
| 1653 | + $Element = $this->filterUnsafeUrlInAttribute( $Element, $safeUrlNameToAtt[$Element['name']] ); |
|
| 1654 | 1654 | } |
| 1655 | 1655 | |
| 1656 | 1656 | if ( ! empty( $Element['attributes'] ) ) { |
| 1657 | 1657 | foreach ( $Element['attributes'] as $att => $val ) { |
| 1658 | 1658 | // filter out badly parsed attribute |
| 1659 | 1659 | if ( ! preg_match( $goodAttribute, $att ) ) { |
| 1660 | - unset( $Element['attributes'][ $att ] ); |
|
| 1660 | + unset( $Element['attributes'][$att] ); |
|
| 1661 | 1661 | } |
| 1662 | 1662 | // dump onevent attribute |
| 1663 | 1663 | elseif ( self::striAtStart( $att, 'on' ) ) { |
| 1664 | - unset( $Element['attributes'][ $att ] ); |
|
| 1664 | + unset( $Element['attributes'][$att] ); |
|
| 1665 | 1665 | } |
| 1666 | 1666 | } |
| 1667 | 1667 | } |
@@ -1671,12 +1671,12 @@ discard block |
||
| 1671 | 1671 | |
| 1672 | 1672 | protected function filterUnsafeUrlInAttribute( array $Element, $attribute ) { |
| 1673 | 1673 | foreach ( $this->safeLinksWhitelist as $scheme ) { |
| 1674 | - if ( self::striAtStart( $Element['attributes'][ $attribute ], $scheme ) ) { |
|
| 1674 | + if ( self::striAtStart( $Element['attributes'][$attribute], $scheme ) ) { |
|
| 1675 | 1675 | return $Element; |
| 1676 | 1676 | } |
| 1677 | 1677 | } |
| 1678 | 1678 | |
| 1679 | - $Element['attributes'][ $attribute ] = str_replace( ':', '%3A', $Element['attributes'][ $attribute ] ); |
|
| 1679 | + $Element['attributes'][$attribute] = str_replace( ':', '%3A', $Element['attributes'][$attribute] ); |
|
| 1680 | 1680 | |
| 1681 | 1681 | return $Element; |
| 1682 | 1682 | } |
@@ -1700,13 +1700,13 @@ discard block |
||
| 1700 | 1700 | } |
| 1701 | 1701 | |
| 1702 | 1702 | static function instance( $name = 'default' ) { |
| 1703 | - if ( isset( self::$instances[ $name ] ) ) { |
|
| 1704 | - return self::$instances[ $name ]; |
|
| 1703 | + if ( isset( self::$instances[$name] ) ) { |
|
| 1704 | + return self::$instances[$name]; |
|
| 1705 | 1705 | } |
| 1706 | 1706 | |
| 1707 | 1707 | $instance = new static(); |
| 1708 | 1708 | |
| 1709 | - self::$instances[ $name ] = $instance; |
|
| 1709 | + self::$instances[$name] = $instance; |
|
| 1710 | 1710 | |
| 1711 | 1711 | return $instance; |
| 1712 | 1712 | } |