Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
nperez0111 authored Aug 12, 2024
2 parents 9e1f933 + 6628ef1 commit b4356d9
Show file tree
Hide file tree
Showing 13 changed files with 123 additions and 64 deletions.
15 changes: 13 additions & 2 deletions .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
name: Check & fix styling

on: [push]
on:
push:
branches:
- main
- develop
- next
- release/*
pull_request:
branches:
- main
- develop
- next

jobs:
php-cs-fixer:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

Expand Down
17 changes: 12 additions & 5 deletions .github/workflows/psalm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,28 @@ name: Psalm

on:
push:
paths:
- '**.php'
- 'psalm.xml.dist'
branches:
- main
- develop
- next
- release/*
pull_request:
branches:
- main
- develop
- next

jobs:
psalm:
name: psalm
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
php-version: "8.0"
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
coverage: none

Expand Down
15 changes: 13 additions & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
name: Tests

on: [push, pull_request]
on:
push:
branches:
- main
- develop
- next
- release/*
pull_request:
branches:
- main
- develop
- next

jobs:
test:
Expand All @@ -17,7 +28,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"require": {
"php": "^7.4|^8.0",
"scrivo/highlight.php": "^9.18",
"spatie/shiki-php": "^1.3"
"spatie/shiki-php": "^2.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.5",
Expand Down
62 changes: 17 additions & 45 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"description": "This package.json has all Node dependencies for the local development of the package.",
"homepage": "https://github.com/ueberdosis/tiptap-php",
"devDependencies": {
"shiki": "^0.10.0"
"shiki": "^1.0.0"
}
}
16 changes: 12 additions & 4 deletions src/Core/DOMParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,17 @@ private function processChildren($node): array
return $this->mergeSimilarNodes($nodes);
}

private function isMultidimensionalArray($array)
{
foreach ($array as $value) {
if (is_array($value)) {
return true;
}
}

return false;
}

private function mergeSimilarNodes($nodes)
{
$result = [];
Expand All @@ -131,10 +142,7 @@ private function mergeSimilarNodes($nodes)
*/
array_reduce($nodes, function ($carry, $node) use (&$result) {
// Ignore multidimensional arrays
if (
count($node) !== count($node, COUNT_RECURSIVE)
|| count($carry) !== count($carry, COUNT_RECURSIVE)
) {
if ($this->isMultidimensionalArray($node) || $this->isMultidimensionalArray($carry)) {
$result[] = $node;

return $node;
Expand Down
4 changes: 4 additions & 0 deletions src/Nodes/CodeBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public function addAttributes()
return [
'language' => [
'parseHTML' => function ($DOMNode) {
if (! ($DOMNode->childNodes[0] instanceof \DOMElement)) {
return null;
}

return preg_replace(
"/^" . $this->options['languageClassPrefix']. "/",
"",
Expand Down
4 changes: 2 additions & 2 deletions src/Nodes/OrderedList.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public function parseHTML()
public function addAttributes()
{
return [
'order' => [
'start' => [
'parseHTML' => fn ($DOMNode) => (int) $DOMNode->getAttribute('start') ?: null,
'renderHTML' => fn ($attributes) => ($attributes->order ?? null) ? ['start' => $attributes->order] : null,
'renderHTML' => fn ($attributes) => ($attributes->start ?? null) ? ['start' => $attributes->start] : null,
],
];
}
Expand Down
25 changes: 25 additions & 0 deletions tests/DOMParser/EmptyNodesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

use Tiptap\Editor;

test('parsing must not fail on empty nodes', function () {
$html = '<p><img /></p><p><img /></p>';

$result = (new Editor)
->setContent($html)
->getDocument();

expect($result)->toEqual([
'type' => 'doc',
'content' => [
[
'type' => 'paragraph',
'content' => [],
],
[
'type' => 'paragraph',
'content' => [],
],
],
]);
});
21 changes: 21 additions & 0 deletions tests/DOMParser/Nodes/CodeBlockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,24 @@
],
]);
});

test('it handles code blocks without a code tag', function () {
$html = '<pre>body { display: none }</pre>';

$result = (new Editor)->setContent($html)->getDocument();

expect($result)->toEqual([
'type' => 'doc',
'content' => [
[
'type' => 'codeBlock',
'content' => [
[
'type' => 'text',
'text' => 'body { display: none }',
],
],
],
],
]);
});
2 changes: 1 addition & 1 deletion tests/DOMParser/Nodes/OrderedListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
[
'type' => 'orderedList',
'attrs' => [
'order' => 3,
'start' => 3,
],
'content' => [
[
Expand Down
2 changes: 1 addition & 1 deletion tests/DOMSerializer/Nodes/OrderedListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
[
'type' => 'orderedList',
'attrs' => [
'order' => 3,
'start' => 3,
],
'content' => [
[
Expand Down

0 comments on commit b4356d9

Please sign in to comment.