3 final class DiffusionReadmeView
extends DiffusionView
{
8 public function setPath($path) {
13 public function getPath() {
17 public function setContent($content) {
18 $this->content
= $content;
22 public function getContent() {
23 return $this->content
;
27 * Get the markup language a README should be interpreted as.
29 * @param string Local README path, like "README.txt".
30 * @return string Best markup interpreter (like "remarkup") for this file.
32 private function getReadmeLanguage($path) {
33 $path = phutil_utf8_strtolower($path);
34 if ($path == 'readme') {
38 $ext = last(explode('.', $path));
52 public function render() {
53 $readme_path = $this->getPath();
54 $readme_name = basename($readme_path);
55 $interpreter = $this->getReadmeLanguage($readme_name);
56 require_celerity_resource('diffusion-readme-css');
58 $content = $this->getContent();
61 switch ($interpreter) {
63 // TODO: This is sketchy, but make sure we hit the markup cache.
64 $markup_object = id(new PhabricatorMarkupOneOff())
65 ->setEngineRuleset('diffusion-readme')
66 ->setContent($content);
67 $markup_field = 'default';
69 $content = id(new PhabricatorMarkupEngine())
70 ->setViewer($this->getUser())
71 ->addObject($markup_object, $markup_field)
73 ->getOutput($markup_object, $markup_field);
75 $engine = $markup_object->newMarkupEngine($markup_field);
77 $readme_content = $content;
81 $content = id(new PhutilRainbowSyntaxHighlighter())
82 ->getHighlightFuture($content)
84 $readme_content = phutil_escape_html_newlines($content);
86 require_celerity_resource('syntax-highlighting-css');
87 $class = 'remarkup-code ml';
91 $readme_content = phutil_escape_html_newlines($content);
96 $readme_content = phutil_tag(
103 $header = id(new PHUIHeaderView())
104 ->setHeader($readme_name)
105 ->addClass('diffusion-panel-header-view');
107 return id(new PHUIObjectBoxView())
109 ->setBackground(PHUIObjectBoxView
::BLUE_PROPERTY
)
110 ->addClass('diffusion-mobile-view')
111 ->appendChild($readme_content)
112 ->addClass('diffusion-readme-view');