Skip to content

Commit a3d1831

Browse files
committedJul 14, 2019
Add text/html to output bundle
- Applies to `echo` results, or any message with message option `OUTPUT_RAW` - fixes Coder-Spirit#24 a
1 parent 2ae08eb commit a3d1831

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed
 

‎src/Actions/ExecuteAction.php

+9-2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public function __construct(
5757
$this->shellSoul = $shellSoul;
5858
}
5959

60+
/** Sends execution requests to the kernel? */
6061
public function call(array $header, array $content, $zmqIds = [])
6162
{
6263
$this->broker->send($this->iopubSocket, 'status', ['execution_state' => 'busy'], $header);
@@ -90,12 +91,18 @@ public function call(array $header, array $content, $zmqIds = [])
9091
$this->broker->send($this->iopubSocket, 'status', ['execution_state' => 'idle'], $this->header);
9192
}
9293

93-
public function notifyMessage(string $message)
94+
public function notifyMessage(string $message, bool $isRaw)
9495
{
96+
$bundle = ['text/plain' => $message];
97+
if ($isRaw) {
98+
// Send over raw results as html. Tags should render and plain text will still look fine.
99+
$bundle['text/html'] = $message;
100+
}
101+
95102
$this->broker->send(
96103
$this->iopubSocket,
97104
'execute_result',
98-
['execution_count' => $this->execCount, 'data' => ['text/plain' => $message], 'metadata' => new \stdClass],
105+
['execution_count' => $this->execCount, 'data' => $bundle, 'metadata' => new \stdClass],
99106
$this->header
100107
);
101108
}

‎src/KernelOutput.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public function __construct(ExecuteAction $executeAction, LoggerInterface $logge
5555
public function write($messages, $newline = false, $options = self::OUTPUT_NORMAL)
5656
{
5757
$types = self::OUTPUT_NORMAL | self::OUTPUT_RAW | self::OUTPUT_PLAIN;
58+
// if $options is 0 or falsy then use OUTPUT_NORMAL as default...
5859
$type = $types & $options ?: self::OUTPUT_NORMAL;
5960

6061
if (\is_string($messages)) {
@@ -79,7 +80,8 @@ public function write($messages, $newline = false, $options = self::OUTPUT_NORMA
7980
return; // TODO: Throw an error?
8081
}
8182

82-
$this->executeAction->notifyMessage($preparedMessage);
83+
$isRaw = $type == self::OUTPUT_RAW ?: false;
84+
$this->executeAction->notifyMessage($preparedMessage, $isRaw);
8385
}
8486

8587
/**

1 commit comments

Comments
 (1)

sangyuxiaowu commented on Jul 22, 2019

@sangyuxiaowu

Wow. It works well, so great.

Please sign in to comment.