mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 09:26:35 +02:00
MDL-66964 markdown: php74 fixup for markdown lib 1.8.0
Note this is different from the upstream commit:
a35858f040
because it was conflicting so only the cases corresponding
to our current 1.8.0 version have been modified.
This commit is trivial, just a pure curly to square replacement.
This commit is contained in:
parent
d547735f2f
commit
c3d8c419e5
2 changed files with 18 additions and 18 deletions
|
@ -952,7 +952,7 @@ class Markdown implements MarkdownInterface {
|
||||||
return $matches[0];
|
return $matches[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
$level = $matches[2]{0} == '=' ? 1 : 2;
|
$level = $matches[2][0] == '=' ? 1 : 2;
|
||||||
|
|
||||||
// ID attribute generation
|
// ID attribute generation
|
||||||
$idAtt = $this->_generateIdFromHeaderValue($matches[1]);
|
$idAtt = $this->_generateIdFromHeaderValue($matches[1]);
|
||||||
|
@ -1358,7 +1358,7 @@ class Markdown implements MarkdownInterface {
|
||||||
} else {
|
} else {
|
||||||
// Other closing marker: close one em or strong and
|
// Other closing marker: close one em or strong 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);
|
||||||
|
@ -1383,7 +1383,7 @@ class Markdown implements MarkdownInterface {
|
||||||
} else {
|
} else {
|
||||||
// Reached opening three-char emphasis marker. Push on token
|
// Reached opening three-char emphasis marker. Push on token
|
||||||
// stack; will be handled by the special condition above.
|
// stack; will be handled by the special condition 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, '');
|
||||||
|
@ -1796,9 +1796,9 @@ class Markdown implements MarkdownInterface {
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function handleSpanToken($token, &$str) {
|
protected function handleSpanToken($token, &$str) {
|
||||||
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',
|
||||||
|
|
|
@ -212,9 +212,9 @@ class MarkdownExtra extends \Michelf\Markdown {
|
||||||
$attributes = array();
|
$attributes = array();
|
||||||
$id = false;
|
$id = false;
|
||||||
foreach ($elements as $element) {
|
foreach ($elements as $element) {
|
||||||
if ($element{0} == '.') {
|
if ($element[0] == '.') {
|
||||||
$classes[] = substr($element, 1);
|
$classes[] = substr($element, 1);
|
||||||
} else if ($element{0} == '#') {
|
} else if ($element[0] == '#') {
|
||||||
if ($id === false) $id = substr($element, 1);
|
if ($id === false) $id = substr($element, 1);
|
||||||
} else if (strpos($element, '=') > 0) {
|
} else if (strpos($element, '=') > 0) {
|
||||||
$parts = explode('=', $element, 2);
|
$parts = explode('=', $element, 2);
|
||||||
|
@ -508,14 +508,14 @@ class MarkdownExtra extends \Michelf\Markdown {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 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: Code span marker
|
// Check for: Code span marker
|
||||||
// Note: need to check this after backtick fenced code blocks
|
// Note: need to check this after backtick fenced code blocks
|
||||||
else if ($tag{0} == "`") {
|
else 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 . '(?!`)}',
|
||||||
|
@ -549,7 +549,7 @@ class MarkdownExtra extends \Michelf\Markdown {
|
||||||
// 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)
|
||||||
|
@ -564,8 +564,8 @@ class MarkdownExtra extends \Michelf\Markdown {
|
||||||
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} == '/') $depth--;
|
if ($tag[1] == '/') $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 and break so we
|
// Going out of parent element. Clean up and break so we
|
||||||
|
@ -664,7 +664,7 @@ class MarkdownExtra extends \Michelf\Markdown {
|
||||||
// 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 infinite loop in the
|
// first character as filtered to prevent an infinite 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.
|
||||||
|
@ -674,7 +674,7 @@ class MarkdownExtra extends \Michelf\Markdown {
|
||||||
// Check for: Auto-close tag (like <hr/>)
|
// Check for: Auto-close tag (like <hr/>)
|
||||||
// Comments and Processing Instructions.
|
// Comments and Processing Instructions.
|
||||||
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;
|
||||||
|
@ -683,8 +683,8 @@ class MarkdownExtra extends \Michelf\Markdown {
|
||||||
// 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} == '/') $depth--;
|
if ($tag[1] == '/') $depth--;
|
||||||
else if ($tag{strlen($tag)-2} != '/') $depth++;
|
else if ($tag[strlen($tag)-2] != '/') $depth++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for `markdown="1"` attribute and handle it.
|
// Check for `markdown="1"` attribute and handle it.
|
||||||
|
@ -1071,7 +1071,7 @@ class MarkdownExtra extends \Michelf\Markdown {
|
||||||
return $matches[0];
|
return $matches[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
$level = $matches[3]{0} == '=' ? 1 : 2;
|
$level = $matches[3][0] == '=' ? 1 : 2;
|
||||||
|
|
||||||
$defaultId = is_callable($this->header_id_func) ? call_user_func($this->header_id_func, $matches[1]) : null;
|
$defaultId = is_callable($this->header_id_func) ? call_user_func($this->header_id_func, $matches[1]) : null;
|
||||||
|
|
||||||
|
@ -1466,7 +1466,7 @@ class MarkdownExtra extends \Michelf\Markdown {
|
||||||
|
|
||||||
$classes = array();
|
$classes = array();
|
||||||
if ($classname != "") {
|
if ($classname != "") {
|
||||||
if ($classname{0} == '.')
|
if ($classname[0] == '.')
|
||||||
$classname = substr($classname, 1);
|
$classname = substr($classname, 1);
|
||||||
$classes[] = $this->code_class_prefix . $classname;
|
$classes[] = $this->code_class_prefix . $classname;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue