Skip to content
This repository has been archived by the owner on Jan 28, 2022. It is now read-only.

Commit

Permalink
Add Images management
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien1138 authored and hanspagel committed Sep 22, 2020
1 parent 1696544 commit e9186f1
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ composer require ueberdosis/prosemirror-to-html
- CodeBlock
- HardBreak
- Heading
- Image
- ListItem
- OrderedList
- Paragraph
Expand Down
24 changes: 24 additions & 0 deletions src/Nodes/Image.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace ProseMirrorToHtml\Nodes;

class Image extends Node
{
protected $nodeType = 'image';
protected $tagName = 'img';

public function selfClosing()
{
return true;
}

public function tag()
{
return [
[
'tag' => $this->tagName,
'attrs' => $this->node->attrs,
],
];
}
}
1 change: 1 addition & 0 deletions src/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Renderer
Nodes\CodeBlock::class,
Nodes\HardBreak::class,
Nodes\Heading::class,
Nodes\Image::class,
Nodes\ListItem::class,
Nodes\OrderedList::class,
Nodes\Paragraph::class,
Expand Down
31 changes: 31 additions & 0 deletions tests/Nodes/ImageTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace ProseMirrorToHtml\Test\Nodes;

use ProseMirrorToHtml\Renderer;
use ProseMirrorToHtml\Test\TestCase;

class ImageTest extends TestCase
{
/** @test */
public function image_gets_rendered_correctly()
{
$json = [
'type' => 'doc',
'content' => [
[
'type' => 'image',
'attrs' => [
'alt' => 'an image',
'src' => 'image/source',
'title' => 'The image title',
],
],
],
];

$html = '<img alt="an image" src="image/source" title="The image title">';

$this->assertEquals($html, (new Renderer)->render($json));
}
}

0 comments on commit e9186f1

Please sign in to comment.