/
NotebookContent.php
48 lines (42 loc) · 1.15 KB
/
NotebookContent.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
/**
* Notebook content model
*
* @file
* @ingroup Extensions
* @ingroup NotebookViewer
*
* @author Ori Livneh <ori@wikimedia.org>
* @author Yuvi Panda <yuvipanda@riseup.net>
*/
use Symfony\Component\Process\Process;
/**
* Represents the configuration of a Jupyter Notebook
*/
class NotebookContent extends TextContent {
function __construct( $text ) {
parent::__construct( $text, 'Notebook' );
}
protected function renderNotebook( $content ) {
$retval = null;
$process = new Process( [ __DIR__ . "/convertor.py" ] );
$process->setInput( $content );
$process->run();
if ( $process->isSuccessful() ) {
return $process->getOutput();
} else {
return "Parsing error";
}
}
protected function fillParserOutput( Title $title, $revId,
ParserOptions $options, $generateHtml, ParserOutput &$output
) {
// FIXME: WikiPage::doEditContent generates parser output before validation.
// As such, native data may be invalid (though output is discarded later in that case).
if ( $generateHtml && $this->isValid() ) {
$output->setText( $this->renderNotebook( $this->getText() ) );
} else {
$output->setText( 'error' );
}
}
}