1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 01:08:50 +02:00

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:
epriestley 2020-05-22 11:47:10 -07:00
parent 87fb35abb7
commit 4fd0628fae
2 changed files with 15 additions and 5 deletions

View file

@ -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();
} }

View file

@ -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');
if (is_array($usource)) {
$usource = implode('', $usource); $usource = implode('', $usource);
}
$vsource = idx($vcell, 'source'); $vsource = idx($vcell, 'source');
if (is_array($vsource)) {
$vsource = implode('', $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 = $cell['source'];
if (is_array($hash_input)) {
$hash_input = implode('', $cell['source']); $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'];
if (is_array($source)) {
$source = implode('', $source); $source = implode('', $source);
}
// Attempt to split contiguous blocks of markdown into smaller // Attempt to split contiguous blocks of markdown into smaller
// pieces. // pieces.