@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | restore_error_handler(); |
| 84 | 84 | |
| 85 | 85 | $body = $doc->getElementsByTagName('html')->item(0)-> // <html> |
| 86 | - getElementsByTagName('body')->item(0); // <body> |
|
| 86 | + getElementsByTagName('body')->item(0); // <body> |
|
| 87 | 87 | |
| 88 | 88 | $div = $body->getElementsByTagName('div')->item(0); // <div> |
| 89 | 89 | $tokens = array(); |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | if ($node->nodeType === XML_TEXT_NODE) { |
| 189 | 189 | $data = $this->getData($node); // Handle variable data property |
| 190 | 190 | if ($data !== null) { |
| 191 | - $tokens[] = $this->factory->createText($data); |
|
| 191 | + $tokens[] = $this->factory->createText($data); |
|
| 192 | 192 | } |
| 193 | 193 | return false; |
| 194 | 194 | } elseif ($node->nodeType === XML_CDATA_SECTION_NODE) { |
@@ -34,7 +34,7 @@ |
||
| 34 | 34 | $tokens = array(); |
| 35 | 35 | $this->tokenizeDOM( |
| 36 | 36 | $doc->getElementsByTagName('html')->item(0)-> // <html> |
| 37 | - getElementsByTagName('body')->item(0) // <body> |
|
| 37 | + getElementsByTagName('body')->item(0) // <body> |
|
| 38 | 38 | , |
| 39 | 39 | $tokens, $config |
| 40 | 40 | ); |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | // Install PSR-0-compatible class autoloader |
| 11 | 11 | spl_autoload_register(function($class){ |
| 12 | - require preg_replace('{\\\\|_(?!.*\\\\)}', DIRECTORY_SEPARATOR, ltrim($class, '\\')).'.php'; |
|
| 12 | + require preg_replace('{\\\\|_(?!.*\\\\)}', DIRECTORY_SEPARATOR, ltrim($class, '\\')).'.php'; |
|
| 13 | 13 | }); |
| 14 | 14 | |
| 15 | 15 | // Get SmartyPants and Markdown classes |
@@ -29,8 +29,8 @@ discard block |
||
| 29 | 29 | </head> |
| 30 | 30 | <body> |
| 31 | 31 | <?php |
| 32 | - # Put HTML content in the document |
|
| 33 | - echo $html; |
|
| 34 | - ?> |
|
| 32 | + # Put HTML content in the document |
|
| 33 | + echo $html; |
|
| 34 | + ?> |
|
| 35 | 35 | </body> |
| 36 | 36 | </html> |
@@ -19,303 +19,303 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | class SmartyPants { |
| 21 | 21 | |
| 22 | - ### Version ### |
|
| 23 | - |
|
| 24 | - const SMARTYPANTSLIB_VERSION = "1.8.1"; |
|
| 25 | - |
|
| 26 | - |
|
| 27 | - ### Presets |
|
| 28 | - |
|
| 29 | - # SmartyPants does nothing at all |
|
| 30 | - const ATTR_DO_NOTHING = 0; |
|
| 31 | - # "--" for em-dashes; no en-dash support |
|
| 32 | - const ATTR_EM_DASH = 1; |
|
| 33 | - # "---" for em-dashes; "--" for en-dashes |
|
| 34 | - const ATTR_LONG_EM_DASH_SHORT_EN = 2; |
|
| 35 | - # "--" for em-dashes; "---" for en-dashes |
|
| 36 | - const ATTR_SHORT_EM_DASH_LONG_EN = 3; |
|
| 37 | - # "--" for em-dashes; "---" for en-dashes |
|
| 38 | - const ATTR_STUPEFY = -1; |
|
| 39 | - |
|
| 40 | - # The default preset: ATTR_EM_DASH |
|
| 41 | - const ATTR_DEFAULT = SmartyPants::ATTR_EM_DASH; |
|
| 42 | - |
|
| 43 | - |
|
| 44 | - ### Standard Function Interface ### |
|
| 45 | - |
|
| 46 | - public static function defaultTransform($text, $attr = SmartyPants::ATTR_DEFAULT) { |
|
| 47 | - # |
|
| 48 | - # Initialize the parser and return the result of its transform method. |
|
| 49 | - # This will work fine for derived classes too. |
|
| 50 | - # |
|
| 51 | - # Take parser class on which this function was called. |
|
| 52 | - $parser_class = \get_called_class(); |
|
| 53 | - |
|
| 54 | - # try to take parser from the static parser list |
|
| 55 | - static $parser_list; |
|
| 56 | - $parser =& $parser_list[$parser_class][$attr]; |
|
| 57 | - |
|
| 58 | - # create the parser if not already set |
|
| 59 | - if (!$parser) |
|
| 60 | - $parser = new $parser_class($attr); |
|
| 61 | - |
|
| 62 | - # Transform text using parser. |
|
| 63 | - return $parser->transform($text); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - |
|
| 67 | - ### Configuration Variables ### |
|
| 68 | - |
|
| 69 | - # Partial regex for matching tags to skip |
|
| 70 | - public $tags_to_skip = 'pre|code|kbd|script|style|math'; |
|
| 71 | - |
|
| 72 | - # Options to specify which transformations to make: |
|
| 73 | - public $do_nothing = 0; # disable all transforms |
|
| 74 | - public $do_quotes = 0; |
|
| 75 | - public $do_backticks = 0; # 1 => double only, 2 => double & single |
|
| 76 | - public $do_dashes = 0; # 1, 2, or 3 for the three modes described above |
|
| 77 | - public $do_ellipses = 0; |
|
| 78 | - public $do_stupefy = 0; |
|
| 79 | - public $convert_quot = 0; # should we translate " entities into normal quotes? |
|
| 80 | - |
|
| 81 | - # Smart quote characters: |
|
| 82 | - # Opening and closing smart double-quotes. |
|
| 83 | - public $smart_doublequote_open = '“'; |
|
| 84 | - public $smart_doublequote_close = '”'; |
|
| 85 | - public $smart_singlequote_open = '‘'; |
|
| 86 | - public $smart_singlequote_close = '’'; # Also apostrophe. |
|
| 87 | - |
|
| 88 | - # ``Backtick quotes'' |
|
| 89 | - public $backtick_doublequote_open = '“'; // replacement for `` |
|
| 90 | - public $backtick_doublequote_close = '”'; // replacement for '' |
|
| 91 | - public $backtick_singlequote_open = '‘'; // replacement for ` |
|
| 92 | - public $backtick_singlequote_close = '’'; // replacement for ' (also apostrophe) |
|
| 93 | - |
|
| 94 | - # Other punctuation |
|
| 95 | - public $em_dash = '—'; |
|
| 96 | - public $en_dash = '–'; |
|
| 97 | - public $ellipsis = '…'; |
|
| 98 | - |
|
| 99 | - ### Parser Implementation ### |
|
| 100 | - |
|
| 101 | - public function __construct($attr = SmartyPants::ATTR_DEFAULT) { |
|
| 102 | - # |
|
| 103 | - # Initialize a parser with certain attributes. |
|
| 104 | - # |
|
| 105 | - # Parser attributes: |
|
| 106 | - # 0 : do nothing |
|
| 107 | - # 1 : set all |
|
| 108 | - # 2 : set all, using old school en- and em- dash shortcuts |
|
| 109 | - # 3 : set all, using inverted old school en and em- dash shortcuts |
|
| 110 | - # |
|
| 111 | - # q : quotes |
|
| 112 | - # b : backtick quotes (``double'' only) |
|
| 113 | - # B : backtick quotes (``double'' and `single') |
|
| 114 | - # d : dashes |
|
| 115 | - # D : old school dashes |
|
| 116 | - # i : inverted old school dashes |
|
| 117 | - # e : ellipses |
|
| 118 | - # w : convert " entities to " for Dreamweaver users |
|
| 119 | - # |
|
| 120 | - if ($attr == "0") { |
|
| 121 | - $this->do_nothing = 1; |
|
| 122 | - } |
|
| 123 | - else if ($attr == "1") { |
|
| 124 | - # Do everything, turn all options on. |
|
| 125 | - $this->do_quotes = 1; |
|
| 126 | - $this->do_backticks = 1; |
|
| 127 | - $this->do_dashes = 1; |
|
| 128 | - $this->do_ellipses = 1; |
|
| 129 | - } |
|
| 130 | - else if ($attr == "2") { |
|
| 131 | - # Do everything, turn all options on, use old school dash shorthand. |
|
| 132 | - $this->do_quotes = 1; |
|
| 133 | - $this->do_backticks = 1; |
|
| 134 | - $this->do_dashes = 2; |
|
| 135 | - $this->do_ellipses = 1; |
|
| 136 | - } |
|
| 137 | - else if ($attr == "3") { |
|
| 138 | - # Do everything, turn all options on, use inverted old school dash shorthand. |
|
| 139 | - $this->do_quotes = 1; |
|
| 140 | - $this->do_backticks = 1; |
|
| 141 | - $this->do_dashes = 3; |
|
| 142 | - $this->do_ellipses = 1; |
|
| 143 | - } |
|
| 144 | - else if ($attr == "-1") { |
|
| 145 | - # Special "stupefy" mode. |
|
| 146 | - $this->do_stupefy = 1; |
|
| 147 | - } |
|
| 148 | - else { |
|
| 149 | - $chars = preg_split('//', $attr); |
|
| 150 | - foreach ($chars as $c){ |
|
| 151 | - if ($c == "q") { $this->do_quotes = 1; } |
|
| 152 | - else if ($c == "b") { $this->do_backticks = 1; } |
|
| 153 | - else if ($c == "B") { $this->do_backticks = 2; } |
|
| 154 | - else if ($c == "d") { $this->do_dashes = 1; } |
|
| 155 | - else if ($c == "D") { $this->do_dashes = 2; } |
|
| 156 | - else if ($c == "i") { $this->do_dashes = 3; } |
|
| 157 | - else if ($c == "e") { $this->do_ellipses = 1; } |
|
| 158 | - else if ($c == "w") { $this->convert_quot = 1; } |
|
| 159 | - else { |
|
| 160 | - # Unknown attribute option, ignore. |
|
| 161 | - } |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - public function transform($text) { |
|
| 167 | - |
|
| 168 | - if ($this->do_nothing) { |
|
| 169 | - return $text; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - $tokens = $this->tokenizeHTML($text); |
|
| 173 | - $result = ''; |
|
| 174 | - $in_pre = 0; # Keep track of when we're inside <pre> or <code> tags. |
|
| 175 | - |
|
| 176 | - $prev_token_last_char = ""; # This is a cheat, used to get some context |
|
| 177 | - # for one-character tokens that consist of |
|
| 178 | - # just a quote char. What we do is remember |
|
| 179 | - # the last character of the previous text |
|
| 180 | - # token, to use as context to curl single- |
|
| 181 | - # character quote tokens correctly. |
|
| 182 | - |
|
| 183 | - foreach ($tokens as $cur_token) { |
|
| 184 | - if ($cur_token[0] == "tag") { |
|
| 185 | - # Don't mess with quotes inside tags. |
|
| 186 | - $result .= $cur_token[1]; |
|
| 187 | - if (preg_match('@<(/?)(?:'.$this->tags_to_skip.')[\s>]@', $cur_token[1], $matches)) { |
|
| 188 | - $in_pre = isset($matches[1]) && $matches[1] == '/' ? 0 : 1; |
|
| 189 | - } |
|
| 190 | - } else { |
|
| 191 | - $t = $cur_token[1]; |
|
| 192 | - $last_char = substr($t, -1); # Remember last char of this token before processing. |
|
| 193 | - if (! $in_pre) { |
|
| 194 | - $t = $this->educate($t, $prev_token_last_char); |
|
| 195 | - } |
|
| 196 | - $prev_token_last_char = $last_char; |
|
| 197 | - $result .= $t; |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - return $result; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - |
|
| 205 | - function decodeEntitiesInConfiguration() { |
|
| 206 | - # |
|
| 207 | - # Utility function that converts entities in configuration variables to |
|
| 208 | - # UTF-8 characters. |
|
| 209 | - # |
|
| 210 | - $output_config_vars = array( |
|
| 211 | - 'smart_doublequote_open', |
|
| 212 | - 'smart_doublequote_close', |
|
| 213 | - 'smart_singlequote_open', |
|
| 214 | - 'smart_singlequote_close', |
|
| 215 | - 'backtick_doublequote_open', |
|
| 216 | - 'backtick_doublequote_close', |
|
| 217 | - 'backtick_singlequote_open', |
|
| 218 | - 'backtick_singlequote_close', |
|
| 219 | - 'em_dash', |
|
| 220 | - 'en_dash', |
|
| 221 | - 'ellipsis', |
|
| 222 | - ); |
|
| 223 | - foreach ($output_config_vars as $var) { |
|
| 224 | - $this->$var = html_entity_decode($this->$var); |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - |
|
| 229 | - protected function educate($t, $prev_token_last_char) { |
|
| 230 | - $t = $this->processEscapes($t); |
|
| 231 | - |
|
| 232 | - if ($this->convert_quot) { |
|
| 233 | - $t = preg_replace('/"/', '"', $t); |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - if ($this->do_dashes) { |
|
| 237 | - if ($this->do_dashes == 1) $t = $this->educateDashes($t); |
|
| 238 | - if ($this->do_dashes == 2) $t = $this->educateDashesOldSchool($t); |
|
| 239 | - if ($this->do_dashes == 3) $t = $this->educateDashesOldSchoolInverted($t); |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - if ($this->do_ellipses) $t = $this->educateEllipses($t); |
|
| 243 | - |
|
| 244 | - # Note: backticks need to be processed before quotes. |
|
| 245 | - if ($this->do_backticks) { |
|
| 246 | - $t = $this->educateBackticks($t); |
|
| 247 | - if ($this->do_backticks == 2) $t = $this->educateSingleBackticks($t); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - if ($this->do_quotes) { |
|
| 251 | - if ($t == "'") { |
|
| 252 | - # Special case: single-character ' token |
|
| 253 | - if (preg_match('/\S/', $prev_token_last_char)) { |
|
| 254 | - $t = $this->smart_singlequote_close; |
|
| 255 | - } |
|
| 256 | - else { |
|
| 257 | - $t = $this->smart_singlequote_open; |
|
| 258 | - } |
|
| 259 | - } |
|
| 260 | - else if ($t == '"') { |
|
| 261 | - # Special case: single-character " token |
|
| 262 | - if (preg_match('/\S/', $prev_token_last_char)) { |
|
| 263 | - $t = $this->smart_doublequote_close; |
|
| 264 | - } |
|
| 265 | - else { |
|
| 266 | - $t = $this->smart_doublequote_open; |
|
| 267 | - } |
|
| 268 | - } |
|
| 269 | - else { |
|
| 270 | - # Normal case: |
|
| 271 | - $t = $this->educateQuotes($t); |
|
| 272 | - } |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - if ($this->do_stupefy) $t = $this->stupefyEntities($t); |
|
| 22 | + ### Version ### |
|
| 23 | + |
|
| 24 | + const SMARTYPANTSLIB_VERSION = "1.8.1"; |
|
| 25 | + |
|
| 26 | + |
|
| 27 | + ### Presets |
|
| 28 | + |
|
| 29 | + # SmartyPants does nothing at all |
|
| 30 | + const ATTR_DO_NOTHING = 0; |
|
| 31 | + # "--" for em-dashes; no en-dash support |
|
| 32 | + const ATTR_EM_DASH = 1; |
|
| 33 | + # "---" for em-dashes; "--" for en-dashes |
|
| 34 | + const ATTR_LONG_EM_DASH_SHORT_EN = 2; |
|
| 35 | + # "--" for em-dashes; "---" for en-dashes |
|
| 36 | + const ATTR_SHORT_EM_DASH_LONG_EN = 3; |
|
| 37 | + # "--" for em-dashes; "---" for en-dashes |
|
| 38 | + const ATTR_STUPEFY = -1; |
|
| 39 | + |
|
| 40 | + # The default preset: ATTR_EM_DASH |
|
| 41 | + const ATTR_DEFAULT = SmartyPants::ATTR_EM_DASH; |
|
| 42 | + |
|
| 43 | + |
|
| 44 | + ### Standard Function Interface ### |
|
| 45 | + |
|
| 46 | + public static function defaultTransform($text, $attr = SmartyPants::ATTR_DEFAULT) { |
|
| 47 | + # |
|
| 48 | + # Initialize the parser and return the result of its transform method. |
|
| 49 | + # This will work fine for derived classes too. |
|
| 50 | + # |
|
| 51 | + # Take parser class on which this function was called. |
|
| 52 | + $parser_class = \get_called_class(); |
|
| 53 | + |
|
| 54 | + # try to take parser from the static parser list |
|
| 55 | + static $parser_list; |
|
| 56 | + $parser =& $parser_list[$parser_class][$attr]; |
|
| 57 | + |
|
| 58 | + # create the parser if not already set |
|
| 59 | + if (!$parser) |
|
| 60 | + $parser = new $parser_class($attr); |
|
| 61 | + |
|
| 62 | + # Transform text using parser. |
|
| 63 | + return $parser->transform($text); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + |
|
| 67 | + ### Configuration Variables ### |
|
| 68 | + |
|
| 69 | + # Partial regex for matching tags to skip |
|
| 70 | + public $tags_to_skip = 'pre|code|kbd|script|style|math'; |
|
| 71 | + |
|
| 72 | + # Options to specify which transformations to make: |
|
| 73 | + public $do_nothing = 0; # disable all transforms |
|
| 74 | + public $do_quotes = 0; |
|
| 75 | + public $do_backticks = 0; # 1 => double only, 2 => double & single |
|
| 76 | + public $do_dashes = 0; # 1, 2, or 3 for the three modes described above |
|
| 77 | + public $do_ellipses = 0; |
|
| 78 | + public $do_stupefy = 0; |
|
| 79 | + public $convert_quot = 0; # should we translate " entities into normal quotes? |
|
| 80 | + |
|
| 81 | + # Smart quote characters: |
|
| 82 | + # Opening and closing smart double-quotes. |
|
| 83 | + public $smart_doublequote_open = '“'; |
|
| 84 | + public $smart_doublequote_close = '”'; |
|
| 85 | + public $smart_singlequote_open = '‘'; |
|
| 86 | + public $smart_singlequote_close = '’'; # Also apostrophe. |
|
| 87 | + |
|
| 88 | + # ``Backtick quotes'' |
|
| 89 | + public $backtick_doublequote_open = '“'; // replacement for `` |
|
| 90 | + public $backtick_doublequote_close = '”'; // replacement for '' |
|
| 91 | + public $backtick_singlequote_open = '‘'; // replacement for ` |
|
| 92 | + public $backtick_singlequote_close = '’'; // replacement for ' (also apostrophe) |
|
| 93 | + |
|
| 94 | + # Other punctuation |
|
| 95 | + public $em_dash = '—'; |
|
| 96 | + public $en_dash = '–'; |
|
| 97 | + public $ellipsis = '…'; |
|
| 98 | + |
|
| 99 | + ### Parser Implementation ### |
|
| 100 | + |
|
| 101 | + public function __construct($attr = SmartyPants::ATTR_DEFAULT) { |
|
| 102 | + # |
|
| 103 | + # Initialize a parser with certain attributes. |
|
| 104 | + # |
|
| 105 | + # Parser attributes: |
|
| 106 | + # 0 : do nothing |
|
| 107 | + # 1 : set all |
|
| 108 | + # 2 : set all, using old school en- and em- dash shortcuts |
|
| 109 | + # 3 : set all, using inverted old school en and em- dash shortcuts |
|
| 110 | + # |
|
| 111 | + # q : quotes |
|
| 112 | + # b : backtick quotes (``double'' only) |
|
| 113 | + # B : backtick quotes (``double'' and `single') |
|
| 114 | + # d : dashes |
|
| 115 | + # D : old school dashes |
|
| 116 | + # i : inverted old school dashes |
|
| 117 | + # e : ellipses |
|
| 118 | + # w : convert " entities to " for Dreamweaver users |
|
| 119 | + # |
|
| 120 | + if ($attr == "0") { |
|
| 121 | + $this->do_nothing = 1; |
|
| 122 | + } |
|
| 123 | + else if ($attr == "1") { |
|
| 124 | + # Do everything, turn all options on. |
|
| 125 | + $this->do_quotes = 1; |
|
| 126 | + $this->do_backticks = 1; |
|
| 127 | + $this->do_dashes = 1; |
|
| 128 | + $this->do_ellipses = 1; |
|
| 129 | + } |
|
| 130 | + else if ($attr == "2") { |
|
| 131 | + # Do everything, turn all options on, use old school dash shorthand. |
|
| 132 | + $this->do_quotes = 1; |
|
| 133 | + $this->do_backticks = 1; |
|
| 134 | + $this->do_dashes = 2; |
|
| 135 | + $this->do_ellipses = 1; |
|
| 136 | + } |
|
| 137 | + else if ($attr == "3") { |
|
| 138 | + # Do everything, turn all options on, use inverted old school dash shorthand. |
|
| 139 | + $this->do_quotes = 1; |
|
| 140 | + $this->do_backticks = 1; |
|
| 141 | + $this->do_dashes = 3; |
|
| 142 | + $this->do_ellipses = 1; |
|
| 143 | + } |
|
| 144 | + else if ($attr == "-1") { |
|
| 145 | + # Special "stupefy" mode. |
|
| 146 | + $this->do_stupefy = 1; |
|
| 147 | + } |
|
| 148 | + else { |
|
| 149 | + $chars = preg_split('//', $attr); |
|
| 150 | + foreach ($chars as $c){ |
|
| 151 | + if ($c == "q") { $this->do_quotes = 1; } |
|
| 152 | + else if ($c == "b") { $this->do_backticks = 1; } |
|
| 153 | + else if ($c == "B") { $this->do_backticks = 2; } |
|
| 154 | + else if ($c == "d") { $this->do_dashes = 1; } |
|
| 155 | + else if ($c == "D") { $this->do_dashes = 2; } |
|
| 156 | + else if ($c == "i") { $this->do_dashes = 3; } |
|
| 157 | + else if ($c == "e") { $this->do_ellipses = 1; } |
|
| 158 | + else if ($c == "w") { $this->convert_quot = 1; } |
|
| 159 | + else { |
|
| 160 | + # Unknown attribute option, ignore. |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + public function transform($text) { |
|
| 167 | + |
|
| 168 | + if ($this->do_nothing) { |
|
| 169 | + return $text; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + $tokens = $this->tokenizeHTML($text); |
|
| 173 | + $result = ''; |
|
| 174 | + $in_pre = 0; # Keep track of when we're inside <pre> or <code> tags. |
|
| 175 | + |
|
| 176 | + $prev_token_last_char = ""; # This is a cheat, used to get some context |
|
| 177 | + # for one-character tokens that consist of |
|
| 178 | + # just a quote char. What we do is remember |
|
| 179 | + # the last character of the previous text |
|
| 180 | + # token, to use as context to curl single- |
|
| 181 | + # character quote tokens correctly. |
|
| 182 | + |
|
| 183 | + foreach ($tokens as $cur_token) { |
|
| 184 | + if ($cur_token[0] == "tag") { |
|
| 185 | + # Don't mess with quotes inside tags. |
|
| 186 | + $result .= $cur_token[1]; |
|
| 187 | + if (preg_match('@<(/?)(?:'.$this->tags_to_skip.')[\s>]@', $cur_token[1], $matches)) { |
|
| 188 | + $in_pre = isset($matches[1]) && $matches[1] == '/' ? 0 : 1; |
|
| 189 | + } |
|
| 190 | + } else { |
|
| 191 | + $t = $cur_token[1]; |
|
| 192 | + $last_char = substr($t, -1); # Remember last char of this token before processing. |
|
| 193 | + if (! $in_pre) { |
|
| 194 | + $t = $this->educate($t, $prev_token_last_char); |
|
| 195 | + } |
|
| 196 | + $prev_token_last_char = $last_char; |
|
| 197 | + $result .= $t; |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + return $result; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + |
|
| 205 | + function decodeEntitiesInConfiguration() { |
|
| 206 | + # |
|
| 207 | + # Utility function that converts entities in configuration variables to |
|
| 208 | + # UTF-8 characters. |
|
| 209 | + # |
|
| 210 | + $output_config_vars = array( |
|
| 211 | + 'smart_doublequote_open', |
|
| 212 | + 'smart_doublequote_close', |
|
| 213 | + 'smart_singlequote_open', |
|
| 214 | + 'smart_singlequote_close', |
|
| 215 | + 'backtick_doublequote_open', |
|
| 216 | + 'backtick_doublequote_close', |
|
| 217 | + 'backtick_singlequote_open', |
|
| 218 | + 'backtick_singlequote_close', |
|
| 219 | + 'em_dash', |
|
| 220 | + 'en_dash', |
|
| 221 | + 'ellipsis', |
|
| 222 | + ); |
|
| 223 | + foreach ($output_config_vars as $var) { |
|
| 224 | + $this->$var = html_entity_decode($this->$var); |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + |
|
| 229 | + protected function educate($t, $prev_token_last_char) { |
|
| 230 | + $t = $this->processEscapes($t); |
|
| 231 | + |
|
| 232 | + if ($this->convert_quot) { |
|
| 233 | + $t = preg_replace('/"/', '"', $t); |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + if ($this->do_dashes) { |
|
| 237 | + if ($this->do_dashes == 1) $t = $this->educateDashes($t); |
|
| 238 | + if ($this->do_dashes == 2) $t = $this->educateDashesOldSchool($t); |
|
| 239 | + if ($this->do_dashes == 3) $t = $this->educateDashesOldSchoolInverted($t); |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + if ($this->do_ellipses) $t = $this->educateEllipses($t); |
|
| 243 | + |
|
| 244 | + # Note: backticks need to be processed before quotes. |
|
| 245 | + if ($this->do_backticks) { |
|
| 246 | + $t = $this->educateBackticks($t); |
|
| 247 | + if ($this->do_backticks == 2) $t = $this->educateSingleBackticks($t); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + if ($this->do_quotes) { |
|
| 251 | + if ($t == "'") { |
|
| 252 | + # Special case: single-character ' token |
|
| 253 | + if (preg_match('/\S/', $prev_token_last_char)) { |
|
| 254 | + $t = $this->smart_singlequote_close; |
|
| 255 | + } |
|
| 256 | + else { |
|
| 257 | + $t = $this->smart_singlequote_open; |
|
| 258 | + } |
|
| 259 | + } |
|
| 260 | + else if ($t == '"') { |
|
| 261 | + # Special case: single-character " token |
|
| 262 | + if (preg_match('/\S/', $prev_token_last_char)) { |
|
| 263 | + $t = $this->smart_doublequote_close; |
|
| 264 | + } |
|
| 265 | + else { |
|
| 266 | + $t = $this->smart_doublequote_open; |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | + else { |
|
| 270 | + # Normal case: |
|
| 271 | + $t = $this->educateQuotes($t); |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + if ($this->do_stupefy) $t = $this->stupefyEntities($t); |
|
| 276 | 276 | |
| 277 | - return $t; |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - |
|
| 281 | - protected function educateQuotes($_) { |
|
| 282 | - # |
|
| 283 | - # Parameter: String. |
|
| 284 | - # |
|
| 285 | - # Returns: The string, with "educated" curly quote HTML entities. |
|
| 286 | - # |
|
| 287 | - # Example input: "Isn't this fun?" |
|
| 288 | - # Example output: “Isn’t this fun?” |
|
| 289 | - # |
|
| 290 | - $dq_open = $this->smart_doublequote_open; |
|
| 291 | - $dq_close = $this->smart_doublequote_close; |
|
| 292 | - $sq_open = $this->smart_singlequote_open; |
|
| 293 | - $sq_close = $this->smart_singlequote_close; |
|
| 277 | + return $t; |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + |
|
| 281 | + protected function educateQuotes($_) { |
|
| 282 | + # |
|
| 283 | + # Parameter: String. |
|
| 284 | + # |
|
| 285 | + # Returns: The string, with "educated" curly quote HTML entities. |
|
| 286 | + # |
|
| 287 | + # Example input: "Isn't this fun?" |
|
| 288 | + # Example output: “Isn’t this fun?” |
|
| 289 | + # |
|
| 290 | + $dq_open = $this->smart_doublequote_open; |
|
| 291 | + $dq_close = $this->smart_doublequote_close; |
|
| 292 | + $sq_open = $this->smart_singlequote_open; |
|
| 293 | + $sq_close = $this->smart_singlequote_close; |
|
| 294 | 294 | |
| 295 | - # Make our own "punctuation" character class, because the POSIX-style |
|
| 296 | - # [:PUNCT:] is only available in Perl 5.6 or later: |
|
| 297 | - $punct_class = "[!\"#\\$\\%'()*+,-.\\/:;<=>?\\@\\[\\\\\]\\^_`{|}~]"; |
|
| 298 | - |
|
| 299 | - # Special case if the very first character is a quote |
|
| 300 | - # followed by punctuation at a non-word-break. Close the quotes by brute force: |
|
| 301 | - $_ = preg_replace( |
|
| 302 | - array("/^'(?=$punct_class\\B)/", "/^\"(?=$punct_class\\B)/"), |
|
| 303 | - array($sq_close, $dq_close), $_); |
|
| 304 | - |
|
| 305 | - # Special case for double sets of quotes, e.g.: |
|
| 306 | - # <p>He said, "'Quoted' words in a larger quote."</p> |
|
| 307 | - $_ = preg_replace( |
|
| 308 | - array("/\"'(?=\w)/", "/'\"(?=\w)/"), |
|
| 309 | - array($dq_open.$sq_open, $sq_open.$dq_open), $_); |
|
| 310 | - |
|
| 311 | - # Special case for decade abbreviations (the '80s): |
|
| 312 | - $_ = preg_replace("/'(?=\\d{2}s)/", $sq_close, $_); |
|
| 313 | - |
|
| 314 | - $close_class = '[^\ \t\r\n\[\{\(\-]'; |
|
| 315 | - $dec_dashes = '&\#8211;|&\#8212;'; |
|
| 316 | - |
|
| 317 | - # Get most opening single quotes: |
|
| 318 | - $_ = preg_replace("{ |
|
| 295 | + # Make our own "punctuation" character class, because the POSIX-style |
|
| 296 | + # [:PUNCT:] is only available in Perl 5.6 or later: |
|
| 297 | + $punct_class = "[!\"#\\$\\%'()*+,-.\\/:;<=>?\\@\\[\\\\\]\\^_`{|}~]"; |
|
| 298 | + |
|
| 299 | + # Special case if the very first character is a quote |
|
| 300 | + # followed by punctuation at a non-word-break. Close the quotes by brute force: |
|
| 301 | + $_ = preg_replace( |
|
| 302 | + array("/^'(?=$punct_class\\B)/", "/^\"(?=$punct_class\\B)/"), |
|
| 303 | + array($sq_close, $dq_close), $_); |
|
| 304 | + |
|
| 305 | + # Special case for double sets of quotes, e.g.: |
|
| 306 | + # <p>He said, "'Quoted' words in a larger quote."</p> |
|
| 307 | + $_ = preg_replace( |
|
| 308 | + array("/\"'(?=\w)/", "/'\"(?=\w)/"), |
|
| 309 | + array($dq_open.$sq_open, $sq_open.$dq_open), $_); |
|
| 310 | + |
|
| 311 | + # Special case for decade abbreviations (the '80s): |
|
| 312 | + $_ = preg_replace("/'(?=\\d{2}s)/", $sq_close, $_); |
|
| 313 | + |
|
| 314 | + $close_class = '[^\ \t\r\n\[\{\(\-]'; |
|
| 315 | + $dec_dashes = '&\#8211;|&\#8212;'; |
|
| 316 | + |
|
| 317 | + # Get most opening single quotes: |
|
| 318 | + $_ = preg_replace("{ |
|
| 319 | 319 | ( |
| 320 | 320 | \\s | # a whitespace char, or |
| 321 | 321 | | # a non-breaking space entity, or |
@@ -327,8 +327,8 @@ discard block |
||
| 327 | 327 | ' # the quote |
| 328 | 328 | (?=\\w) # followed by a word character |
| 329 | 329 | }x", '\1'.$sq_open, $_); |
| 330 | - # Single closing quotes: |
|
| 331 | - $_ = preg_replace("{ |
|
| 330 | + # Single closing quotes: |
|
| 331 | + $_ = preg_replace("{ |
|
| 332 | 332 | ($close_class)? |
| 333 | 333 | ' |
| 334 | 334 | (?(1)| # If $1 captured, then do nothing; |
@@ -338,12 +338,12 @@ discard block |
||
| 338 | 338 | # \"<i>Custer</i>'s Last Stand.\" |
| 339 | 339 | }xi", '\1'.$sq_close, $_); |
| 340 | 340 | |
| 341 | - # Any remaining single quotes should be opening ones: |
|
| 342 | - $_ = str_replace("'", $sq_open, $_); |
|
| 341 | + # Any remaining single quotes should be opening ones: |
|
| 342 | + $_ = str_replace("'", $sq_open, $_); |
|
| 343 | 343 | |
| 344 | 344 | |
| 345 | - # Get most opening double quotes: |
|
| 346 | - $_ = preg_replace("{ |
|
| 345 | + # Get most opening double quotes: |
|
| 346 | + $_ = preg_replace("{ |
|
| 347 | 347 | ( |
| 348 | 348 | \\s | # a whitespace char, or |
| 349 | 349 | | # a non-breaking space entity, or |
@@ -356,205 +356,205 @@ discard block |
||
| 356 | 356 | (?=\\w) # followed by a word character |
| 357 | 357 | }x", '\1'.$dq_open, $_); |
| 358 | 358 | |
| 359 | - # Double closing quotes: |
|
| 360 | - $_ = preg_replace("{ |
|
| 359 | + # Double closing quotes: |
|
| 360 | + $_ = preg_replace("{ |
|
| 361 | 361 | ($close_class)? |
| 362 | 362 | \" |
| 363 | 363 | (?(1)|(?=\\s)) # If $1 captured, then do nothing; |
| 364 | 364 | # if not, then make sure the next char is whitespace. |
| 365 | 365 | }x", '\1'.$dq_close, $_); |
| 366 | 366 | |
| 367 | - # Any remaining quotes should be opening ones. |
|
| 368 | - $_ = str_replace('"', $dq_open, $_); |
|
| 369 | - |
|
| 370 | - return $_; |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - |
|
| 374 | - protected function educateBackticks($_) { |
|
| 375 | - # |
|
| 376 | - # Parameter: String. |
|
| 377 | - # Returns: The string, with ``backticks'' -style double quotes |
|
| 378 | - # translated into HTML curly quote entities. |
|
| 379 | - # |
|
| 380 | - # Example input: ``Isn't this fun?'' |
|
| 381 | - # Example output: “Isn't this fun?” |
|
| 382 | - # |
|
| 383 | - |
|
| 384 | - $_ = str_replace(array("``", "''",), |
|
| 385 | - array($this->backtick_doublequote_open, |
|
| 386 | - $this->backtick_doublequote_close), $_); |
|
| 387 | - return $_; |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - |
|
| 391 | - protected function educateSingleBackticks($_) { |
|
| 392 | - # |
|
| 393 | - # Parameter: String. |
|
| 394 | - # Returns: The string, with `backticks' -style single quotes |
|
| 395 | - # translated into HTML curly quote entities. |
|
| 396 | - # |
|
| 397 | - # Example input: `Isn't this fun?' |
|
| 398 | - # Example output: ‘Isn’t this fun?’ |
|
| 399 | - # |
|
| 400 | - |
|
| 401 | - $_ = str_replace(array("`", "'",), |
|
| 402 | - array($this->backtick_singlequote_open, |
|
| 403 | - $this->backtick_singlequote_close), $_); |
|
| 404 | - return $_; |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - |
|
| 408 | - protected function educateDashes($_) { |
|
| 409 | - # |
|
| 410 | - # Parameter: String. |
|
| 411 | - # |
|
| 412 | - # Returns: The string, with each instance of "--" translated to |
|
| 413 | - # an em-dash HTML entity. |
|
| 414 | - # |
|
| 415 | - |
|
| 416 | - $_ = str_replace('--', $this->em_dash, $_); |
|
| 417 | - return $_; |
|
| 418 | - } |
|
| 419 | - |
|
| 420 | - |
|
| 421 | - protected function educateDashesOldSchool($_) { |
|
| 422 | - # |
|
| 423 | - # Parameter: String. |
|
| 424 | - # |
|
| 425 | - # Returns: The string, with each instance of "--" translated to |
|
| 426 | - # an en-dash HTML entity, and each "---" translated to |
|
| 427 | - # an em-dash HTML entity. |
|
| 428 | - # |
|
| 429 | - |
|
| 430 | - # em en |
|
| 431 | - $_ = str_replace(array("---", "--",), |
|
| 432 | - array($this->em_dash, $this->en_dash), $_); |
|
| 433 | - return $_; |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - |
|
| 437 | - protected function educateDashesOldSchoolInverted($_) { |
|
| 438 | - # |
|
| 439 | - # Parameter: String. |
|
| 440 | - # |
|
| 441 | - # Returns: The string, with each instance of "--" translated to |
|
| 442 | - # an em-dash HTML entity, and each "---" translated to |
|
| 443 | - # an en-dash HTML entity. Two reasons why: First, unlike the |
|
| 444 | - # en- and em-dash syntax supported by |
|
| 445 | - # EducateDashesOldSchool(), it's compatible with existing |
|
| 446 | - # entries written before SmartyPants 1.1, back when "--" was |
|
| 447 | - # only used for em-dashes. Second, em-dashes are more |
|
| 448 | - # common than en-dashes, and so it sort of makes sense that |
|
| 449 | - # the shortcut should be shorter to type. (Thanks to Aaron |
|
| 450 | - # Swartz for the idea.) |
|
| 451 | - # |
|
| 452 | - |
|
| 453 | - # en em |
|
| 454 | - $_ = str_replace(array("---", "--",), |
|
| 455 | - array($this->en_dash, $this->em_dash), $_); |
|
| 456 | - return $_; |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - |
|
| 460 | - protected function educateEllipses($_) { |
|
| 461 | - # |
|
| 462 | - # Parameter: String. |
|
| 463 | - # Returns: The string, with each instance of "..." translated to |
|
| 464 | - # an ellipsis HTML entity. Also converts the case where |
|
| 465 | - # there are spaces between the dots. |
|
| 466 | - # |
|
| 467 | - # Example input: Huh...? |
|
| 468 | - # Example output: Huh…? |
|
| 469 | - # |
|
| 470 | - |
|
| 471 | - $_ = str_replace(array("...", ". . .",), $this->ellipsis, $_); |
|
| 472 | - return $_; |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - |
|
| 476 | - protected function stupefyEntities($_) { |
|
| 477 | - # |
|
| 478 | - # Parameter: String. |
|
| 479 | - # Returns: The string, with each SmartyPants HTML entity translated to |
|
| 480 | - # its ASCII counterpart. |
|
| 481 | - # |
|
| 482 | - # Example input: “Hello — world.” |
|
| 483 | - # Example output: "Hello -- world." |
|
| 484 | - # |
|
| 485 | - |
|
| 486 | - # en-dash em-dash |
|
| 487 | - $_ = str_replace(array('–', '—'), |
|
| 488 | - array('-', '--'), $_); |
|
| 489 | - |
|
| 490 | - # single quote open close |
|
| 491 | - $_ = str_replace(array('‘', '’'), "'", $_); |
|
| 492 | - |
|
| 493 | - # double quote open close |
|
| 494 | - $_ = str_replace(array('“', '”'), '"', $_); |
|
| 495 | - |
|
| 496 | - $_ = str_replace('…', '...', $_); # ellipsis |
|
| 497 | - |
|
| 498 | - return $_; |
|
| 499 | - } |
|
| 500 | - |
|
| 501 | - |
|
| 502 | - protected function processEscapes($_) { |
|
| 503 | - # |
|
| 504 | - # Parameter: String. |
|
| 505 | - # Returns: The string, with after processing the following backslash |
|
| 506 | - # escape sequences. This is useful if you want to force a "dumb" |
|
| 507 | - # quote or other character to appear. |
|
| 508 | - # |
|
| 509 | - # Escape Value |
|
| 510 | - # ------ ----- |
|
| 511 | - # \\ \ |
|
| 512 | - # \" " |
|
| 513 | - # \' ' |
|
| 514 | - # \. . |
|
| 515 | - # \- - |
|
| 516 | - # \` ` |
|
| 517 | - # |
|
| 518 | - $_ = str_replace( |
|
| 519 | - array('\\\\', '\"', "\'", '\.', '\-', '\`'), |
|
| 520 | - array('\', '"', ''', '.', '-', '`'), $_); |
|
| 521 | - |
|
| 522 | - return $_; |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - |
|
| 526 | - protected function tokenizeHTML($str) { |
|
| 527 | - # |
|
| 528 | - # Parameter: String containing HTML markup. |
|
| 529 | - # Returns: An array of the tokens comprising the input |
|
| 530 | - # string. Each token is either a tag (possibly with nested, |
|
| 531 | - # tags contained therein, such as <a href="<MTFoo>">, or a |
|
| 532 | - # run of text between tags. Each element of the array is a |
|
| 533 | - # two-element array; the first is either 'tag' or 'text'; |
|
| 534 | - # the second is the actual value. |
|
| 535 | - # |
|
| 536 | - # |
|
| 537 | - # Regular expression derived from the _tokenize() subroutine in |
|
| 538 | - # Brad Choate's MTRegex plugin. |
|
| 539 | - # <http://www.bradchoate.com/past/mtregex.php> |
|
| 540 | - # |
|
| 541 | - $index = 0; |
|
| 542 | - $tokens = array(); |
|
| 543 | - |
|
| 544 | - $match = '(?s:<!--.*?-->)|'. # comment |
|
| 545 | - '(?s:<\?.*?\?>)|'. # processing instruction |
|
| 546 | - # regular tags |
|
| 547 | - '(?:<[/!$]?[-a-zA-Z0-9:]+\b(?>[^"\'>]+|"[^"]*"|\'[^\']*\')*>)'; |
|
| 548 | - |
|
| 549 | - $parts = preg_split("{($match)}", $str, -1, PREG_SPLIT_DELIM_CAPTURE); |
|
| 550 | - |
|
| 551 | - foreach ($parts as $part) { |
|
| 552 | - if (++$index % 2 && $part != '') |
|
| 553 | - $tokens[] = array('text', $part); |
|
| 554 | - else |
|
| 555 | - $tokens[] = array('tag', $part); |
|
| 556 | - } |
|
| 557 | - return $tokens; |
|
| 558 | - } |
|
| 367 | + # Any remaining quotes should be opening ones. |
|
| 368 | + $_ = str_replace('"', $dq_open, $_); |
|
| 369 | + |
|
| 370 | + return $_; |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + |
|
| 374 | + protected function educateBackticks($_) { |
|
| 375 | + # |
|
| 376 | + # Parameter: String. |
|
| 377 | + # Returns: The string, with ``backticks'' -style double quotes |
|
| 378 | + # translated into HTML curly quote entities. |
|
| 379 | + # |
|
| 380 | + # Example input: ``Isn't this fun?'' |
|
| 381 | + # Example output: “Isn't this fun?” |
|
| 382 | + # |
|
| 383 | + |
|
| 384 | + $_ = str_replace(array("``", "''",), |
|
| 385 | + array($this->backtick_doublequote_open, |
|
| 386 | + $this->backtick_doublequote_close), $_); |
|
| 387 | + return $_; |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + |
|
| 391 | + protected function educateSingleBackticks($_) { |
|
| 392 | + # |
|
| 393 | + # Parameter: String. |
|
| 394 | + # Returns: The string, with `backticks' -style single quotes |
|
| 395 | + # translated into HTML curly quote entities. |
|
| 396 | + # |
|
| 397 | + # Example input: `Isn't this fun?' |
|
| 398 | + # Example output: ‘Isn’t this fun?’ |
|
| 399 | + # |
|
| 400 | + |
|
| 401 | + $_ = str_replace(array("`", "'",), |
|
| 402 | + array($this->backtick_singlequote_open, |
|
| 403 | + $this->backtick_singlequote_close), $_); |
|
| 404 | + return $_; |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + |
|
| 408 | + protected function educateDashes($_) { |
|
| 409 | + # |
|
| 410 | + # Parameter: String. |
|
| 411 | + # |
|
| 412 | + # Returns: The string, with each instance of "--" translated to |
|
| 413 | + # an em-dash HTML entity. |
|
| 414 | + # |
|
| 415 | + |
|
| 416 | + $_ = str_replace('--', $this->em_dash, $_); |
|
| 417 | + return $_; |
|
| 418 | + } |
|
| 419 | + |
|
| 420 | + |
|
| 421 | + protected function educateDashesOldSchool($_) { |
|
| 422 | + # |
|
| 423 | + # Parameter: String. |
|
| 424 | + # |
|
| 425 | + # Returns: The string, with each instance of "--" translated to |
|
| 426 | + # an en-dash HTML entity, and each "---" translated to |
|
| 427 | + # an em-dash HTML entity. |
|
| 428 | + # |
|
| 429 | + |
|
| 430 | + # em en |
|
| 431 | + $_ = str_replace(array("---", "--",), |
|
| 432 | + array($this->em_dash, $this->en_dash), $_); |
|
| 433 | + return $_; |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + |
|
| 437 | + protected function educateDashesOldSchoolInverted($_) { |
|
| 438 | + # |
|
| 439 | + # Parameter: String. |
|
| 440 | + # |
|
| 441 | + # Returns: The string, with each instance of "--" translated to |
|
| 442 | + # an em-dash HTML entity, and each "---" translated to |
|
| 443 | + # an en-dash HTML entity. Two reasons why: First, unlike the |
|
| 444 | + # en- and em-dash syntax supported by |
|
| 445 | + # EducateDashesOldSchool(), it's compatible with existing |
|
| 446 | + # entries written before SmartyPants 1.1, back when "--" was |
|
| 447 | + # only used for em-dashes. Second, em-dashes are more |
|
| 448 | + # common than en-dashes, and so it sort of makes sense that |
|
| 449 | + # the shortcut should be shorter to type. (Thanks to Aaron |
|
| 450 | + # Swartz for the idea.) |
|
| 451 | + # |
|
| 452 | + |
|
| 453 | + # en em |
|
| 454 | + $_ = str_replace(array("---", "--",), |
|
| 455 | + array($this->en_dash, $this->em_dash), $_); |
|
| 456 | + return $_; |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + |
|
| 460 | + protected function educateEllipses($_) { |
|
| 461 | + # |
|
| 462 | + # Parameter: String. |
|
| 463 | + # Returns: The string, with each instance of "..." translated to |
|
| 464 | + # an ellipsis HTML entity. Also converts the case where |
|
| 465 | + # there are spaces between the dots. |
|
| 466 | + # |
|
| 467 | + # Example input: Huh...? |
|
| 468 | + # Example output: Huh…? |
|
| 469 | + # |
|
| 470 | + |
|
| 471 | + $_ = str_replace(array("...", ". . .",), $this->ellipsis, $_); |
|
| 472 | + return $_; |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + |
|
| 476 | + protected function stupefyEntities($_) { |
|
| 477 | + # |
|
| 478 | + # Parameter: String. |
|
| 479 | + # Returns: The string, with each SmartyPants HTML entity translated to |
|
| 480 | + # its ASCII counterpart. |
|
| 481 | + # |
|
| 482 | + # Example input: “Hello — world.” |
|
| 483 | + # Example output: "Hello -- world." |
|
| 484 | + # |
|
| 485 | + |
|
| 486 | + # en-dash em-dash |
|
| 487 | + $_ = str_replace(array('–', '—'), |
|
| 488 | + array('-', '--'), $_); |
|
| 489 | + |
|
| 490 | + # single quote open close |
|
| 491 | + $_ = str_replace(array('‘', '’'), "'", $_); |
|
| 492 | + |
|
| 493 | + # double quote open close |
|
| 494 | + $_ = str_replace(array('“', '”'), '"', $_); |
|
| 495 | + |
|
| 496 | + $_ = str_replace('…', '...', $_); # ellipsis |
|
| 497 | + |
|
| 498 | + return $_; |
|
| 499 | + } |
|
| 500 | + |
|
| 501 | + |
|
| 502 | + protected function processEscapes($_) { |
|
| 503 | + # |
|
| 504 | + # Parameter: String. |
|
| 505 | + # Returns: The string, with after processing the following backslash |
|
| 506 | + # escape sequences. This is useful if you want to force a "dumb" |
|
| 507 | + # quote or other character to appear. |
|
| 508 | + # |
|
| 509 | + # Escape Value |
|
| 510 | + # ------ ----- |
|
| 511 | + # \\ \ |
|
| 512 | + # \" " |
|
| 513 | + # \' ' |
|
| 514 | + # \. . |
|
| 515 | + # \- - |
|
| 516 | + # \` ` |
|
| 517 | + # |
|
| 518 | + $_ = str_replace( |
|
| 519 | + array('\\\\', '\"', "\'", '\.', '\-', '\`'), |
|
| 520 | + array('\', '"', ''', '.', '-', '`'), $_); |
|
| 521 | + |
|
| 522 | + return $_; |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + |
|
| 526 | + protected function tokenizeHTML($str) { |
|
| 527 | + # |
|
| 528 | + # Parameter: String containing HTML markup. |
|
| 529 | + # Returns: An array of the tokens comprising the input |
|
| 530 | + # string. Each token is either a tag (possibly with nested, |
|
| 531 | + # tags contained therein, such as <a href="<MTFoo>">, or a |
|
| 532 | + # run of text between tags. Each element of the array is a |
|
| 533 | + # two-element array; the first is either 'tag' or 'text'; |
|
| 534 | + # the second is the actual value. |
|
| 535 | + # |
|
| 536 | + # |
|
| 537 | + # Regular expression derived from the _tokenize() subroutine in |
|
| 538 | + # Brad Choate's MTRegex plugin. |
|
| 539 | + # <http://www.bradchoate.com/past/mtregex.php> |
|
| 540 | + # |
|
| 541 | + $index = 0; |
|
| 542 | + $tokens = array(); |
|
| 543 | + |
|
| 544 | + $match = '(?s:<!--.*?-->)|'. # comment |
|
| 545 | + '(?s:<\?.*?\?>)|'. # processing instruction |
|
| 546 | + # regular tags |
|
| 547 | + '(?:<[/!$]?[-a-zA-Z0-9:]+\b(?>[^"\'>]+|"[^"]*"|\'[^\']*\')*>)'; |
|
| 548 | + |
|
| 549 | + $parts = preg_split("{($match)}", $str, -1, PREG_SPLIT_DELIM_CAPTURE); |
|
| 550 | + |
|
| 551 | + foreach ($parts as $part) { |
|
| 552 | + if (++$index % 2 && $part != '') |
|
| 553 | + $tokens[] = array('text', $part); |
|
| 554 | + else |
|
| 555 | + $tokens[] = array('tag', $part); |
|
| 556 | + } |
|
| 557 | + return $tokens; |
|
| 558 | + } |
|
| 559 | 559 | |
| 560 | 560 | } |
@@ -18,374 +18,374 @@ discard block |
||
| 18 | 18 | # |
| 19 | 19 | class SmartyPantsTypographer extends \Michelf\SmartyPants { |
| 20 | 20 | |
| 21 | - ### Configuration Variables ### |
|
| 22 | - |
|
| 23 | - # Options to specify which transformations to make: |
|
| 24 | - public $do_comma_quotes = 0; |
|
| 25 | - public $do_guillemets = 0; |
|
| 26 | - public $do_geresh_gershayim = 0; |
|
| 27 | - public $do_space_emdash = 0; |
|
| 28 | - public $do_space_endash = 0; |
|
| 29 | - public $do_space_colon = 0; |
|
| 30 | - public $do_space_semicolon = 0; |
|
| 31 | - public $do_space_marks = 0; |
|
| 32 | - public $do_space_frenchquote = 0; |
|
| 33 | - public $do_space_thousand = 0; |
|
| 34 | - public $do_space_unit = 0; |
|
| 35 | - |
|
| 36 | - # Quote characters for replacing ASCII approximations |
|
| 37 | - public $doublequote_low = "„"; // replacement for ,, |
|
| 38 | - public $guillemet_leftpointing = "«"; // replacement for << |
|
| 39 | - public $guillemet_rightpointing = "»"; // replacement for >> |
|
| 40 | - public $geresh = "׳"; |
|
| 41 | - public $gershayim = "״"; |
|
| 42 | - |
|
| 43 | - # Space characters for different places: |
|
| 44 | - # Space around em-dashes. "He_—_or she_—_should change that." |
|
| 45 | - public $space_emdash = " "; |
|
| 46 | - # Space around en-dashes. "He_–_or she_–_should change that." |
|
| 47 | - public $space_endash = " "; |
|
| 48 | - # Space before a colon. "He said_: here it is." |
|
| 49 | - public $space_colon = " "; |
|
| 50 | - # Space before a semicolon. "That's what I said_; that's what he said." |
|
| 51 | - public $space_semicolon = " "; |
|
| 52 | - # Space before a question mark and an exclamation mark: "¡_Holà_! What_?" |
|
| 53 | - public $space_marks = " "; |
|
| 54 | - # Space inside french quotes. "Voici la «_chose_» qui m'a attaqué." |
|
| 55 | - public $space_frenchquote = " "; |
|
| 56 | - # Space as thousand separator. "On compte 10_000 maisons sur cette liste." |
|
| 57 | - public $space_thousand = " "; |
|
| 58 | - # Space before a unit abreviation. "This 12_kg of matter costs 10_$." |
|
| 59 | - public $space_unit = " "; |
|
| 21 | + ### Configuration Variables ### |
|
| 22 | + |
|
| 23 | + # Options to specify which transformations to make: |
|
| 24 | + public $do_comma_quotes = 0; |
|
| 25 | + public $do_guillemets = 0; |
|
| 26 | + public $do_geresh_gershayim = 0; |
|
| 27 | + public $do_space_emdash = 0; |
|
| 28 | + public $do_space_endash = 0; |
|
| 29 | + public $do_space_colon = 0; |
|
| 30 | + public $do_space_semicolon = 0; |
|
| 31 | + public $do_space_marks = 0; |
|
| 32 | + public $do_space_frenchquote = 0; |
|
| 33 | + public $do_space_thousand = 0; |
|
| 34 | + public $do_space_unit = 0; |
|
| 35 | + |
|
| 36 | + # Quote characters for replacing ASCII approximations |
|
| 37 | + public $doublequote_low = "„"; // replacement for ,, |
|
| 38 | + public $guillemet_leftpointing = "«"; // replacement for << |
|
| 39 | + public $guillemet_rightpointing = "»"; // replacement for >> |
|
| 40 | + public $geresh = "׳"; |
|
| 41 | + public $gershayim = "״"; |
|
| 42 | + |
|
| 43 | + # Space characters for different places: |
|
| 44 | + # Space around em-dashes. "He_—_or she_—_should change that." |
|
| 45 | + public $space_emdash = " "; |
|
| 46 | + # Space around en-dashes. "He_–_or she_–_should change that." |
|
| 47 | + public $space_endash = " "; |
|
| 48 | + # Space before a colon. "He said_: here it is." |
|
| 49 | + public $space_colon = " "; |
|
| 50 | + # Space before a semicolon. "That's what I said_; that's what he said." |
|
| 51 | + public $space_semicolon = " "; |
|
| 52 | + # Space before a question mark and an exclamation mark: "¡_Holà_! What_?" |
|
| 53 | + public $space_marks = " "; |
|
| 54 | + # Space inside french quotes. "Voici la «_chose_» qui m'a attaqué." |
|
| 55 | + public $space_frenchquote = " "; |
|
| 56 | + # Space as thousand separator. "On compte 10_000 maisons sur cette liste." |
|
| 57 | + public $space_thousand = " "; |
|
| 58 | + # Space before a unit abreviation. "This 12_kg of matter costs 10_$." |
|
| 59 | + public $space_unit = " "; |
|
| 60 | 60 | |
| 61 | 61 | |
| 62 | - # Expression of a space (breakable or not): |
|
| 63 | - public $space = '(?: | | |�*160;|�*[aA]0;)'; |
|
| 64 | - |
|
| 65 | - |
|
| 66 | - ### Parser Implementation ### |
|
| 67 | - |
|
| 68 | - public function __construct($attr = SmartyPants::ATTR_DEFAULT) { |
|
| 69 | - # |
|
| 70 | - # Initialize a SmartyPantsTypographer_Parser with certain attributes. |
|
| 71 | - # |
|
| 72 | - # Parser attributes: |
|
| 73 | - # 0 : do nothing |
|
| 74 | - # 1 : set all, except dash spacing |
|
| 75 | - # 2 : set all, except dash spacing, using old school en- and em- dash shortcuts |
|
| 76 | - # 3 : set all, except dash spacing, using inverted old school en and em- dash shortcuts |
|
| 77 | - # |
|
| 78 | - # Punctuation: |
|
| 79 | - # q -> quotes |
|
| 80 | - # b -> backtick quotes (``double'' only) |
|
| 81 | - # B -> backtick quotes (``double'' and `single') |
|
| 82 | - # c -> comma quotes (,,double`` only) |
|
| 83 | - # g -> guillemets (<<double>> only) |
|
| 84 | - # d -> dashes |
|
| 85 | - # D -> old school dashes |
|
| 86 | - # i -> inverted old school dashes |
|
| 87 | - # e -> ellipses |
|
| 88 | - # w -> convert " entities to " for Dreamweaver users |
|
| 89 | - # |
|
| 90 | - # Spacing: |
|
| 91 | - # : -> colon spacing +- |
|
| 92 | - # ; -> semicolon spacing +- |
|
| 93 | - # m -> question and exclamation marks spacing +- |
|
| 94 | - # h -> em-dash spacing +- |
|
| 95 | - # H -> en-dash spacing +- |
|
| 96 | - # f -> french quote spacing +- |
|
| 97 | - # t -> thousand separator spacing - |
|
| 98 | - # u -> unit spacing +- |
|
| 99 | - # (you can add a plus sign after some of these options denoted by + to |
|
| 100 | - # add the space when it is not already present, or you can add a minus |
|
| 101 | - # sign to completly remove any space present) |
|
| 102 | - # |
|
| 103 | - # Initialize inherited SmartyPants parser. |
|
| 104 | - parent::__construct($attr); |
|
| 62 | + # Expression of a space (breakable or not): |
|
| 63 | + public $space = '(?: | | |�*160;|�*[aA]0;)'; |
|
| 64 | + |
|
| 65 | + |
|
| 66 | + ### Parser Implementation ### |
|
| 67 | + |
|
| 68 | + public function __construct($attr = SmartyPants::ATTR_DEFAULT) { |
|
| 69 | + # |
|
| 70 | + # Initialize a SmartyPantsTypographer_Parser with certain attributes. |
|
| 71 | + # |
|
| 72 | + # Parser attributes: |
|
| 73 | + # 0 : do nothing |
|
| 74 | + # 1 : set all, except dash spacing |
|
| 75 | + # 2 : set all, except dash spacing, using old school en- and em- dash shortcuts |
|
| 76 | + # 3 : set all, except dash spacing, using inverted old school en and em- dash shortcuts |
|
| 77 | + # |
|
| 78 | + # Punctuation: |
|
| 79 | + # q -> quotes |
|
| 80 | + # b -> backtick quotes (``double'' only) |
|
| 81 | + # B -> backtick quotes (``double'' and `single') |
|
| 82 | + # c -> comma quotes (,,double`` only) |
|
| 83 | + # g -> guillemets (<<double>> only) |
|
| 84 | + # d -> dashes |
|
| 85 | + # D -> old school dashes |
|
| 86 | + # i -> inverted old school dashes |
|
| 87 | + # e -> ellipses |
|
| 88 | + # w -> convert " entities to " for Dreamweaver users |
|
| 89 | + # |
|
| 90 | + # Spacing: |
|
| 91 | + # : -> colon spacing +- |
|
| 92 | + # ; -> semicolon spacing +- |
|
| 93 | + # m -> question and exclamation marks spacing +- |
|
| 94 | + # h -> em-dash spacing +- |
|
| 95 | + # H -> en-dash spacing +- |
|
| 96 | + # f -> french quote spacing +- |
|
| 97 | + # t -> thousand separator spacing - |
|
| 98 | + # u -> unit spacing +- |
|
| 99 | + # (you can add a plus sign after some of these options denoted by + to |
|
| 100 | + # add the space when it is not already present, or you can add a minus |
|
| 101 | + # sign to completly remove any space present) |
|
| 102 | + # |
|
| 103 | + # Initialize inherited SmartyPants parser. |
|
| 104 | + parent::__construct($attr); |
|
| 105 | 105 | |
| 106 | - if ($attr == "1" || $attr == "2" || $attr == "3") { |
|
| 107 | - # Do everything, turn all options on. |
|
| 108 | - $this->do_comma_quotes = 1; |
|
| 109 | - $this->do_guillemets = 1; |
|
| 110 | - $this->do_geresh_gershayim = 1; |
|
| 111 | - $this->do_space_emdash = 1; |
|
| 112 | - $this->do_space_endash = 1; |
|
| 113 | - $this->do_space_colon = 1; |
|
| 114 | - $this->do_space_semicolon = 1; |
|
| 115 | - $this->do_space_marks = 1; |
|
| 116 | - $this->do_space_frenchquote = 1; |
|
| 117 | - $this->do_space_thousand = 1; |
|
| 118 | - $this->do_space_unit = 1; |
|
| 119 | - } |
|
| 120 | - else if ($attr == "-1") { |
|
| 121 | - # Special "stupefy" mode. |
|
| 122 | - $this->do_stupefy = 1; |
|
| 123 | - } |
|
| 124 | - else { |
|
| 125 | - $chars = preg_split('//', $attr); |
|
| 126 | - foreach ($chars as $c){ |
|
| 127 | - if ($c == "c") { $current =& $this->do_comma_quotes; } |
|
| 128 | - else if ($c == "g") { $current =& $this->do_guillemets; } |
|
| 129 | - else if ($c == "G") { $current =& $this->do_geresh_gershayim; } |
|
| 130 | - else if ($c == ":") { $current =& $this->do_space_colon; } |
|
| 131 | - else if ($c == ";") { $current =& $this->do_space_semicolon; } |
|
| 132 | - else if ($c == "m") { $current =& $this->do_space_marks; } |
|
| 133 | - else if ($c == "h") { $current =& $this->do_space_emdash; } |
|
| 134 | - else if ($c == "H") { $current =& $this->do_space_endash; } |
|
| 135 | - else if ($c == "f") { $current =& $this->do_space_frenchquote; } |
|
| 136 | - else if ($c == "t") { $current =& $this->do_space_thousand; } |
|
| 137 | - else if ($c == "u") { $current =& $this->do_space_unit; } |
|
| 138 | - else if ($c == "+") { |
|
| 139 | - $current = 2; |
|
| 140 | - unset($current); |
|
| 141 | - } |
|
| 142 | - else if ($c == "-") { |
|
| 143 | - $current = -1; |
|
| 144 | - unset($current); |
|
| 145 | - } |
|
| 146 | - else { |
|
| 147 | - # Unknown attribute option, ignore. |
|
| 148 | - } |
|
| 149 | - $current = 1; |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - |
|
| 155 | - function decodeEntitiesInConfiguration() { |
|
| 156 | - parent::decodeEntitiesInConfiguration(); |
|
| 157 | - $output_config_vars = array( |
|
| 158 | - 'doublequote_low', |
|
| 159 | - 'guillemet_leftpointing', |
|
| 160 | - 'guillemet_rightpointing', |
|
| 161 | - 'space_emdash', |
|
| 162 | - 'space_endash', |
|
| 163 | - 'space_colon', |
|
| 164 | - 'space_semicolon', |
|
| 165 | - 'space_marks', |
|
| 166 | - 'space_frenchquote', |
|
| 167 | - 'space_thousand', |
|
| 168 | - 'space_unit', |
|
| 169 | - ); |
|
| 170 | - foreach ($output_config_vars as $var) { |
|
| 171 | - $this->$var = html_entity_decode($this->$var); |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - |
|
| 176 | - function educate($t, $prev_token_last_char) { |
|
| 177 | - # must happen before regular smart quotes |
|
| 178 | - if ($this->do_geresh_gershayim) $t = $this->educateGereshGershayim($t); |
|
| 179 | - |
|
| 180 | - $t = parent::educate($t, $prev_token_last_char); |
|
| 106 | + if ($attr == "1" || $attr == "2" || $attr == "3") { |
|
| 107 | + # Do everything, turn all options on. |
|
| 108 | + $this->do_comma_quotes = 1; |
|
| 109 | + $this->do_guillemets = 1; |
|
| 110 | + $this->do_geresh_gershayim = 1; |
|
| 111 | + $this->do_space_emdash = 1; |
|
| 112 | + $this->do_space_endash = 1; |
|
| 113 | + $this->do_space_colon = 1; |
|
| 114 | + $this->do_space_semicolon = 1; |
|
| 115 | + $this->do_space_marks = 1; |
|
| 116 | + $this->do_space_frenchquote = 1; |
|
| 117 | + $this->do_space_thousand = 1; |
|
| 118 | + $this->do_space_unit = 1; |
|
| 119 | + } |
|
| 120 | + else if ($attr == "-1") { |
|
| 121 | + # Special "stupefy" mode. |
|
| 122 | + $this->do_stupefy = 1; |
|
| 123 | + } |
|
| 124 | + else { |
|
| 125 | + $chars = preg_split('//', $attr); |
|
| 126 | + foreach ($chars as $c){ |
|
| 127 | + if ($c == "c") { $current =& $this->do_comma_quotes; } |
|
| 128 | + else if ($c == "g") { $current =& $this->do_guillemets; } |
|
| 129 | + else if ($c == "G") { $current =& $this->do_geresh_gershayim; } |
|
| 130 | + else if ($c == ":") { $current =& $this->do_space_colon; } |
|
| 131 | + else if ($c == ";") { $current =& $this->do_space_semicolon; } |
|
| 132 | + else if ($c == "m") { $current =& $this->do_space_marks; } |
|
| 133 | + else if ($c == "h") { $current =& $this->do_space_emdash; } |
|
| 134 | + else if ($c == "H") { $current =& $this->do_space_endash; } |
|
| 135 | + else if ($c == "f") { $current =& $this->do_space_frenchquote; } |
|
| 136 | + else if ($c == "t") { $current =& $this->do_space_thousand; } |
|
| 137 | + else if ($c == "u") { $current =& $this->do_space_unit; } |
|
| 138 | + else if ($c == "+") { |
|
| 139 | + $current = 2; |
|
| 140 | + unset($current); |
|
| 141 | + } |
|
| 142 | + else if ($c == "-") { |
|
| 143 | + $current = -1; |
|
| 144 | + unset($current); |
|
| 145 | + } |
|
| 146 | + else { |
|
| 147 | + # Unknown attribute option, ignore. |
|
| 148 | + } |
|
| 149 | + $current = 1; |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + |
|
| 155 | + function decodeEntitiesInConfiguration() { |
|
| 156 | + parent::decodeEntitiesInConfiguration(); |
|
| 157 | + $output_config_vars = array( |
|
| 158 | + 'doublequote_low', |
|
| 159 | + 'guillemet_leftpointing', |
|
| 160 | + 'guillemet_rightpointing', |
|
| 161 | + 'space_emdash', |
|
| 162 | + 'space_endash', |
|
| 163 | + 'space_colon', |
|
| 164 | + 'space_semicolon', |
|
| 165 | + 'space_marks', |
|
| 166 | + 'space_frenchquote', |
|
| 167 | + 'space_thousand', |
|
| 168 | + 'space_unit', |
|
| 169 | + ); |
|
| 170 | + foreach ($output_config_vars as $var) { |
|
| 171 | + $this->$var = html_entity_decode($this->$var); |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + |
|
| 176 | + function educate($t, $prev_token_last_char) { |
|
| 177 | + # must happen before regular smart quotes |
|
| 178 | + if ($this->do_geresh_gershayim) $t = $this->educateGereshGershayim($t); |
|
| 179 | + |
|
| 180 | + $t = parent::educate($t, $prev_token_last_char); |
|
| 181 | 181 | |
| 182 | - if ($this->do_comma_quotes) $t = $this->educateCommaQuotes($t); |
|
| 183 | - if ($this->do_guillemets) $t = $this->educateGuillemets($t); |
|
| 182 | + if ($this->do_comma_quotes) $t = $this->educateCommaQuotes($t); |
|
| 183 | + if ($this->do_guillemets) $t = $this->educateGuillemets($t); |
|
| 184 | 184 | |
| 185 | - if ($this->do_space_emdash) $t = $this->spaceEmDash($t); |
|
| 186 | - if ($this->do_space_endash) $t = $this->spaceEnDash($t); |
|
| 187 | - if ($this->do_space_colon) $t = $this->spaceColon($t); |
|
| 188 | - if ($this->do_space_semicolon) $t = $this->spaceSemicolon($t); |
|
| 189 | - if ($this->do_space_marks) $t = $this->spaceMarks($t); |
|
| 190 | - if ($this->do_space_frenchquote) $t = $this->spaceFrenchQuotes($t); |
|
| 191 | - if ($this->do_space_thousand) $t = $this->spaceThousandSeparator($t); |
|
| 192 | - if ($this->do_space_unit) $t = $this->spaceUnit($t); |
|
| 185 | + if ($this->do_space_emdash) $t = $this->spaceEmDash($t); |
|
| 186 | + if ($this->do_space_endash) $t = $this->spaceEnDash($t); |
|
| 187 | + if ($this->do_space_colon) $t = $this->spaceColon($t); |
|
| 188 | + if ($this->do_space_semicolon) $t = $this->spaceSemicolon($t); |
|
| 189 | + if ($this->do_space_marks) $t = $this->spaceMarks($t); |
|
| 190 | + if ($this->do_space_frenchquote) $t = $this->spaceFrenchQuotes($t); |
|
| 191 | + if ($this->do_space_thousand) $t = $this->spaceThousandSeparator($t); |
|
| 192 | + if ($this->do_space_unit) $t = $this->spaceUnit($t); |
|
| 193 | 193 | |
| 194 | - return $t; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - |
|
| 198 | - protected function educateCommaQuotes($_) { |
|
| 199 | - # |
|
| 200 | - # Parameter: String. |
|
| 201 | - # Returns: The string, with ,,comma,, -style double quotes |
|
| 202 | - # translated into HTML curly quote entities. |
|
| 203 | - # |
|
| 204 | - # Example input: ,,Isn't this fun?,, |
|
| 205 | - # Example output: „Isn't this fun?„ |
|
| 206 | - # |
|
| 207 | - # Note: this is meant to be used alongside with backtick quotes; there is |
|
| 208 | - # no language that use only lower quotations alone mark like in the example. |
|
| 209 | - # |
|
| 210 | - $_ = str_replace(",,", $this->doublequote_low, $_); |
|
| 211 | - return $_; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - |
|
| 215 | - protected function educateGuillemets($_) { |
|
| 216 | - # |
|
| 217 | - # Parameter: String. |
|
| 218 | - # Returns: The string, with << guillemets >> -style quotes |
|
| 219 | - # translated into HTML guillemets entities. |
|
| 220 | - # |
|
| 221 | - # Example input: << Isn't this fun? >> |
|
| 222 | - # Example output: „ Isn't this fun? „ |
|
| 223 | - # |
|
| 224 | - $_ = preg_replace("/(?:<|<){2}/", $this->guillemet_leftpointing, $_); |
|
| 225 | - $_ = preg_replace("/(?:>|>){2}/", $this->guillemet_rightpointing, $_); |
|
| 226 | - return $_; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - |
|
| 230 | - protected function educateGereshGershayim($_) { |
|
| 231 | - # |
|
| 232 | - # Parameter: String, UTF-8 encoded. |
|
| 233 | - # Returns: The string, where simple a or double quote surrounded by |
|
| 234 | - # two hebrew characters is replaced into a typographic |
|
| 235 | - # geresh or gershayim punctuation mark. |
|
| 236 | - # |
|
| 237 | - # Example input: צה"ל / צ'ארלס |
|
| 238 | - # Example output: צה״ל / צ׳ארלס |
|
| 239 | - # |
|
| 240 | - // surrounding code points can be U+0590 to U+05BF and U+05D0 to U+05F2 |
|
| 241 | - // encoded in UTF-8: D6.90 to D6.BF and D7.90 to D7.B2 |
|
| 242 | - $_ = preg_replace('/(?<=\xD6[\x90-\xBF]|\xD7[\x90-\xB2])\'(?=\xD6[\x90-\xBF]|\xD7[\x90-\xB2])/', $this->geresh, $_); |
|
| 243 | - $_ = preg_replace('/(?<=\xD6[\x90-\xBF]|\xD7[\x90-\xB2])"(?=\xD6[\x90-\xBF]|\xD7[\x90-\xB2])/', $this->gershayim, $_); |
|
| 244 | - return $_; |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - |
|
| 248 | - protected function spaceFrenchQuotes($_) { |
|
| 249 | - # |
|
| 250 | - # Parameters: String, replacement character, and forcing flag. |
|
| 251 | - # Returns: The string, with appropriates spaces replaced |
|
| 252 | - # inside french-style quotes, only french quotes. |
|
| 253 | - # |
|
| 254 | - # Example input: Quotes in « French », »German« and »Finnish» style. |
|
| 255 | - # Example output: Quotes in «_French_», »German« and »Finnish» style. |
|
| 256 | - # |
|
| 257 | - $opt = ( $this->do_space_frenchquote == 2 ? '?' : '' ); |
|
| 258 | - $chr = ( $this->do_space_frenchquote != -1 ? $this->space_frenchquote : '' ); |
|
| 194 | + return $t; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + |
|
| 198 | + protected function educateCommaQuotes($_) { |
|
| 199 | + # |
|
| 200 | + # Parameter: String. |
|
| 201 | + # Returns: The string, with ,,comma,, -style double quotes |
|
| 202 | + # translated into HTML curly quote entities. |
|
| 203 | + # |
|
| 204 | + # Example input: ,,Isn't this fun?,, |
|
| 205 | + # Example output: „Isn't this fun?„ |
|
| 206 | + # |
|
| 207 | + # Note: this is meant to be used alongside with backtick quotes; there is |
|
| 208 | + # no language that use only lower quotations alone mark like in the example. |
|
| 209 | + # |
|
| 210 | + $_ = str_replace(",,", $this->doublequote_low, $_); |
|
| 211 | + return $_; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + |
|
| 215 | + protected function educateGuillemets($_) { |
|
| 216 | + # |
|
| 217 | + # Parameter: String. |
|
| 218 | + # Returns: The string, with << guillemets >> -style quotes |
|
| 219 | + # translated into HTML guillemets entities. |
|
| 220 | + # |
|
| 221 | + # Example input: << Isn't this fun? >> |
|
| 222 | + # Example output: „ Isn't this fun? „ |
|
| 223 | + # |
|
| 224 | + $_ = preg_replace("/(?:<|<){2}/", $this->guillemet_leftpointing, $_); |
|
| 225 | + $_ = preg_replace("/(?:>|>){2}/", $this->guillemet_rightpointing, $_); |
|
| 226 | + return $_; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + |
|
| 230 | + protected function educateGereshGershayim($_) { |
|
| 231 | + # |
|
| 232 | + # Parameter: String, UTF-8 encoded. |
|
| 233 | + # Returns: The string, where simple a or double quote surrounded by |
|
| 234 | + # two hebrew characters is replaced into a typographic |
|
| 235 | + # geresh or gershayim punctuation mark. |
|
| 236 | + # |
|
| 237 | + # Example input: צה"ל / צ'ארלס |
|
| 238 | + # Example output: צה״ל / צ׳ארלס |
|
| 239 | + # |
|
| 240 | + // surrounding code points can be U+0590 to U+05BF and U+05D0 to U+05F2 |
|
| 241 | + // encoded in UTF-8: D6.90 to D6.BF and D7.90 to D7.B2 |
|
| 242 | + $_ = preg_replace('/(?<=\xD6[\x90-\xBF]|\xD7[\x90-\xB2])\'(?=\xD6[\x90-\xBF]|\xD7[\x90-\xB2])/', $this->geresh, $_); |
|
| 243 | + $_ = preg_replace('/(?<=\xD6[\x90-\xBF]|\xD7[\x90-\xB2])"(?=\xD6[\x90-\xBF]|\xD7[\x90-\xB2])/', $this->gershayim, $_); |
|
| 244 | + return $_; |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + |
|
| 248 | + protected function spaceFrenchQuotes($_) { |
|
| 249 | + # |
|
| 250 | + # Parameters: String, replacement character, and forcing flag. |
|
| 251 | + # Returns: The string, with appropriates spaces replaced |
|
| 252 | + # inside french-style quotes, only french quotes. |
|
| 253 | + # |
|
| 254 | + # Example input: Quotes in « French », »German« and »Finnish» style. |
|
| 255 | + # Example output: Quotes in «_French_», »German« and »Finnish» style. |
|
| 256 | + # |
|
| 257 | + $opt = ( $this->do_space_frenchquote == 2 ? '?' : '' ); |
|
| 258 | + $chr = ( $this->do_space_frenchquote != -1 ? $this->space_frenchquote : '' ); |
|
| 259 | 259 | |
| 260 | - # Characters allowed immediatly outside quotes. |
|
| 261 | - $outside_char = $this->space . '|\s|[.,:;!?\[\](){}|@*~=+-]|¡|¿'; |
|
| 260 | + # Characters allowed immediatly outside quotes. |
|
| 261 | + $outside_char = $this->space . '|\s|[.,:;!?\[\](){}|@*~=+-]|¡|¿'; |
|
| 262 | 262 | |
| 263 | - $_ = preg_replace( |
|
| 264 | - "/(^|$outside_char)(«|«|›|‹)$this->space$opt/", |
|
| 265 | - "\\1\\2$chr", $_); |
|
| 266 | - $_ = preg_replace( |
|
| 267 | - "/$this->space$opt(»|»|‹|›)($outside_char|$)/", |
|
| 268 | - "$chr\\1\\2", $_); |
|
| 269 | - return $_; |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - |
|
| 273 | - protected function spaceColon($_) { |
|
| 274 | - # |
|
| 275 | - # Parameters: String, replacement character, and forcing flag. |
|
| 276 | - # Returns: The string, with appropriates spaces replaced |
|
| 277 | - # before colons. |
|
| 278 | - # |
|
| 279 | - # Example input: Ingredients : fun. |
|
| 280 | - # Example output: Ingredients_: fun. |
|
| 281 | - # |
|
| 282 | - $opt = ( $this->do_space_colon == 2 ? '?' : '' ); |
|
| 283 | - $chr = ( $this->do_space_colon != -1 ? $this->space_colon : '' ); |
|
| 263 | + $_ = preg_replace( |
|
| 264 | + "/(^|$outside_char)(«|«|›|‹)$this->space$opt/", |
|
| 265 | + "\\1\\2$chr", $_); |
|
| 266 | + $_ = preg_replace( |
|
| 267 | + "/$this->space$opt(»|»|‹|›)($outside_char|$)/", |
|
| 268 | + "$chr\\1\\2", $_); |
|
| 269 | + return $_; |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + |
|
| 273 | + protected function spaceColon($_) { |
|
| 274 | + # |
|
| 275 | + # Parameters: String, replacement character, and forcing flag. |
|
| 276 | + # Returns: The string, with appropriates spaces replaced |
|
| 277 | + # before colons. |
|
| 278 | + # |
|
| 279 | + # Example input: Ingredients : fun. |
|
| 280 | + # Example output: Ingredients_: fun. |
|
| 281 | + # |
|
| 282 | + $opt = ( $this->do_space_colon == 2 ? '?' : '' ); |
|
| 283 | + $chr = ( $this->do_space_colon != -1 ? $this->space_colon : '' ); |
|
| 284 | 284 | |
| 285 | - $_ = preg_replace("/$this->space$opt(:)(\\s|$)/m", |
|
| 286 | - "$chr\\1\\2", $_); |
|
| 287 | - return $_; |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - |
|
| 291 | - protected function spaceSemicolon($_) { |
|
| 292 | - # |
|
| 293 | - # Parameters: String, replacement character, and forcing flag. |
|
| 294 | - # Returns: The string, with appropriates spaces replaced |
|
| 295 | - # before semicolons. |
|
| 296 | - # |
|
| 297 | - # Example input: There he goes ; there she goes. |
|
| 298 | - # Example output: There he goes_; there she goes. |
|
| 299 | - # |
|
| 300 | - $opt = ( $this->do_space_semicolon == 2 ? '?' : '' ); |
|
| 301 | - $chr = ( $this->do_space_semicolon != -1 ? $this->space_semicolon : '' ); |
|
| 285 | + $_ = preg_replace("/$this->space$opt(:)(\\s|$)/m", |
|
| 286 | + "$chr\\1\\2", $_); |
|
| 287 | + return $_; |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + |
|
| 291 | + protected function spaceSemicolon($_) { |
|
| 292 | + # |
|
| 293 | + # Parameters: String, replacement character, and forcing flag. |
|
| 294 | + # Returns: The string, with appropriates spaces replaced |
|
| 295 | + # before semicolons. |
|
| 296 | + # |
|
| 297 | + # Example input: There he goes ; there she goes. |
|
| 298 | + # Example output: There he goes_; there she goes. |
|
| 299 | + # |
|
| 300 | + $opt = ( $this->do_space_semicolon == 2 ? '?' : '' ); |
|
| 301 | + $chr = ( $this->do_space_semicolon != -1 ? $this->space_semicolon : '' ); |
|
| 302 | 302 | |
| 303 | - $_ = preg_replace("/$this->space(;)(?=\\s|$)/m", |
|
| 304 | - " \\1", $_); |
|
| 305 | - $_ = preg_replace("/((?:^|\\s)(?>[^&;\\s]+|&#?[a-zA-Z0-9]+;)*)". |
|
| 306 | - " $opt(;)(?=\\s|$)/m", |
|
| 307 | - "\\1$chr\\2", $_); |
|
| 308 | - return $_; |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - |
|
| 312 | - protected function spaceMarks($_) { |
|
| 313 | - # |
|
| 314 | - # Parameters: String, replacement character, and forcing flag. |
|
| 315 | - # Returns: The string, with appropriates spaces replaced |
|
| 316 | - # around question and exclamation marks. |
|
| 317 | - # |
|
| 318 | - # Example input: ¡ Holà ! What ? |
|
| 319 | - # Example output: ¡_Holà_! What_? |
|
| 320 | - # |
|
| 321 | - $opt = ( $this->do_space_marks == 2 ? '?' : '' ); |
|
| 322 | - $chr = ( $this->do_space_marks != -1 ? $this->space_marks : '' ); |
|
| 323 | - |
|
| 324 | - // Regular marks. |
|
| 325 | - $_ = preg_replace("/$this->space$opt([?!]+)/", "$chr\\1", $_); |
|
| 326 | - |
|
| 327 | - // Inverted marks. |
|
| 328 | - $imarks = "(?:¡|¡|¡|&#x[Aa]1;|¿|¿|¿|&#x[Bb][Ff];)"; |
|
| 329 | - $_ = preg_replace("/($imarks+)$this->space$opt/", "\\1$chr", $_); |
|
| 303 | + $_ = preg_replace("/$this->space(;)(?=\\s|$)/m", |
|
| 304 | + " \\1", $_); |
|
| 305 | + $_ = preg_replace("/((?:^|\\s)(?>[^&;\\s]+|&#?[a-zA-Z0-9]+;)*)". |
|
| 306 | + " $opt(;)(?=\\s|$)/m", |
|
| 307 | + "\\1$chr\\2", $_); |
|
| 308 | + return $_; |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + |
|
| 312 | + protected function spaceMarks($_) { |
|
| 313 | + # |
|
| 314 | + # Parameters: String, replacement character, and forcing flag. |
|
| 315 | + # Returns: The string, with appropriates spaces replaced |
|
| 316 | + # around question and exclamation marks. |
|
| 317 | + # |
|
| 318 | + # Example input: ¡ Holà ! What ? |
|
| 319 | + # Example output: ¡_Holà_! What_? |
|
| 320 | + # |
|
| 321 | + $opt = ( $this->do_space_marks == 2 ? '?' : '' ); |
|
| 322 | + $chr = ( $this->do_space_marks != -1 ? $this->space_marks : '' ); |
|
| 323 | + |
|
| 324 | + // Regular marks. |
|
| 325 | + $_ = preg_replace("/$this->space$opt([?!]+)/", "$chr\\1", $_); |
|
| 326 | + |
|
| 327 | + // Inverted marks. |
|
| 328 | + $imarks = "(?:¡|¡|¡|&#x[Aa]1;|¿|¿|¿|&#x[Bb][Ff];)"; |
|
| 329 | + $_ = preg_replace("/($imarks+)$this->space$opt/", "\\1$chr", $_); |
|
| 330 | 330 | |
| 331 | - return $_; |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - |
|
| 335 | - protected function spaceEmDash($_) { |
|
| 336 | - # |
|
| 337 | - # Parameters: String, two replacement characters separated by a hyphen (`-`), |
|
| 338 | - # and forcing flag. |
|
| 339 | - # |
|
| 340 | - # Returns: The string, with appropriates spaces replaced |
|
| 341 | - # around dashes. |
|
| 342 | - # |
|
| 343 | - # Example input: Then — without any plan — the fun happend. |
|
| 344 | - # Example output: Then_—_without any plan_—_the fun happend. |
|
| 345 | - # |
|
| 346 | - $opt = ( $this->do_space_emdash == 2 ? '?' : '' ); |
|
| 347 | - $chr = ( $this->do_space_emdash != -1 ? $this->space_emdash : '' ); |
|
| 348 | - $_ = preg_replace("/$this->space$opt(—|—)$this->space$opt/", |
|
| 349 | - "$chr\\1$chr", $_); |
|
| 350 | - return $_; |
|
| 351 | - } |
|
| 331 | + return $_; |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + |
|
| 335 | + protected function spaceEmDash($_) { |
|
| 336 | + # |
|
| 337 | + # Parameters: String, two replacement characters separated by a hyphen (`-`), |
|
| 338 | + # and forcing flag. |
|
| 339 | + # |
|
| 340 | + # Returns: The string, with appropriates spaces replaced |
|
| 341 | + # around dashes. |
|
| 342 | + # |
|
| 343 | + # Example input: Then — without any plan — the fun happend. |
|
| 344 | + # Example output: Then_—_without any plan_—_the fun happend. |
|
| 345 | + # |
|
| 346 | + $opt = ( $this->do_space_emdash == 2 ? '?' : '' ); |
|
| 347 | + $chr = ( $this->do_space_emdash != -1 ? $this->space_emdash : '' ); |
|
| 348 | + $_ = preg_replace("/$this->space$opt(—|—)$this->space$opt/", |
|
| 349 | + "$chr\\1$chr", $_); |
|
| 350 | + return $_; |
|
| 351 | + } |
|
| 352 | 352 | |
| 353 | 353 | |
| 354 | - protected function spaceEnDash($_) { |
|
| 355 | - # |
|
| 356 | - # Parameters: String, two replacement characters separated by a hyphen (`-`), |
|
| 357 | - # and forcing flag. |
|
| 358 | - # |
|
| 359 | - # Returns: The string, with appropriates spaces replaced |
|
| 360 | - # around dashes. |
|
| 361 | - # |
|
| 362 | - # Example input: Then — without any plan — the fun happend. |
|
| 363 | - # Example output: Then_—_without any plan_—_the fun happend. |
|
| 364 | - # |
|
| 365 | - $opt = ( $this->do_space_endash == 2 ? '?' : '' ); |
|
| 366 | - $chr = ( $this->do_space_endash != -1 ? $this->space_endash : '' ); |
|
| 367 | - $_ = preg_replace("/$this->space$opt(–|–)$this->space$opt/", |
|
| 368 | - "$chr\\1$chr", $_); |
|
| 369 | - return $_; |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - |
|
| 373 | - protected function spaceThousandSeparator($_) { |
|
| 374 | - # |
|
| 375 | - # Parameters: String, replacement character, and forcing flag. |
|
| 376 | - # Returns: The string, with appropriates spaces replaced |
|
| 377 | - # inside numbers (thousand separator in french). |
|
| 378 | - # |
|
| 379 | - # Example input: Il y a 10 000 insectes amusants dans ton jardin. |
|
| 380 | - # Example output: Il y a 10_000 insectes amusants dans ton jardin. |
|
| 381 | - # |
|
| 382 | - $chr = ( $this->do_space_thousand != -1 ? $this->space_thousand : '' ); |
|
| 383 | - $_ = preg_replace('/([0-9]) ([0-9])/', "\\1$chr\\2", $_); |
|
| 384 | - return $_; |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - |
|
| 388 | - protected $units = ' |
|
| 354 | + protected function spaceEnDash($_) { |
|
| 355 | + # |
|
| 356 | + # Parameters: String, two replacement characters separated by a hyphen (`-`), |
|
| 357 | + # and forcing flag. |
|
| 358 | + # |
|
| 359 | + # Returns: The string, with appropriates spaces replaced |
|
| 360 | + # around dashes. |
|
| 361 | + # |
|
| 362 | + # Example input: Then — without any plan — the fun happend. |
|
| 363 | + # Example output: Then_—_without any plan_—_the fun happend. |
|
| 364 | + # |
|
| 365 | + $opt = ( $this->do_space_endash == 2 ? '?' : '' ); |
|
| 366 | + $chr = ( $this->do_space_endash != -1 ? $this->space_endash : '' ); |
|
| 367 | + $_ = preg_replace("/$this->space$opt(–|–)$this->space$opt/", |
|
| 368 | + "$chr\\1$chr", $_); |
|
| 369 | + return $_; |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + |
|
| 373 | + protected function spaceThousandSeparator($_) { |
|
| 374 | + # |
|
| 375 | + # Parameters: String, replacement character, and forcing flag. |
|
| 376 | + # Returns: The string, with appropriates spaces replaced |
|
| 377 | + # inside numbers (thousand separator in french). |
|
| 378 | + # |
|
| 379 | + # Example input: Il y a 10 000 insectes amusants dans ton jardin. |
|
| 380 | + # Example output: Il y a 10_000 insectes amusants dans ton jardin. |
|
| 381 | + # |
|
| 382 | + $chr = ( $this->do_space_thousand != -1 ? $this->space_thousand : '' ); |
|
| 383 | + $_ = preg_replace('/([0-9]) ([0-9])/', "\\1$chr\\2", $_); |
|
| 384 | + return $_; |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + |
|
| 388 | + protected $units = ' |
|
| 389 | 389 | ### Metric units (with prefixes) |
| 390 | 390 | (?: |
| 391 | 391 | p | |
@@ -411,76 +411,76 @@ discard block |
||
| 411 | 411 | %|pt|pi|M?px|em|en|gal|lb|[NSEOW]|[NS][EOW]|ha|mbar |
| 412 | 412 | '; //x |
| 413 | 413 | |
| 414 | - protected function spaceUnit($_) { |
|
| 415 | - # |
|
| 416 | - # Parameters: String, replacement character, and forcing flag. |
|
| 417 | - # Returns: The string, with appropriates spaces replaced |
|
| 418 | - # before unit symbols. |
|
| 419 | - # |
|
| 420 | - # Example input: Get 3 mol of fun for 3 $. |
|
| 421 | - # Example output: Get 3_mol of fun for 3_$. |
|
| 422 | - # |
|
| 423 | - $opt = ( $this->do_space_unit == 2 ? '?' : '' ); |
|
| 424 | - $chr = ( $this->do_space_unit != -1 ? $this->space_unit : '' ); |
|
| 425 | - |
|
| 426 | - $_ = preg_replace('/ |
|
| 414 | + protected function spaceUnit($_) { |
|
| 415 | + # |
|
| 416 | + # Parameters: String, replacement character, and forcing flag. |
|
| 417 | + # Returns: The string, with appropriates spaces replaced |
|
| 418 | + # before unit symbols. |
|
| 419 | + # |
|
| 420 | + # Example input: Get 3 mol of fun for 3 $. |
|
| 421 | + # Example output: Get 3_mol of fun for 3_$. |
|
| 422 | + # |
|
| 423 | + $opt = ( $this->do_space_unit == 2 ? '?' : '' ); |
|
| 424 | + $chr = ( $this->do_space_unit != -1 ? $this->space_unit : '' ); |
|
| 425 | + |
|
| 426 | + $_ = preg_replace('/ |
|
| 427 | 427 | (?:([0-9])[ ]'.$opt.') # Number followed by space. |
| 428 | 428 | ('.$this->units.') # Unit. |
| 429 | 429 | (?![a-zA-Z0-9]) # Negative lookahead for other unit characters. |
| 430 | 430 | /x', |
| 431 | - "\\1$chr\\2", $_); |
|
| 432 | - |
|
| 433 | - return $_; |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - |
|
| 437 | - protected function spaceAbbr($_) { |
|
| 438 | - # |
|
| 439 | - # Parameters: String, replacement character, and forcing flag. |
|
| 440 | - # Returns: The string, with appropriates spaces replaced |
|
| 441 | - # around abbreviations. |
|
| 442 | - # |
|
| 443 | - # Example input: Fun i.e. something pleasant. |
|
| 444 | - # Example output: Fun i.e._something pleasant. |
|
| 445 | - # |
|
| 446 | - $opt = ( $this->do_space_abbr == 2 ? '?' : '' ); |
|
| 431 | + "\\1$chr\\2", $_); |
|
| 432 | + |
|
| 433 | + return $_; |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + |
|
| 437 | + protected function spaceAbbr($_) { |
|
| 438 | + # |
|
| 439 | + # Parameters: String, replacement character, and forcing flag. |
|
| 440 | + # Returns: The string, with appropriates spaces replaced |
|
| 441 | + # around abbreviations. |
|
| 442 | + # |
|
| 443 | + # Example input: Fun i.e. something pleasant. |
|
| 444 | + # Example output: Fun i.e._something pleasant. |
|
| 445 | + # |
|
| 446 | + $opt = ( $this->do_space_abbr == 2 ? '?' : '' ); |
|
| 447 | 447 | |
| 448 | - $_ = preg_replace("/(^|\s)($this->abbr_after) $opt/m", |
|
| 449 | - "\\1\\2$this->space_abbr", $_); |
|
| 450 | - $_ = preg_replace("/( )$opt($this->abbr_sp_before)(?![a-zA-Z'])/m", |
|
| 451 | - "\\1$this->space_abbr\\2", $_); |
|
| 452 | - return $_; |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - |
|
| 456 | - protected function stupefyEntities($_) { |
|
| 457 | - # |
|
| 458 | - # Adding angle quotes and lower quotes to SmartyPants's stupefy mode. |
|
| 459 | - # |
|
| 460 | - $_ = parent::stupefyEntities($_); |
|
| 461 | - |
|
| 462 | - $_ = str_replace(array('„', '«', '»'), '"', $_); |
|
| 463 | - |
|
| 464 | - return $_; |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - |
|
| 468 | - protected function processEscapes($_) { |
|
| 469 | - # |
|
| 470 | - # Adding a few more escapes to SmartyPants's escapes: |
|
| 471 | - # |
|
| 472 | - # Escape Value |
|
| 473 | - # ------ ----- |
|
| 474 | - # \, , |
|
| 475 | - # \< < |
|
| 476 | - # \> > |
|
| 477 | - # |
|
| 478 | - $_ = parent::processEscapes($_); |
|
| 479 | - |
|
| 480 | - $_ = str_replace( |
|
| 481 | - array('\,', '\<', '\>', '\<', '\>'), |
|
| 482 | - array(',', '<', '>', '<', '>'), $_); |
|
| 483 | - |
|
| 484 | - return $_; |
|
| 485 | - } |
|
| 448 | + $_ = preg_replace("/(^|\s)($this->abbr_after) $opt/m", |
|
| 449 | + "\\1\\2$this->space_abbr", $_); |
|
| 450 | + $_ = preg_replace("/( )$opt($this->abbr_sp_before)(?![a-zA-Z'])/m", |
|
| 451 | + "\\1$this->space_abbr\\2", $_); |
|
| 452 | + return $_; |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + |
|
| 456 | + protected function stupefyEntities($_) { |
|
| 457 | + # |
|
| 458 | + # Adding angle quotes and lower quotes to SmartyPants's stupefy mode. |
|
| 459 | + # |
|
| 460 | + $_ = parent::stupefyEntities($_); |
|
| 461 | + |
|
| 462 | + $_ = str_replace(array('„', '«', '»'), '"', $_); |
|
| 463 | + |
|
| 464 | + return $_; |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + |
|
| 468 | + protected function processEscapes($_) { |
|
| 469 | + # |
|
| 470 | + # Adding a few more escapes to SmartyPants's escapes: |
|
| 471 | + # |
|
| 472 | + # Escape Value |
|
| 473 | + # ------ ----- |
|
| 474 | + # \, , |
|
| 475 | + # \< < |
|
| 476 | + # \> > |
|
| 477 | + # |
|
| 478 | + $_ = parent::processEscapes($_); |
|
| 479 | + |
|
| 480 | + $_ = str_replace( |
|
| 481 | + array('\,', '\<', '\>', '\<', '\>'), |
|
| 482 | + array(',', '<', '>', '<', '>'), $_); |
|
| 483 | + |
|
| 484 | + return $_; |
|
| 485 | + } |
|
| 486 | 486 | } |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | |
| 7 | 7 | // Install PSR-4-compatible class autoloader |
| 8 | 8 | spl_autoload_register(function($class){ |
| 9 | - require str_replace('\\', DIRECTORY_SEPARATOR, ltrim($class, '\\')).'.php'; |
|
| 9 | + require str_replace('\\', DIRECTORY_SEPARATOR, ltrim($class, '\\')).'.php'; |
|
| 10 | 10 | }); |
| 11 | 11 | // If using Composer, use this instead: |
| 12 | 12 | //require 'vendor/autoload.php'; |
@@ -26,8 +26,8 @@ discard block |
||
| 26 | 26 | </head> |
| 27 | 27 | <body> |
| 28 | 28 | <?php |
| 29 | - // Put HTML content in the document |
|
| 30 | - echo $html; |
|
| 31 | - ?> |
|
| 29 | + // Put HTML content in the document |
|
| 30 | + echo $html; |
|
| 31 | + ?> |
|
| 32 | 32 | </body> |
| 33 | 33 | </html> |
@@ -6,168 +6,168 @@ |
||
| 6 | 6 | |
| 7 | 7 | class PhpMarkdownTest extends TestCase |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * Returns all php-markdown.mdtest tests |
|
| 11 | - * @return array |
|
| 12 | - */ |
|
| 13 | - public function dataProviderForPhpMarkdown() { |
|
| 14 | - $dir = TEST_RESOURCES_ROOT . '/php-markdown.mdtest'; |
|
| 15 | - return MarkdownTestHelper::getInputOutputPaths($dir); |
|
| 16 | - } |
|
| 17 | - |
|
| 18 | - /** |
|
| 19 | - * Runs php-markdown.mdtest against Markdown::defaultTransform |
|
| 20 | - * |
|
| 21 | - * @dataProvider dataProviderForPhpMarkdown |
|
| 22 | - * |
|
| 23 | - * @param string $inputPath Input markdown path |
|
| 24 | - * @param string $htmlPath File path of expected transformed output (X)HTML |
|
| 25 | - * |
|
| 26 | - * @param bool $xhtml True if XHTML. Otherwise, HTML is assumed. |
|
| 27 | - * |
|
| 28 | - * @return void |
|
| 29 | - */ |
|
| 30 | - public function testTransformingOfPhpMarkdown($inputPath, $htmlPath, $xhtml = false) { |
|
| 31 | - $inputMarkdown = file_get_contents($inputPath); |
|
| 32 | - $expectedHtml = file_get_contents($htmlPath); |
|
| 33 | - $result = Markdown::defaultTransform($inputMarkdown); |
|
| 34 | - |
|
| 35 | - MarkdownTestHelper::assertSameNormalized( |
|
| 36 | - $expectedHtml, |
|
| 37 | - $result, |
|
| 38 | - "Markdown in $inputPath converts exactly to expected $htmlPath", |
|
| 39 | - $xhtml |
|
| 40 | - ); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Returns all php-markdown.mdtest tests EXCEPT Emphasis test. |
|
| 45 | - * @return array |
|
| 46 | - */ |
|
| 47 | - public function dataProviderForPhpMarkdownExceptEmphasis() |
|
| 48 | - { |
|
| 49 | - $dir = TEST_RESOURCES_ROOT . '/php-markdown.mdtest'; |
|
| 50 | - $allTests = MarkdownTestHelper::getInputOutputPaths($dir); |
|
| 51 | - |
|
| 52 | - foreach ($allTests as $index => $test) { |
|
| 53 | - // Because MarkdownExtra treats underscore emphasis differently, this one test has to be excluded |
|
| 54 | - if (preg_match('~/Emphasis\.text$~', $test[0])) { |
|
| 55 | - unset($allTests[$index]); |
|
| 56 | - } |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - return array_values($allTests); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Runs php-markdown.mdtest against MarkdownExtra::defaultTransform |
|
| 64 | - * |
|
| 65 | - * @dataProvider dataProviderForPhpMarkdownExceptEmphasis |
|
| 66 | - * |
|
| 67 | - * @param $inputPath |
|
| 68 | - * @param $htmlPath |
|
| 69 | - * @param bool $xhtml |
|
| 70 | - */ |
|
| 71 | - public function testPhpMarkdownMdTestWithMarkdownExtra($inputPath, $htmlPath, $xhtml = false) |
|
| 72 | - { |
|
| 73 | - $inputMarkdown = file_get_contents($inputPath); |
|
| 74 | - $expectedHtml = file_get_contents($htmlPath); |
|
| 75 | - |
|
| 76 | - $result = MarkdownExtra::defaultTransform($inputMarkdown); |
|
| 77 | - |
|
| 78 | - MarkdownTestHelper::assertSameNormalized( |
|
| 79 | - $expectedHtml, |
|
| 80 | - $result, |
|
| 81 | - "Markdown in $inputPath converts exactly to expected $htmlPath", |
|
| 82 | - $xhtml |
|
| 83 | - ); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * @return array |
|
| 88 | - */ |
|
| 89 | - public function dataProviderForMarkdownExtra() { |
|
| 90 | - $dir = TEST_RESOURCES_ROOT . '/php-markdown-extra.mdtest'; |
|
| 91 | - return MarkdownTestHelper::getInputOutputPaths($dir); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * @dataProvider dataProviderForMarkdownExtra |
|
| 96 | - * |
|
| 97 | - * @param string $inputPath Input markdown path |
|
| 98 | - * @param string $htmlPath File path of expected transformed output (X)HTML |
|
| 99 | - * |
|
| 100 | - * @param bool $xhtml True if XHTML. Otherwise, HTML is assumed. |
|
| 101 | - * |
|
| 102 | - * @return void |
|
| 103 | - */ |
|
| 104 | - public function testTransformingOfMarkdownExtra($inputPath, $htmlPath, $xhtml = false) { |
|
| 105 | - $inputMarkdown = file_get_contents($inputPath); |
|
| 106 | - $expectedHtml = file_get_contents($htmlPath); |
|
| 107 | - $result = MarkdownExtra::defaultTransform($inputMarkdown); |
|
| 108 | - |
|
| 109 | - MarkdownTestHelper::assertSameNormalized( |
|
| 110 | - $expectedHtml, |
|
| 111 | - $result, |
|
| 112 | - "Markdown in $inputPath converts exactly to expected $htmlPath", |
|
| 113 | - $xhtml |
|
| 114 | - ); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * @return array |
|
| 119 | - */ |
|
| 120 | - public function dataProviderForRegularMarkdown() |
|
| 121 | - { |
|
| 122 | - $dir = TEST_RESOURCES_ROOT . '/markdown.mdtest'; |
|
| 123 | - return MarkdownTestHelper::getInputOutputPaths($dir); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * @dataProvider dataProviderForRegularMarkdown |
|
| 128 | - * |
|
| 129 | - * @param string $inputPath Input markdown path |
|
| 130 | - * @param string $htmlPath File path of expected transformed output (X)HTML |
|
| 131 | - * |
|
| 132 | - * @param bool $xhtml True if XHTML. Otherwise, HTML is assumed. |
|
| 133 | - * |
|
| 134 | - * @return void |
|
| 135 | - */ |
|
| 136 | - public function testTransformingOfRegularMarkdown($inputPath, $htmlPath, $xhtml = false) |
|
| 137 | - { |
|
| 138 | - $inputMarkdown = file_get_contents($inputPath); |
|
| 139 | - $expectedHtml = file_get_contents($htmlPath); |
|
| 140 | - $result = Markdown::defaultTransform($inputMarkdown); |
|
| 141 | - |
|
| 142 | - MarkdownTestHelper::assertSameNormalized( |
|
| 143 | - $expectedHtml, |
|
| 144 | - $result, |
|
| 145 | - "Markdown in $inputPath converts exactly to expected $htmlPath", |
|
| 146 | - $xhtml |
|
| 147 | - ); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * Runs markdown.mdtest against MarkdownExtra::defaultTransform |
|
| 152 | - * |
|
| 153 | - * @dataProvider dataProviderForRegularMarkdown |
|
| 154 | - * |
|
| 155 | - * @param $inputPath |
|
| 156 | - * @param $htmlPath |
|
| 157 | - * @param bool $xhtml |
|
| 158 | - */ |
|
| 159 | - public function testMarkdownMdTestWithMarkdownExtra($inputPath, $htmlPath, $xhtml = false) |
|
| 160 | - { |
|
| 161 | - $inputMarkdown = file_get_contents($inputPath); |
|
| 162 | - $expectedHtml = file_get_contents($htmlPath); |
|
| 163 | - |
|
| 164 | - $result = MarkdownExtra::defaultTransform($inputMarkdown); |
|
| 165 | - |
|
| 166 | - MarkdownTestHelper::assertSameNormalized( |
|
| 167 | - $expectedHtml, |
|
| 168 | - $result, |
|
| 169 | - "Markdown in $inputPath converts exactly to expected $htmlPath", |
|
| 170 | - $xhtml |
|
| 171 | - ); |
|
| 172 | - } |
|
| 9 | + /** |
|
| 10 | + * Returns all php-markdown.mdtest tests |
|
| 11 | + * @return array |
|
| 12 | + */ |
|
| 13 | + public function dataProviderForPhpMarkdown() { |
|
| 14 | + $dir = TEST_RESOURCES_ROOT . '/php-markdown.mdtest'; |
|
| 15 | + return MarkdownTestHelper::getInputOutputPaths($dir); |
|
| 16 | + } |
|
| 17 | + |
|
| 18 | + /** |
|
| 19 | + * Runs php-markdown.mdtest against Markdown::defaultTransform |
|
| 20 | + * |
|
| 21 | + * @dataProvider dataProviderForPhpMarkdown |
|
| 22 | + * |
|
| 23 | + * @param string $inputPath Input markdown path |
|
| 24 | + * @param string $htmlPath File path of expected transformed output (X)HTML |
|
| 25 | + * |
|
| 26 | + * @param bool $xhtml True if XHTML. Otherwise, HTML is assumed. |
|
| 27 | + * |
|
| 28 | + * @return void |
|
| 29 | + */ |
|
| 30 | + public function testTransformingOfPhpMarkdown($inputPath, $htmlPath, $xhtml = false) { |
|
| 31 | + $inputMarkdown = file_get_contents($inputPath); |
|
| 32 | + $expectedHtml = file_get_contents($htmlPath); |
|
| 33 | + $result = Markdown::defaultTransform($inputMarkdown); |
|
| 34 | + |
|
| 35 | + MarkdownTestHelper::assertSameNormalized( |
|
| 36 | + $expectedHtml, |
|
| 37 | + $result, |
|
| 38 | + "Markdown in $inputPath converts exactly to expected $htmlPath", |
|
| 39 | + $xhtml |
|
| 40 | + ); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Returns all php-markdown.mdtest tests EXCEPT Emphasis test. |
|
| 45 | + * @return array |
|
| 46 | + */ |
|
| 47 | + public function dataProviderForPhpMarkdownExceptEmphasis() |
|
| 48 | + { |
|
| 49 | + $dir = TEST_RESOURCES_ROOT . '/php-markdown.mdtest'; |
|
| 50 | + $allTests = MarkdownTestHelper::getInputOutputPaths($dir); |
|
| 51 | + |
|
| 52 | + foreach ($allTests as $index => $test) { |
|
| 53 | + // Because MarkdownExtra treats underscore emphasis differently, this one test has to be excluded |
|
| 54 | + if (preg_match('~/Emphasis\.text$~', $test[0])) { |
|
| 55 | + unset($allTests[$index]); |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + return array_values($allTests); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Runs php-markdown.mdtest against MarkdownExtra::defaultTransform |
|
| 64 | + * |
|
| 65 | + * @dataProvider dataProviderForPhpMarkdownExceptEmphasis |
|
| 66 | + * |
|
| 67 | + * @param $inputPath |
|
| 68 | + * @param $htmlPath |
|
| 69 | + * @param bool $xhtml |
|
| 70 | + */ |
|
| 71 | + public function testPhpMarkdownMdTestWithMarkdownExtra($inputPath, $htmlPath, $xhtml = false) |
|
| 72 | + { |
|
| 73 | + $inputMarkdown = file_get_contents($inputPath); |
|
| 74 | + $expectedHtml = file_get_contents($htmlPath); |
|
| 75 | + |
|
| 76 | + $result = MarkdownExtra::defaultTransform($inputMarkdown); |
|
| 77 | + |
|
| 78 | + MarkdownTestHelper::assertSameNormalized( |
|
| 79 | + $expectedHtml, |
|
| 80 | + $result, |
|
| 81 | + "Markdown in $inputPath converts exactly to expected $htmlPath", |
|
| 82 | + $xhtml |
|
| 83 | + ); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * @return array |
|
| 88 | + */ |
|
| 89 | + public function dataProviderForMarkdownExtra() { |
|
| 90 | + $dir = TEST_RESOURCES_ROOT . '/php-markdown-extra.mdtest'; |
|
| 91 | + return MarkdownTestHelper::getInputOutputPaths($dir); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * @dataProvider dataProviderForMarkdownExtra |
|
| 96 | + * |
|
| 97 | + * @param string $inputPath Input markdown path |
|
| 98 | + * @param string $htmlPath File path of expected transformed output (X)HTML |
|
| 99 | + * |
|
| 100 | + * @param bool $xhtml True if XHTML. Otherwise, HTML is assumed. |
|
| 101 | + * |
|
| 102 | + * @return void |
|
| 103 | + */ |
|
| 104 | + public function testTransformingOfMarkdownExtra($inputPath, $htmlPath, $xhtml = false) { |
|
| 105 | + $inputMarkdown = file_get_contents($inputPath); |
|
| 106 | + $expectedHtml = file_get_contents($htmlPath); |
|
| 107 | + $result = MarkdownExtra::defaultTransform($inputMarkdown); |
|
| 108 | + |
|
| 109 | + MarkdownTestHelper::assertSameNormalized( |
|
| 110 | + $expectedHtml, |
|
| 111 | + $result, |
|
| 112 | + "Markdown in $inputPath converts exactly to expected $htmlPath", |
|
| 113 | + $xhtml |
|
| 114 | + ); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * @return array |
|
| 119 | + */ |
|
| 120 | + public function dataProviderForRegularMarkdown() |
|
| 121 | + { |
|
| 122 | + $dir = TEST_RESOURCES_ROOT . '/markdown.mdtest'; |
|
| 123 | + return MarkdownTestHelper::getInputOutputPaths($dir); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * @dataProvider dataProviderForRegularMarkdown |
|
| 128 | + * |
|
| 129 | + * @param string $inputPath Input markdown path |
|
| 130 | + * @param string $htmlPath File path of expected transformed output (X)HTML |
|
| 131 | + * |
|
| 132 | + * @param bool $xhtml True if XHTML. Otherwise, HTML is assumed. |
|
| 133 | + * |
|
| 134 | + * @return void |
|
| 135 | + */ |
|
| 136 | + public function testTransformingOfRegularMarkdown($inputPath, $htmlPath, $xhtml = false) |
|
| 137 | + { |
|
| 138 | + $inputMarkdown = file_get_contents($inputPath); |
|
| 139 | + $expectedHtml = file_get_contents($htmlPath); |
|
| 140 | + $result = Markdown::defaultTransform($inputMarkdown); |
|
| 141 | + |
|
| 142 | + MarkdownTestHelper::assertSameNormalized( |
|
| 143 | + $expectedHtml, |
|
| 144 | + $result, |
|
| 145 | + "Markdown in $inputPath converts exactly to expected $htmlPath", |
|
| 146 | + $xhtml |
|
| 147 | + ); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * Runs markdown.mdtest against MarkdownExtra::defaultTransform |
|
| 152 | + * |
|
| 153 | + * @dataProvider dataProviderForRegularMarkdown |
|
| 154 | + * |
|
| 155 | + * @param $inputPath |
|
| 156 | + * @param $htmlPath |
|
| 157 | + * @param bool $xhtml |
|
| 158 | + */ |
|
| 159 | + public function testMarkdownMdTestWithMarkdownExtra($inputPath, $htmlPath, $xhtml = false) |
|
| 160 | + { |
|
| 161 | + $inputMarkdown = file_get_contents($inputPath); |
|
| 162 | + $expectedHtml = file_get_contents($htmlPath); |
|
| 163 | + |
|
| 164 | + $result = MarkdownExtra::defaultTransform($inputMarkdown); |
|
| 165 | + |
|
| 166 | + MarkdownTestHelper::assertSameNormalized( |
|
| 167 | + $expectedHtml, |
|
| 168 | + $result, |
|
| 169 | + "Markdown in $inputPath converts exactly to expected $htmlPath", |
|
| 170 | + $xhtml |
|
| 171 | + ); |
|
| 172 | + } |
|
| 173 | 173 | } |
@@ -4,264 +4,264 @@ |
||
| 4 | 4 | |
| 5 | 5 | class MarkdownTestHelper |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * Takes an input directory containing .text and .(x)html files, and returns an array |
|
| 9 | - * of .text files and the corresponding output xhtml or html file. Can be used in a unit test data provider. |
|
| 10 | - * |
|
| 11 | - * @param string $directory Input directory |
|
| 12 | - * |
|
| 13 | - * @return array |
|
| 14 | - */ |
|
| 15 | - public static function getInputOutputPaths($directory) { |
|
| 16 | - $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)); |
|
| 17 | - $regexIterator = new RegexIterator( |
|
| 18 | - $iterator, |
|
| 19 | - '/^.+\.text$/', |
|
| 20 | - RecursiveRegexIterator::GET_MATCH |
|
| 21 | - ); |
|
| 7 | + /** |
|
| 8 | + * Takes an input directory containing .text and .(x)html files, and returns an array |
|
| 9 | + * of .text files and the corresponding output xhtml or html file. Can be used in a unit test data provider. |
|
| 10 | + * |
|
| 11 | + * @param string $directory Input directory |
|
| 12 | + * |
|
| 13 | + * @return array |
|
| 14 | + */ |
|
| 15 | + public static function getInputOutputPaths($directory) { |
|
| 16 | + $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)); |
|
| 17 | + $regexIterator = new RegexIterator( |
|
| 18 | + $iterator, |
|
| 19 | + '/^.+\.text$/', |
|
| 20 | + RecursiveRegexIterator::GET_MATCH |
|
| 21 | + ); |
|
| 22 | 22 | |
| 23 | - $dataValues = []; |
|
| 23 | + $dataValues = []; |
|
| 24 | 24 | |
| 25 | - /** @var SplFileInfo $inputFile */ |
|
| 26 | - foreach ($regexIterator as $inputFiles) { |
|
| 27 | - foreach ($inputFiles as $inputMarkdownPath) { |
|
| 28 | - $xhtml = true; |
|
| 29 | - $expectedHtmlPath = substr($inputMarkdownPath, 0, -4) . 'xhtml'; |
|
| 30 | - if (!file_exists($expectedHtmlPath)) { |
|
| 31 | - $expectedHtmlPath = substr($inputMarkdownPath, 0, -4) . 'html'; |
|
| 32 | - $xhtml = false; |
|
| 33 | - } |
|
| 34 | - $dataValues[] = [$inputMarkdownPath, $expectedHtmlPath, $xhtml]; |
|
| 35 | - } |
|
| 36 | - } |
|
| 25 | + /** @var SplFileInfo $inputFile */ |
|
| 26 | + foreach ($regexIterator as $inputFiles) { |
|
| 27 | + foreach ($inputFiles as $inputMarkdownPath) { |
|
| 28 | + $xhtml = true; |
|
| 29 | + $expectedHtmlPath = substr($inputMarkdownPath, 0, -4) . 'xhtml'; |
|
| 30 | + if (!file_exists($expectedHtmlPath)) { |
|
| 31 | + $expectedHtmlPath = substr($inputMarkdownPath, 0, -4) . 'html'; |
|
| 32 | + $xhtml = false; |
|
| 33 | + } |
|
| 34 | + $dataValues[] = [$inputMarkdownPath, $expectedHtmlPath, $xhtml]; |
|
| 35 | + } |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - return $dataValues; |
|
| 39 | - } |
|
| 38 | + return $dataValues; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Applies PHPUnit's assertSame after normalizing both strings (e.g. ignoring whitespace differences). |
|
| 43 | - * Uses logic found originally in MDTest. |
|
| 44 | - * |
|
| 45 | - * @param string $string1 |
|
| 46 | - * @param string $string2 |
|
| 47 | - * @param string $message Positive message to print when test fails (e.g. "String1 matches String2") |
|
| 48 | - * @param bool $xhtml |
|
| 49 | - */ |
|
| 50 | - public static function assertSameNormalized($string1, $string2, $message, $xhtml = true) { |
|
| 41 | + /** |
|
| 42 | + * Applies PHPUnit's assertSame after normalizing both strings (e.g. ignoring whitespace differences). |
|
| 43 | + * Uses logic found originally in MDTest. |
|
| 44 | + * |
|
| 45 | + * @param string $string1 |
|
| 46 | + * @param string $string2 |
|
| 47 | + * @param string $message Positive message to print when test fails (e.g. "String1 matches String2") |
|
| 48 | + * @param bool $xhtml |
|
| 49 | + */ |
|
| 50 | + public static function assertSameNormalized($string1, $string2, $message, $xhtml = true) { |
|
| 51 | 51 | |
| 52 | - $t_result = $string1; |
|
| 53 | - $t_output = $string2; |
|
| 52 | + $t_result = $string1; |
|
| 53 | + $t_output = $string2; |
|
| 54 | 54 | |
| 55 | - // DOMDocuments |
|
| 56 | - if ($xhtml) { |
|
| 57 | - $document = new DOMDocument(); |
|
| 58 | - $doc_result = $document->loadXML('<!DOCTYPE html>' . |
|
| 59 | - "<html xmlns='http://www.w3.org/1999/xhtml'>" . |
|
| 60 | - "<body>$t_result</body></html>"); |
|
| 55 | + // DOMDocuments |
|
| 56 | + if ($xhtml) { |
|
| 57 | + $document = new DOMDocument(); |
|
| 58 | + $doc_result = $document->loadXML('<!DOCTYPE html>' . |
|
| 59 | + "<html xmlns='http://www.w3.org/1999/xhtml'>" . |
|
| 60 | + "<body>$t_result</body></html>"); |
|
| 61 | 61 | |
| 62 | - $document2 = new DOMDocument(); |
|
| 63 | - $doc_output = $document2->loadXML('<!DOCTYPE html>' . |
|
| 64 | - "<html xmlns='http://www.w3.org/1999/xhtml'>" . |
|
| 65 | - "<body>$t_output</body></html>"); |
|
| 62 | + $document2 = new DOMDocument(); |
|
| 63 | + $doc_output = $document2->loadXML('<!DOCTYPE html>' . |
|
| 64 | + "<html xmlns='http://www.w3.org/1999/xhtml'>" . |
|
| 65 | + "<body>$t_output</body></html>"); |
|
| 66 | 66 | |
| 67 | - if ($doc_result) { |
|
| 68 | - static::normalizeElementContent($document->documentElement, false); |
|
| 69 | - $n_result = $document->saveXML(); |
|
| 70 | - } else { |
|
| 71 | - $n_result = '--- Expected Result: XML Parse Error ---'; |
|
| 72 | - } |
|
| 73 | - if ($doc_output) { |
|
| 74 | - static::normalizeElementContent($document2->documentElement, false); |
|
| 75 | - $n_output = $document2->saveXML(); |
|
| 76 | - } else { |
|
| 77 | - $n_output = '--- Output: XML Parse Error ---'; |
|
| 78 | - } |
|
| 79 | - } else { |
|
| 67 | + if ($doc_result) { |
|
| 68 | + static::normalizeElementContent($document->documentElement, false); |
|
| 69 | + $n_result = $document->saveXML(); |
|
| 70 | + } else { |
|
| 71 | + $n_result = '--- Expected Result: XML Parse Error ---'; |
|
| 72 | + } |
|
| 73 | + if ($doc_output) { |
|
| 74 | + static::normalizeElementContent($document2->documentElement, false); |
|
| 75 | + $n_output = $document2->saveXML(); |
|
| 76 | + } else { |
|
| 77 | + $n_output = '--- Output: XML Parse Error ---'; |
|
| 78 | + } |
|
| 79 | + } else { |
|
| 80 | 80 | |
| 81 | - // '@' suppressors used because some tests have invalid HTML (multiple elements with the same id attribute) |
|
| 82 | - // Perhaps isolate to a separate test and remove this? |
|
| 81 | + // '@' suppressors used because some tests have invalid HTML (multiple elements with the same id attribute) |
|
| 82 | + // Perhaps isolate to a separate test and remove this? |
|
| 83 | 83 | |
| 84 | - $document = new DOMDocument(); |
|
| 85 | - $doc_result = @$document->loadHTML($t_result); |
|
| 84 | + $document = new DOMDocument(); |
|
| 85 | + $doc_result = @$document->loadHTML($t_result); |
|
| 86 | 86 | |
| 87 | - $document2 = new DOMDocument(); |
|
| 88 | - $doc_output = @$document2->loadHTML($t_output); |
|
| 87 | + $document2 = new DOMDocument(); |
|
| 88 | + $doc_output = @$document2->loadHTML($t_output); |
|
| 89 | 89 | |
| 90 | - if ($doc_result) { |
|
| 91 | - static::normalizeElementContent($document->documentElement, false); |
|
| 92 | - $n_result = $document->saveHTML(); |
|
| 93 | - } else { |
|
| 94 | - $n_result = '--- Expected Result: HTML Parse Error ---'; |
|
| 95 | - } |
|
| 90 | + if ($doc_result) { |
|
| 91 | + static::normalizeElementContent($document->documentElement, false); |
|
| 92 | + $n_result = $document->saveHTML(); |
|
| 93 | + } else { |
|
| 94 | + $n_result = '--- Expected Result: HTML Parse Error ---'; |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - if ($doc_output) { |
|
| 98 | - static::normalizeElementContent($document2->documentElement, false); |
|
| 99 | - $n_output = $document2->saveHTML(); |
|
| 100 | - } else { |
|
| 101 | - $n_output = '--- Output: HTML Parse Error ---'; |
|
| 102 | - } |
|
| 103 | - } |
|
| 97 | + if ($doc_output) { |
|
| 98 | + static::normalizeElementContent($document2->documentElement, false); |
|
| 99 | + $n_output = $document2->saveHTML(); |
|
| 100 | + } else { |
|
| 101 | + $n_output = '--- Output: HTML Parse Error ---'; |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - $n_result = preg_replace('{^.*?<body>|</body>.*?$}is', '', $n_result); |
|
| 106 | - $n_output = preg_replace('{^.*?<body>|</body>.*?$}is', '', $n_output); |
|
| 105 | + $n_result = preg_replace('{^.*?<body>|</body>.*?$}is', '', $n_result); |
|
| 106 | + $n_output = preg_replace('{^.*?<body>|</body>.*?$}is', '', $n_output); |
|
| 107 | 107 | |
| 108 | - $c_result = $n_result; |
|
| 109 | - $c_output = $n_output; |
|
| 108 | + $c_result = $n_result; |
|
| 109 | + $c_output = $n_output; |
|
| 110 | 110 | |
| 111 | - $c_result = trim($c_result) . "\n"; |
|
| 112 | - $c_output = trim($c_output) . "\n"; |
|
| 111 | + $c_result = trim($c_result) . "\n"; |
|
| 112 | + $c_output = trim($c_output) . "\n"; |
|
| 113 | 113 | |
| 114 | - // This will throw a test exception if the strings don't exactly match |
|
| 115 | - TestCase::assertSame($c_result, $c_output, $message); |
|
| 116 | - } |
|
| 114 | + // This will throw a test exception if the strings don't exactly match |
|
| 115 | + TestCase::assertSame($c_result, $c_output, $message); |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - /** |
|
| 119 | - * @param DOMElement $element Modifies this element by reference |
|
| 120 | - * @param bool $whitespace_preserve Preserve Whitespace |
|
| 121 | - * @return void |
|
| 122 | - */ |
|
| 123 | - protected static function normalizeElementContent($element, $whitespace_preserve) { |
|
| 124 | - # |
|
| 125 | - # Normalize content of HTML DOM $element. The $whitespace_preserve |
|
| 126 | - # argument indicates that whitespace is significant and shouldn't be |
|
| 127 | - # normalized; it should be used for the content of certain elements like |
|
| 128 | - # <pre> or <script>. |
|
| 129 | - # |
|
| 130 | - $node_list = $element->childNodes; |
|
| 131 | - switch (strtolower($element->nodeName)) { |
|
| 132 | - case 'body': |
|
| 133 | - case 'div': |
|
| 134 | - case 'blockquote': |
|
| 135 | - case 'ul': |
|
| 136 | - case 'ol': |
|
| 137 | - case 'dl': |
|
| 138 | - case 'h1': |
|
| 139 | - case 'h2': |
|
| 140 | - case 'h3': |
|
| 141 | - case 'h4': |
|
| 142 | - case 'h5': |
|
| 143 | - case 'h6': |
|
| 144 | - $whitespace = "\n\n"; |
|
| 145 | - break; |
|
| 118 | + /** |
|
| 119 | + * @param DOMElement $element Modifies this element by reference |
|
| 120 | + * @param bool $whitespace_preserve Preserve Whitespace |
|
| 121 | + * @return void |
|
| 122 | + */ |
|
| 123 | + protected static function normalizeElementContent($element, $whitespace_preserve) { |
|
| 124 | + # |
|
| 125 | + # Normalize content of HTML DOM $element. The $whitespace_preserve |
|
| 126 | + # argument indicates that whitespace is significant and shouldn't be |
|
| 127 | + # normalized; it should be used for the content of certain elements like |
|
| 128 | + # <pre> or <script>. |
|
| 129 | + # |
|
| 130 | + $node_list = $element->childNodes; |
|
| 131 | + switch (strtolower($element->nodeName)) { |
|
| 132 | + case 'body': |
|
| 133 | + case 'div': |
|
| 134 | + case 'blockquote': |
|
| 135 | + case 'ul': |
|
| 136 | + case 'ol': |
|
| 137 | + case 'dl': |
|
| 138 | + case 'h1': |
|
| 139 | + case 'h2': |
|
| 140 | + case 'h3': |
|
| 141 | + case 'h4': |
|
| 142 | + case 'h5': |
|
| 143 | + case 'h6': |
|
| 144 | + $whitespace = "\n\n"; |
|
| 145 | + break; |
|
| 146 | 146 | |
| 147 | - case 'table': |
|
| 148 | - $whitespace = "\n"; |
|
| 149 | - break; |
|
| 147 | + case 'table': |
|
| 148 | + $whitespace = "\n"; |
|
| 149 | + break; |
|
| 150 | 150 | |
| 151 | - case 'pre': |
|
| 152 | - case 'script': |
|
| 153 | - case 'style': |
|
| 154 | - case 'title': |
|
| 155 | - $whitespace_preserve = true; |
|
| 156 | - $whitespace = ""; |
|
| 157 | - break; |
|
| 151 | + case 'pre': |
|
| 152 | + case 'script': |
|
| 153 | + case 'style': |
|
| 154 | + case 'title': |
|
| 155 | + $whitespace_preserve = true; |
|
| 156 | + $whitespace = ""; |
|
| 157 | + break; |
|
| 158 | 158 | |
| 159 | - default: |
|
| 160 | - $whitespace = ""; |
|
| 161 | - break; |
|
| 162 | - } |
|
| 163 | - foreach ($node_list as $node) { |
|
| 164 | - switch ($node->nodeType) { |
|
| 165 | - case XML_ELEMENT_NODE: |
|
| 166 | - static::normalizeElementContent($node, $whitespace_preserve); |
|
| 167 | - static::normalizeElementAttributes($node); |
|
| 159 | + default: |
|
| 160 | + $whitespace = ""; |
|
| 161 | + break; |
|
| 162 | + } |
|
| 163 | + foreach ($node_list as $node) { |
|
| 164 | + switch ($node->nodeType) { |
|
| 165 | + case XML_ELEMENT_NODE: |
|
| 166 | + static::normalizeElementContent($node, $whitespace_preserve); |
|
| 167 | + static::normalizeElementAttributes($node); |
|
| 168 | 168 | |
| 169 | - switch (strtolower($node->nodeName)) { |
|
| 170 | - case 'p': |
|
| 171 | - case 'div': |
|
| 172 | - case 'hr': |
|
| 173 | - case 'blockquote': |
|
| 174 | - case 'ul': |
|
| 175 | - case 'ol': |
|
| 176 | - case 'dl': |
|
| 177 | - case 'li': |
|
| 178 | - case 'address': |
|
| 179 | - case 'table': |
|
| 180 | - case 'dd': |
|
| 181 | - case 'pre': |
|
| 182 | - case 'h1': |
|
| 183 | - case 'h2': |
|
| 184 | - case 'h3': |
|
| 185 | - case 'h4': |
|
| 186 | - case 'h5': |
|
| 187 | - case 'h6': |
|
| 188 | - $whitespace = "\n\n"; |
|
| 189 | - break; |
|
| 169 | + switch (strtolower($node->nodeName)) { |
|
| 170 | + case 'p': |
|
| 171 | + case 'div': |
|
| 172 | + case 'hr': |
|
| 173 | + case 'blockquote': |
|
| 174 | + case 'ul': |
|
| 175 | + case 'ol': |
|
| 176 | + case 'dl': |
|
| 177 | + case 'li': |
|
| 178 | + case 'address': |
|
| 179 | + case 'table': |
|
| 180 | + case 'dd': |
|
| 181 | + case 'pre': |
|
| 182 | + case 'h1': |
|
| 183 | + case 'h2': |
|
| 184 | + case 'h3': |
|
| 185 | + case 'h4': |
|
| 186 | + case 'h5': |
|
| 187 | + case 'h6': |
|
| 188 | + $whitespace = "\n\n"; |
|
| 189 | + break; |
|
| 190 | 190 | |
| 191 | - case 'tr': |
|
| 192 | - case 'td': |
|
| 193 | - case 'dt': |
|
| 194 | - $whitespace = "\n"; |
|
| 195 | - break; |
|
| 191 | + case 'tr': |
|
| 192 | + case 'td': |
|
| 193 | + case 'dt': |
|
| 194 | + $whitespace = "\n"; |
|
| 195 | + break; |
|
| 196 | 196 | |
| 197 | - default: |
|
| 198 | - $whitespace = ""; |
|
| 199 | - break; |
|
| 200 | - } |
|
| 197 | + default: |
|
| 198 | + $whitespace = ""; |
|
| 199 | + break; |
|
| 200 | + } |
|
| 201 | 201 | |
| 202 | - if (($whitespace === "\n\n" || $whitespace === "\n") && |
|
| 203 | - $node->nextSibling && |
|
| 204 | - $node->nextSibling->nodeType != XML_TEXT_NODE) { |
|
| 205 | - $element->insertBefore(new DOMText($whitespace), $node->nextSibling); |
|
| 206 | - } |
|
| 207 | - break; |
|
| 202 | + if (($whitespace === "\n\n" || $whitespace === "\n") && |
|
| 203 | + $node->nextSibling && |
|
| 204 | + $node->nextSibling->nodeType != XML_TEXT_NODE) { |
|
| 205 | + $element->insertBefore(new DOMText($whitespace), $node->nextSibling); |
|
| 206 | + } |
|
| 207 | + break; |
|
| 208 | 208 | |
| 209 | - case XML_TEXT_NODE: |
|
| 210 | - if (!$whitespace_preserve) { |
|
| 211 | - if (trim($node->data) === "") { |
|
| 212 | - $node->data = $whitespace; |
|
| 213 | - } |
|
| 214 | - else { |
|
| 215 | - $node->data = preg_replace('{\s+}', ' ', $node->data); |
|
| 216 | - } |
|
| 217 | - } |
|
| 218 | - break; |
|
| 219 | - } |
|
| 220 | - } |
|
| 221 | - if (!$whitespace_preserve && |
|
| 222 | - ($whitespace === "\n\n" || $whitespace === "\n")) { |
|
| 223 | - if ($element->firstChild) { |
|
| 224 | - if ($element->firstChild->nodeType == XML_TEXT_NODE) { |
|
| 225 | - $element->firstChild->data = |
|
| 226 | - preg_replace('{^\s+}', "\n", $element->firstChild->data); |
|
| 227 | - } |
|
| 228 | - else { |
|
| 229 | - $element->insertBefore(new DOMText("\n"), $element->firstChild); |
|
| 230 | - } |
|
| 231 | - } |
|
| 232 | - if ($element->lastChild) { |
|
| 233 | - if ($element->lastChild->nodeType == XML_TEXT_NODE) { |
|
| 234 | - $element->lastChild->data = |
|
| 235 | - preg_replace('{\s+$}', "\n", $element->lastChild->data); |
|
| 236 | - } |
|
| 237 | - else { |
|
| 238 | - $element->insertBefore(new DOMText("\n"), null); |
|
| 239 | - } |
|
| 240 | - } |
|
| 241 | - } |
|
| 242 | - } |
|
| 209 | + case XML_TEXT_NODE: |
|
| 210 | + if (!$whitespace_preserve) { |
|
| 211 | + if (trim($node->data) === "") { |
|
| 212 | + $node->data = $whitespace; |
|
| 213 | + } |
|
| 214 | + else { |
|
| 215 | + $node->data = preg_replace('{\s+}', ' ', $node->data); |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | + break; |
|
| 219 | + } |
|
| 220 | + } |
|
| 221 | + if (!$whitespace_preserve && |
|
| 222 | + ($whitespace === "\n\n" || $whitespace === "\n")) { |
|
| 223 | + if ($element->firstChild) { |
|
| 224 | + if ($element->firstChild->nodeType == XML_TEXT_NODE) { |
|
| 225 | + $element->firstChild->data = |
|
| 226 | + preg_replace('{^\s+}', "\n", $element->firstChild->data); |
|
| 227 | + } |
|
| 228 | + else { |
|
| 229 | + $element->insertBefore(new DOMText("\n"), $element->firstChild); |
|
| 230 | + } |
|
| 231 | + } |
|
| 232 | + if ($element->lastChild) { |
|
| 233 | + if ($element->lastChild->nodeType == XML_TEXT_NODE) { |
|
| 234 | + $element->lastChild->data = |
|
| 235 | + preg_replace('{\s+$}', "\n", $element->lastChild->data); |
|
| 236 | + } |
|
| 237 | + else { |
|
| 238 | + $element->insertBefore(new DOMText("\n"), null); |
|
| 239 | + } |
|
| 240 | + } |
|
| 241 | + } |
|
| 242 | + } |
|
| 243 | 243 | |
| 244 | - /** |
|
| 245 | - * @param DOMElement $element Modifies this element by reference |
|
| 246 | - */ |
|
| 247 | - protected static function normalizeElementAttributes (DOMElement $element) |
|
| 248 | - { |
|
| 249 | - # |
|
| 250 | - # Sort attributes by name. |
|
| 251 | - # |
|
| 252 | - // Gather the list of attributes as an array. |
|
| 253 | - $attr_list = array(); |
|
| 254 | - foreach ($element->attributes as $attr_node) { |
|
| 255 | - $attr_list[$attr_node->name] = $attr_node; |
|
| 256 | - } |
|
| 244 | + /** |
|
| 245 | + * @param DOMElement $element Modifies this element by reference |
|
| 246 | + */ |
|
| 247 | + protected static function normalizeElementAttributes (DOMElement $element) |
|
| 248 | + { |
|
| 249 | + # |
|
| 250 | + # Sort attributes by name. |
|
| 251 | + # |
|
| 252 | + // Gather the list of attributes as an array. |
|
| 253 | + $attr_list = array(); |
|
| 254 | + foreach ($element->attributes as $attr_node) { |
|
| 255 | + $attr_list[$attr_node->name] = $attr_node; |
|
| 256 | + } |
|
| 257 | 257 | |
| 258 | - // Sort attribute list by name. |
|
| 259 | - ksort($attr_list); |
|
| 258 | + // Sort attribute list by name. |
|
| 259 | + ksort($attr_list); |
|
| 260 | 260 | |
| 261 | - // Remove then put back each attribute following sort order. |
|
| 262 | - foreach ($attr_list as $attr_node) { |
|
| 263 | - $element->removeAttributeNode($attr_node); |
|
| 264 | - $element->setAttributeNode($attr_node); |
|
| 265 | - } |
|
| 266 | - } |
|
| 261 | + // Remove then put back each attribute following sort order. |
|
| 262 | + foreach ($attr_list as $attr_node) { |
|
| 263 | + $element->removeAttributeNode($attr_node); |
|
| 264 | + $element->setAttributeNode($attr_node); |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | 267 | } |
@@ -2,50 +2,50 @@ |
||
| 2 | 2 | |
| 3 | 3 | class MarkdownExtraTest extends \PHPUnit\Framework\TestCase |
| 4 | 4 | { |
| 5 | - public function testSetupOfPredefinedAttributes() |
|
| 6 | - { |
|
| 7 | - $obj = new \Michelf\MarkdownExtra(); |
|
| 8 | - |
|
| 9 | - // Allows custom expansions of arreviations to their full version with the abbr tag |
|
| 10 | - $obj->predef_abbr = array( |
|
| 11 | - 'foo' => 'foobar-test', |
|
| 12 | - ); |
|
| 13 | - $result = $obj->transform('**Hello world, foo**'); |
|
| 14 | - |
|
| 15 | - $this->assertSame( |
|
| 16 | - '<p><strong>Hello world, <abbr title="foobar-test">foo</abbr></strong></p>', |
|
| 17 | - trim($result) |
|
| 18 | - ); |
|
| 19 | - } |
|
| 20 | - |
|
| 21 | - public function testSetupOfMultiplePredefinedAttributes() |
|
| 22 | - { |
|
| 23 | - $obj = new \Michelf\MarkdownExtra(); |
|
| 24 | - |
|
| 25 | - // Allows custom expansions of arreviations to their full version with the abbr tag |
|
| 26 | - $obj->predef_abbr = array( |
|
| 27 | - 'foo' => 'foobar-test', |
|
| 28 | - 'ISP' => 'Internet Service Provider', |
|
| 29 | - ); |
|
| 30 | - $result = $obj->transform('**I get internet from an ISP. foo.**'); |
|
| 31 | - |
|
| 32 | - $this->assertSame( |
|
| 33 | - '<p><strong>I get internet from an <abbr title="Internet Service Provider">ISP' . |
|
| 34 | - '</abbr>. <abbr title="foobar-test">foo</abbr>.</strong></p>', |
|
| 35 | - trim($result) |
|
| 36 | - ); |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - public function testTransformWithNoMarkup() |
|
| 40 | - { |
|
| 41 | - $obj = new \Michelf\MarkdownExtra(); |
|
| 42 | - $obj->no_markup = true; |
|
| 43 | - |
|
| 44 | - $result = $obj->transform('This is a <strong class="custom">no markup</strong> test.'); |
|
| 45 | - |
|
| 46 | - $this->assertSame( |
|
| 47 | - '<p>This is a <strong class="custom">no markup</strong> test.</p>', |
|
| 48 | - trim($result) |
|
| 49 | - ); |
|
| 50 | - } |
|
| 5 | + public function testSetupOfPredefinedAttributes() |
|
| 6 | + { |
|
| 7 | + $obj = new \Michelf\MarkdownExtra(); |
|
| 8 | + |
|
| 9 | + // Allows custom expansions of arreviations to their full version with the abbr tag |
|
| 10 | + $obj->predef_abbr = array( |
|
| 11 | + 'foo' => 'foobar-test', |
|
| 12 | + ); |
|
| 13 | + $result = $obj->transform('**Hello world, foo**'); |
|
| 14 | + |
|
| 15 | + $this->assertSame( |
|
| 16 | + '<p><strong>Hello world, <abbr title="foobar-test">foo</abbr></strong></p>', |
|
| 17 | + trim($result) |
|
| 18 | + ); |
|
| 19 | + } |
|
| 20 | + |
|
| 21 | + public function testSetupOfMultiplePredefinedAttributes() |
|
| 22 | + { |
|
| 23 | + $obj = new \Michelf\MarkdownExtra(); |
|
| 24 | + |
|
| 25 | + // Allows custom expansions of arreviations to their full version with the abbr tag |
|
| 26 | + $obj->predef_abbr = array( |
|
| 27 | + 'foo' => 'foobar-test', |
|
| 28 | + 'ISP' => 'Internet Service Provider', |
|
| 29 | + ); |
|
| 30 | + $result = $obj->transform('**I get internet from an ISP. foo.**'); |
|
| 31 | + |
|
| 32 | + $this->assertSame( |
|
| 33 | + '<p><strong>I get internet from an <abbr title="Internet Service Provider">ISP' . |
|
| 34 | + '</abbr>. <abbr title="foobar-test">foo</abbr>.</strong></p>', |
|
| 35 | + trim($result) |
|
| 36 | + ); |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + public function testTransformWithNoMarkup() |
|
| 40 | + { |
|
| 41 | + $obj = new \Michelf\MarkdownExtra(); |
|
| 42 | + $obj->no_markup = true; |
|
| 43 | + |
|
| 44 | + $result = $obj->transform('This is a <strong class="custom">no markup</strong> test.'); |
|
| 45 | + |
|
| 46 | + $this->assertSame( |
|
| 47 | + '<p>This is a <strong class="custom">no markup</strong> test.</p>', |
|
| 48 | + trim($result) |
|
| 49 | + ); |
|
| 50 | + } |
|
| 51 | 51 | } |