Core update (Markdown)

This commit is contained in:
markseu 2015-08-05 10:46:19 +02:00
parent 2bee745a54
commit bfe60ffec7
3 changed files with 35 additions and 24 deletions

View file

@ -1,4 +1,4 @@
Yellow 0.5.28
Yellow 0.5.29
=============
[![Yellow](https://raw.githubusercontent.com/wiki/datenstrom/yellow/images/yellow.jpg)](http://datenstrom.se/yellow)

View file

@ -5,7 +5,7 @@
// Yellow main class
class Yellow
{
const Version = "0.5.28";
const Version = "0.5.29";
var $page; //current page
var $pages; //pages from file system
var $files; //files from file system

View file

@ -5,7 +5,7 @@
// Markdown plugin
class YellowMarkdown
{
const Version = "0.5.7";
const Version = "0.5.8";
var $yellow; //access to API
// Handle initialisation
@ -100,9 +100,8 @@ class YellowMarkdownParser extends MarkdownExtraParser
// Handle fenced code blocks
function _doFencedCodeBlocks_callback($matches)
{
$name = trim($matches[2]." ".$matches[3]);
$text = $matches[4];
$output = $this->page->parseContentBlock($name, $text, false);
if(!empty($matches[2])) $output = $this->page->parseContentBlock($matches[2]." ".$matches[3], $text, false);
if(is_null($output))
{
$attr = $this->doExtraAttributes("pre", $dummy =& $matches[3]);
@ -177,7 +176,7 @@ class YellowMarkdownParser extends MarkdownExtraParser
//
// Original Markdown
// Copyright (c) 2004-2006 John Gruber
// <http://daringfireball.net/projects/markdown/>
// <https://daringfireball.net/projects/markdown/>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
@ -253,6 +252,9 @@ class MarkdownParser {
# Optional header id="" generation callback function.
public $header_id_func = null;
# Optional function for converting code block content to HTML
public $code_block_content_func = null;
# Class attribute to toggle "enhanced ordered list" behaviour
# setting this to true will allow ordered lists to start from the index
@ -682,7 +684,7 @@ class MarkdownParser {
"doImages" => 10,
"doAnchors" => 20,
# Make links out of things like `<http://example.com/>`
# Make links out of things like `<https://example.com/>`
# Must come after doAnchors, because you can use < and >
# delimiters in inline links like [this](<url>).
"doAutoLinks" => 30,
@ -1213,7 +1215,11 @@ class MarkdownParser {
$codeblock = $matches[1];
$codeblock = $this->outdent($codeblock);
$codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES);
if ($this->code_block_content_func) {
$codeblock = call_user_func($this->code_block_content_func, $codeblock, "");
} else {
$codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES);
}
# trim leading newlines and trailing newlines
$codeblock = preg_replace('/\A\n+|\n+\z/', '', $codeblock);
@ -1822,7 +1828,7 @@ class MarkdownExtraParser extends MarkdownParser {
# Class attribute for code blocks goes on the `code` tag;
# setting this to true will put attributes on the `pre` tag instead.
public $code_attr_on_pre = false;
# Predefined abbreviations.
public $predef_abbr = array();
@ -1915,7 +1921,7 @@ class MarkdownExtraParser extends MarkdownParser {
# Expression to use when parsing in a context when no capture is desired
protected $id_class_attr_nocatch_re = '\{(?:[ ]*[#.a-z][-_:a-zA-Z0-9=]+){1,}[ ]*\}';
protected function doExtraAttributes($tag_name, $attr, $defaultIdValue = null) {
protected function doExtraAttributes($tag_name, $attr, $defaultIdValue = null, $classes = array()) {
#
# Parse attributes caught by the $this->id_class_attr_catch_re expression
# and return the HTML-formatted list of attributes.
@ -1925,14 +1931,13 @@ class MarkdownExtraParser extends MarkdownParser {
# In addition, this method also supports supplying a default Id value,
# which will be used to populate the id attribute in case it was not
# overridden.
if (empty($attr) && !$defaultIdValue) return "";
if (empty($attr) && !$defaultIdValue && empty($classes)) return "";
# Split on components
preg_match_all('/[#.a-z][-_:a-zA-Z0-9=]+/', $attr, $matches);
$elements = $matches[0];
# handle classes and ids (only first id taken into account)
$classes = array();
$attributes = array();
$id = false;
foreach ($elements as $element) {
@ -2129,12 +2134,10 @@ class MarkdownExtraParser extends MarkdownParser {
# Fenced code block marker
(?<= ^ | \n )
[ ]{0,'.($indent+3).'}(?:~{3,}|`{3,})
[ ]*
(?:
\.?[-_:a-zA-Z0-9]+ # standalone class name
|
'.$this->id_class_attr_nocatch_re.' # extra attributes
)?
[ ]*
(?: \.?[-_:a-zA-Z0-9]+ )? # standalone class name
[ ]*
(?: '.$this->id_class_attr_nocatch_re.' )? # extra attributes
[ ]*
(?= \n )
' : '' ). ' # End (if not is span).
@ -2190,7 +2193,7 @@ class MarkdownExtraParser extends MarkdownParser {
# Note: need to recheck the whole tag to disambiguate backtick
# fences from code spans
#
if (preg_match('{^\n?([ ]{0,'.($indent+3).'})(~{3,}|`{3,})[ ]*(?:\.?[-_:a-zA-Z0-9]+|'.$this->id_class_attr_nocatch_re.')?[ ]*\n?$}', $tag, $capture)) {
if (preg_match('{^\n?([ ]{0,'.($indent+3).'})(~{3,}|`{3,})[ ]*(?:\.?[-_:a-zA-Z0-9]+)?[ ]*(?:'.$this->id_class_attr_nocatch_re.')?[ ]*\n?$}', $tag, $capture)) {
# Fenced code block marker: find matching end marker.
$fence_indent = strlen($capture[1]); # use captured indent in re
$fence_re = $capture[2]; # use captured fence in re
@ -3074,7 +3077,9 @@ class MarkdownExtraParser extends MarkdownParser {
[ ]*
(?:
\.?([-_:a-zA-Z0-9]+) # 2: standalone class name
|
)?
[ ]*
(?:
'.$this->id_class_attr_catch_re.' # 3: Extra attributes
)?
[ ]* \n # Whitespace and newline following marker.
@ -3098,17 +3103,23 @@ class MarkdownExtraParser extends MarkdownParser {
$classname =& $matches[2];
$attrs =& $matches[3];
$codeblock = $matches[4];
$codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES);
if ($this->code_block_content_func) {
$codeblock = call_user_func($this->code_block_content_func, $codeblock, $classname);
} else {
$codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES);
}
$codeblock = preg_replace_callback('/^\n+/',
array($this, '_doFencedCodeBlocks_newlines'), $codeblock);
$classes = array();
if ($classname != "") {
if ($classname{0} == '.')
$classname = substr($classname, 1);
$attr_str = ' class="'.$this->code_class_prefix.$classname.'"';
} else {
$attr_str = $this->doExtraAttributes($this->code_attr_on_pre ? "pre" : "code", $attrs);
$classes[] = $this->code_class_prefix.$classname;
}
$attr_str = $this->doExtraAttributes($this->code_attr_on_pre ? "pre" : "code", $attrs, null, $classes);
$pre_attr_str = $this->code_attr_on_pre ? $attr_str : '';
$code_attr_str = $this->code_attr_on_pre ? '' : $attr_str;
$codeblock = "<pre$pre_attr_str><code$code_attr_str>$codeblock</code></pre>";