mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-09 16:32:39 +01:00
Add a basic Remarkup document rendering engine
Summary: Ref T13105. Although Markdown is trickier to deal with, we can handle Remarkup easily. This may need some support for encoding options. Test Plan: Viewed `.remarkup` files, got remarkup document presentation by default. Viewed other text files, got an option to render as remarkup. Reviewers: avivey Reviewed By: avivey Subscribers: mydeveloperday, avivey Maniphest Tasks: T13105 Differential Revision: https://secure.phabricator.com/D19251
This commit is contained in:
parent
df3c937dab
commit
8b658706a8
5 changed files with 70 additions and 3 deletions
|
@ -9,7 +9,7 @@ return array(
|
|||
'names' => array(
|
||||
'conpherence.pkg.css' => 'e68cf1fa',
|
||||
'conpherence.pkg.js' => '15191c65',
|
||||
'core.pkg.css' => '6da3c0e5',
|
||||
'core.pkg.css' => 'afe29a6c',
|
||||
'core.pkg.js' => 'b9b4a943',
|
||||
'differential.pkg.css' => '113e692c',
|
||||
'differential.pkg.js' => 'f6d809c0',
|
||||
|
@ -168,7 +168,7 @@ return array(
|
|||
'rsrc/css/phui/phui-object-box.css' => '9cff003c',
|
||||
'rsrc/css/phui/phui-pager.css' => 'edcbc226',
|
||||
'rsrc/css/phui/phui-pinboard-view.css' => '2495140e',
|
||||
'rsrc/css/phui/phui-property-list-view.css' => '6ef560df',
|
||||
'rsrc/css/phui/phui-property-list-view.css' => '94a14381',
|
||||
'rsrc/css/phui/phui-remarkup-preview.css' => '54a34863',
|
||||
'rsrc/css/phui/phui-segment-bar-view.css' => 'b1d1b892',
|
||||
'rsrc/css/phui/phui-spacing.css' => '042804d6',
|
||||
|
@ -850,7 +850,7 @@ return array(
|
|||
'phui-oi-simple-ui-css' => 'a8beebea',
|
||||
'phui-pager-css' => 'edcbc226',
|
||||
'phui-pinboard-view-css' => '2495140e',
|
||||
'phui-property-list-view-css' => '6ef560df',
|
||||
'phui-property-list-view-css' => '94a14381',
|
||||
'phui-remarkup-preview-css' => '54a34863',
|
||||
'phui-segment-bar-view-css' => 'b1d1b892',
|
||||
'phui-spacing-css' => '042804d6',
|
||||
|
|
|
@ -3967,6 +3967,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorRemarkupCowsayBlockInterpreter' => 'infrastructure/markup/interpreter/PhabricatorRemarkupCowsayBlockInterpreter.php',
|
||||
'PhabricatorRemarkupCustomBlockRule' => 'infrastructure/markup/rule/PhabricatorRemarkupCustomBlockRule.php',
|
||||
'PhabricatorRemarkupCustomInlineRule' => 'infrastructure/markup/rule/PhabricatorRemarkupCustomInlineRule.php',
|
||||
'PhabricatorRemarkupDocumentEngine' => 'applications/files/document/PhabricatorRemarkupDocumentEngine.php',
|
||||
'PhabricatorRemarkupEditField' => 'applications/transactions/editfield/PhabricatorRemarkupEditField.php',
|
||||
'PhabricatorRemarkupFigletBlockInterpreter' => 'infrastructure/markup/interpreter/PhabricatorRemarkupFigletBlockInterpreter.php',
|
||||
'PhabricatorRemarkupUIExample' => 'applications/uiexample/examples/PhabricatorRemarkupUIExample.php',
|
||||
|
@ -9710,6 +9711,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorRemarkupCowsayBlockInterpreter' => 'PhutilRemarkupBlockInterpreter',
|
||||
'PhabricatorRemarkupCustomBlockRule' => 'PhutilRemarkupBlockRule',
|
||||
'PhabricatorRemarkupCustomInlineRule' => 'PhutilRemarkupRule',
|
||||
'PhabricatorRemarkupDocumentEngine' => 'PhabricatorDocumentEngine',
|
||||
'PhabricatorRemarkupEditField' => 'PhabricatorEditField',
|
||||
'PhabricatorRemarkupFigletBlockInterpreter' => 'PhutilRemarkupBlockInterpreter',
|
||||
'PhabricatorRemarkupUIExample' => 'PhabricatorUIExample',
|
||||
|
|
|
@ -7,6 +7,7 @@ final class PhabricatorDocumentRef
|
|||
private $mimeType;
|
||||
private $file;
|
||||
private $byteLength;
|
||||
private $snippet;
|
||||
|
||||
public function setFile(PhabricatorFile $file) {
|
||||
$this->file = $file;
|
||||
|
@ -104,4 +105,17 @@ final class PhabricatorDocumentRef
|
|||
return $mime_type;
|
||||
}
|
||||
|
||||
public function isProbablyText() {
|
||||
$snippet = $this->getSnippet();
|
||||
return (strpos($snippet, "\0") === false);
|
||||
}
|
||||
|
||||
public function getSnippet() {
|
||||
if ($this->snippet === null) {
|
||||
$this->snippet = $this->loadData(null, (1024 * 1024 * 1));
|
||||
}
|
||||
|
||||
return $this->snippet;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorRemarkupDocumentEngine
|
||||
extends PhabricatorDocumentEngine {
|
||||
|
||||
const ENGINEKEY = 'remarkup';
|
||||
|
||||
public function getViewAsLabel(PhabricatorDocumentRef $ref) {
|
||||
return pht('View as Remarkup');
|
||||
}
|
||||
|
||||
protected function getDocumentIconIcon(PhabricatorDocumentRef $ref) {
|
||||
return 'fa-file-text-o';
|
||||
}
|
||||
|
||||
protected function getContentScore(PhabricatorDocumentRef $ref) {
|
||||
$name = $ref->getName();
|
||||
if (preg_match('/\\.remarkup\z/i', $name)) {
|
||||
return 2000;
|
||||
}
|
||||
|
||||
return 500;
|
||||
}
|
||||
|
||||
protected function canRenderDocumentType(PhabricatorDocumentRef $ref) {
|
||||
return $ref->isProbablyText();
|
||||
}
|
||||
|
||||
protected function newDocumentContent(PhabricatorDocumentRef $ref) {
|
||||
$viewer = $this->getViewer();
|
||||
|
||||
$content = $ref->loadData();
|
||||
$content = phutil_utf8ize($content);
|
||||
|
||||
$remarkup = new PHUIRemarkupView($viewer, $content);
|
||||
|
||||
$container = phutil_tag(
|
||||
'div',
|
||||
array(
|
||||
'class' => 'document-engine-remarkup',
|
||||
),
|
||||
$remarkup);
|
||||
|
||||
return $container;
|
||||
}
|
||||
|
||||
}
|
|
@ -244,3 +244,7 @@ div.phui-property-list-stacked .phui-property-list-properties
|
|||
margin: 20px;
|
||||
white-space: pre;
|
||||
}
|
||||
|
||||
.document-engine-remarkup {
|
||||
margin: 20px;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue