Skip to content

Commit

Permalink
Merge pull request #135 from k10blogger/master
Browse files Browse the repository at this point in the history
Attempt to Render Markdown if README.md found on the current path.
  • Loading branch information
k10blogger committed Jan 25, 2021
2 parents 4811e65 + 53f82b7 commit 94aa3eb
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 7 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"require": {
"geshi/geshi": "^1.0.9",
"pear/archive_tar": "^1.4",
"pear/text_diff": "^1.2"
"pear/text_diff": "^1.2",
"erusev/parsedown": "^1.7"
}
}
16 changes: 16 additions & 0 deletions include/configclass.php
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,7 @@ class WebSvnConfig {
var $useEnscript = false;
var $useEnscriptBefore_1_6_3 = false;
var $useGeshi = false;
var $useParsedown = false;
var $inlineMimeTypes = array();
var $allowDownload = false;
var $tempDir = '';
Expand Down Expand Up @@ -876,6 +877,21 @@ function getUseGeshi() {

// }}}

// {{{ Parsedown

// useParsedown
//
// Use Parsedown to render README.md
function useParsedown() {
$this->useParsedown = true;
}

function getUseParsedown() {
return $this->useParsedown;
}

// }}}

// {{{ Inline MIME Types

// inlineMimeTypes
Expand Down
11 changes: 11 additions & 0 deletions include/distconfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,17 @@

// }}}

// {{{ Markdown Render

// Uncomment this line if you want to enable Markdown Rendering of README.md file in the path.
// You will need the Parsedown.php (https://github.com/erusev/parsedown) library for this to work.
// This will look for README.md file on the path and render it.
// The name of "README.md" isn't configurable for now to simply follow GitHub's conventions.

// $config->useParsedown();

// }}}

// {{{ RSSFEED ---

// Uncomment this line to hide the RSS feed links across all repositories
Expand Down
44 changes: 44 additions & 0 deletions include/svnlook.php
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,50 @@ function listFileContents($path, $rev = 0, $peg = '') {
}
}

// }}}

// {{{ listReadmeContents
//
// Parse the README.md file
function listReadmeContents($path, $rev = 0, $peg = '') {
global $config;

$file = "README.md";

if ($this->isFile($path.$file) != True)
{
return;
}

if (!$config->getUseParsedown())
{
return;
}

// Autoloader handles most of the time
if (!defined('USE_AUTOLOADER')) {
require_once 'Parsedown.php';
}

$mdParser = new Parsedown();
$cmd = $this->svnCommandString('cat', $path.$file, $rev, $peg);

if (!($result = popenCommand($cmd, 'r')))
{
return;
}

echo('<div id="wrap">');
while (!feof($result))
{
$line = fgets($result, 1024);
echo $mdParser->text($line);
}
echo('</div>');
pclose($result);

}

// }}}

// {{{ getBlameDetails
Expand Down
25 changes: 21 additions & 4 deletions include/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,9 @@ function parseTags($line, $vars) {
//
// Renders the templates for the given view

function renderTemplate($view) {
function renderTemplate($view, $readmePath = null)
{

global $config, $rep, $vars, $listing, $lang, $locwebsvnhttp;

// Set the view in the templates variables
Expand All @@ -272,16 +274,31 @@ function renderTemplate($view) {
// Check if we are using a PHP powered template or the standard one
$path = !empty($rep) ? $rep->getTemplatePath() : $config->getTemplatePath();
$path = $path . 'template.php';
if (is_readable($path)) {

if (is_readable($path))
{
$vars['templateentrypoint'] = $path;
executePlainPhpTemplate($vars);
} else {
}
else
{
parseTemplate('header.tmpl');
flush(); // http://developer.yahoo.com/performance/rules.html#flush
parseTemplate($view . '.tmpl');
if ($view === 'directory' || $view === 'log') {

if (($view === 'directory') || ($view === 'log'))
{
print '<script type="text/javascript" src="'.$locwebsvnhttp.'/javascript/compare-checkboxes.js"></script>';
}

if ($readmePath == null)
{
parseTemplate('footer.tmpl');
return;
}

$svnrep = new SVNRepository($rep);
$svnrep->listReadmeContents($readmePath);
parseTemplate('footer.tmpl');
}
}
Expand Down
3 changes: 1 addition & 2 deletions listing.php
Original file line number Diff line number Diff line change
Expand Up @@ -631,5 +631,4 @@ function showTreeDir($svnrep, $path, $rev, $peg, $listing)
}

$vars['restricted'] = !$rep->hasReadAccess($path, false);

renderTemplate('directory');
renderTemplate('directory', $path);

0 comments on commit 94aa3eb

Please sign in to comment.