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

Add horizontal rule #41

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
18 changes: 18 additions & 0 deletions src/Nodes/HorizontalRule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace HtmlToProseMirror\Nodes;

class HorizontalRule extends Node
{
public function matching()
{
return $this->DOMNode->nodeName === 'hr';
}

public function data()
{
return [
'type' => 'horizontal_rule',
];
}
}
1 change: 1 addition & 0 deletions src/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Renderer
Nodes\CodeBlockWrapper::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/HorizontalRuleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace HtmlToProseMirror\Test\Nodes;

use HtmlToProseMirror\Renderer;
use HtmlToProseMirror\Test\TestCase;

class HorizontalRuleTest extends TestCase
{
/** @test */
public function hr_gets_rendered_correctly()
{
$html = '<p>Horizontal</p><hr /><p>Rule</p>';

$json = [
'type' => 'doc',
'content' => [
[
'type' => 'paragraph',
'content' => [
[
'type' => 'text',
'text' => 'Horizontal',
],
],
],
[
'type' => 'horizontal_rule',
],
[
'type' => 'paragraph',
'content' => [
[
'type' => 'text',
'text' => 'Rule',
],
],
],
],
];

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