mikuli.cz

:)
git clone https://git.sr.ht/~ashymad/mikuli.cz
Log | Files | Refs

commit 716772f0bbed9f29e7ce2b3ade0bde3f9d6b8d79
parent 4f7541ad6f34a2ac5301c654e925fd47d4bbc489
Author: markseu <mark2011@mayberg.se>
Date:   Fri, 21 Mar 2014 10:12:56 +0100

Markdown update (headers with id)

Diffstat:
Msystem/core/core-markdownextra.php | 42++++++++++++++++++++++++++++++++++++++++--
Msystem/core/core.php | 13+++++++------
2 files changed, 47 insertions(+), 8 deletions(-)

diff --git a/system/core/core-markdownextra.php b/system/core/core-markdownextra.php @@ -5,7 +5,7 @@ // Markdown extra core plugin class YellowMarkdownExtra { - const Version = "0.2.8"; + const Version = "0.2.9"; var $yellow; //access to API // Initialise plugin @@ -25,11 +25,13 @@ class YellowMarkdownExtra // Markdown extra parser class YellowMarkdownExtraParser extends MarkdownExtraParser { - var $yellow; //access to API + var $yellow; //access to API + var $idAttributes; //id attributes function __construct($yellow) { $this->yellow = $yellow; + $this->idAttributes = array(); parent::__construct(); } @@ -44,6 +46,19 @@ class YellowMarkdownExtraParser extends MarkdownExtraParser "<a$1href=\"$location$2\"$3>", $this->transform($text)); } + // Return unique id attribute + function getIdAttribute($text) + { + $text = $this->yellow->toolbox->normaliseName($text, false, true); + $text = trim(preg_replace("/-+/", "-", $text), "-"); + if(is_null($this->idAttributes[$text])) + { + $this->idAttributes[$text] = $text; + $attr = " id=\"$text\""; + } + return $attr; + } + // Handle links function doAutoLinks($text) { @@ -75,6 +90,29 @@ class YellowMarkdownExtraParser extends MarkdownExtraParser return "\n\n".$this->hashBlock($output)."\n\n"; } + // Handle headers, text style + function _doHeaders_callback_setext($matches) + { + if ($matches[3] == '-' && preg_match('{^- }', $matches[1])) return $matches[0]; + $text = $matches[1]; + $level = $matches[3]{0} == '=' ? 1 : 2; + $attr = $this->doExtraAttributes("h$level", $dummy =& $matches[2]); + if(empty($attr) && $level==2) $attr = $this->getIdAttribute($text); + $output = "<h$level$attr>".$this->runSpanGamut($text)."</h$level>"; + return "\n".$this->hashBlock($output)."\n\n"; + } + + // Handle headers, atx style + function _doHeaders_callback_atx($matches) + { + $text = $matches[2]; + $level = strlen($matches[1]); + $attr = $this->doExtraAttributes("h$level", $dummy =& $matches[3]); + if(empty($attr) && $level==2) $attr = $this->getIdAttribute($text); + $output = "<h$level$attr>".$this->runSpanGamut($text)."</h$level>"; + return "\n".$this->hashBlock($output)."\n\n"; + } + // Handle inline links function _doAnchors_inline_callback($matches) { diff --git a/system/core/core.php b/system/core/core.php @@ -5,9 +5,9 @@ // Yellow main class class Yellow { - const Version = "0.2.12"; - var $page; //current page data - var $pages; //current page tree from file system + const Version = "0.2.13"; + var $page; //current page + var $pages; //pages from file system var $config; //configuration var $text; //text strings var $toolbox; //toolbox with helpers @@ -330,7 +330,7 @@ class Yellow } } -// Yellow page data +// Yellow page class YellowPage { var $yellow; //access to API @@ -831,7 +831,7 @@ class YellowPageCollection extends ArrayObject } } -// Yellow page tree from file system +// Yellow pages from file system class YellowPages { var $yellow; //access to API @@ -1486,10 +1486,11 @@ class YellowToolbox } // Normalise directory/file name - function normaliseName($text, $removeExtension = false) + function normaliseName($text, $removeExtension = false, $lowerCase = false) { if(preg_match("/^[\d\-\_\.]+(.*)$/", $text, $matches)) $text = $matches[1]; if($removeExtension) $text = ($pos = strrposu($text, '.')) ? substru($text, 0, $pos) : $text; + if($lowerCase) $text = strtoloweru($text); return preg_replace("/[^\pL\d\-\_\.]/u", "-", $text); }