Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Miscellaneous minor cleanaps #8

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions geshi/classes/class.geshistyler.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ function removeStyleData ($context_name, $context_start_name = 'start', $context

function getStyle ($context_name)
{
if (isset($this->_styleData[$context_name])) {
if (array_key_exists($context_name, $this->_styleData)) {
return $this->_styleData[$context_name];
}
// If style for starter/ender requested and we got here, use the default
Expand All @@ -187,7 +187,7 @@ function getStyle ($context_name)

// Check for a one-level wildcard match
$wildcard_idx = substr($context_name, 0, strrpos($context_name, '/'));
if (isset($this->_wildcardStyleData[$wildcard_idx])) {
if (array_key_exists($wildcard_idx, $this->_wildcardStyleData)) {
$this->_styleData[$context_name] = $this->_wildcardStyleData[$wildcard_idx];
return $this->_wildcardStyleData[$wildcard_idx];
}
Expand Down Expand Up @@ -470,7 +470,7 @@ function setRendererOption ($name, $value) {}
* @param mixed The input format information to convert
* @return array
*/
function _parseCSS ($style) {
private static function _parseCSS ($style) {
$result = array(
"font" => array(
"color" => array(
Expand Down Expand Up @@ -616,21 +616,21 @@ private static function _parseColor($color)

);

if(isset($htmlColors[$color])) {
if(array_key_exists($color, $htmlColors)) {
return $htmlColors[$color];
} else {
return $result;
}
}

if(4 == strlen($color)) {
$result['R'] = intval($color[1], 16) / 15.0;
$result['G'] = intval($color[2], 16) / 15.0;
$result['B'] = intval($color[3], 16) / 15.0;
$result['R'] = hexdec($color[1]) / 15.0;
$result['G'] = hexdec($color[2]) / 15.0;
$result['B'] = hexdec($color[3]) / 15.0;
} else {
$result['R'] = intval($color[1].$color[2], 16) / 255.0;
$result['G'] = intval($color[3].$color[4], 16) / 255.0;
$result['B'] = intval($color[5].$color[6], 16) / 255.0;
$result['R'] = hexdec($color[1].$color[2]) / 255.0;
$result['G'] = hexdec($color[3].$color[4]) / 255.0;
$result['B'] = hexdec($color[5].$color[6]) / 255.0;
}

return $result;
Expand Down
11 changes: 7 additions & 4 deletions geshi/classes/renderers/class.geshirendererhtml.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,11 @@ class GeSHiRendererHTML extends GeSHiRenderer

private static function _colorToCSSColor($color)
{
$a = unpack('H*',
return '#' . bin2hex(
chr(round($color['R'] * 255)) .
chr(round($color['G'] * 255)) .
chr(round($color['B'] * 255))
);
return '#' . $a[1];
}

private static function _styleToCSS($style) {
Expand Down Expand Up @@ -103,8 +102,12 @@ function parseToken ($token, $context_name, $data)
$this->contextCSS[$context_name] = self::_styleToCSS($this->_styler->getStyle($context_name));
}

$result .= '<span style="' . $this->contextCSS[$context_name] . '" ';
$result .= 'title="' . GeSHi::hsc($context_name) . '">' . GeSHi::hsc($token) . '</span>';
$style = $this->contextCSS[$context_name];
if($style) {
$style = ' style="' . $style . '"';
}
$result .= '<span' . $style;
$result .= ' title="' . GeSHi::hsc($context_name) . '">' . GeSHi::hsc($token) . '</span>';
if (isset($data['url'])) {
// Finish the link
$result .= '</a>';
Expand Down
23 changes: 10 additions & 13 deletions geshi/classes/renderers/class.geshirendererpango.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,26 @@ class GeSHiRendererPango extends GeSHiRenderer

private static function _colorToCSSColor($color)
{
$a = unpack('H*',
return '#' . bin2hex(
chr(round($color['R'] * 255)) .
chr(round($color['G'] * 255)) .
chr(round($color['B'] * 255))
);
return '#' . $a[1];
}

private static function _styleToAttributes($style) {
//Add the color
$attributes = 'color="' . self::_colorToCSSColor($style['font']['color']) . '" ';
$attributes = ' color="' . self::_colorToCSSColor($style['font']['color']) . '"';

//Add font styles
if ($style['font']['style']['bold']) {
$attributes .= 'font-weight="bold" ';
$attributes .= ' font-weight="bold"';
}
if ($style['font']['style']['italic']) {
$attributes .= 'font_style="italic" ';
$attributes .= ' font_style="italic"';
}
if ($style['font']['style']['underline']) {
$attributes .= 'underline="single" ';
$attributes .= ' underline="single"';
}

return $attributes;
Expand Down Expand Up @@ -100,18 +99,16 @@ function parseToken ($token, $context_name, $data)
$style = $this->_styler->getStyle($context_name);

// Add the basic tag
$result .= '<span ';

$result .= self::_styleToAttributes($style);

// Finish the opening tag
$result .= '>';
$attrs = self::_styleToAttributes($style);
if ($attrs)
$result .= '<span' . $attrs . '>';

// Now add in the token
$result .= GeSHi::hsc($token);

// Add the closing tag
$result .= '</span>';
if ($attrs)
$result .= '</span>';

// Return the result
return $result;
Expand Down