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

Add Horizontal Rule #46

Merged
merged 1 commit into from
Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/Nodes/HorizontalRule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace ProseMirrorToHtml\Nodes;

class HorizontalRule extends Node
{
protected $nodeType = 'horizontal_rule';
protected $tagName = 'hr';

public function selfClosing()
{
return true;
}
}
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\HorizontalRule::class,
Nodes\Image::class,
Nodes\ListItem::class,
Nodes\OrderedList::class,
Expand Down
44 changes: 44 additions & 0 deletions tests/Nodes/HorizontalRuleNodeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace ProseMirrorToHtml\Test\Nodes;

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

class HorizontalRuleNodeTest extends TestCase
{
/** @test */
public function self_closing_node_gets_rendered_correctly()
{
$json = [
'type' => 'doc',
'content' => [
[
'type' => 'paragraph',
'content' => [
[
'type' => 'text',
'text' => 'some text',
],
],
],
[
'type' => 'horizontal_rule',
],
[
'type' => 'paragraph',
'content' => [
[
'type' => 'text',
'text' => 'some more text',
],
],
],
],
];

$html = '<p>some text</p><hr><p>some more text</p>';

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