-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e526e91
commit 2956740
Showing
3 changed files
with
58 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace SyntaxPhoenix\EJSParserBundle\Parser\Extension; | ||
|
||
use DOMElement; | ||
use DOMDocument; | ||
use Masterminds\HTML5; | ||
use SyntaxPhoenix\EJSParserBundle\Parser\EditorjsParserExtension; | ||
|
||
class SimpleImageParser implements EditorjsParserExtension | ||
{ | ||
|
||
public function parseBlock(HTML5 $html5, DOMDocument $document, object $block, string $prefix): DOMElement | ||
{ | ||
$figure = $document->createElement('figure'); | ||
|
||
$figure->setAttribute('class', "{$prefix}-simpleimage"); | ||
|
||
$img = $document->createElement('img'); | ||
|
||
$imgAttrs = []; | ||
|
||
if ($block->data->withBorder) { | ||
$imgAttrs[] = "{$prefix}-simpleimage-border"; | ||
} | ||
if ($block->data->withBackground) { | ||
$imgAttrs[] = "{$prefix}-simpleimage-background"; | ||
} | ||
if ($block->data->stretched) { | ||
$imgAttrs[] = "{$prefix}-simpleimage-stretched"; | ||
} | ||
|
||
$img->setAttribute('src', $block->data->url); | ||
$img->setAttribute('class', implode(' ', $imgAttrs)); | ||
|
||
$figCaption = $document->createElement('figcaption'); | ||
|
||
$figCaption->appendChild($html5->loadHTMLFragment($block->data->caption)); | ||
|
||
$figure->appendChild($img); | ||
|
||
$figure->appendChild($figCaption); | ||
|
||
return $figure; | ||
} | ||
} |