Skip to content
Permalink
Browse files Browse the repository at this point in the history
Ignore wrong urls on markdown plugin
  • Loading branch information
yurabakhtin committed Jan 19, 2017
1 parent 274ad58 commit ce5b36e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions plugins/markdown_plugin/_parsedown.inc.php
Expand Up @@ -29,6 +29,7 @@
9. Don't apply <p> around list and already existing paragraph tags
10. Don't convert HTML entities inside <code> html tags because the "Escape code" plugin does this
11. Fix the missed empty lines in code blocks which are started and ended with ```
12. Ignore wrong URLs for links and images; Allow only which begin with http://, https:// or /
*/

class Parsedown
Expand Down Expand Up @@ -100,7 +101,7 @@ function parse($text)

# Extracts link references.

if (preg_match_all('/^[ ]{0,3}\[(.+)\][ ]?:[ ]*\n?[ ]*(.+)$/m', $text, $matches, PREG_SET_ORDER))
if (preg_match_all('/^[ ]{0,3}\[(.+)\][ ]?:[ ]*\n?[ ]*((https?:\/\/|\/).+)$/m', $text, $matches, PREG_SET_ORDER))
{
foreach ($matches as $matches)
{
Expand Down Expand Up @@ -589,23 +590,23 @@ private function parse_inline_elements($text)
if( strpos($text, '](') !== FALSE ) # inline
{
$text = str_replace( '&quot;', '"', $text ); // revert from html entity
if( preg_match_all( '/(!?)(\[((?:[^][]+|(?2))*)\])\(([^"]*?)( "([^"]+)")?\)/', $text, $matches, PREG_SET_ORDER ) )
if( preg_match_all( '/(!?)(\[((?:[^][]+|(?2))*)\])\((https?:\/\/|\/)([^"]*?)( "([^"]+)")?\)/', $text, $matches, PREG_SET_ORDER ) )
{
foreach ($matches as $matches)
{
if ($matches[1]) # image
{
if( $this->parse_images )
{ // Parse images only if it is enabled
$element = '<img src="'.$matches[4].'" alt="'.$matches[3].'"'.( ! empty( $matches[6] ) ? ' title="'.$matches[6].'"' : '' ).'>';
$element = '<img src="'.$matches[4].$matches[5].'" alt="'.$matches[3].'"'.( ! empty( $matches[7] ) ? ' title="'.$matches[7].'"' : '' ).'>';
}
}
else
{
if( $this->parse_links )
{ // Parse links only if it is enabled
$element_text = $this->parse_inline_elements($matches[3]);
$element = '<a href="'.$matches[4].'"'.( ! empty( $matches[6] ) ? ' title="'.$matches[6].'"' : '' ).'>'.$element_text.'</a>';
$element = '<a href="'.$matches[4].$matches[5].'"'.( ! empty( $matches[7] ) ? ' title="'.$matches[7].'"' : '' ).'>'.$element_text.'</a>';
}
}

Expand Down

0 comments on commit ce5b36e

Please sign in to comment.