View Single Post
Old Mar 20th, 2007, 1:41 AM   #11
grimpirate
King of Portal
 
grimpirate's Avatar
 
Join Date: Sep 2005
Posts: 431
Rep Power: 4 grimpirate is on a distinguished road
Send a message via Yahoo to grimpirate
The only way I could address the problem in IE was to rewrite the code to insert line breaks at a given number of characters, and thus wordwrap the source code to that specific number. If the window gets resized smaller than that character count then obviously some bad stuff happens but it's all I could figure out:[PHP]<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Grim PHP Syntax Highlighter</title>
<style type="text/css">
body {
font-family: Courier New;
font-size: 10pt;
}
div.lineNumbers {
float: left;
text-align: right;
margin-right: 8px;
padding-right: 8px;
padding-left: 8px;
border-right: 1px #999999 solid;
color: #777777;
}
span.v {
color: #0000BB;
}
span.k {
color: #007700;
}
span.s {
color: #DD0000;
}
span.c {
color: #FF8000;
}
</style>
</head>
<body>
<?php
define('SPLIT', 112);
$filename = 'syntax_h.php';
ob_start();
highlight_file($filename);
$source = ob_get_contents();
ob_end_clean();
$source = str_replace('<span style="color: #0000BB">', '<span class="v">', $source);
$source = str_replace('<span style="color: #007700">', '<span class="k">', $source);
$source = str_replace('<span style="color: #DD0000">', '<span class="s">', $source);
$source = str_replace('<span style="color: #FF8000">', '<span class="c">', $source);
$source = explode(chr(13), $source);
$source = implode('', $source);
$source = explode(chr(10), $source);
$source = implode('', $source);
$source = explode('<br />', $source);
$source[0] = substr($source[0], 35);
$source[count($source) - 1] = substr($source[count($source) - 1], 0, strlen($source[count($source) - 1]) - 14);
for($i = 0; $i < count($source) - 1; $i++){
$count = 0;
$temp = '';
while(strlen($source[$i]) > 0){
if(strpos($source[$i], '<span class="v">') === 0){
$source[$i] = substr($source[$i], 16);
$temp .= '<span class="v">';
}elseif(strpos($source[$i], '<span class="k">') === 0){
$source[$i] = substr($source[$i], 16);
$temp .= '<span class="k">';
}elseif(strpos($source[$i], '<span class="s">') === 0){
$source[$i] = substr($source[$i], 16);
$temp .= '<span class="s">';
}elseif(strpos($source[$i], '<span class="c">') === 0){
$source[$i] = substr($source[$i], 16);
$temp .= '<span class="c">';
}elseif(strpos($source[$i], '</span>') === 0){
$source[$i] = substr($source[$i], 7);
$temp .= '</span>';
}elseif(strpos($source[$i], '&nbsp;') === 0){
$source[$i] = substr($source[$i], 6);
$temp .= '&nbsp;';
$count++;
}elseif(strpos($source[$i], '&lt;') === 0){
$source[$i] = substr($source[$i], 4);
$temp .= '&lt;';
$count++;
}elseif(strpos($source[$i], '&gt;') === 0){
$source[$i] = substr($source[$i], 4);
$temp .= '&gt;';
$count++;
}elseif(strpos($source[$i], '&amp;') === 0){
$source[$i] = substr($source[$i], 5);
$temp .= '&amp;';
$count++;
}else{
$temp .= substr($source[$i], 0, 1);
$source[$i] = substr($source[$i], 1);
$count++;
}
if($count == SPLIT){
$temp .= '<br />' . "\n";
$count = 0;
}
}
if($count != 0){
$temp .= '<br />' . "\n";
}
$source[$i] = $temp;
}
echo '<div class="lineNumbers">' . "\n";
for($i = 0; $i < count($source); $i++){
echo $i + 1 . '<br />' . "\n";
for($j = 1; $j < substr_count($source[$i], '<br />'); $j++){
echo '<strong>&hellip;</strong><br />' . "\n";
}
}
echo "\n" . '</div>' . "\n";
echo '<div class="sourceCode">' . "\n";
for($i = 0; $i < count($source); $i++){
echo $source[$i];
}
echo "\n" . '</div>' . "\n";
?>
</body>
</html>[/PHP]The constant SPLIT controls the amount of characters you wish to display on a line.
__________________
Lo, there do I see my father. 'Lo, there do I see My mother, and my sisters, and my brothers. 'Lo, there do I see The line of my people... Back to the beginning. 'Lo, they do call to me. They bid me take my place among them. In the halls of Valhalla... Where the brave... May live... ...forever.. GrimBB | Mimesis
grimpirate is offline   Reply With Quote