Make basic Juypter notebook rendering improvements and roughly support folding unchanged context

Summary:
Depends on D20843. Ref T13425. Add very basic support for "Show Hidden Context", in the form of folding it behind an unclickable shield. This isn't ideal, but should be better than nothing.

Prepare for "intraline" diffs on content blocks.

Fix newline handling in Markdown sections in Jupyter notebooks.

Remove the word "visibile" from the codebase.

Test Plan: {F6898192}

Maniphest Tasks: T13425

Differential Revision: https://secure.phabricator.com/D20844
This commit is contained in:
epriestley
2019-09-27 14:02:53 -07:00
parent a7f3316aa3
commit 5afdc620db
9 changed files with 137 additions and 33 deletions

View File

@@ -307,7 +307,8 @@ final class PhabricatorJupyterDocumentEngine
return $this->newCodeOutputCell($cell);
}
return $this->newRawCell(id(new PhutilJSON())->encodeFormatted($cell));
return $this->newRawCell(id(new PhutilJSON())
->encodeFormatted($cell));
}
private function newRawCell($content) {
@@ -328,8 +329,9 @@ final class PhabricatorJupyterDocumentEngine
$content = array();
}
$content = implode('', $content);
$content = phutil_escape_html_newlines($content);
// TODO: This should ideally highlight as Markdown, but the "md"
// highlighter in Pygments is painfully slow and not terribly useful.
$content = $this->highlightLines($content, 'txt');
return array(
null,
@@ -514,15 +516,20 @@ final class PhabricatorJupyterDocumentEngine
return $label;
}
private function highlightLines(array $lines) {
$head = head($lines);
$matches = null;
if (preg_match('/^%%(.*)$/', $head, $matches)) {
$restore = array_shift($lines);
$lang = $matches[1];
private function highlightLines(array $lines, $force_language = null) {
if ($force_language === null) {
$head = head($lines);
$matches = null;
if (preg_match('/^%%(.*)$/', $head, $matches)) {
$restore = array_shift($lines);
$lang = $matches[1];
} else {
$restore = null;
$lang = 'py';
}
} else {
$restore = null;
$lang = 'py';
$lang = $force_language;
}
$content = PhabricatorSyntaxHighlighter::highlightWithLanguage(