Skip to content
This repository
Browse code

PHP Markdown Extra 1.1.1

  • Loading branch information...
commit 07f1eebb0975422c264cdbd9080adc5146bb720e 1 parent a151a9c
Michel Fortin authored
10  License.text
... ...
@@ -1,9 +1,11 @@
1  
-Copyright (c) 2004-2006, John Gruber  
2  
-<http://daringfireball.net/>  
  1
+PHP Markdown & Extra
  2
+Copyright (c) 2004-2006 Michel Fortin  
  3
+<http://www.michelf.com/>  
3 4
 All rights reserved.
4 5
 
5  
-Copyright (c) 2004-2006, Michel Fortin  
6  
-<http://www.michelf.com/>  
  6
+Based on Markdown  
  7
+Copyright (c) 2003-2006 John Gruber   
  8
+<http://daringfireball.net/>   
7 9
 All rights reserved.
8 10
 
9 11
 Redistribution and use in source and binary forms, with or without
52  PHP Markdown Extra Readme.text
... ...
@@ -1,7 +1,7 @@
1 1
 PHP Markdown Extra
2 2
 ==================
3 3
 
4  
-Version 1.1 - Fri 1 Dec 2006
  4
+Version 1.1.1 - Thu 28 Dec 2006
5 5
 
6 6
 by Michel Fortin
7 7
 <http://www.michelf.com/>
@@ -148,6 +148,27 @@ located at `(MT CGI root)/php/extlib/smarty/plugins`. This will allow
148 148
 Markdown to work on dynamic pages.
149 149
 
150 150
 
  151
+### Updating Markdown in Other Programs ###
  152
+
  153
+Many web applications now ship with PHP Markdown, or have plugins to 
  154
+perform the conversion to HTML. You can update PHP Markdown -- or 
  155
+replace it with PHP Markdown Extra -- in many of these programs by 
  156
+swapping the old "markdown.php" file for the new one.
  157
+
  158
+Here is a short non-exaustive list of some programs and where they 
  159
+hide the "markdown.php" file.
  160
+
  161
+| Program   | Path to Markdown
  162
+| -------   | ----------------
  163
+| [Pivot][] | `(site home)/pivot/includes/markdown/`
  164
+
  165
+If you're unsure if you can do this with your application, ask the 
  166
+developer, or wait for the developer to update his application or 
  167
+plugin with the new version of PHP Markdown.
  168
+
  169
+ [Pivot]: http://pivotlog.net/
  170
+
  171
+
151 172
 Configuration
152 173
 -------------
153 174
 
@@ -186,6 +207,35 @@ expected; (3) the output PHP Markdown actually produced.
186 207
 Version History
187 208
 ---------------
188 209
 
  210
+Extra 1.1.1 (28 Dec 2006)
  211
+
  212
+*	Fixed a problem where whitespace at the end of the line of an atx-style
  213
+	header would cause tailing `#` to appear as part of the header's content.
  214
+	This was caused by a small error in the regex that handles the definition
  215
+	for the id attribute in PHP Markdown Extra.
  216
+
  217
+*	Fixed a problem where empty abbreviations definitions would eat the 
  218
+	following line as its definition.
  219
+
  220
+*	Fixed an issue with calling the Markdown parser repetitivly with text 
  221
+	containing footnotes. The footnote hashes were not reinitialized properly.
  222
+
  223
+
  224
+1.0.1e (28 Dec 2006)
  225
+
  226
+*	Added support for internationalized domain names for email addresses in 
  227
+	automatic link. Improved the speed at which email addresses are converted 
  228
+	to entities. Thanks to Milian Wolff for his optimisations.
  229
+
  230
+*	Made deterministic the conversion to entities of email addresses in 
  231
+	automatic links. This means that a given email address will always be 
  232
+	encoded the same way.
  233
+
  234
+*	PHP Markdown will now use its own function to calculate the length of an 
  235
+	UTF-8 string in `detab` when `mb_strlen` is not available instead of 
  236
+	giving a fatal error.
  237
+
  238
+
189 239
 Extra 1.1 (1 Dec 2006)
190 240
 
191 241
 *	Added a syntax for footnotes.
96  markdown.php
@@ -12,8 +12,8 @@
12 12
 #
13 13
 
14 14
 
15  
-define( 'MARKDOWN_VERSION',       "1.0.1d" ); # Fri 1 Dec 2006
16  
-define( 'MARKDOWNEXTRA_VERSION',  "1.1" );    # Fri 1 Dec 2006
  15
+define( 'MARKDOWN_VERSION',       "1.0.1e" ); # Thu 28 Dec 2006
  16
+define( 'MARKDOWNEXTRA_VERSION',  "1.1.1" );  # Thu 28 Dec 2006
17 17
 
18 18
 
19 19
 #
@@ -71,7 +71,7 @@ function Markdown($text) {
71 71
 Plugin Name: Markdown Extra
72 72
 Plugin URI: http://www.michelf.com/projects/php-markdown/
73 73
 Description: <a href="http://daringfireball.net/projects/markdown/syntax">Markdown syntax</a> allows you to write using an easy-to-read, easy-to-write plain text format. Based on the original Perl version by <a href="http://daringfireball.net/">John Gruber</a>. <a href="http://www.michelf.com/projects/php-markdown/">More...</a>
74  
-Version: 1.1
  74
+Version: 1.1.1
75 75
 Author: Michel Fortin
76 76
 Author URI: http://www.michelf.com/
77 77
 */
@@ -214,6 +214,8 @@ function Markdown_Parser() {
214 214
 	#
215 215
 	# Constructor function. Initialize appropriate member variables.
216 216
 	#
  217
+		$this->_initDetab();
  218
+	
217 219
 		$this->nested_brackets = 
218 220
 			str_repeat('(?>[^\[\]]+|\[', $this->nested_brackets_depth).
219 221
 			str_repeat('\])*', $this->nested_brackets_depth);
@@ -1337,9 +1339,9 @@ function doAutoLinks($text) {
1337 1339
 			<
1338 1340
 			(?:mailto:)?
1339 1341
 			(
1340  
-				[-.\w]+
  1342
+				[-.\w\x80-\xFF]+
1341 1343
 				\@
1342  
-				[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+
  1344
+				[-a-z0-9\x80-\xFF]+(\.[-a-z0-9\x80-\xFF]+)*\.[a-z]+
1343 1345
 			)
1344 1346
 			>
1345 1347
 			}xi',
@@ -1363,35 +1365,37 @@ function encodeEmailAddress($addr) {
1363 1365
 	#		of the address encoded as either a decimal or hex entity, in
1364 1366
 	#		the hopes of foiling most address harvesting spam bots. E.g.:
1365 1367
 	#
1366  
-	#	  <a href="&#x6D;&#97;&#105;&#108;&#x74;&#111;:&#102;&#111;&#111;&#64;&#101;
1367  
-	#		x&#x61;&#109;&#x70;&#108;&#x65;&#x2E;&#99;&#111;&#109;">&#102;&#111;&#111;
1368  
-	#		&#64;&#101;x&#x61;&#109;&#x70;&#108;&#x65;&#x2E;&#99;&#111;&#109;</a>
  1368
+	#	  <p><a href="&#109;&#x61;&#105;&#x6c;&#116;&#x6f;&#58;&#x66;o&#111;
  1369
+	#        &#x40;&#101;&#x78;&#97;&#x6d;&#112;&#x6c;&#101;&#46;&#x63;&#111;
  1370
+	#        &#x6d;">&#x66;o&#111;&#x40;&#101;&#x78;&#97;&#x6d;&#112;&#x6c;
  1371
+	#        &#101;&#46;&#x63;&#111;&#x6d;</a></p>
1369 1372
 	#
1370  
-	#	Based by a filter by Matthew Wickline, posted to the BBEdit-Talk
1371  
-	#	mailing list: <http://tinyurl.com/yu7ue>
  1373
+	#	Based by a filter by Matthew Wickline, posted to BBEdit-Talk.
  1374
+	#   With some optimizations by Milian Wolff.
1372 1375
 	#
1373 1376
 		$addr = "mailto:" . $addr;
1374  
-		$length = strlen($addr);
1375  
-
1376  
-		# leave ':' alone (to spot mailto: later)
1377  
-		$addr = preg_replace_callback('/([^\:])/', 
1378  
-									  array(&$this, '_encodeEmailAddress_callback'), $addr);
1379  
-
1380  
-		$addr = "<a href=\"$addr\">$addr</a>";
1381  
-		# strip the mailto: from the visible part
1382  
-		$addr = preg_replace('/">.+?:/', '">', $addr);
  1377
+		$chars = preg_split('/(?<!^)(?!$)/', $addr);
  1378
+		$seed = (int)abs(crc32($addr) / strlen($addr)); # Deterministic seed.
  1379
+		
  1380
+		foreach ($chars as $key => $char) {
  1381
+			$ord = ord($char);
  1382
+			# Ignore non-ascii chars.
  1383
+			if ($ord < 128) {
  1384
+				$r = ($seed * (1 + $key)) % 100; # Pseudo-random function.
  1385
+				# roughly 10% raw, 45% hex, 45% dec
  1386
+				# '@' *must* be encoded. I insist.
  1387
+				if ($r > 90 && $char != '@') /* do nothing */;
  1388
+				else if ($r < 45) $chars[$key] = '&#x'.dechex($ord).';';
  1389
+				else              $chars[$key] = '&#'.$ord.';';
  1390
+			}
  1391
+		}
  1392
+		
  1393
+		$addr = implode('', $chars);
  1394
+		$text = implode('', array_slice($chars, 7)); # text without `mailto:`
  1395
+		$addr = "<a href=\"$addr\">$text</a>";
1383 1396
 
1384 1397
 		return $addr;
1385 1398
 	}
1386  
-	function _encodeEmailAddress_callback($matches) {
1387  
-		$char = $matches[1];
1388  
-		$r = rand(0, 100);
1389  
-		# roughly 10% raw, 45% hex, 45% dec
1390  
-		# '@' *must* be encoded. I insist.
1391  
-		if ($r > 90 && $char != '@') return $char;
1392  
-		if ($r < 45) return '&#x'.dechex(ord($char)).';';
1393  
-		return '&#'.ord($char).';';
1394  
-	}
1395 1399
 
1396 1400
 
1397 1401
 	function unescapeSpecialChars($text) {
@@ -1481,6 +1485,10 @@ function outdent($text) {
1481 1485
 	}
1482 1486
 
1483 1487
 
  1488
+	# Strlen function that will be used by detab. _initDetab will create a 
  1489
+	# function to hanlde UTF-8 if the default function does not exist.
  1490
+	var $utf8_strlen = 'mb_strlen';
  1491
+	
1484 1492
 	function detab($text) {
1485 1493
 	#
1486 1494
 	# Replace tabs with the appropriate amount of space.
@@ -1489,6 +1497,7 @@ function detab($text) {
1489 1497
 		# tab characters. Then we reconstruct every line by adding the 
1490 1498
 		# appropriate number of space between each blocks.
1491 1499
 		
  1500
+		$strlen = $this->utf8_strlen; # best strlen function for UTF-8.
1492 1501
 		$lines = explode("\n", $text);
1493 1502
 		$text = "";
1494 1503
 		
@@ -1501,13 +1510,29 @@ function detab($text) {
1501 1510
 			foreach ($blocks as $block) {
1502 1511
 				# Calculate amount of space, insert spaces, insert block.
1503 1512
 				$amount = $this->tab_width - 
1504  
-					mb_strlen($line, 'UTF-8') % $this->tab_width;
  1513
+					$strlen($line, 'UTF-8') % $this->tab_width;
1505 1514
 				$line .= str_repeat(" ", $amount) . $block;
1506 1515
 			}
1507 1516
 			$text .= "$line\n";
1508 1517
 		}
1509 1518
 		return $text;
1510 1519
 	}
  1520
+	function _initDetab() {
  1521
+	#
  1522
+	# Check for the availability of the function in the `utf8_strlen` property
  1523
+	# (probably `mb_strlen`). If the function is not available, create a 
  1524
+	# function that will loosely count the number of UTF-8 characters with a
  1525
+	# regular expression.
  1526
+	#
  1527
+		if (function_exists($this->utf8_strlen)) return;
  1528
+		$this->utf8_strlen = 'Markdown_UTF8_strlen';
  1529
+		
  1530
+		if (function_exists($this->utf8_strlen)) return;
  1531
+		function Markdown_UTF8_strlen($text) {
  1532
+			return preg_match_all('/[\x00-\xBF]|[\xC0-\xFF][\x80-\xBF]*/', 
  1533
+				$text, $m);
  1534
+		}
  1535
+	}
1511 1536
 
1512 1537
 
1513 1538
 	function unhash($text) {
@@ -1584,8 +1609,8 @@ function transform($text) {
1584 1609
 		# from other articles when generating a page which contains more than
1585 1610
 		# one article (e.g. an index page that shows the N most recent
1586 1611
 		# articles):
1587  
-		$this->footnote_content = array();
1588  
-		$this->footnote_numbers = array();
  1612
+		$this->footnotes = array();
  1613
+		$this->footnotes_ordered = array();
1589 1614
 		$this->abbr_desciptions = array();
1590 1615
 		$this->abbr_matches = array();
1591 1616
 		$this->html_cleans = array();
@@ -2031,7 +2056,8 @@ function doHeaders($text) {
2031 2056
 				(.+?)		# $2 = Header text
2032 2057
 				[ \t]*
2033 2058
 				\#*			# optional closing #\'s (not counted)
2034  
-				(?:[ ]+\{\#([-_:a-zA-Z0-9]+)\}[ ]*)? # id attribute
  2059
+				(?:[ ]+\{\#([-_:a-zA-Z0-9]+)\})? # id attribute
  2060
+				[ \t]*
2035 2061
 				\n+
2036 2062
 			}xm',
2037 2063
 			array(&$this, '_doHeaders_callback_atx'), $text);
@@ -2556,7 +2582,6 @@ function stripAbbreviations($text) {
2556 2582
 		# Link defs are in the form: [id]*: url "optional title"
2557 2583
 		$text = preg_replace_callback('{
2558 2584
 			^[ ]{0,'.$less_than_tab.'}\*\[(.+?)\][ ]?:	# abbr_id = $1
2559  
-			  [ \t]* \n?			# maybe *one* newline
2560 2585
 			(.*)					# text = $2 (no blank lines allowed)	
2561 2586
 			}xm',
2562 2587
 			array(&$this, '_stripAbbreviations_callback'),
@@ -2642,10 +2667,12 @@ function _doAbbreviations_callback($matches) {
2642 2667
 
2643 2668
 
2644 2669
 Version History
2645  
---------------- 
  2670
+---------------
2646 2671
 
2647 2672
 See Readme file for details.
2648 2673
 
  2674
+Extra 1.1.1 (21 Dec 2006)
  2675
+
2649 2676
 Extra 1.1 (1 Dec 2006)
2650 2677
 
2651 2678
 Extra 1.0.1 (9 Dec 2005)
@@ -2666,6 +2693,7 @@ function _doAbbreviations_callback($matches) {
2666 2693
 Copyright and License
2667 2694
 ---------------------
2668 2695
 
  2696
+PHP Markdown & Extra
2669 2697
 Copyright (c) 2004-2006 Michel Fortin  
2670 2698
 <http://www.michelf.com/>  
2671 2699
 All rights reserved.

0 notes on commit 07f1eeb

Please sign in to comment.
Something went wrong with that request. Please try again.