diff --git a/lib/markdown/Markdown.php b/lib/markdown/Markdown.php
index 094b0ee9650..088b7cddb66 100644
--- a/lib/markdown/Markdown.php
+++ b/lib/markdown/Markdown.php
@@ -17,11 +17,11 @@ namespace Michelf;
# Markdown Parser Class
#
-class Markdown {
+class Markdown implements MarkdownInterface {
### Version ###
- const MARKDOWNLIB_VERSION = "1.3";
+ const MARKDOWNLIB_VERSION = "1.4.0";
### Simple Function Interface ###
@@ -1269,7 +1269,7 @@ class Markdown {
# Ampersand-encoding based entirely on Nat Irons's Amputator
# MT plugin:
$text = preg_replace('/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/',
- '&', $text);;
+ '&', $text);
}
# Encode remaining <'s
$text = str_replace('<', '<', $text);
@@ -1302,9 +1302,16 @@ class Markdown {
>
}xi',
array(&$this, '_doAutoLinks_email_callback'), $text);
+ $text = preg_replace_callback('{<(tel:([^\'">\s]+))>}i',array(&$this, '_doAutoLinks_tel_callback'), $text);
return $text;
}
+ protected function _doAutoLinks_tel_callback($matches) {
+ $url = $this->encodeAttribute($matches[1]);
+ $tel = $this->encodeAttribute($matches[2]);
+ $link = "$tel";
+ return $this->hashPart($link);
+ }
protected function _doAutoLinks_url_callback($matches) {
$url = $this->encodeAttribute($matches[1]);
$link = "$url";
@@ -1524,7 +1531,7 @@ class Markdown {
# one.
#
-class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
+abstract class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
### Configuration Variables ###
@@ -1832,9 +1839,6 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
<\?.*?\?> | <%.*?%> # Processing instruction
|
# CData Block
- |
- # Code span marker
- `+
'. ( !$span ? ' # If not in span.
|
# Indented code block
@@ -1846,7 +1850,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
|
# Fenced code block marker
(?<= ^ | \n )
- [ ]{0,'.($indent+3).'}~{3,}
+ [ ]{0,'.($indent+3).'}(?:~{3,}|`{3,})
[ ]*
(?:
\.?[-_:a-zA-Z0-9]+ # standalone class name
@@ -1854,8 +1858,14 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
'.$this->id_class_attr_nocatch_re.' # extra attributes
)?
[ ]*
- \n
+ (?= \n )
' : '' ). ' # End (if not is span).
+ |
+ # Code span marker
+ # Note, this regex needs to go after backtick fenced
+ # code blocks but it should also be kept outside of the
+ # "if not in span" condition adding backticks to the parser
+ `+
)
}xs';
@@ -1897,28 +1907,12 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
$text = $parts[2]; # Remaining text after current tag.
$tag_re = preg_quote($tag); # For use in a regular expression.
- #
- # Check for: Code span marker
- #
- if ($tag{0} == "`") {
- # Find corresponding end marker.
- $tag_re = preg_quote($tag);
- if (preg_match('{^(?>.+?|\n(?!\n))*?(?id_class_attr_nocatch_re.')?[ ]*\n?$}', $tag, $capture)) {
# Fenced code block marker: find matching end marker.
$fence_indent = strlen($capture[1]); # use captured indent in re
$fence_re = $capture[2]; # use captured fence in re
@@ -1943,6 +1937,25 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
$parsed .= $tag;
}
#
+ # Check for: Code span marker
+ # Note: need to check this after backtick fenced code blocks
+ #
+ else if ($tag{0} == "`") {
+ # Find corresponding end marker.
+ $tag_re = preg_quote($tag);
+ if (preg_match('{^(?>.+?|\n(?!\n))*?(?\n";
$text .= "
empty_element_suffix ."\n";
$text .= "\n\n";
-
- $attr = " rev=\"footnote\"";
+
+ $attr = "";
if ($this->fn_backlink_class != "") {
$class = $this->fn_backlink_class;
$class = $this->encodeAttribute($class);
@@ -3091,6 +3104,3 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
}
}
-
-
-?>
\ No newline at end of file
diff --git a/lib/markdown/MarkdownExtra.php b/lib/markdown/MarkdownExtra.php
index 267bf16df32..04e45292ad6 100644
--- a/lib/markdown/MarkdownExtra.php
+++ b/lib/markdown/MarkdownExtra.php
@@ -36,5 +36,3 @@ class MarkdownExtra extends \Michelf\_MarkdownExtra_TmpImpl {
}
-
-?>
\ No newline at end of file
diff --git a/lib/markdown/MarkdownInterface.php b/lib/markdown/MarkdownInterface.php
new file mode 100644
index 00000000000..22c571a0d09
--- /dev/null
+++ b/lib/markdown/MarkdownInterface.php
@@ -0,0 +1,37 @@
+
+#
+# Original Markdown
+# Copyright (c) 2004-2006 John Gruber
+#
+#
+namespace Michelf;
+
+
+#
+# Markdown Parser Interface
+#
+
+interface MarkdownInterface {
+
+ #
+ # Initialize the parser and return the result of its transform method.
+ # This will work fine for derived classes too.
+ #
+ public static function defaultTransform($text);
+
+ #
+ # Main function. Performs some preprocessing on the input text
+ # and pass it through the document gamut.
+ #
+ public function transform($text);
+
+}
+
+
+?>
\ No newline at end of file
diff --git a/lib/markdown/Readme.md b/lib/markdown/Readme.md
index 8ee5fae3ac7..6430c47b83d 100644
--- a/lib/markdown/Readme.md
+++ b/lib/markdown/Readme.md
@@ -1,7 +1,7 @@
PHP Markdown
============
-PHP Markdown Lib 1.3 - 11 Apr 2013
+PHP Markdown Lib 1.4.0 - 29 Nov 2013
by Michel Fortin
@@ -14,23 +14,21 @@ Introduction
------------
This is a library package that includes the PHP Markdown parser and its
-sibling PHP Markdown Extra which additional features.
+sibling PHP Markdown Extra with additional features.
Markdown is a text-to-HTML conversion tool for web writers. Markdown
allows you to write using an easy-to-read, easy-to-write plain text
format, then convert it to structurally valid XHTML (or HTML).
-"Markdown" is two things: a plain text markup syntax, and a software
-tool, written in Perl, that converts the plain text markup to HTML.
-PHP Markdown is a port to PHP of the original Markdown program by
-John Gruber.
+"Markdown" is actually two things: a plain text markup syntax, and a
+software tool, originally written in Perl, that converts the plain text
+markup to HTML. PHP Markdown is a port to PHP of the original Markdown
+program by John Gruber.
-PHP Markdown can work as a plug-in for WordPress, as a modifier for
-the Smarty templating engine, or as a replacement for Textile
-formatting in any software that supports Textile.
-
-Full documentation of Markdown's syntax is available on John's
-Markdown page:
+* [Full documentation of the Markdown syntax]()
+ - Daring Fireball (John Gruber)
+* [Markdown Extra syntax additions]()
+ - Michel Fortin
Requirement
@@ -51,48 +49,8 @@ Usage
This library package is meant to be used with class autoloading. For autoloading
to work, your project needs have setup a PSR-0-compatible autoloader. See the
-included Readme.php file for a minimal autoloader setup. (If you don't want to
-use autoloading you can do a classic `require_once` to manually include the
-files prior use instead.)
-
-With class autoloading in place, putting the 'Michelf' folder in your
-include path should be enough for this to work:
-
- use \Michelf\Markdown;
- $my_html = Markdown::defaultTransform($my_text);
-
-Markdown Extra syntax is also available the same way:
-
- use \Michelf\MarkdownExtra;
- $my_html = MarkdownExtra::defaultTransform($my_text);
-
-If you wish to use PHP Markdown with another text filter function
-built to parse HTML, you should filter the text *after* the `transform`
-function call. This is an example with [PHP SmartyPants][psp]:
-
- use \Michelf\Markdown, \Michelf\SmartyPants;
- $my_html = Markdown::defaultTransform($my_text);
- $my_html = SmartyPants::defaultTransform($my_html);
-
-All these examples are using the static `defaultTransform` static function
-found inside the parser class. If you want to customize the parser
-configuration, you can also instantiate it directly and change some
-configuration variables:
-
- use \Michelf\MarkdownExtra;
- $parser = new MarkdownExtra;
- $parser->fn_id_prefix = "post22-";
- $my_html = $parser->transform($my_text);
-
-
-Usage
------
-
-This library package is meant to be used with class autoloading. For autoloading
-to work, your project needs have setup a PSR-0-compatible autoloader. See the
-included Readme.php file for a minimal autoloader setup. (If you don't want to
-use autoloading you can do a classic `require_once` to manually include the
-files prior use instead.)
+included Readme.php file for a minimal autoloader setup. (If you cannot use
+autoloading, see below.)
With class autoloading in place, putting the 'Michelf' folder in your
include path should be enough for this to work:
@@ -125,10 +83,26 @@ configuration variables:
To learn more, see the full list of [configuration variables].
- [configuration variables]: http://michelf.ca/project/php-markdown/configuration/
+ [configuration variables]: http://michelf.ca/projects/php-markdown/configuration/
-Public API and Versionning Policy
+### Usage without an autoloader
+
+If you cannot use class autoloading, you can still use `include` or `require`
+to access the parser. To load the `\Michelf\Markdown` parser, do it this way:
+
+ require_once 'Michelf/Markdown.inc.php';
+
+Or, if you need the `\Michelf\MarkdownExtra` parser:
+
+ require_once 'Michelf/MarkdownExtra.inc.php';
+
+While the plain `.php` files depend on autoloading to work correctly, using the
+`.inc.php` files instead will eagerly load the dependencies that would be
+loaded on demand if you were using autoloading.
+
+
+Public API and Versioning Policy
---------------------------------
Version numbers are of the form *major*.*minor*.*patch*.
@@ -139,22 +113,22 @@ functions and their configuration variables. The public API is stable for
a given major version number. It might get additions when the minor version
number increments.
-**Protected members are not considered public API.** This is unconventionnal
+**Protected members are not considered public API.** This is unconventional
and deserves an explanation. Incrementing the major version number every time
-the underlying implementation of something changes is going to give nonsential
-version numbers for the vast majority of people who just use the parser.
-Protected members are meant to create parser subclasses that behave in
+the underlying implementation of something changes is going to give
+nonessential version numbers for the vast majority of people who just use the
+parser. Protected members are meant to create parser subclasses that behave in
different ways. Very few people create parser subclasses. I don't want to
discourage it by making everything private, but at the same time I can't
-guarenty any stable hook between versions if you use protected members.
+guarantee any stable hook between versions if you use protected members.
**Syntax changes** will increment the minor number for new features, and the
patch number for small corrections. A *new feature* is something that needs a
change in the syntax documentation. Note that since PHP Markdown Lib includes
two parsers, a syntax change for either of them will increment the minor
-number. Also note that there is nothigng perfectly backward-compatible with the
+number. Also note that there is nothing perfectly backward-compatible with the
Markdown syntax: all inputs are always valid, so new features always replace
-something that was previously legal, although generally non-sensial to do.
+something that was previously legal, although generally nonsensical to do.
Bugs
@@ -171,17 +145,55 @@ that the backtrack limit is not too low by running `php --info | grep pcre`.
See Installation and Requirement above for details.
+Development and Testing
+-----------------------
+
+Pull requests for fixing bugs are welcome. Proposed new features are
+going meticulously reviewed -- taking into account backward compatibility,
+potential side effects, and future extensibility -- before deciding on
+acceptance or rejection.
+
+If you make a pull request that includes changes to the parser please add
+tests for what is being changed to [MDTest][] and make a pull request there
+too.
+
+ [MDTest]: https://github.com/michelf/mdtest/
+
+
Version History
---------------
-PHP Markdown Lib 1.3 (11 Apr 2013):
+PHP Markdown Lib 1.4.0 (29 Nov 2013)
+
+* Added support for the `tel:` URL scheme in automatic links.
+
+
+
+ It gets converted to this (note the `tel:` prefix becomes invisible):
+
+ +1-111-111-1111
+
+* Added backtick fenced code blocks to MarkdownExtra, originally from
+ Github-Flavored Markdown.
+
+* Added an interface called MarkdownInterface implemented by both
+ the Markdown and MarkdownExtra parsers. You can use the interface if
+ you want to create a mockup parser object for unit testing.
+
+* For those of you who cannot use class autoloading, you can now
+ include `Michelf/Markdown.inc.php` or `Michelf/MarkdownExtra.inc.php` (note
+ the `.inc.php` extension) to automatically include other files required
+ by the parser.
+
+
+PHP Markdown Lib 1.3 (11 Apr 2013)
This is the first release of PHP Markdown Lib. This package requires PHP
-version 4.3 or later and is designed to work with PSR-0 autoloading and,
+version 5.3 or later and is designed to work with PSR-0 autoloading and,
optionally with Composer. Here is a list of the changes since
PHP Markdown Extra 1.2.6:
-* Plugin interface for Wordpress and other systems is no longer present in
+* Plugin interface for WordPress and other systems is no longer present in
the Lib package. The classic package is still available if you need it:
diff --git a/lib/thirdpartylibs.xml b/lib/thirdpartylibs.xml
index 7656bdc7c6c..4d879c9df5f 100644
--- a/lib/thirdpartylibs.xml
+++ b/lib/thirdpartylibs.xml
@@ -235,7 +235,7 @@
markdown
Markdown original+extra
BSD
- 1.3.0
+ 1.4.0
diff --git a/lib/weblib.php b/lib/weblib.php
index 43abf4dd5fc..431f846fb49 100644
--- a/lib/weblib.php
+++ b/lib/weblib.php
@@ -1784,6 +1784,7 @@ function markdown_to_html($text) {
return $text;
}
+ require_once($CFG->libdir .'/markdown/MarkdownInterface.php');
require_once($CFG->libdir .'/markdown/Markdown.php');
require_once($CFG->libdir .'/markdown/MarkdownExtra.php');