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

Commit

Permalink
Add horizontal rule (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonvarga authored Jan 19, 2021
1 parent 946bb92 commit 1ab69d7
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
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 @@ -29,6 +29,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));
}
}

0 comments on commit 1ab69d7

Please sign in to comment.