From e4ba066f1d19f6704a27a0b71780ee828dd5fc90 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Sat, 21 Apr 2012 22:17:41 +0200 Subject: [PATCH] MDL-32576 import Markdown 1.2.5 --- lib/markdown.php | 46 +++++++++++++------------- lib/markdown_license.txt | 36 ++++++++++++++++++++ lib/tests/markdown_test.php | 66 +++++++++++++++++++++++++++++++++++++ lib/thirdpartylibs.xml | 2 +- 4 files changed, 126 insertions(+), 24 deletions(-) create mode 100644 lib/markdown_license.txt create mode 100644 lib/tests/markdown_test.php diff --git a/lib/markdown.php b/lib/markdown.php index ee3dddbf918..f548fc26c3f 100644 --- a/lib/markdown.php +++ b/lib/markdown.php @@ -3,7 +3,7 @@ # Markdown Extra - A text-to-HTML conversion tool for web writers # # PHP Markdown & Extra -# Copyright (c) 2004-2009 Michel Fortin +# Copyright (c) 2004-2012 Michel Fortin # # # Original Markdown @@ -12,8 +12,8 @@ # -define( 'MARKDOWN_VERSION', "1.0.1n" ); # Sat 10 Oct 2009 -define( 'MARKDOWNEXTRA_VERSION', "1.2.4" ); # Sat 10 Oct 2009 +define( 'MARKDOWN_VERSION', "1.0.1o" ); # Sun 8 Jan 2012 +define( 'MARKDOWNEXTRA_VERSION', "1.2.5" ); # Sun 8 Jan 2012 # @@ -71,7 +71,7 @@ function Markdown($text) { Plugin Name: Markdown Extra Plugin URI: http://michelf.com/projects/php-markdown/ Description: Markdown syntax allows you to write using an easy-to-read, easy-to-write plain text format. Based on the original Perl version by John Gruber. More... -Version: 1.2.4 +Version: 1.2.5 Author: Michel Fortin Author URI: http://michelf.com/ */ @@ -950,7 +950,7 @@ class Markdown_Parser { # Re-usable patterns to match list item bullets and number markers: $marker_ul_re = '[*+-]'; - $marker_ol_re = '\d+[.]'; + $marker_ol_re = '\d+[\.]'; $marker_any_re = "(?:$marker_ul_re|$marker_ol_re)"; $markers_relist = array( @@ -1011,7 +1011,7 @@ class Markdown_Parser { function _doLists_callback($matches) { # Re-usable patterns to match list item bullets and number markers: $marker_ul_re = '[*+-]'; - $marker_ol_re = '\d+[.]'; + $marker_ol_re = '\d+[\.]'; $marker_any_re = "(?:$marker_ul_re|$marker_ol_re)"; $list = $matches[1]; @@ -1141,17 +1141,17 @@ class Markdown_Parser { var $em_relist = array( - '' => '(?:(? '(?:(? '(?<=\S|^)(? '(?<=\S|^)(? '(?:(? '(?:(? '(?<=\S|^)(? '(?<=\S|^)(? '(?:(? '(?:(? '(?<=\S|^)(? '(?<=\S|^)(? ^ | \n ) - [ ]{'.($indent).'}~~~+[ ]*\n + [ ]{0,'.($indent).'}~~~+[ ]*\n ' : '' ). ' # End (if not is span). ) }xs'; @@ -1947,20 +1947,12 @@ class MarkdownExtra_Parser extends Markdown_Parser { } } # - # Check for: Indented code block. - # - else if ($tag{0} == "\n" || $tag{0} == " ") { - # Indented code block: pass it unchanged, will be handled - # later. - $parsed .= $tag; - } - # # Check for: Fenced code block marker. # - else if ($tag{0} == "~") { + else if (preg_match('{^\n?[ ]{0,'.($indent+3).'}~}', $tag)) { # Fenced code block marker: find matching end marker. $tag_re = preg_quote(trim($tag)); - if (preg_match('{^(?>.*\n)+?'.$tag_re.' *\n}', $text, + if (preg_match('{^(?>.*\n)+?[ ]{0,'.($indent).'}'.$tag_re.'[ ]*\n}', $text, $matches)) { # End marker found: pass text unchanged until marker. @@ -1973,6 +1965,14 @@ class MarkdownExtra_Parser extends Markdown_Parser { } } # + # Check for: Indented code block. + # + else if ($tag{0} == "\n" || $tag{0} == " ") { + # Indented code block: pass it unchanged, will be handled + # later. + $parsed .= $tag; + } + # # Check for: Opening Block level tag or # Opening Context Block tag (like ins and del) # used as a block tag (tag is alone on it's line). @@ -2588,17 +2588,17 @@ class MarkdownExtra_Parser extends Markdown_Parser { # work in the middle of a word. # var $em_relist = array( - '' => '(?:(? '(?:(? '(?<=\S|^)(? '(?<=\S|^)(? '(?:(? '(?:(? '(?<=\S|^)(? '(?<=\S|^)(? '(?:(? '(?:(? '(?<=\S|^)(? '(?<=\S|^)(? +All rights reserved. + +Based on Markdown +Copyright (c) 2003-2006 John Gruber + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + +* Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +* Neither the name "Markdown" nor the names of its contributors may + be used to endorse or promote products derived from this software + without specific prior written permission. + +This software is provided by the copyright holders and contributors "as +is" and any express or implied warranties, including, but not limited +to, the implied warranties of merchantability and fitness for a +particular purpose are disclaimed. In no event shall the copyright owner +or contributors be liable for any direct, indirect, incidental, special, +exemplary, or consequential damages (including, but not limited to, +procurement of substitute goods or services; loss of use, data, or +profits; or business interruption) however caused and on any theory of +liability, whether in contract, strict liability, or tort (including +negligence or otherwise) arising in any way out of the use of this +software, even if advised of the possibility of such damage. diff --git a/lib/tests/markdown_test.php b/lib/tests/markdown_test.php new file mode 100644 index 00000000000..b564e8408e5 --- /dev/null +++ b/lib/tests/markdown_test.php @@ -0,0 +1,66 @@ +. + +/** + * Test markdown text format + * + * @package core + * @category phpunit + * @copyright 2012 Petr Skoda {@link http://skodak.org} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + + +/** + * This is not a complete markdown test, it just validates + * Moodle integration works. + * + * See http://daringfireball.net/projects/markdown/basics + * for more format information. + * + * @package core + * @category phpunit + * @copyright 2012 Petr Skoda {@link http://skodak.org} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class core_markdown_testcase extends basic_testcase { + + public function test_paragraphs() { + $text = "one\n\ntwo"; + $result = "

one

\n\n

two

\n"; + $this->assertEquals($result, markdown_to_html($text)); + } + + public function test_headings() { + $text = "Header 1\n====================\n\n## Header 2"; + $result = "

Header 1

\n\n

Header 2

\n"; + $this->assertEquals($result, markdown_to_html($text)); + } + + public function test_lists() { + $text = "* one\n* two\n* three\n"; + $result = "
    \n
  • one
  • \n
  • two
  • \n
  • three
  • \n
\n"; + $this->assertEquals($result, markdown_to_html($text)); + } + + public function test_links() { + $text = "some [example link](http://example.com/)"; + $result = "

some example link

\n"; + $this->assertEquals($result, markdown_to_html($text)); + } +} diff --git a/lib/thirdpartylibs.xml b/lib/thirdpartylibs.xml index 21241ebe043..29598057d5d 100644 --- a/lib/thirdpartylibs.xml +++ b/lib/thirdpartylibs.xml @@ -242,7 +242,7 @@ markdown.php Markdown original+extra BSD - 1.2.4 + 1.2.5