"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "framework/vendors/markdown/markdown.php" between
yii-1.1.21.733ac5.tar.gz and yii-1.1.22.bf1d26.tar.gz

About: Yii is a high-performance component-based PHP framework for developing large-scale Web applications. Hint: Yii 1.1 is now in maintenance mode.

markdown.php  (yii-1.1.21.733ac5):markdown.php  (yii-1.1.22.bf1d26)
skipping to change at line 48 skipping to change at line 48
public $no_entities = false; public $no_entities = false;
# Predefined urls and titles for reference links and images. # Predefined urls and titles for reference links and images.
public $predef_urls = array(); public $predef_urls = array();
public $predef_titles = array(); public $predef_titles = array();
public function __construct() { public function __construct() {
# #
# Constructor function. Initialize appropriate member variables. # Constructor function. Initialize appropriate member variables.
# #
$this->_initDetab();
$this->prepareItalicsAndBold(); $this->prepareItalicsAndBold();
$this->nested_brackets_re = $this->nested_brackets_re =
str_repeat('(?>[^\[\]]+|\[', $this->nested_brackets_depth ). str_repeat('(?>[^\[\]]+|\[', $this->nested_brackets_depth ).
str_repeat('\])*', $this->nested_brackets_depth); str_repeat('\])*', $this->nested_brackets_depth);
$this->nested_url_parenthesis_re = $this->nested_url_parenthesis_re =
str_repeat('(?>[^()\s]+|\(', $this->nested_url_parenthesi s_depth). str_repeat('(?>[^()\s]+|\(', $this->nested_url_parenthesi s_depth).
str_repeat('(?>\)))*', $this->nested_url_parenthesis_dept h); str_repeat('(?>\)))*', $this->nested_url_parenthesis_dept h);
skipping to change at line 722 skipping to change at line 721
}xm', }xm',
array(&$this, '_doHeaders_callback_atx'), $text); array(&$this, '_doHeaders_callback_atx'), $text);
return $text; return $text;
} }
public function _doHeaders_callback_setext($matches) { public function _doHeaders_callback_setext($matches) {
# Terrible hack to check we haven't found an empty list item. # Terrible hack to check we haven't found an empty list item.
if ($matches[2] == '-' && preg_match('{^-(?: |$)}', $matches[1])) if ($matches[2] == '-' && preg_match('{^-(?: |$)}', $matches[1]))
return $matches[0]; return $matches[0];
$level = $matches[2]{0} == '=' ? 1 : 2; $level = $matches[2][0] == '=' ? 1 : 2;
$block = "<h$level>".$this->runSpanGamut($matches[1])."</h$level> "; $block = "<h$level>".$this->runSpanGamut($matches[1])."</h$level> ";
return "\n" . $this->hashBlock($block) . "\n\n"; return "\n" . $this->hashBlock($block) . "\n\n";
} }
public function _doHeaders_callback_atx($matches) { public function _doHeaders_callback_atx($matches) {
$level = strlen($matches[1]); $level = strlen($matches[1]);
$block = "<h$level>".$this->runSpanGamut($matches[2])."</h$level> "; $block = "<h$level>".$this->runSpanGamut($matches[2])."</h$level> ";
return "\n" . $this->hashBlock($block) . "\n\n"; return "\n" . $this->hashBlock($block) . "\n\n";
} }
public function doLists($text) { public function doLists($text) {
skipping to change at line 1015 skipping to change at line 1014
array_shift($token_stack); array_shift($token_stack);
$span = array_shift($text_stack); $span = array_shift($text_stack);
$span = $this->runSpanGamut($span); $span = $this->runSpanGamut($span);
$span = "<strong><em>$span</em></strong>" ; $span = "<strong><em>$span</em></strong>" ;
$text_stack[0] .= $this->hashPart($span); $text_stack[0] .= $this->hashPart($span);
$em = ''; $em = '';
$strong = ''; $strong = '';
} else { } else {
# Other closing marker: close one em or s trong and # Other closing marker: close one em or s trong and
# change current token state to match the other # change current token state to match the other
$token_stack[0] = str_repeat($token{0}, 3 -$token_len); $token_stack[0] = str_repeat($token[0], 3 -$token_len);
$tag = $token_len == 2 ? "strong" : "em"; $tag = $token_len == 2 ? "strong" : "em";
$span = $text_stack[0]; $span = $text_stack[0];
$span = $this->runSpanGamut($span); $span = $this->runSpanGamut($span);
$span = "<$tag>$span</$tag>"; $span = "<$tag>$span</$tag>";
$text_stack[0] = $this->hashPart($span); $text_stack[0] = $this->hashPart($span);
$$tag = ''; # $$tag stands for $em or $st rong $$tag = ''; # $$tag stands for $em or $st rong
} }
$tree_char_em = false; $tree_char_em = false;
} else if ($token_len == 3) { } else if ($token_len == 3) {
if ($em) { if ($em) {
skipping to change at line 1040 skipping to change at line 1039
$tag = strlen($shifted_token) == 2 ? "strong" : "em"; $tag = strlen($shifted_token) == 2 ? "strong" : "em";
$span = array_shift($text_stack); $span = array_shift($text_stack);
$span = $this->runSpanGamut($span ); $span = $this->runSpanGamut($span );
$span = "<$tag>$span</$tag>"; $span = "<$tag>$span</$tag>";
$text_stack[0] .= $this->hashPart ($span); $text_stack[0] .= $this->hashPart ($span);
$$tag = ''; # $$tag stands for $e m or $strong $$tag = ''; # $$tag stands for $e m or $strong
} }
} else { } else {
# Reached opening three-char emphasis mar ker. Push on token # Reached opening three-char emphasis mar ker. Push on token
# stack; will be handled by the special c ondition above. # stack; will be handled by the special c ondition above.
$em = $token{0}; $em = $token[0];
$strong = "$em$em"; $strong = "$em$em";
array_unshift($token_stack, $token); array_unshift($token_stack, $token);
array_unshift($text_stack, ''); array_unshift($text_stack, '');
$tree_char_em = true; $tree_char_em = true;
} }
} else if ($token_len == 2) { } else if ($token_len == 2) {
if ($strong) { if ($strong) {
# Unwind any dangling emphasis marker: # Unwind any dangling emphasis marker:
if (strlen($token_stack[0]) == 1) { if (strlen($token_stack[0]) == 1) {
$text_stack[1] .= array_shift($to ken_stack); $text_stack[1] .= array_shift($to ken_stack);
skipping to change at line 1363 skipping to change at line 1362
} }
return $output; return $output;
} }
public function handleSpanToken($token, &$str) { public function handleSpanToken($token, &$str) {
# #
# Handle $token provided by parseSpan by determining its nature and # Handle $token provided by parseSpan by determining its nature and
# returning the corresponding value that should replace it. # returning the corresponding value that should replace it.
# #
switch ($token{0}) { switch ($token[0]) {
case "\\": case "\\":
return $this->hashPart("&#". ord($token{1}). ";") ; return $this->hashPart("&#". ord($token[1]). ";") ;
case "`": case "`":
# Search for end marker in remaining text. # Search for end marker in remaining text.
if (preg_match('/^(.*?[^`])'.preg_quote($token).' (?!`)(.*)$/sm', if (preg_match('/^(.*?[^`])'.preg_quote($token).' (?!`)(.*)$/sm',
$str, $matches)) $str, $matches))
{ {
$str = $matches[2]; $str = $matches[2];
$codespan = $this->makeCodeSpan($matches[ 1]); $codespan = $this->makeCodeSpan($matches[ 1]);
return $this->hashPart($codespan); return $this->hashPart($codespan);
} }
return $token; // return as text since no ending marker found. return $token; // return as text since no ending marker found.
skipping to change at line 1388 skipping to change at line 1387
} }
} }
public function outdent($text) { public function outdent($text) {
# #
# Remove one level of line-leading tabs or spaces # Remove one level of line-leading tabs or spaces
# #
return preg_replace('/^(\t|[ ]{1,'.$this->tab_width.'})/m', '', $ text); return preg_replace('/^(\t|[ ]{1,'.$this->tab_width.'})/m', '', $ text);
} }
# String length function for detab. `_initDetab` will create a function t
o
# hanlde UTF-8 if the default function does not exist.
public $utf8_strlen = 'mb_strlen';
public function detab($text) { public function detab($text) {
# #
# Replace tabs with the appropriate amount of space. # Replace tabs with the appropriate amount of space.
# #
# For each line we separate the line in blocks delemited by # For each line we separate the line in blocks delemited by
# tab characters. Then we reconstruct every line by adding the # tab characters. Then we reconstruct every line by adding the
# appropriate number of space between each blocks. # appropriate number of space between each blocks.
$text = preg_replace_callback('/^.*\t.*$/m', $text = preg_replace_callback('/^.*\t.*$/m',
array(&$this, '_detab_callback'), $text); array(&$this, '_detab_callback'), $text);
return $text; return $text;
} }
public function _detab_callback($matches) { public function _detab_callback($matches) {
$line = $matches[0]; $line = $matches[0];
$strlen = $this->utf8_strlen; # strlen function for UTF-8.
# Split in blocks. # Split in blocks.
$blocks = explode("\t", $line); $blocks = explode("\t", $line);
# Add each blocks to the line. # Add each blocks to the line.
$line = $blocks[0]; $line = $blocks[0];
unset($blocks[0]); # Do not add first block twice. unset($blocks[0]); # Do not add first block twice.
foreach ($blocks as $block) { foreach ($blocks as $block) {
# Calculate amount of space, insert spaces, insert block. # Calculate amount of space, insert spaces, insert block.
$amount = $this->tab_width - $amount = $this->tab_width -
$strlen($line, 'UTF-8') % $this->tab_width; $this->utf8_strlen($line) % $this->tab_width;
$line .= str_repeat(" ", $amount) . $block; $line .= str_repeat(" ", $amount) . $block;
} }
return $line; return $line;
} }
public function _initDetab() {
# protected function utf8_strlen($string) {
# Check for the availability of the function in the `utf8_strlen` propert if (function_exists('mb_strlen')) {
y return mb_strlen($string, 'UTF-8');
# (initially `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. return preg_match_all(
# "/[\x00-\xBF]|[\xC0-\xFF][\x80-\xBF]*/",
if (function_exists($this->utf8_strlen)) return; $text,
$this->utf8_strlen = create_function('$text', 'return preg_match_ $m
all( );
"/[\\\\x00-\\\\xBF]|[\\\\xC0-\\\\xFF][\\\\x80-\\\\xBF]*/"
,
$text, $m);');
} }
public function unhash($text) { public function unhash($text) {
# #
# Swap back in all the tags hashed by _HashHTMLBlocks. # Swap back in all the tags hashed by _HashHTMLBlocks.
# #
return preg_replace_callback('/(.)\x1A[0-9]+\1/', return preg_replace_callback('/(.)\x1A[0-9]+\1/',
array(&$this, '_unhash_callback'), $text); array(&$this, '_unhash_callback'), $text);
} }
public function _unhash_callback($matches) { public function _unhash_callback($matches) {
skipping to change at line 1703 skipping to change at line 1697
break; break;
} }
$tag = $parts[1]; # Tag to handle. $tag = $parts[1]; # Tag to handle.
$text = $parts[2]; # Remaining text after current tag. $text = $parts[2]; # Remaining text after current tag.
$tag_re = preg_quote($tag); # For use in a regular expres sion. $tag_re = preg_quote($tag); # For use in a regular expres sion.
# #
# Check for: Code span marker # Check for: Code span marker
# #
if ($tag{0} == "`") { if ($tag[0] == "`") {
# Find corresponding end marker. # Find corresponding end marker.
$tag_re = preg_quote($tag); $tag_re = preg_quote($tag);
if (preg_match('{^(?>.+?|\n(?!\n))*?(?<!`)'.$tag_ re.'(?!`)}', if (preg_match('{^(?>.+?|\n(?!\n))*?(?<!`)'.$tag_ re.'(?!`)}',
$text, $matches)) $text, $matches))
{ {
# End marker found: pass text unchanged u ntil marker. # End marker found: pass text unchanged u ntil marker.
$parsed .= $tag . $matches[0]; $parsed .= $tag . $matches[0];
$text = substr($text, strlen($matches[0]) ); $text = substr($text, strlen($matches[0]) );
} }
else { else {
skipping to change at line 1739 skipping to change at line 1733
$text = substr($text, strlen($matches[0]) ); $text = substr($text, strlen($matches[0]) );
} }
else { else {
# No end marker: just skip it. # No end marker: just skip it.
$parsed .= $tag; $parsed .= $tag;
} }
} }
# #
# Check for: Indented code block. # Check for: Indented code block.
# #
else if ($tag{0} == "\n" || $tag{0} == " ") { else if ($tag[0] == "\n" || $tag[0] == " ") {
# Indented code block: pass it unchanged, will be handled # Indented code block: pass it unchanged, will be handled
# later. # later.
$parsed .= $tag; $parsed .= $tag;
} }
# #
# Check for: Opening Block level tag or # Check for: Opening Block level tag or
# Opening Context Block tag (like ins and del) # Opening Context Block tag (like ins and del)
# used as a block tag (tag is alone on it's line). # used as a block tag (tag is alone on it's line).
# #
else if (preg_match('{^<(?:'.$this->block_tags_re.')\b}', $tag) || else if (preg_match('{^<(?:'.$this->block_tags_re.')\b}', $tag) ||
skipping to change at line 1767 skipping to change at line 1761
$this->_hashHTMLBlocks_inHTML($tag . $tex t, "hashBlock", true); $this->_hashHTMLBlocks_inHTML($tag . $tex t, "hashBlock", true);
# Make sure it stays outside of any paragraph by adding newlines. # Make sure it stays outside of any paragraph by adding newlines.
$parsed .= "\n\n$block_text\n\n"; $parsed .= "\n\n$block_text\n\n";
} }
# #
# Check for: Clean tag (like script, math) # Check for: Clean tag (like script, math)
# HTML Comments, processing instructions. # HTML Comments, processing instructions.
# #
else if (preg_match('{^<(?:'.$this->clean_tags_re.')\b}', $tag) || else if (preg_match('{^<(?:'.$this->clean_tags_re.')\b}', $tag) ||
$tag{1} == '!' || $tag{1} == '?') $tag[1] == '!' || $tag[1] == '?')
{ {
# Need to parse tag and following text using the HTML parser. # Need to parse tag and following text using the HTML parser.
# (don't check for markdown attribute) # (don't check for markdown attribute)
list($block_text, $text) = list($block_text, $text) =
$this->_hashHTMLBlocks_inHTML($tag . $tex t, "hashClean", false); $this->_hashHTMLBlocks_inHTML($tag . $tex t, "hashClean", false);
$parsed .= $block_text; $parsed .= $block_text;
} }
# #
# Check for: Tag with same name as enclosing tag. # Check for: Tag with same name as enclosing tag.
# #
else if ($enclosing_tag_re !== '' && else if ($enclosing_tag_re !== '' &&
# Same name as enclosing tag. # Same name as enclosing tag.
preg_match('{^</?(?:'.$enclosing_tag_re.')\b}', $ tag)) preg_match('{^</?(?:'.$enclosing_tag_re.')\b}', $ tag))
{ {
# #
# Increase/decrease nested tag count. # Increase/decrease nested tag count.
# #
if ($tag{1} == '/') if ($tag[1] == '/')
$depth--; $depth--;
else if ($tag{strlen($tag)-2} != '/') $depth++; else if ($tag[strlen($tag)-2] != '/') $depth++;
if ($depth < 0) { if ($depth < 0) {
# #
# Going out of parent element. Clean up a nd break so we # Going out of parent element. Clean up a nd break so we
# return to the calling function. # return to the calling function.
# #
$text = $tag . $text; $text = $tag . $text;
break; break;
} }
skipping to change at line 1891 skipping to change at line 1885
# #
$parts = preg_split($tag_re, $text, 2, PREG_SPLIT_DELIM_C APTURE); $parts = preg_split($tag_re, $text, 2, PREG_SPLIT_DELIM_C APTURE);
if (count($parts) < 3) { if (count($parts) < 3) {
# #
# End of $text reached with unbalenced tag(s). # End of $text reached with unbalenced tag(s).
# In that case, we return original text unchanged and pass the # In that case, we return original text unchanged and pass the
# first character as filtered to prevent an infin ite loop in the # first character as filtered to prevent an infin ite loop in the
# parent function. # parent function.
# #
return array($original_text{0}, substr($original_ text, 1)); return array($original_text[0], substr($original_ text, 1));
} }
$block_text .= $parts[0]; # Text before current tag. $block_text .= $parts[0]; # Text before current tag.
$tag = $parts[1]; # Tag to handle. $tag = $parts[1]; # Tag to handle.
$text = $parts[2]; # Remaining text after current tag. $text = $parts[2]; # Remaining text after current tag.
# #
# Check for: Auto-close tag (like <hr/>) # Check for: Auto-close tag (like <hr/>)
# Comments and Processing Instruct ions. # Comments and Processing Instruct ions.
# #
if (preg_match('{^</?(?:'.$this->auto_close_tags_re.')\b} ', $tag) || if (preg_match('{^</?(?:'.$this->auto_close_tags_re.')\b} ', $tag) ||
$tag{1} == '!' || $tag{1} == '?') $tag[1] == '!' || $tag[1] == '?')
{ {
# Just add the tag to the block as if it was text . # Just add the tag to the block as if it was text .
$block_text .= $tag; $block_text .= $tag;
} }
else { else {
# #
# Increase/decrease nested tag count. Only do so if # Increase/decrease nested tag count. Only do so if
# the tag's name match base tag's. # the tag's name match base tag's.
# #
if (preg_match('{^</?'.$base_tag_name_re.'\b}', $ tag)) { if (preg_match('{^</?'.$base_tag_name_re.'\b}', $ tag)) {
if ($tag{1} == '/') if ($tag[1] == '/')
$depth--; $depth--;
else if ($tag{strlen($tag)-2} != '/') $ else if ($tag[strlen($tag)-2] != '/') $
depth++; depth++;
} }
# #
# Check for `markdown="1"` attribute and handle i t. # Check for `markdown="1"` attribute and handle i t.
# #
if ($md_attr && if ($md_attr &&
preg_match($markdown_attr_re, $tag, $attr _m) && preg_match($markdown_attr_re, $tag, $attr _m) &&
preg_match('/^1|block|span$/', $attr_m[2] . $attr_m[3])) preg_match('/^1|block|span$/', $attr_m[2] . $attr_m[3]))
{ {
# Remove `markdown` attribute from openin g tag. # Remove `markdown` attribute from openin g tag.
$tag = preg_replace($markdown_attr_re, '' , $tag); $tag = preg_replace($markdown_attr_re, '' , $tag);
# Check if text inside this tag must be p arsed in span mode. # Check if text inside this tag must be p arsed in span mode.
$this->mode = $attr_m[2] . $attr_m[3]; $this->mode = $attr_m[2] . $attr_m[3];
$span_mode = $this->mode == 'span' || $th is->mode != 'block' && $span_mode = $this->mode == 'span' || $th is->mode != 'block' &&
preg_match('{^<(?:'.$this->contai n_span_tags_re.')\b}', $tag); preg_match('{^<(?:'.$this->contai n_span_tags_re.')\b}', $tag);
# Calculate indent before tag. # Calculate indent before tag.
if (preg_match('/(?:^|\n)( *?)(?! ).*?$/' , $block_text, $matches)) { if (preg_match('/(?:^|\n)( *?)(?! ).*?$/' , $block_text, $matches)) {
$strlen = $this->utf8_strlen; $indent = $this->utf8_strlen($mat
$indent = $strlen($matches[1], 'U ches[1]);
TF-8');
} else { } else {
$indent = 0; $indent = 0;
} }
# End preceding block with this tag. # End preceding block with this tag.
$block_text .= $tag; $block_text .= $tag;
$parsed .= $this->$hash_method($block_tex t); $parsed .= $this->$hash_method($block_tex t);
# Get enclosing tag name for the ParseMar kdown function. # Get enclosing tag name for the ParseMar kdown function.
# (This pattern makes $tag_name_re safe w ithout quoting.) # (This pattern makes $tag_name_re safe w ithout quoting.)
skipping to change at line 2037 skipping to change at line 2030
return $text; return $text;
} }
public function _doHeaders_attr($attr) { public function _doHeaders_attr($attr) {
if (empty($attr)) return ""; if (empty($attr)) return "";
return " id=\"$attr\""; return " id=\"$attr\"";
} }
public function _doHeaders_callback_setext($matches) { public function _doHeaders_callback_setext($matches) {
if ($matches[3] == '-' && preg_match('{^- }', $matches[1])) if ($matches[3] == '-' && preg_match('{^- }', $matches[1]))
return $matches[0]; return $matches[0];
$level = $matches[3]{0} == '=' ? 1 : 2; $level = $matches[3][0] == '=' ? 1 : 2;
$attr = $this->_doHeaders_attr($id =& $matches[2]); $attr = $this->_doHeaders_attr($id =& $matches[2]);
$block = "<h$level$attr>".$this->runSpanGamut($matches[1])."</h$l evel>"; $block = "<h$level$attr>".$this->runSpanGamut($matches[1])."</h$l evel>";
return "\n" . $this->hashBlock($block) . "\n\n"; return "\n" . $this->hashBlock($block) . "\n\n";
} }
public function _doHeaders_callback_atx($matches) { public function _doHeaders_callback_atx($matches) {
$level = strlen($matches[1]); $level = strlen($matches[1]);
$attr = $this->_doHeaders_attr($id =& $matches[3]); $attr = $this->_doHeaders_attr($id =& $matches[3]);
$block = "<h$level$attr>".$this->runSpanGamut($matches[2])."</h$l evel>"; $block = "<h$level$attr>".$this->runSpanGamut($matches[2])."</h$l evel>";
return "\n" . $this->hashBlock($block) . "\n\n"; return "\n" . $this->hashBlock($block) . "\n\n";
} }
 End of changes. 19 change blocks. 
43 lines changed or deleted 32 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)