From 828798f3e1b4bad0ff9b9bba25cd870576689fef Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 22 May 2020 11:47:10 -0700 Subject: [PATCH] (stable) Fix two rendering issues with Jupyter notebooks Summary: See PHI1752. - Early exit of document layout can cause us to fail to populate available rows. - Some Jupyter documents have "markdown" cells with plain strings, apparently. Test Plan: Successfully rendered example diff from PHI1752. Differential Revision: https://secure.phabricator.com/D21285 --- .../diff/PhabricatorDocumentEngineBlocks.php | 1 + .../PhabricatorJupyterDocumentEngine.php | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/applications/files/diff/PhabricatorDocumentEngineBlocks.php b/src/applications/files/diff/PhabricatorDocumentEngineBlocks.php index d07f341815..3897af2f02 100644 --- a/src/applications/files/diff/PhabricatorDocumentEngineBlocks.php +++ b/src/applications/files/diff/PhabricatorDocumentEngineBlocks.php @@ -61,6 +61,7 @@ final class PhabricatorDocumentEngineBlocks $lists = $this->lists; if (count($lists) != 2) { + $this->layoutAvailableRowCount = 0; return array(); } diff --git a/src/applications/files/document/PhabricatorJupyterDocumentEngine.php b/src/applications/files/document/PhabricatorJupyterDocumentEngine.php index 3e479fdace..753cdf3921 100644 --- a/src/applications/files/document/PhabricatorJupyterDocumentEngine.php +++ b/src/applications/files/document/PhabricatorJupyterDocumentEngine.php @@ -63,6 +63,7 @@ final class PhabricatorJupyterDocumentEngine $blocks->addBlockList($uref, $u_blocks); $blocks->addBlockList($vref, $v_blocks); } catch (Exception $ex) { + phlog($ex); $blocks->addMessage($ex->getMessage()); } @@ -85,10 +86,14 @@ final class PhabricatorJupyterDocumentEngine switch ($utype) { case 'markdown': $usource = idx($ucell, 'source'); - $usource = implode('', $usource); + if (is_array($usource)) { + $usource = implode('', $usource); + } $vsource = idx($vcell, 'source'); - $vsource = implode('', $vsource); + if (is_array($vsource)) { + $vsource = implode('', $vsource); + } $diff = id(new PhutilProseDifferenceEngine()) ->getDiff($usource, $vsource); @@ -254,7 +259,10 @@ final class PhabricatorJupyterDocumentEngine $hash_input = $cell['raw']; break; case 'markdown': - $hash_input = implode('', $cell['source']); + $hash_input = $cell['source']; + if (is_array($hash_input)) { + $hash_input = implode('', $cell['source']); + } break; default: $hash_input = serialize($cell); @@ -367,10 +375,11 @@ final class PhabricatorJupyterDocumentEngine $results = array(); foreach ($cells as $cell) { $cell_type = idx($cell, 'cell_type'); - if ($cell_type === 'markdown') { $source = $cell['source']; - $source = implode('', $source); + if (is_array($source)) { + $source = implode('', $source); + } // Attempt to split contiguous blocks of markdown into smaller // pieces.