mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-17 01:08:41 +01:00
Disable default syntax highlighting for large files in DocumentEngine
Summary: Ref T13105. See also T7895. When users render very large files as source via DocumentEngine, skip highlighting. Test Plan: Fiddled with the limit, viewed files, saw highlighting degrade. Reviewers: mydeveloperday Reviewed By: mydeveloperday Maniphest Tasks: T13105 Differential Revision: https://secure.phabricator.com/D19306
This commit is contained in:
parent
6dea2ba3b3
commit
0363febeb2
1 changed files with 17 additions and 4 deletions
|
@ -24,18 +24,31 @@ final class PhabricatorSourceDocumentEngine
|
||||||
protected function newDocumentContent(PhabricatorDocumentRef $ref) {
|
protected function newDocumentContent(PhabricatorDocumentRef $ref) {
|
||||||
$content = $this->loadTextData($ref);
|
$content = $this->loadTextData($ref);
|
||||||
|
|
||||||
|
$messages = array();
|
||||||
|
|
||||||
$highlighting = $this->getHighlightingConfiguration();
|
$highlighting = $this->getHighlightingConfiguration();
|
||||||
if ($highlighting !== null) {
|
if ($highlighting !== null) {
|
||||||
$content = PhabricatorSyntaxHighlighter::highlightWithLanguage(
|
$content = PhabricatorSyntaxHighlighter::highlightWithLanguage(
|
||||||
$highlighting,
|
$highlighting,
|
||||||
$content);
|
$content);
|
||||||
|
} else {
|
||||||
|
$highlight_limit = DifferentialChangesetParser::HIGHLIGHT_BYTE_LIMIT;
|
||||||
|
if (strlen($content) > $highlight_limit) {
|
||||||
|
$messages[] = $this->newMessage(
|
||||||
|
pht(
|
||||||
|
'This file is larger than %s, so syntax highlighting was skipped.',
|
||||||
|
phutil_format_bytes($highlight_limit)));
|
||||||
} else {
|
} else {
|
||||||
$content = PhabricatorSyntaxHighlighter::highlightWithFilename(
|
$content = PhabricatorSyntaxHighlighter::highlightWithFilename(
|
||||||
$ref->getName(),
|
$ref->getName(),
|
||||||
$content);
|
$content);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $this->newTextDocumentContent($content);
|
return array(
|
||||||
|
$messages,
|
||||||
|
$this->newTextDocumentContent($content),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue