Updated the pretty print not to need extra <pre></pre>.

dev
Loic d'Anterroches 2008-11-15 21:23:29 +01:00
parent 5c32145e13
commit 7ca43e0ec2
3 changed files with 9 additions and 11 deletions

View File

@ -115,12 +115,10 @@ class IDF_Diff
{
$out = '';
foreach ($this->files as $filename=>$file) {
$openPre = '';
$closePre = '';
$pretty = '';
$fileinfo = IDF_Views_Source::getMimeType($filename);
if (IDF_Views_Source::isSupportedExtension($fileinfo[2])) {
$openPre = '<pre class="prettyprint">';
$closePre = '</pre>';
$pretty = ' prettyprint';
}
$out .= "\n".'<table class="diff" summary="">'."\n";
$out .= '<tr id="diff-'.md5($filename).'"><th colspan="3">'.Pluf_esc($filename).'</th></tr>'."\n";
@ -135,7 +133,7 @@ class IDF_Diff
$class = 'diff-a';
}
$line_content = self::padLine(Pluf_esc($line[2]));
$out .= sprintf('<tr class="diff-line"><td class="diff-lc">%s</td><td class="diff-lc">%s</td><td class="%s mono">%s%s%s</td></tr>'."\n", $line[0], $line[1], $class, $openPre, $line_content, $closePre);
$out .= sprintf('<tr class="diff-line"><td class="diff-lc">%s</td><td class="diff-lc">%s</td><td class="%s%s mono">%s</td></tr>'."\n", $line[0], $line[1], $class, $pretty, $line_content);
}
if (count($file['chunks']) > $cc)
$out .= '<tr class="diff-next"><td>...</td><td>...</td><td>&nbsp;</td></tr>'."\n";

View File

@ -384,17 +384,15 @@ class IDF_Views_Source
public static function highLight($fileinfo, $content)
{
$openPre = '';
$closePre = '';
$pretty = '';
if (IDF_Views_Source::isSupportedExtension($fileinfo[2])) {
$openPre = '<pre class="prettyprint">';
$closePre = '</pre>';
$pretty = ' prettyprint';
}
$table = array();
$i = 1;
foreach (preg_split("/\015\012|\015|\012/", $content) as $line) {
$table[] = '<tr class="c-line"><td class="code-lc" id="L'.$i.'"><a href="#L'.$i.'">'.$i.'</a></td>'
.'<td class="code mono">'.$openPre.IDF_Diff::padLine(Pluf_esc($line)).$closePre.'</td></tr>';
.'<td class="code mono'.$pretty.'">'.IDF_Diff::padLine(Pluf_esc($line)).'</td></tr>';
$i++;
}
return Pluf_Template::markSafe(implode("\n", $table));

View File

@ -31,7 +31,8 @@
* 1) include this source file in an html page via
* <script type="text/javascript" src="/path/to/prettify.js"></script>
* 2) define style rules. See the example page for examples.
* 3) mark the <pre> and <code> tags in your source with class=prettyprint.
* 3) mark the <td>, <pre> and <code> tags in your source
* with class=prettyprint.
* You can also use the (html deprecated) <xmp> tag, but the pretty printer
* needs to do more substantial DOM manipulations to support that, so some
* css styles may not be preserved.
@ -1273,6 +1274,7 @@ function prettyPrint() {
var codeSegments = [
document.getElementsByTagName('pre'),
document.getElementsByTagName('code'),
document.getElementsByTagName('td'),
document.getElementsByTagName('xmp') ];
var elements = [];
for (var i = 0; i < codeSegments.length; ++i) {