1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-24 14:30:56 +01:00

Diffusion - re-jigger how README files get rendered

Summary: be more aggressive about assuming plain-text, use remarkup for no extension, .remarkup, and .md, and last but not least use rainbow for .rainbow. Fixes T5818.

Test Plan: my README rendered just fine post these changes

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: asherkin, epriestley, Korvin

Maniphest Tasks: T5818

Differential Revision: https://secure.phabricator.com/D10340
This commit is contained in:
Bob Trahan 2014-08-22 15:49:03 -07:00
parent 6f246bd351
commit c1e8d97069

View file

@ -34,6 +34,7 @@ final class DiffusionReadmeQueryConduitAPIMethod
$best = -1; $best = -1;
$readme = ''; $readme = '';
$best_render_type = 'plain';
foreach ($paths as $result_path) { foreach ($paths as $result_path) {
$file_type = $result_path->getFileType(); $file_type = $result_path->getFileType();
if (($file_type != ArcanistDiffChangeType::FILE_NORMAL) && if (($file_type != ArcanistDiffChangeType::FILE_NORMAL) &&
@ -45,7 +46,7 @@ final class DiffusionReadmeQueryConduitAPIMethod
$path = strtolower($result_path->getPath()); $path = strtolower($result_path->getPath());
if ($path === 'readme') { if ($path === 'readme') {
$path .= '.txt'; $path .= '.remarkup';
} }
if (strncmp($path, 'readme.', 7) !== 0) { if (strncmp($path, 'readme.', 7) !== 0) {
@ -56,21 +57,30 @@ final class DiffusionReadmeQueryConduitAPIMethod
switch (substr($path, 7)) { switch (substr($path, 7)) {
case 'remarkup': case 'remarkup':
$priority = 100; $priority = 100;
$render_type = 'remarkup';
break; break;
case 'rainbow': case 'rainbow':
$priority = 90; $priority = 90;
$render_type = 'rainbow';
break; break;
case 'md': case 'md':
$priority = 50; $priority = 50;
$render_type = 'remarkup';
break; break;
case 'txt': case 'txt':
$priority = 10; $priority = 10;
$render_type = 'plain';
break;
default:
$priority = 0;
$render_type = 'plain';
break; break;
} }
if ($priority > $best) { if ($priority > $best) {
$best = $priority; $best = $priority;
$readme = $result_path; $readme = $result_path;
$best_render_type = $render_type;
} }
} }
@ -98,47 +108,50 @@ final class DiffusionReadmeQueryConduitAPIMethod
))); )));
$readme_content = $file_content->getCorpus(); $readme_content = $file_content->getCorpus();
if (preg_match('/\\.txt$/', $readme->getPath())) { switch ($best_render_type) {
$readme_content = phutil_escape_html_newlines($readme_content); case 'plain':
$readme_content = phutil_escape_html_newlines($readme_content);
$class = null;
break;
case 'rainbow':
$highlighter = new PhutilRainbowSyntaxHighlighter();
$readme_content = $highlighter
->getHighlightFuture($readme_content)
->resolve();
$readme_content = phutil_escape_html_newlines($readme_content);
$class = null; require_celerity_resource('syntax-highlighting-css');
} else if (preg_match('/\\.rainbow$/', $readme->getPath())) { $class = 'remarkup-code';
$highlighter = new PhutilRainbowSyntaxHighlighter(); break;
$readme_content = $highlighter case 'remarkup':
->getHighlightFuture($readme_content) // TODO: This is sketchy, but make sure we hit the markup cache.
->resolve(); $markup_object = id(new PhabricatorMarkupOneOff())
$readme_content = phutil_escape_html_newlines($readme_content); ->setEngineRuleset('diffusion-readme')
->setContent($readme_content);
$markup_field = 'default';
require_celerity_resource('syntax-highlighting-css'); $readme_content = id(new PhabricatorMarkupEngine())
$class = 'remarkup-code'; ->setViewer($request->getUser())
} else { ->addObject($markup_object, $markup_field)
// TODO: This is sketchy, but make sure we hit the markup cache. ->process()
$markup_object = id(new PhabricatorMarkupOneOff()) ->getOutput($markup_object, $markup_field);
->setEngineRuleset('diffusion-readme')
->setContent($readme_content);
$markup_field = 'default';
$readme_content = id(new PhabricatorMarkupEngine()) $engine = $markup_object->newMarkupEngine($markup_field);
->setViewer($request->getUser()) $toc = PhutilRemarkupHeaderBlockRule::renderTableOfContents($engine);
->addObject($markup_object, $markup_field) if ($toc) {
->process() $toc = phutil_tag_div(
->getOutput($markup_object, $markup_field); 'phabricator-remarkup-toc',
array(
phutil_tag_div(
'phabricator-remarkup-toc-header',
pht('Table of Contents')),
$toc,
));
$readme_content = array($toc, $readme_content);
}
$engine = $markup_object->newMarkupEngine($markup_field); $class = 'phabricator-remarkup';
$toc = PhutilRemarkupHeaderBlockRule::renderTableOfContents($engine); break;
if ($toc) {
$toc = phutil_tag_div(
'phabricator-remarkup-toc',
array(
phutil_tag_div(
'phabricator-remarkup-toc-header',
pht('Table of Contents')),
$toc,
));
$readme_content = array($toc, $readme_content);
}
$class = 'phabricator-remarkup';
} }
$readme_content = phutil_tag( $readme_content = phutil_tag(