Permalink
Browse files

PHP Markdown 1.0.1e

  • Loading branch information...
1 parent 8699f81 commit d3693aa2a703082775daa01461055400e88022fa @michelf committed Aug 14, 2007
Showing with 100 additions and 35 deletions.
  1. +6 −4 License.text
  2. +39 −3 PHP Markdown Readme.text
  3. +55 −28 markdown.php
View
@@ -1,9 +1,11 @@
-Copyright (c) 2004-2006, John Gruber
-<http://daringfireball.net/>
+PHP Markdown
+Copyright (c) 2004-2006 Michel Fortin
+<http://www.michelf.com/>
All rights reserved.
-Copyright (c) 2004-2006, Michel Fortin
-<http://www.michelf.com/>
+Based on Markdown
+Copyright (c) 2003-2006 John Gruber
+<http://daringfireball.net/>
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -1,7 +1,7 @@
PHP Markdown
============
-Version 1.0.1d - Fri 1 Dec 2006
+Version 1.0.1e - Thu 28 Dec 2006
by Michel Fortin
<http://www.michelf.com/>
@@ -116,6 +116,26 @@ further modification.
[psp]: http://www.michelf.com/projects/php-smartypants/
+### Updating Markdown in Other Programs ###
+
+Many web applications now ship with PHP Markdown, or have plugins to
+perform the conversion to HTML. You can update PHP Markdown in many of
+these programs by swapping the old "markdown.php" file for the new one.
+
+Here is a short non-exaustive list of some programs and where they
+hide the "markdown.php" file.
+
+| Program | Path to Markdown
+| ------- | ----------------
+| [Pivot][] | `(site home)/pivot/includes/markdown/markdown.php`
+
+If you're unsure if you can do this with your application, ask the
+developer, or wait for the developer to update his application or
+plugin with the new version of PHP Markdown.
+
+ [Pivot]: http://pivotlog.net/
+
+
### In Your Own Programs ###
You can use PHP Markdown easily in your current PHP program. Simply
@@ -183,6 +203,21 @@ expected; (3) the output PHP Markdown actually produced.
Version History
---------------
+1.0.1e (28 Dec 2006)
+
+* Added support for internationalized domain names for email addresses in
+ automatic link. Improved the speed at which email addresses are converted
+ to entities. Thanks to Milian Wolff for his optimisations.
+
+* Made deterministic the conversion to entities of email addresses in
+ automatic links. This means that a given email address will always be
+ encoded the same way.
+
+* PHP Markdown will now use its own function to calculate the length of an
+ UTF-8 string in `detab` when `mb_strlen` is not available instead of
+ giving a fatal error.
+
+
1.0.1d (1 Dec 2006)
* Fixed a bug where inline images always had an empty title attribute. The
@@ -479,12 +514,13 @@ Version History
Copyright and License
---------------------
-Copyright (c) 2004-2005 Michel Fortin
+PHP Markdown
+Copyright (c) 2004-2006 Michel Fortin
<http://www.michelf.com/>
All rights reserved.
Based on Markdown
-Copyright (c) 2003-2005 John Gruber
+Copyright (c) 2003-2006 John Gruber
<http://daringfireball.net/>
All rights reserved.
View
@@ -12,7 +12,7 @@
#
-define( 'MARKDOWN_VERSION', "1.0.1d" ); # Fri 1 Dec 2006
+define( 'MARKDOWN_VERSION', "1.0.1e" ); # Thu 28 Dec 2006
#
@@ -62,7 +62,7 @@ function Markdown($text) {
Plugin Name: Markdown
Plugin URI: http://www.michelf.com/projects/php-markdown/
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>
-Version: 1.0.1d
+Version: 1.0.1e
Author: Michel Fortin
Author URI: http://www.michelf.com/
*/
@@ -209,6 +209,8 @@ function Markdown_Parser() {
#
# Constructor function. Initialize appropriate member variables.
#
+ $this->_initDetab();
+
$this->nested_brackets =
str_repeat('(?>[^\[\]]+|\[', $this->nested_brackets_depth).
str_repeat('\])*', $this->nested_brackets_depth);
@@ -1332,9 +1334,9 @@ function doAutoLinks($text) {
<
(?:mailto:)?
(
- [-.\w]+
+ [-.\w\x80-\xFF]+
\@
- [-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+
+ [-a-z0-9\x80-\xFF]+(\.[-a-z0-9\x80-\xFF]+)*\.[a-z]+
)
>
}xi',
@@ -1358,35 +1360,37 @@ function encodeEmailAddress($addr) {
# of the address encoded as either a decimal or hex entity, in
# the hopes of foiling most address harvesting spam bots. E.g.:
#
- # <a href="&#x6D;&#97;&#105;&#108;&#x74;&#111;:&#102;&#111;&#111;&#64;&#101;
- # x&#x61;&#109;&#x70;&#108;&#x65;&#x2E;&#99;&#111;&#109;">&#102;&#111;&#111;
- # &#64;&#101;x&#x61;&#109;&#x70;&#108;&#x65;&#x2E;&#99;&#111;&#109;</a>
+ # <p><a href="&#109;&#x61;&#105;&#x6c;&#116;&#x6f;&#58;&#x66;o&#111;
+ # &#x40;&#101;&#x78;&#97;&#x6d;&#112;&#x6c;&#101;&#46;&#x63;&#111;
+ # &#x6d;">&#x66;o&#111;&#x40;&#101;&#x78;&#97;&#x6d;&#112;&#x6c;
+ # &#101;&#46;&#x63;&#111;&#x6d;</a></p>
#
- # Based by a filter by Matthew Wickline, posted to the BBEdit-Talk
- # mailing list: <http://tinyurl.com/yu7ue>
+ # Based by a filter by Matthew Wickline, posted to BBEdit-Talk.
+ # With some optimizations by Milian Wolff.
#
$addr = "mailto:" . $addr;
- $length = strlen($addr);
-
- # leave ':' alone (to spot mailto: later)
- $addr = preg_replace_callback('/([^\:])/',
- array(&$this, '_encodeEmailAddress_callback'), $addr);
-
- $addr = "<a href=\"$addr\">$addr</a>";
- # strip the mailto: from the visible part
- $addr = preg_replace('/">.+?:/', '">', $addr);
+ $chars = preg_split('/(?<!^)(?!$)/', $addr);
+ $seed = (int)abs(crc32($addr) / strlen($addr)); # Deterministic seed.
+
+ foreach ($chars as $key => $char) {
+ $ord = ord($char);
+ # Ignore non-ascii chars.
+ if ($ord < 128) {
+ $r = ($seed * (1 + $key)) % 100; # Pseudo-random function.
+ # roughly 10% raw, 45% hex, 45% dec
+ # '@' *must* be encoded. I insist.
+ if ($r > 90 && $char != '@') /* do nothing */;
+ else if ($r < 45) $chars[$key] = '&#x'.dechex($ord).';';
+ else $chars[$key] = '&#'.$ord.';';
+ }
+ }
+
+ $addr = implode('', $chars);
+ $text = implode('', array_slice($chars, 7)); # text without `mailto:`
+ $addr = "<a href=\"$addr\">$text</a>";
return $addr;
}
- function _encodeEmailAddress_callback($matches) {
- $char = $matches[1];
- $r = rand(0, 100);
- # roughly 10% raw, 45% hex, 45% dec
- # '@' *must* be encoded. I insist.
- if ($r > 90 && $char != '@') return $char;
- if ($r < 45) return '&#x'.dechex(ord($char)).';';
- return '&#'.ord($char).';';
- }
function unescapeSpecialChars($text) {
@@ -1476,6 +1480,10 @@ function outdent($text) {
}
+ # String length function for detab. `_initDetab` will create a function to
+ # hanlde UTF-8 if the default function does not exist.
+ var $utf8_strlen = 'mb_strlen';
+
function detab($text) {
#
# Replace tabs with the appropriate amount of space.
@@ -1484,6 +1492,7 @@ function detab($text) {
# tab characters. Then we reconstruct every line by adding the
# appropriate number of space between each blocks.
+ $strlen = $this->utf8_strlen; # best strlen function for UTF-8.
$lines = explode("\n", $text);
$text = "";
@@ -1496,13 +1505,29 @@ function detab($text) {
foreach ($blocks as $block) {
# Calculate amount of space, insert spaces, insert block.
$amount = $this->tab_width -
- mb_strlen($line, 'UTF-8') % $this->tab_width;
+ $strlen($line, 'UTF-8') % $this->tab_width;
$line .= str_repeat(" ", $amount) . $block;
}
$text .= "$line\n";
}
return $text;
}
+ function _initDetab() {
+ #
+ # Check for the availability of the function in the `utf8_strlen` property
+ # (probably `mb_strlen`). If the function is not available, create a
+ # function that will loosely count the number of UTF-8 characters with a
+ # regular expression.
+ #
+ if (function_exists($this->utf8_strlen)) return;
+ $this->utf8_strlen = 'Markdown_UTF8_strlen';
+
+ if (function_exists($this->utf8_strlen)) return;
+ function Markdown_UTF8_strlen($text) {
+ return preg_match_all('/[\x00-\xBF]|[\xC0-\xFF][\x80-\xBF]*/',
+ $text, $m);
+ }
+ }
function unhash($text) {
@@ -1558,6 +1583,8 @@ function unhash($text) {
See the readme file for detailed release notes for this version.
+1.0.1e (21 Dec 2006)
+
1.0.1d (1 Dec 2006)
1.0.1c (9 Dec 2005)

0 comments on commit d3693aa

Please sign in to comment.