PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Text » Text_Wiki_BBCode » Bug #5760

[size=(+/-)\d] format not supported

Details

Request #5760[size=(+/-)\d] format not supported
Submitted2005-10-23 22:24 UTC
Fromme at ben-xo dot com
StatusSuspended
PackageText_Wiki_BBCode
PHP VersionIrrelevant
Roadmaps(Not assigned)

Comments

[2005-10-23 22:24 UTC] me at ben-xo dot com

Description:
------------
No support for relative sizes in [size], which makes Text_Wiki_BBCode's markup incompatible with vBulletin.

Test script:
---------------
the correct regex to match size tags is something like

[size=((\+|-)?\d+)...

Actual result:
--------------
[size=+1]...[/size] is rendered instead of as <font size="+1">...</font>

[2005-10-24 03:36 UTC] me at ben-xo dot com

I've fixed this to my satisfaction by editing the two following files.

Render/Xhtml/Font.php
$Id: Font.php,v 1.1 2005/08/06 11:36:45 toggg Exp $

uncomment class var $size

function token($options)
{
if ($options['type'] == 'end') {
return '</span>';
}
if ($options['type'] != 'start') {
return '';
}

$ret = '<span style="';
if (isset($options['size'])) {
$size = trim($options['size']);
if (is_numeric($size)) {
switch($options['relative']) {
case '+':
$size = (100+($size*5)).'%';
break;
case '-':
$size = (100-($size*5)).'%';
break;
default:
/* use $size as an index into $this->size */
$size = min(7,$size);
$size = max(1,$size);
$size = $this->size[$size-1];
}
}
$ret .= "font-size: $size;";
}

return $ret.'">';
}

***

Parse/BBCode/Font.php
$Id: Font.php,v 1.3 2005/08/11 10:23:50 toggg Exp $

var $regex = "#\[size=(\+|\-|)(\d+)]((?:((?R))|.)*?)\[/size]#msi";

69: if (array_key_exists(4, $matches)) {
74: $matches[3]
78: $expsub = $matches[3];
82: $options = array('type' => 'start', 'level' => $this->_level, 'size' => $matches[2], 'relative' => $matches[1]);

there. looks lovely in Wordpress now.

[2005-10-24 12:23 UTC] me at ben-xo dot com

Here is the patch in unified diff format.

diff -ur Text_Wiki-1.0.1/Text/Wiki/Render/Xhtml/Font.php Text_Wiki-1.0.1-benxo/Text/Wiki/Render/Xhtml/Font.php
--- Text_Wiki-1.0.1/Text/Wiki/Render/Xhtml/Font.php 2005-08-06 12:36:46.000000000 +0100
+++ Text_Wiki-1.0.1-benxo/Text/Wiki/Render/Xhtml/Font.php 2005-10-24 13:10:58.000000000 +0100
@@ -28,7 +28,7 @@
*/
class Text_Wiki_Render_Xhtml_Font extends Text_Wiki_Render {

-/* var $size = array(
+ var $size = array(
'xx-small',
'x-small',
'small',
@@ -49,7 +49,7 @@
'pt',
'pc'
);
-*/
+

/**
* Renders a token into text matching the requested format.
@@ -70,9 +70,25 @@

$ret = '<span style="';
if (isset($options['size'])) {
+
+ // size between 1 and 7
$size = trim($options['size']);
+ $size = min(7,max(1,$size));
+
if (is_numeric($size)) {
- $size .= 'px';
+ switch($options['relative']) {
+ // relative size: from 65% to 135%
+ case '+':
+ $size = (100+($size*5)).'%';
+ break;
+ case '-':
+ $size = (100-($size*5)).'%';
+ break;
+
+ // default: use $size as an index into $this->size for an absolute size
+ default:
+ $size = $this->size[$size-1];
+ }
}
$ret .= "font-size: $size;";
}
diff -ur Text_Wiki_BBCode-0.0.1/Text/Wiki/Parse/BBCode/Font.php Text_Wiki_BBCode-0.0.1-benxo/Text/Wiki/Parse/BBCode/Font.php
--- Text_Wiki_BBCode-0.0.1/Text/Wiki/Parse/BBCode/Font.php 2005-08-11 11:23:50.000000000 +0100
+++ Text_Wiki_BBCode-0.0.1-benxo/Text/Wiki/Parse/BBCode/Font.php 2005-10-24 03:49:59.000000000 +0100
@@ -41,7 +41,7 @@
* @var string
* @see parse()
*/
- var $regex = "#\[size=(\d+)]((?:((?R))|.)*?)\[/size]#msi";
+ var $regex = "#\[size=(\+|\-|)(\d+)]((?:((?R))|.)*?)\[/size]#msi";

/**
* The current font nesting depth, starts by zero
@@ -66,20 +66,20 @@
function process(&$matches)
{
// nested block ?
- if (array_key_exists(3, $matches)) {
+ if (array_key_exists(4, $matches)) {
$this->_level++;
$expsub = preg_replace_callback(
$this->regex,
array(&$this, 'process'),
- $matches[2]
+ $matches[3]
);
$this->_level--;
} else {
- $expsub = $matches[2];
+ $expsub = $matches[3];
}

// builds the option array
- $options = array('type' => 'start', 'level' => $this->_level, 'size' => $matches[1]);
+ $options = array('type' => 'start', 'level' => $this->_level, 'size' => $matches[2], 'relative' => $matches[1]);
$statok = $this->wiki->addToken($this->rule, $options);
$options['type'] = 'end';
return $statok . $expsub . $this->wiki->addToken($this->rule, $options);