Update PHP Markdown lib and get MarkdownExtra working. (#54)

* Get MarkdownExtra working.

It's not enough to import the right library
(Markdown or MarkdownExtra); you'll have to
call the right functions, too!

For the "classic" implementation, there's no
difference, as it seems.

Signed-off-by: Thomas Hochstein <thh@inter.net>

* Upgrade PHP Markdown Lib to 1.7.0

Former version was 1.4.0 from 2013.

Signed-off-by: Thomas Hochstein <thh@inter.net>

* serendipity_event_markdown 1.23

Update Changelog, bump version number.

Add me as author.

Signed-off-by: Thomas Hochstein <thh@inter.net>
This commit is contained in:
Thomas Hochstein 2017-04-19 14:02:25 +02:00 committed by onli
parent 97606ed36b
commit 7f04883ef1
12 changed files with 2885 additions and 2207 deletions

View file

@ -1,3 +1,18 @@
Version 1.23:
=============
Changes by Thomas Hochstein <thh@inter.net>
- Notice: The "classic" version is no longer supported from Feb 1, 2013
and stuck at PHP Markdown 1.0.2 / PHP Markdown Extra 1.2.8
- Upgrade PHP Markdown Lib to 1.7.0 (was 1.4.0).
- Get Markdown Extra working when using the PHP Markdown Lib;
it didn't before.
Version 1.22:
=============
- Added parameters to html_entity_decode() and htmlentities().
Version 1.21:
=============
@ -13,7 +28,6 @@ Version 1.21:
typographic punctuation HTML entities.
- extend to PHP >= 5.3 only (while lib using namespaces)
Version 1.1.5:
==============
Changes by Lukas Reindl (ljr_nbg [at] web [dot] de)

View file

@ -1,11 +1,11 @@
PHP Markdown Lib
Copyright (c) 2004-2013 Michel Fortin
<http://michelf.ca/>
Copyright (c) 2004-2016 Michel Fortin
<https://michelf.ca/>
All rights reserved.
Based on Markdown
Copyright (c) 2003-2006 John Gruber
<http://daringfireball.net/>
<https://daringfireball.net/>
All rights reserved.
Redistribution and use in source and binary forms, with or without

View file

@ -1,10 +1,10 @@
<?php
# Use this file if you cannot use class autoloading. It will include all the
# files needed for the Markdown parser.
#
# Take a look at the PSR-0-compatible class autoloading implementation
# in the Readme.php file if you want a simple autoloader setup.
// Use this file if you cannot use class autoloading. It will include all the
// files needed for the Markdown parser.
//
// Take a look at the PSR-0-compatible class autoloading implementation
// in the Readme.php file if you want a simple autoloader setup.
require_once dirname(__FILE__) . '/MarkdownInterface.php';
require_once dirname(__FILE__) . '/Markdown.php';

File diff suppressed because it is too large Load diff

View file

@ -1,10 +1,10 @@
<?php
# Use this file if you cannot use class autoloading. It will include all the
# files needed for the MarkdownExtra parser.
#
# Take a look at the PSR-0-compatible class autoloading implementation
# in the Readme.php file if you want a simple autoloader setup.
// Use this file if you cannot use class autoloading. It will include all the
// files needed for the MarkdownExtra parser.
//
// Take a look at the PSR-0-compatible class autoloading implementation
// in the Readme.php file if you want a simple autoloader setup.
require_once dirname(__FILE__) . '/MarkdownInterface.php';
require_once dirname(__FILE__) . '/Markdown.php';

File diff suppressed because it is too large Load diff

View file

@ -1,9 +1,9 @@
<?php
# Use this file if you cannot use class autoloading. It will include all the
# files needed for the MarkdownInterface interface.
#
# Take a look at the PSR-0-compatible class autoloading implementation
# in the Readme.php file if you want a simple autoloader setup.
// Use this file if you cannot use class autoloading. It will include all the
// files needed for the MarkdownInterface interface.
//
// Take a look at the PSR-0-compatible class autoloading implementation
// in the Readme.php file if you want a simple autoloader setup.
require_once dirname(__FILE__) . '/MarkdownInterface.php';

View file

@ -1,37 +1,38 @@
<?php
#
# Markdown - A text-to-HTML conversion tool for web writers
#
# PHP Markdown
# Copyright (c) 2004-2013 Michel Fortin
# <http://michelf.com/projects/php-markdown/>
#
# Original Markdown
# Copyright (c) 2004-2006 John Gruber
# <http://daringfireball.net/projects/markdown/>
#
/**
* Markdown - A text-to-HTML conversion tool for web writers
*
* @package php-markdown
* @author Michel Fortin <michel.fortin@michelf.com>
* @copyright 2004-2016 Michel Fortin <https://michelf.com/projects/php-markdown/>
* @copyright (Original Markdown) 2004-2006 John Gruber <https://daringfireball.net/projects/markdown/>
*/
namespace Michelf;
#
# Markdown Parser Interface
#
/**
* Markdown Parser Interface
*/
interface MarkdownInterface {
/**
* Initialize the parser and return the result of its transform method.
* This will work fine for derived classes too.
*
* @api
*
* @param string $text
* @return string
*/
public static function defaultTransform($text);
#
# 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);
/**
* Main function. Performs some preprocessing on the input text
* and pass it through the document gamut.
*
* @api
*
* @param string $text
* @return string
*/
public function transform($text);
}
?>

View file

@ -1,13 +1,13 @@
PHP Markdown
============
PHP Markdown Lib 1.4.0 - 29 Nov 2013
PHP Markdown Lib 1.7.0 - 29 Oct 2016
by Michel Fortin
<http://michelf.ca/>
<https://michelf.ca/>
based on Markdown by John Gruber
<http://daringfireball.net/>
<https://daringfireball.net/>
Introduction
@ -25,10 +25,10 @@ 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.
* [Full documentation of the Markdown syntax](<http://daringfireball.net/projects/markdown/>)
- Daring Fireball (John Gruber)
* [Markdown Extra syntax additions](<http://michelf.ca/projects/php-markdown/extra/>)
- Michel Fortin
* [Full documentation of the Markdown syntax](<https://daringfireball.net/projects/markdown/>)
Daring Fireball (John Gruber)
* [Markdown Extra syntax additions](<https://michelf.ca/projects/php-markdown/extra/>)
Michel Fortin
Requirement
@ -83,7 +83,7 @@ configuration variables:
To learn more, see the full list of [configuration variables].
[configuration variables]: http://michelf.ca/projects/php-markdown/configuration/
[configuration variables]: https://michelf.ca/projects/php-markdown/configuration/
### Usage without an autoloader
@ -149,7 +149,7 @@ Development and Testing
-----------------------
Pull requests for fixing bugs are welcome. Proposed new features are
going meticulously reviewed -- taking into account backward compatibility,
going to be meticulously reviewed -- taking into account backward compatibility,
potential side effects, and future extensibility -- before deciding on
acceptance or rejection.
@ -160,9 +160,122 @@ too.
[MDTest]: https://github.com/michelf/mdtest/
Donations
---------
If you wish to make a donation that will help me devote more time to
PHP Markdown, please visit [michelf.ca/donate] or send Bitcoin to
[1HiuX34czvVPPdhXbUAsAu7pZcesniDCGH].
[michelf.ca/donate]: https://michelf.ca/donate/#!Thanks%20for%20PHP%20Markdown
[1HiuX34czvVPPdhXbUAsAu7pZcesniDCGH]: bitcoin:1HiuX34czvVPPdhXbUAsAu7pZcesniDCGH
Version History
---------------
PHP Markdown Lib 1.7.0 (29 Oct 2016)
* Added a `hard_wrap` configuration variable to make all newline characters
in the text become `<br>` tags in the HTML output. By default, according
to the standard Markdown syntax these newlines are ignored unless they a
preceded by two spaces. Thanks to Jonathan Cohlmeyer for the implementation.
* Improved the parsing of list items to fix problematic cases that came to
light with the addition of `hard_wrap`. This should have no effect on the
output except span-level list items that ended with two spaces (and thus
ended with a line break).
* Added a `code_span_content_func` configuration variable which takes a
function that will convert the content of the code span to HTML. This can
be useful to implement syntax highlighting. Although contrary to its
code block equivalent, there is no syntax for specifying a language.
Credits to styxit for the implementation.
* Fixed a Markdwon Extra issue where two-space-at-end-of-line hard breaks
wouldn't work inside of HTML block elements such as `<p markdown="1">`
where the element expects only span-level content.
* In the parser code, switched to PHPDoc comment format. Thanks to
Robbie Averill for the help.
PHP Markdown Lib 1.6.0 (23 Dec 2015)
Note: this version was incorrectly released as 1.5.1 on Dec 22, a number
that contradicted the versioning policy.
* For fenced code blocks in Markdown Extra, can now set a class name for the
code block's language before the special attribute block. Previously, this
class name was only allowed in the absence of the special attribute block.
* Added a `code_block_content_func` configuration variable which takes a
function that will convert the content of the code block to HTML. This is
most useful for syntax highlighting. For fenced code blocks in Markdown
Extra, the function has access to the language class name (the one outside
of the special attribute block). Credits to Mario Konrad for providing the
implementation.
* The curled arrow character for the backlink in footnotes is now followed
by a Unicode variant selector to prevent it from being displayed in emoji
form on iOS.
Note that in older browsers the variant selector is often interpreted as a
separate character, making it visible after the arrow. So there is now a
also a `fn_backlink_html` configuration variable that can be used to set
the link text to something else. Credits to Dana for providing the
implementation.
* Fixed an issue in MarkdownExtra where long header lines followed by a
special attribute block would hit the backtrack limit an cause an empty
string to be returned.
PHP Markdown Lib 1.5.0 (1 Mar 2015)
* Added the ability start ordered lists with a number different from 1 and
and have that reflected in the HTML output. This can be enabled with
the `enhanced_ordered_lists` configuration variable for the Markdown
parser; it is enabled by default for Markdown Extra.
Credits to Matt Gorle for providing the implementation.
* Added the ability to insert custom HTML attributes with simple values
everywhere an extra attribute block is allowed (links, images, headers).
The value must be unquoted, cannot contains spaces and is limited to
alphanumeric ASCII characters.
Credits to Peter Droogmans for providing the implementation.
* Added a `header_id_func` configuration variable which takes a function
that can generate an `id` attribute value from the header text.
Credits to Evert Pot for providing the implementation.
* Added a `url_filter_func` configuration variable which takes a function
that can rewrite any link or image URL to something different.
PHP Markdown Lib 1.4.1 (4 May 2014)
* The HTML block parser will now treat `<figure>` as a block-level element
(as it should) and no longer wrap it in `<p>` or parse it's content with
the as Markdown syntax (although with Extra you can use `markdown="1"`
if you wish to use the Markdown syntax inside it).
* The content of `<style>` elements will now be left alone, its content
won't be interpreted as Markdown.
* Corrected an bug where some inline links with spaces in them would not
work even when surounded with angle brackets:
[link](<s p a c e s>)
* Fixed an issue where email addresses with quotes in them would not always
have the quotes escaped in the link attribute, causing broken links (and
invalid HTML).
* Fixed the case were a link definition following a footnote definition would
be swallowed by the footnote unless it was separated by a blank line.
PHP Markdown Lib 1.4.0 (29 Nov 2013)
* Added support for the `tel:` URL scheme in automatic links.
@ -195,7 +308,7 @@ PHP Markdown Extra 1.2.6:
* 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:
<http://michelf.ca/projects/php-markdown/classic/>
<https://michelf.ca/projects/php-markdown/classic/>
* Added `public` and `protected` protection attributes, plus a section about
what is "public API" and what isn't in the Readme file.
@ -233,13 +346,13 @@ Copyright and License
---------------------
PHP Markdown Lib
Copyright (c) 2004-2013 Michel Fortin
<http://michelf.ca/>
Copyright (c) 2004-2016 Michel Fortin
<https://michelf.ca/>
All rights reserved.
Based on Markdown
Copyright (c) 2003-2005 John Gruber
<http://daringfireball.net/>
<https://daringfireball.net/>
All rights reserved.
Redistribution and use in source and binary forms, with or without

View file

@ -1,18 +1,18 @@
<?php
# This file passes the content of the Readme.md file in the same directory
# through the Markdown filter. You can adapt this sample code in any way
# you like.
// This file passes the content of the Readme.md file in the same directory
// through the Markdown filter. You can adapt this sample code in any way
// you like.
# Install PSR-0-compatible class autoloader
// Install PSR-0-compatible class autoloader
spl_autoload_register(function($class){
require preg_replace('{\\\\|_(?!.*\\\\)}', DIRECTORY_SEPARATOR, ltrim($class, '\\')).'.php';
});
# Get Markdown class
// Get Markdown class
use \Michelf\Markdown;
# Read file and pass content through the Markdown parser
// Read file and pass content through the Markdown parser
$text = file_get_contents('Readme.md');
$html = Markdown::defaultTransform($text);
@ -24,7 +24,7 @@ $html = Markdown::defaultTransform($text);
</head>
<body>
<?php
# Put HTML content in the document
// Put HTML content in the document
echo $html;
?>
</body>

View file

@ -2,19 +2,19 @@
"name": "michelf/php-markdown",
"type": "library",
"description": "PHP Markdown",
"homepage": "http://michelf.ca/projects/php-markdown/",
"homepage": "https://michelf.ca/projects/php-markdown/",
"keywords": ["markdown"],
"license": "BSD-3-Clause",
"authors": [
{
"name": "Michel Fortin",
"email": "michel.fortin@michelf.ca",
"homepage": "http://michelf.ca/",
"homepage": "https://michelf.ca/",
"role": "Developer"
},
{
"name": "John Gruber",
"homepage": "http://daringfireball.net/"
"homepage": "https://daringfireball.net/"
}
],
"require": {

View file

@ -25,13 +25,13 @@ class serendipity_event_markdown extends serendipity_event
$propbag->add('name', PLUGIN_EVENT_MARKDOWN_NAME);
$propbag->add('description', PLUGIN_EVENT_MARKDOWN_DESC);
$propbag->add('stackable', false);
$propbag->add('author', 'Serendipity Team and Jan Lehnardt');
$propbag->add('author', 'Serendipity Team, Jan Lehnardt and Thomas Hochstein');
$propbag->add('requirements', array(
'serendipity' => '0.7',
'smarty' => '2.6.7',
'php' => '5.3.0'
));
$propbag->add('version', '1.22');
$propbag->add('version', '1.23');
$propbag->add('cachable_events', array('frontend_display' => true));
$propbag->add('event_hooks', array('frontend_display' => true, 'frontend_comment' => true));
$propbag->add('groups', array('MARKUP'));
@ -134,10 +134,11 @@ class serendipity_event_markdown extends serendipity_event
$mdsp = $this->get_config('MARKDOWN_SMARTYPANTS');
$mdv = $this->get_config('MARKDOWN_VERSION');
$mde = serendipity_db_bool($this->get_config('MARKDOWN_EXTRA', false));
switch($mdv) {
case 2:
if ($this->get_config('MARKDOWN_EXTRA', false)) {
if ($mde) {
require_once dirname(__FILE__) . '/lib/Michelf/MarkdownExtra.inc.php';
} else {
require_once dirname(__FILE__) . '/lib/Michelf/Markdown.inc.php';
@ -151,7 +152,7 @@ class serendipity_event_markdown extends serendipity_event
break;
case 1:
if (serendipity_db_bool($this->get_config('MARKDOWN_EXTRA', false))) {
if ($mde) {
include_once dirname(__FILE__) . '/markdown_extra.php';
} else {
include_once dirname(__FILE__) . '/markdown.php';
@ -171,7 +172,11 @@ class serendipity_event_markdown extends serendipity_event
!isset($serendipity['POST']['properties']['disable_markup_' . $this->instance])) {
$element = $temp['element'];
if ($mdv == 2) {
$eventData[$element] = str_replace('javascript:', '', Markdown::defaultTransform($eventData[$element]));
if ($mde) {
$eventData[$element] = str_replace('javascript:', '', MarkdownExtra::defaultTransform($eventData[$element]));
} else {
$eventData[$element] = str_replace('javascript:', '', Markdown::defaultTransform($eventData[$element]));
}
if ($mdsp == 1) $eventData[$element] = SmartyPants::defaultTransform($eventData[$element]);
if ($mdsp == 2) $eventData[$element] = SmartyPantsTypographer::defaultTransform($eventData[$element]);
} else {
@ -179,7 +184,7 @@ class serendipity_event_markdown extends serendipity_event
}
}
}
$this->setPlaintextBody($eventData, $mdv, $mdsp);
$this->setPlaintextBody($eventData, $mde, $mdv, $mdsp);
return true;
break;
@ -203,16 +208,24 @@ class serendipity_event_markdown extends serendipity_event
* @see http://board.s9y.org/viewtopic.php?f=11&t=18351 Discussion of this feature in the S9y forum.
*
* @param array $eventData
* @param bool $extra Markdown Extra default FALSE
* @param int $version Markdown Classic or Lib default 2
* @param int $pants SmartyPants option default 0
*/
function setPlaintextBody(array $eventData, $version=2, $pants=0)
function setPlaintextBody(array $eventData, $extra=FALSE, $version=2, $pants=0)
{
if (isset($GLOBALS['entry'][0]['plaintext_body'])) {
$html = ($version == 2) ? Markdown::defaultTransform($GLOBALS['entry'][0]['plaintext_body']) : Markdown($GLOBALS['entry'][0]['plaintext_body']);
$plaintext_body = $GLOBALS['entry'][0]['plaintext_body'];
} else {
$html = ($version == 2) ? Markdown::defaultTransform(html_entity_decode($eventData['body'], ENT_COMPAT, LANG_CHARSET)) : Markdown(html_entity_decode($eventData['body'], ENT_COMPAT, LANG_CHARSET));
$plaintext_body = html_entity_decode($eventData['body'], ENT_COMPAT, LANG_CHARSET);
}
if ($mde) {
$html = ($version == 2) ? MarkdownExtra::defaultTransform($plaintext_body) : Markdown($plaintext_body);
} else {
$html = ($version == 2) ? Markdown::defaultTransform($plaintext_body) : Markdown($plaintext_body);
}
if ($pants > 0) $html = ($pants == 2) ? SmartyPantsTypographer::defaultTransform($html) : SmartyPants::defaultTransform($html);
$GLOBALS['entry'][0]['plaintext_body'] = trim(strip_tags(str_replace('javascript:', '', $html)));
}