Index: trunk/phase3/includes/parser/Parser.php |
— | — | @@ -1112,36 +1112,21 @@ |
1113 | 1113 | * Helper function for doAllQuotes() |
1114 | 1114 | */ |
1115 | 1115 | public function doQuotes( $text ) { |
1116 | | - # Split in groups of 2, 3, 5 or 6 apostrophes. |
1117 | | - # If there are ever four apostrophes, assume the first is supposed to |
1118 | | - # be text, and the remaining three constitute mark-up for bold text. |
1119 | | - # If there are more than 6 apostrophes in a row, assume they're all |
1120 | | - # text except for the last 6. |
1121 | | - $arr = preg_split( "/('{2,3}(?:''')?)(?!')/", $text, -1, PREG_SPLIT_DELIM_CAPTURE ); |
| 1116 | + # Counts the number of occurrences of bold and italics mark-ups. |
| 1117 | + self::countBoldAndItalic($text, $numbold, $numitalics); |
1122 | 1118 | |
1123 | | - if ( count( $arr ) == 1 ) |
| 1119 | + if ( ( $numbold == 0 ) && ( $numitalics == 0 ) ) |
1124 | 1120 | return $text; |
1125 | 1121 | else |
1126 | 1122 | { |
1127 | | - # First, do some preliminary work. This may shift some apostrophes from |
1128 | | - # being mark-up to being text. It also counts the number of occurrences |
1129 | | - # of bold and italics mark-ups. |
1130 | | - $i = 0; |
1131 | | - $numbold = 0; |
1132 | | - $numitalics = 0; |
1133 | | - foreach ( $arr as $r ) |
1134 | | - { |
1135 | | - if ( ( $i % 2 ) == 1 ) |
1136 | | - { |
1137 | | - # Count the number of occurrences of bold and italics mark-ups. |
1138 | | - if ( strlen( $arr[$i] ) == 2 ) { $numitalics++; } |
1139 | | - elseif ( strlen( $arr[$i] ) == 3 ) { $numbold++; } |
1140 | | - elseif ( strlen( $arr[$i] ) == 5 ) { $numitalics++; $numbold++; } |
1141 | | - elseif ( strlen( $arr[$i] ) == 6 ) { $numbold+=2; } |
1142 | | - } |
1143 | | - $i++; |
1144 | | - } |
| 1123 | + # Split in groups of 2, 3, 5 or 6 apostrophes. |
| 1124 | + # If there are ever four apostrophes, assume the first is supposed to |
| 1125 | + # be text, and the remaining three constitute mark-up for bold text. |
| 1126 | + # If there are more than 6 apostrophes in a row, assume they're all |
| 1127 | + # text except for the last 6. |
| 1128 | + $arr = preg_split( "/('{2,3}(?:''')?)(?!')/", $text, -1, PREG_SPLIT_DELIM_CAPTURE ); |
1145 | 1129 | |
| 1130 | + |
1146 | 1131 | # If there is an odd number of both bold and italics, it is likely |
1147 | 1132 | # that one of the bold ones was meant to be an apostrophe followed |
1148 | 1133 | # by italics. Which one we cannot know for certain, but it is more |
— | — | @@ -1288,6 +1273,57 @@ |
1289 | 1274 | } |
1290 | 1275 | |
1291 | 1276 | /** |
| 1277 | + * Counts the number of bold and italic items from a line of text. |
| 1278 | + * Helper function for doQuotes() |
| 1279 | + */ |
| 1280 | + private static function countBoldAndItalic($text, &$numBold, &$numItalics) { |
| 1281 | + $numBold = 0; |
| 1282 | + $numItalics = 0; |
| 1283 | + $offset = 0; |
| 1284 | + |
| 1285 | + do { |
| 1286 | + $offset = strpos($text, "'", $offset); |
| 1287 | + if ($offset === false) |
| 1288 | + return; |
| 1289 | + |
| 1290 | + $quoteLen = strspn($text, "'", $offset); |
| 1291 | + $offset += $quoteLen; |
| 1292 | + |
| 1293 | + switch ($quoteLen) { |
| 1294 | + case 0: |
| 1295 | + case 1: |
| 1296 | + break; |
| 1297 | + |
| 1298 | + case 2: |
| 1299 | + $numItalics++; |
| 1300 | + break; |
| 1301 | + |
| 1302 | + case 3: |
| 1303 | + $numBold++; |
| 1304 | + break; |
| 1305 | + |
| 1306 | + case 4: |
| 1307 | + # If there are ever four apostrophes, assume the first is supposed to |
| 1308 | + # be text, and the remaining three constitute mark-up for bold text. |
| 1309 | + $numBold++; |
| 1310 | + $numItalics++; |
| 1311 | + break; |
| 1312 | + |
| 1313 | + case 5: |
| 1314 | + $numItalics++; |
| 1315 | + $numBold++; |
| 1316 | + break; |
| 1317 | + |
| 1318 | + case 6: |
| 1319 | + default: |
| 1320 | + # If there are more than 6 apostrophes in a row, assume they're all |
| 1321 | + # text except for the last 6. |
| 1322 | + $numBold+=2; |
| 1323 | + } |
| 1324 | + } while (true); |
| 1325 | + } |
| 1326 | + |
| 1327 | + /** |
1292 | 1328 | * Replace external links (REL) |
1293 | 1329 | * |
1294 | 1330 | * Note: this is all very hackish and the order of execution matters a lot. |