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
This commit is contained in:
		@@ -61,6 +61,7 @@ final class PhabricatorDocumentEngineBlocks
 | 
				
			|||||||
    $lists = $this->lists;
 | 
					    $lists = $this->lists;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (count($lists) != 2) {
 | 
					    if (count($lists) != 2) {
 | 
				
			||||||
 | 
					      $this->layoutAvailableRowCount = 0;
 | 
				
			||||||
      return array();
 | 
					      return array();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -63,6 +63,7 @@ final class PhabricatorJupyterDocumentEngine
 | 
				
			|||||||
      $blocks->addBlockList($uref, $u_blocks);
 | 
					      $blocks->addBlockList($uref, $u_blocks);
 | 
				
			||||||
      $blocks->addBlockList($vref, $v_blocks);
 | 
					      $blocks->addBlockList($vref, $v_blocks);
 | 
				
			||||||
    } catch (Exception $ex) {
 | 
					    } catch (Exception $ex) {
 | 
				
			||||||
 | 
					      phlog($ex);
 | 
				
			||||||
      $blocks->addMessage($ex->getMessage());
 | 
					      $blocks->addMessage($ex->getMessage());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -85,10 +86,14 @@ final class PhabricatorJupyterDocumentEngine
 | 
				
			|||||||
      switch ($utype) {
 | 
					      switch ($utype) {
 | 
				
			||||||
        case 'markdown':
 | 
					        case 'markdown':
 | 
				
			||||||
          $usource = idx($ucell, 'source');
 | 
					          $usource = idx($ucell, 'source');
 | 
				
			||||||
          $usource = implode('', $usource);
 | 
					          if (is_array($usource)) {
 | 
				
			||||||
 | 
					            $usource = implode('', $usource);
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          $vsource = idx($vcell, 'source');
 | 
					          $vsource = idx($vcell, 'source');
 | 
				
			||||||
          $vsource = implode('', $vsource);
 | 
					          if (is_array($vsource)) {
 | 
				
			||||||
 | 
					            $vsource = implode('', $vsource);
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          $diff = id(new PhutilProseDifferenceEngine())
 | 
					          $diff = id(new PhutilProseDifferenceEngine())
 | 
				
			||||||
            ->getDiff($usource, $vsource);
 | 
					            ->getDiff($usource, $vsource);
 | 
				
			||||||
@@ -254,7 +259,10 @@ final class PhabricatorJupyterDocumentEngine
 | 
				
			|||||||
          $hash_input = $cell['raw'];
 | 
					          $hash_input = $cell['raw'];
 | 
				
			||||||
          break;
 | 
					          break;
 | 
				
			||||||
        case 'markdown':
 | 
					        case 'markdown':
 | 
				
			||||||
          $hash_input = implode('', $cell['source']);
 | 
					          $hash_input = $cell['source'];
 | 
				
			||||||
 | 
					          if (is_array($hash_input)) {
 | 
				
			||||||
 | 
					            $hash_input = implode('', $cell['source']);
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
          break;
 | 
					          break;
 | 
				
			||||||
        default:
 | 
					        default:
 | 
				
			||||||
          $hash_input = serialize($cell);
 | 
					          $hash_input = serialize($cell);
 | 
				
			||||||
@@ -367,10 +375,11 @@ final class PhabricatorJupyterDocumentEngine
 | 
				
			|||||||
    $results = array();
 | 
					    $results = array();
 | 
				
			||||||
    foreach ($cells as $cell) {
 | 
					    foreach ($cells as $cell) {
 | 
				
			||||||
      $cell_type = idx($cell, 'cell_type');
 | 
					      $cell_type = idx($cell, 'cell_type');
 | 
				
			||||||
 | 
					 | 
				
			||||||
      if ($cell_type === 'markdown') {
 | 
					      if ($cell_type === 'markdown') {
 | 
				
			||||||
        $source = $cell['source'];
 | 
					        $source = $cell['source'];
 | 
				
			||||||
        $source = implode('', $source);
 | 
					        if (is_array($source)) {
 | 
				
			||||||
 | 
					          $source = implode('', $source);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Attempt to split contiguous blocks of markdown into smaller
 | 
					        // Attempt to split contiguous blocks of markdown into smaller
 | 
				
			||||||
        // pieces.
 | 
					        // pieces.
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user