Skip to content

Commit

Permalink
Submitted features:
Browse files Browse the repository at this point in the history
#1 - size parameter can be quoted
#2 - size parameter accepts a numeric ordering for CSS size keywords (0=>xx-small, ..., 6=>xx-large)
  • Loading branch information
lmachucab authored and Michael Klier committed Jun 4, 2010
1 parent 588232a commit 58d627b
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions syntax/size.php
Expand Up @@ -4,6 +4,7 @@
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Esther Brunner <esther@kaffeehaus.ch>
* @author Luis Machuca Bezzaza <luis.machuca@gulix.cl>
*/

if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
Expand All @@ -29,7 +30,9 @@ function handle($match, $state, $pos, &$handler) {
switch ($state) {
case DOKU_LEXER_ENTER :
$match = substr($match, 6, -1);
if (preg_match('/^\d+$/',$match)) $match .= 'px';
if (preg_match('/".+?"/',$match)) $match = substr($match, 1, -1); // addition #1: unquote
if (preg_match('/^[0-6]$/',$match)) $match = self::_relsz(intval($match) ); // addition #2: relative size number
else if (preg_match('/^\d+$/',$match)) $match .= 'px';
return array($state, $match);

case DOKU_LEXER_UNMATCHED :
Expand Down Expand Up @@ -66,5 +69,36 @@ function render($mode, &$renderer, $data) {
}
return false;
}

/**
* @fn _relsz
* @brief Returns a relative-size CSS keyword based on numbering.
* @author Luis Machuca Bezzaza <luis.machuca@gulix.cl>
*
* Provides a mapping to the series of size-related keywords in CSS 2.1
* (http://www.w3.org/TR/REC-CSS1/#font-size)
* Valid values are [0-6], with 3 for "medium" (as recommended by standard)
*/
private function _relsz ($value) {
switch ($value) {
case 0:
return 'xx-small'; break;
case 1:
return 'x-small'; break;
case 2:
return 'small'; break;
case 4:
return 'large'; break;
case 5:
return 'x-large'; break;
case 6:
return 'xx-large'; break;
case 3:
return 'medium'; break;
default:
return false; break;
}
}

}
// vim:ts=4:sw=4:et:enc=utf-8:
// vim:ts=4:sw=4:et:enc=utf-8:

0 comments on commit 58d627b

Please sign in to comment.