Skip to content
This repository has been archived by the owner on Sep 18, 2023. It is now read-only.

Commit

Permalink
Image support
Browse files Browse the repository at this point in the history
* Basic image support
  • Loading branch information
deanblackborough committed Apr 24, 2017
1 parent 10d52eb commit 9c3d338
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Full changelog for PHP Quill Renderer
* Added tests for setting attributes. [Tests]
* Switched to PSR4
* Minor change to API if using Quill (Render) class, after the PSR4 change I didn't like Quill/Quill.
* Basic support for images (outputting the base64 directly via <img> src="")

## v0.70.0 - 2017-04-19

Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Created for use in [Dlayer](https://github.com/Dlayer/dlayer) but works as a sta
The easiest way to use the renderer is with composer. ```composer require deanblackborough/php-quill-renderer```,
alternatively include the classes in src/ in your library.

## Usage, using Quill API
## Usage
```
try {
$quill = new \DBlackborough\Quill\Render($deltas, 'HTML');
Expand All @@ -28,7 +28,7 @@ try {
}
```

## Usage, direct
## Usage, direct, parse and then render
```
$parser = new \DBlackborough\Quill\Parser\Html();
$parser->load($deltas);
Expand Down Expand Up @@ -59,13 +59,13 @@ Script:Sub | `<sub>`
Script:Super | `<sup>`
Underline | `<u>`
Header | `<h[n]>`
Image | `<img>`

## Planned features in possible order
## Planned features

* Markdown support
* Lists (Bullets and Ordered)
* Formatting
* Formatting options (justification etc.)
* Improved newline and paragraph support
* External images
* Remaining toolbar options
* Missing tests (options)
* Markdown support
18 changes: 14 additions & 4 deletions src/Parser/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ private function splitDeltas()
$this->deltas = array();

foreach ($deltas as $delta) {
if (array_key_exists('insert', $delta) === true && array_key_exists('attributes', $delta) === false &&
if (array_key_exists('insert', $delta) === true &&
array_key_exists('attributes', $delta) === false &&
is_array($delta['insert']) === false &&
preg_match("/[\n]{2}/", $delta['insert']) !== 0) {

foreach (explode("\n\n", $delta['insert']) as $match) {
Expand Down Expand Up @@ -280,8 +282,16 @@ private function assignTags()
}
}

if (array_key_exists('insert', $insert) === true && strlen(trim($insert['insert'])) > 0) {
$this->content[$i]['content'] = $insert['insert'];
if (array_key_exists('insert', $insert) === true) {
if (is_array($insert['insert']) === false && strlen(trim($insert['insert'])) > 0) {
$this->content[$i]['content'] = $insert['insert'];
} else {
var_dump($insert['insert']);
if (is_array($insert['insert']) === true &&
array_key_exists('image', $insert['insert']) === true) {
$this->content[$i]['content'] = [ 'image' => $insert['insert']['image'] ];
}
}
}

$i++;
Expand Down Expand Up @@ -356,7 +366,7 @@ private function removeEmptyElements()
$existing_content = $this->content;
$this->content = array();
foreach ($existing_content as $content) {
if (strlen($content['content']) !== 0) {
if (is_array($content['content']) === true || strlen($content['content']) !== 0) {
$this->content[] = $content;
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/Renderer/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ public function render()
}
}

$this->html .= $content['content'];
if (is_array($content['content']) === false) {
$this->html .= $content['content'];
} else {
$this->html .= '<img src="' . $content['content']['image'] . '" />';
}

foreach (array_reverse($content['tags']) as $tag) {
if (array_key_exists('close', $tag) === true && $tag['close'] !== null) {
Expand Down

0 comments on commit 9c3d338

Please sign in to comment.