Fixed issue 37, syntax highlighting of source.
This commit is contained in:
parent
316a7d1a54
commit
99a2e2b83f
@ -31,6 +31,12 @@ Pluf::loadFunction('Pluf_Shortcuts_GetFormForModel');
|
|||||||
*/
|
*/
|
||||||
class IDF_Views_Source
|
class IDF_Views_Source
|
||||||
{
|
{
|
||||||
|
public static $supportedExtenstions = array('c', 'cc', 'cpp', 'cs', 'css',
|
||||||
|
'cyc', 'java', 'bsh', 'csh',
|
||||||
|
'sh', 'cv', 'py', 'perl', 'php',
|
||||||
|
'pl', 'pm', 'rb', 'js', 'html',
|
||||||
|
'html', 'xhtml', 'xml', 'xsl');
|
||||||
|
|
||||||
public $changeLog_precond = array('IDF_Precondition::accessSource');
|
public $changeLog_precond = array('IDF_Precondition::accessSource');
|
||||||
public function changeLog($request, $match)
|
public function changeLog($request, $match)
|
||||||
{
|
{
|
||||||
@ -378,16 +384,32 @@ class IDF_Views_Source
|
|||||||
|
|
||||||
public static function highLight($fileinfo, $content)
|
public static function highLight($fileinfo, $content)
|
||||||
{
|
{
|
||||||
|
$openPre = '';
|
||||||
|
$closePre = '';
|
||||||
|
if (IDF_Views_Source::isSupportedExtension($fileinfo[2])) {
|
||||||
|
$openPre = '<pre class="prettyprint">';
|
||||||
|
$closePre = '</pre>';
|
||||||
|
}
|
||||||
$table = array();
|
$table = array();
|
||||||
$i = 1;
|
$i = 1;
|
||||||
foreach (preg_split("/\015\012|\015|\012/", $content) as $line) {
|
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>'
|
$table[] = '<tr class="c-line"><td class="code-lc" id="L'.$i.'"><a href="#L'.$i.'">'.$i.'</a></td>'
|
||||||
.'<td class="code mono">'.IDF_Diff::padLine(Pluf_esc($line)).'</td></tr>';
|
.'<td class="code mono">'.$openPre.IDF_Diff::padLine(Pluf_esc($line)).$closePre.'</td></tr>';
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
return Pluf_Template::markSafe(implode("\n", $table));
|
return Pluf_Template::markSafe(implode("\n", $table));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string the extension to test
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static function isSupportedExtension($extension)
|
||||||
|
{
|
||||||
|
return in_array($extension, IDF_Views_Source::$supportedExtenstions);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the scm type for page title
|
* Get the scm type for page title
|
||||||
*
|
*
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
{extends "source/base.html"}
|
{extends "source/base.html"}
|
||||||
|
{block extraheader}<link rel="stylesheet" type="text/css" href="{media '/idf/css/prettify.css'}" />{/block}
|
||||||
{block docclass}yui-t1{assign $inSourceTree=true}{/block}
|
{block docclass}yui-t1{assign $inSourceTree=true}{/block}
|
||||||
{block body}
|
{block body}
|
||||||
<h2 class="top"><a href="{url 'IDF_Views_Source::treeBase', array($project.shortname, $commit)}">{trans 'Root'}</a><span class="sep">/</span>{if $breadcrumb}{$breadcrumb|safe}{/if}</h2>
|
<h2 class="top"><a href="{url 'IDF_Views_Source::treeBase', array($project.shortname, $commit)}">{trans 'Root'}</a><span class="sep">/</span>{if $breadcrumb}{$breadcrumb|safe}{/if}</h2>
|
||||||
@ -19,7 +20,6 @@
|
|||||||
{aurl 'url', 'IDF_Views_Source::getFile', array($project.shortname, $commit, $fullpath)}
|
{aurl 'url', 'IDF_Views_Source::getFile', array($project.shortname, $commit, $fullpath)}
|
||||||
<p class="right soft"><a href="{$url}"><img style="vertical-align: text-bottom;" src="{media '/idf/img/package-grey.png'}" alt="{trans 'Archive'}" align="bottom" /></a> <a href="{$url}">{trans 'Download this file'}</a></p>
|
<p class="right soft"><a href="{$url}"><img style="vertical-align: text-bottom;" src="{media '/idf/img/package-grey.png'}" alt="{trans 'Archive'}" align="bottom" /></a> <a href="{$url}">{trans 'Download this file'}</a></p>
|
||||||
|
|
||||||
|
|
||||||
{/block}
|
{/block}
|
||||||
{block context}
|
{block context}
|
||||||
<p><strong>{trans 'Branches:'}</strong><br />
|
<p><strong>{trans 'Branches:'}</strong><br />
|
||||||
@ -29,3 +29,8 @@
|
|||||||
{/foreach}
|
{/foreach}
|
||||||
</p>
|
</p>
|
||||||
{/block}
|
{/block}
|
||||||
|
|
||||||
|
{block javascript}
|
||||||
|
<script type="text/javascript" src="{media '/idf/js/prettify.js'}"></script>
|
||||||
|
<script type="text/javascript">prettyPrint();</script>
|
||||||
|
{/block}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
{extends "source/base.html"}
|
{extends "source/base.html"}
|
||||||
|
{block extraheader}<link rel="stylesheet" type="text/css" href="{media '/idf/css/prettify.css'}" />{/block}
|
||||||
{block docclass}yui-t1{assign $inSourceTree=true}{/block}
|
{block docclass}yui-t1{assign $inSourceTree=true}{/block}
|
||||||
{block body}
|
{block body}
|
||||||
<h2 class="top"><a href="{url 'IDF_Views_Source::treeBase', array($project.shortname, $commit)}">{trans 'Root'}</a><span class="sep">/</span>{if $breadcrumb}{$breadcrumb|safe}{/if}</h2>
|
<h2 class="top"><a href="{url 'IDF_Views_Source::treeBase', array($project.shortname, $commit)}">{trans 'Root'}</a><span class="sep">/</span>{if $breadcrumb}{$breadcrumb|safe}{/if}</h2>
|
||||||
@ -30,7 +31,6 @@
|
|||||||
{aurl 'url', 'IDF_Views_Source::getFile', array($project.shortname, $commit, $fullpath)}
|
{aurl 'url', 'IDF_Views_Source::getFile', array($project.shortname, $commit, $fullpath)}
|
||||||
<p class="right soft"><a href="{$url}"><img style="vertical-align: text-bottom;" src="{media '/idf/img/package-grey.png'}" alt="{trans 'Archive'}" align="bottom" /></a> <a href="{$url}">{trans 'Download this file'}</a></p>
|
<p class="right soft"><a href="{$url}"><img style="vertical-align: text-bottom;" src="{media '/idf/img/package-grey.png'}" alt="{trans 'Archive'}" align="bottom" /></a> <a href="{$url}">{trans 'Download this file'}</a></p>
|
||||||
|
|
||||||
|
|
||||||
{/block}
|
{/block}
|
||||||
{block context}
|
{block context}
|
||||||
<form class="star" action="{url 'IDF_Views_Source_Svn::treeRev', array($project.shortname)}" method="get">
|
<form class="star" action="{url 'IDF_Views_Source_Svn::treeRev', array($project.shortname)}" method="get">
|
||||||
@ -42,3 +42,8 @@
|
|||||||
</form>
|
</form>
|
||||||
|
|
||||||
{/block}
|
{/block}
|
||||||
|
|
||||||
|
{block javascript}
|
||||||
|
<script type="text/javascript" src="{media '/idf/js/prettify.js'}"></script>
|
||||||
|
<script type="text/javascript">prettyPrint();</script>
|
||||||
|
{/block}
|
||||||
|
27
www/media/idf/css/prettify.css
Normal file
27
www/media/idf/css/prettify.css
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/* Pretty printing styles. Used with prettify.js. */
|
||||||
|
|
||||||
|
.str { color: #080; }
|
||||||
|
.kwd { color: #008; }
|
||||||
|
.com { color: #800; }
|
||||||
|
.typ { color: #606; }
|
||||||
|
.lit { color: #066; }
|
||||||
|
.pun { color: #660; }
|
||||||
|
.pln { color: #000; }
|
||||||
|
.tag { color: #008; }
|
||||||
|
.atn { color: #606; }
|
||||||
|
.atv { color: #080; }
|
||||||
|
.dec { color: #606; }
|
||||||
|
pre.prettyprint { border:0px; padding:0; margin:0; }
|
||||||
|
|
||||||
|
@media print {
|
||||||
|
.str { color: #060; }
|
||||||
|
.kwd { color: #006; font-weight: bold; }
|
||||||
|
.com { color: #600; font-style: italic; }
|
||||||
|
.typ { color: #404; font-weight: bold; }
|
||||||
|
.lit { color: #044; }
|
||||||
|
.pun { color: #440; }
|
||||||
|
.pln { color: #000; }
|
||||||
|
.tag { color: #006; font-weight: bold; }
|
||||||
|
.atn { color: #404; }
|
||||||
|
.atv { color: #060; }
|
||||||
|
}
|
1348
www/media/idf/js/prettify.js
Normal file
1348
www/media/idf/js/prettify.js
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user