From b76747ac3e5aba7273f23a5c0dd3758378cf317d Mon Sep 17 00:00:00 2001
From: sunil-lakshman <104969541+sunil-lakshman@users.noreply.github.com>
Date: Mon, 26 Jun 2023 18:40:41 +0530
Subject: [PATCH] added support for the br tag and added support for nested
assets in the the image (#8)
---
CHANGELOG.md | 2 +
composer.lock | 144 ++++++++++++++++++------------------
src/BaseParser.php | 3 +
src/Enum/MarkType.php | 1 +
src/Model/Option.php | 10 +++
tests/DefaultOptionTest.php | 12 +++
6 files changed, 101 insertions(+), 71 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ca16168..2acc128 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,6 @@
# Changelog
+## [1.2.0](https://github.com/contentstack/contentstack-utils-php/tree/v1.2.0) (2023-06-27)
+ - Support for the br tag and support for nested assets in the the image
## [1.1.0](https://github.com/contentstack/contentstack-utils-php/tree/v1.1.0) (2021-07-16)
- JSON RTE to html content functionality for GQL API added
## [1.0.1](https://github.com/contentstack/contentstack-utils-php/tree/v1.0.1) (2021-07-16)
diff --git a/composer.lock b/composer.lock
index ceb6ad5..69c2dd4 100644
--- a/composer.lock
+++ b/composer.lock
@@ -83,30 +83,30 @@
"packages-dev": [
{
"name": "doctrine/instantiator",
- "version": "1.4.1",
+ "version": "1.5.0",
"source": {
"type": "git",
"url": "https://github.com/doctrine/instantiator.git",
- "reference": "10dcfce151b967d20fde1b34ae6640712c3891bc"
+ "reference": "0a0fa9780f5d4e507415a065172d26a98d02047b"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/doctrine/instantiator/zipball/10dcfce151b967d20fde1b34ae6640712c3891bc",
- "reference": "10dcfce151b967d20fde1b34ae6640712c3891bc",
+ "url": "https://api.github.com/repos/doctrine/instantiator/zipball/0a0fa9780f5d4e507415a065172d26a98d02047b",
+ "reference": "0a0fa9780f5d4e507415a065172d26a98d02047b",
"shasum": ""
},
"require": {
"php": "^7.1 || ^8.0"
},
"require-dev": {
- "doctrine/coding-standard": "^9",
+ "doctrine/coding-standard": "^9 || ^11",
"ext-pdo": "*",
"ext-phar": "*",
"phpbench/phpbench": "^0.16 || ^1",
"phpstan/phpstan": "^1.4",
"phpstan/phpstan-phpunit": "^1",
"phpunit/phpunit": "^7.5 || ^8.5 || ^9.5",
- "vimeo/psalm": "^4.22"
+ "vimeo/psalm": "^4.30 || ^5.4"
},
"type": "library",
"autoload": {
@@ -133,7 +133,7 @@
],
"support": {
"issues": "https://github.com/doctrine/instantiator/issues",
- "source": "https://github.com/doctrine/instantiator/tree/1.4.1"
+ "source": "https://github.com/doctrine/instantiator/tree/1.5.0"
},
"funding": [
{
@@ -149,20 +149,20 @@
"type": "tidelift"
}
],
- "time": "2022-03-03T08:28:38+00:00"
+ "time": "2022-12-30T00:15:36+00:00"
},
{
"name": "myclabs/deep-copy",
- "version": "1.11.0",
+ "version": "1.11.1",
"source": {
"type": "git",
"url": "https://github.com/myclabs/DeepCopy.git",
- "reference": "14daed4296fae74d9e3201d2c4925d1acb7aa614"
+ "reference": "7284c22080590fb39f2ffa3e9057f10a4ddd0e0c"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/14daed4296fae74d9e3201d2c4925d1acb7aa614",
- "reference": "14daed4296fae74d9e3201d2c4925d1acb7aa614",
+ "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/7284c22080590fb39f2ffa3e9057f10a4ddd0e0c",
+ "reference": "7284c22080590fb39f2ffa3e9057f10a4ddd0e0c",
"shasum": ""
},
"require": {
@@ -200,7 +200,7 @@
],
"support": {
"issues": "https://github.com/myclabs/DeepCopy/issues",
- "source": "https://github.com/myclabs/DeepCopy/tree/1.11.0"
+ "source": "https://github.com/myclabs/DeepCopy/tree/1.11.1"
},
"funding": [
{
@@ -208,20 +208,20 @@
"type": "tidelift"
}
],
- "time": "2022-03-03T13:19:32+00:00"
+ "time": "2023-03-08T13:26:56+00:00"
},
{
"name": "nikic/php-parser",
- "version": "v4.15.1",
+ "version": "v4.16.0",
"source": {
"type": "git",
"url": "https://github.com/nikic/PHP-Parser.git",
- "reference": "0ef6c55a3f47f89d7a374e6f835197a0b5fcf900"
+ "reference": "19526a33fb561ef417e822e85f08a00db4059c17"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/0ef6c55a3f47f89d7a374e6f835197a0b5fcf900",
- "reference": "0ef6c55a3f47f89d7a374e6f835197a0b5fcf900",
+ "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/19526a33fb561ef417e822e85f08a00db4059c17",
+ "reference": "19526a33fb561ef417e822e85f08a00db4059c17",
"shasum": ""
},
"require": {
@@ -262,9 +262,9 @@
],
"support": {
"issues": "https://github.com/nikic/PHP-Parser/issues",
- "source": "https://github.com/nikic/PHP-Parser/tree/v4.15.1"
+ "source": "https://github.com/nikic/PHP-Parser/tree/v4.16.0"
},
- "time": "2022-09-04T07:30:47+00:00"
+ "time": "2023-06-25T14:52:30+00:00"
},
{
"name": "phar-io/manifest",
@@ -379,23 +379,23 @@
},
{
"name": "phpunit/php-code-coverage",
- "version": "9.2.17",
+ "version": "9.2.26",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-code-coverage.git",
- "reference": "aa94dc41e8661fe90c7316849907cba3007b10d8"
+ "reference": "443bc6912c9bd5b409254a40f4b0f4ced7c80ea1"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/aa94dc41e8661fe90c7316849907cba3007b10d8",
- "reference": "aa94dc41e8661fe90c7316849907cba3007b10d8",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/443bc6912c9bd5b409254a40f4b0f4ced7c80ea1",
+ "reference": "443bc6912c9bd5b409254a40f4b0f4ced7c80ea1",
"shasum": ""
},
"require": {
"ext-dom": "*",
"ext-libxml": "*",
"ext-xmlwriter": "*",
- "nikic/php-parser": "^4.14",
+ "nikic/php-parser": "^4.15",
"php": ">=7.3",
"phpunit/php-file-iterator": "^3.0.3",
"phpunit/php-text-template": "^2.0.2",
@@ -410,8 +410,8 @@
"phpunit/phpunit": "^9.3"
},
"suggest": {
- "ext-pcov": "*",
- "ext-xdebug": "*"
+ "ext-pcov": "PHP extension that provides line coverage",
+ "ext-xdebug": "PHP extension that provides line coverage as well as branch and path coverage"
},
"type": "library",
"extra": {
@@ -444,7 +444,7 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/php-code-coverage/issues",
- "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.17"
+ "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.26"
},
"funding": [
{
@@ -452,7 +452,7 @@
"type": "github"
}
],
- "time": "2022-08-30T12:24:04+00:00"
+ "time": "2023-03-06T12:58:08+00:00"
},
{
"name": "phpunit/php-file-iterator",
@@ -697,20 +697,20 @@
},
{
"name": "phpunit/phpunit",
- "version": "9.5.25",
+ "version": "9.6.9",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
- "reference": "3e6f90ca7e3d02025b1d147bd8d4a89fd4ca8a1d"
+ "reference": "a9aceaf20a682aeacf28d582654a1670d8826778"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/3e6f90ca7e3d02025b1d147bd8d4a89fd4ca8a1d",
- "reference": "3e6f90ca7e3d02025b1d147bd8d4a89fd4ca8a1d",
+ "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a9aceaf20a682aeacf28d582654a1670d8826778",
+ "reference": "a9aceaf20a682aeacf28d582654a1670d8826778",
"shasum": ""
},
"require": {
- "doctrine/instantiator": "^1.3.1",
+ "doctrine/instantiator": "^1.3.1 || ^2",
"ext-dom": "*",
"ext-json": "*",
"ext-libxml": "*",
@@ -739,8 +739,8 @@
"sebastian/version": "^3.0.2"
},
"suggest": {
- "ext-soap": "*",
- "ext-xdebug": "*"
+ "ext-soap": "To be able to generate mocks based on WSDL files",
+ "ext-xdebug": "PHP extension that provides line coverage as well as branch and path coverage"
},
"bin": [
"phpunit"
@@ -748,7 +748,7 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "9.5-dev"
+ "dev-master": "9.6-dev"
}
},
"autoload": {
@@ -779,7 +779,8 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/phpunit/issues",
- "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.25"
+ "security": "https://github.com/sebastianbergmann/phpunit/security/policy",
+ "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.9"
},
"funding": [
{
@@ -795,7 +796,7 @@
"type": "tidelift"
}
],
- "time": "2022-09-25T03:44:45+00:00"
+ "time": "2023-06-11T06:13:56+00:00"
},
{
"name": "sebastian/cli-parser",
@@ -1097,16 +1098,16 @@
},
{
"name": "sebastian/diff",
- "version": "4.0.4",
+ "version": "4.0.5",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/diff.git",
- "reference": "3461e3fccc7cfdfc2720be910d3bd73c69be590d"
+ "reference": "74be17022044ebaaecfdf0c5cd504fc9cd5a7131"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/3461e3fccc7cfdfc2720be910d3bd73c69be590d",
- "reference": "3461e3fccc7cfdfc2720be910d3bd73c69be590d",
+ "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/74be17022044ebaaecfdf0c5cd504fc9cd5a7131",
+ "reference": "74be17022044ebaaecfdf0c5cd504fc9cd5a7131",
"shasum": ""
},
"require": {
@@ -1151,7 +1152,7 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/diff/issues",
- "source": "https://github.com/sebastianbergmann/diff/tree/4.0.4"
+ "source": "https://github.com/sebastianbergmann/diff/tree/4.0.5"
},
"funding": [
{
@@ -1159,20 +1160,20 @@
"type": "github"
}
],
- "time": "2020-10-26T13:10:38+00:00"
+ "time": "2023-05-07T05:35:17+00:00"
},
{
"name": "sebastian/environment",
- "version": "5.1.4",
+ "version": "5.1.5",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/environment.git",
- "reference": "1b5dff7bb151a4db11d49d90e5408e4e938270f7"
+ "reference": "830c43a844f1f8d5b7a1f6d6076b784454d8b7ed"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/1b5dff7bb151a4db11d49d90e5408e4e938270f7",
- "reference": "1b5dff7bb151a4db11d49d90e5408e4e938270f7",
+ "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/830c43a844f1f8d5b7a1f6d6076b784454d8b7ed",
+ "reference": "830c43a844f1f8d5b7a1f6d6076b784454d8b7ed",
"shasum": ""
},
"require": {
@@ -1214,7 +1215,7 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/environment/issues",
- "source": "https://github.com/sebastianbergmann/environment/tree/5.1.4"
+ "source": "https://github.com/sebastianbergmann/environment/tree/5.1.5"
},
"funding": [
{
@@ -1222,7 +1223,7 @@
"type": "github"
}
],
- "time": "2022-04-03T09:37:03+00:00"
+ "time": "2023-02-03T06:03:51+00:00"
},
{
"name": "sebastian/exporter",
@@ -1536,16 +1537,16 @@
},
{
"name": "sebastian/recursion-context",
- "version": "4.0.4",
+ "version": "4.0.5",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/recursion-context.git",
- "reference": "cd9d8cf3c5804de4341c283ed787f099f5506172"
+ "reference": "e75bd0f07204fec2a0af9b0f3cfe97d05f92efc1"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/cd9d8cf3c5804de4341c283ed787f099f5506172",
- "reference": "cd9d8cf3c5804de4341c283ed787f099f5506172",
+ "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/e75bd0f07204fec2a0af9b0f3cfe97d05f92efc1",
+ "reference": "e75bd0f07204fec2a0af9b0f3cfe97d05f92efc1",
"shasum": ""
},
"require": {
@@ -1584,10 +1585,10 @@
}
],
"description": "Provides functionality to recursively process PHP variables",
- "homepage": "http://www.github.com/sebastianbergmann/recursion-context",
+ "homepage": "https://github.com/sebastianbergmann/recursion-context",
"support": {
"issues": "https://github.com/sebastianbergmann/recursion-context/issues",
- "source": "https://github.com/sebastianbergmann/recursion-context/tree/4.0.4"
+ "source": "https://github.com/sebastianbergmann/recursion-context/tree/4.0.5"
},
"funding": [
{
@@ -1595,7 +1596,7 @@
"type": "github"
}
],
- "time": "2020-10-26T13:17:30+00:00"
+ "time": "2023-02-03T06:07:39+00:00"
},
{
"name": "sebastian/resource-operations",
@@ -1654,16 +1655,16 @@
},
{
"name": "sebastian/type",
- "version": "3.2.0",
+ "version": "3.2.1",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/type.git",
- "reference": "fb3fe09c5f0bae6bc27ef3ce933a1e0ed9464b6e"
+ "reference": "75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/fb3fe09c5f0bae6bc27ef3ce933a1e0ed9464b6e",
- "reference": "fb3fe09c5f0bae6bc27ef3ce933a1e0ed9464b6e",
+ "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7",
+ "reference": "75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7",
"shasum": ""
},
"require": {
@@ -1698,7 +1699,7 @@
"homepage": "https://github.com/sebastianbergmann/type",
"support": {
"issues": "https://github.com/sebastianbergmann/type/issues",
- "source": "https://github.com/sebastianbergmann/type/tree/3.2.0"
+ "source": "https://github.com/sebastianbergmann/type/tree/3.2.1"
},
"funding": [
{
@@ -1706,7 +1707,7 @@
"type": "github"
}
],
- "time": "2022-09-12T14:47:03+00:00"
+ "time": "2023-02-03T06:13:03+00:00"
},
{
"name": "sebastian/version",
@@ -1763,16 +1764,16 @@
},
{
"name": "squizlabs/php_codesniffer",
- "version": "3.7.1",
+ "version": "3.7.2",
"source": {
"type": "git",
"url": "https://github.com/squizlabs/PHP_CodeSniffer.git",
- "reference": "1359e176e9307e906dc3d890bcc9603ff6d90619"
+ "reference": "ed8e00df0a83aa96acf703f8c2979ff33341f879"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/1359e176e9307e906dc3d890bcc9603ff6d90619",
- "reference": "1359e176e9307e906dc3d890bcc9603ff6d90619",
+ "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/ed8e00df0a83aa96acf703f8c2979ff33341f879",
+ "reference": "ed8e00df0a83aa96acf703f8c2979ff33341f879",
"shasum": ""
},
"require": {
@@ -1808,14 +1809,15 @@
"homepage": "https://github.com/squizlabs/PHP_CodeSniffer",
"keywords": [
"phpcs",
- "standards"
+ "standards",
+ "static analysis"
],
"support": {
"issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues",
"source": "https://github.com/squizlabs/PHP_CodeSniffer",
"wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki"
},
- "time": "2022-06-18T07:21:10+00:00"
+ "time": "2023-02-22T23:07:41+00:00"
},
{
"name": "theseer/tokenizer",
@@ -1877,5 +1879,5 @@
"php": ">=7.2"
},
"platform-dev": [],
- "plugin-api-version": "2.2.0"
+ "plugin-api-version": "2.3.0"
}
diff --git a/src/BaseParser.php b/src/BaseParser.php
index 3ecb92e..709f5b2 100644
--- a/src/BaseParser.php
+++ b/src/BaseParser.php
@@ -68,6 +68,9 @@ protected static function textToHtml(object $node, Option $option)
if (isset($node->bold) && $node->bold) {
$text = $option->renderMark(MarkType::get(MarkType::BOLD), $text);
}
+ if (isset($node->break) && $node->break) {
+ $text = $option->renderMark(MarkType::get(MarkType::BREAK), $text);
+ }
return $text;
}
diff --git a/src/Enum/MarkType.php b/src/Enum/MarkType.php
index eb4a687..7b14539 100644
--- a/src/Enum/MarkType.php
+++ b/src/Enum/MarkType.php
@@ -17,4 +17,5 @@ class MarkType extends Enum
const SUBSCRIPT = 'subscript';
const SUPERSCRIPT = 'superscript';
+ const BREAK = 'break';
}
\ No newline at end of file
diff --git a/src/Model/Option.php b/src/Model/Option.php
index f30369d..b90f26d 100644
--- a/src/Model/Option.php
+++ b/src/Model/Option.php
@@ -50,6 +50,9 @@ function renderMark(MarkType $markType, string $text): string
case MarkType::get(MarkType::SUPERSCRIPT):
$resultString = "".$text."";
break;
+ case MarkType::get(MarkType::BREAK):
+ $resultString = "
";
+ break;
}
return $resultString;
}
@@ -129,6 +132,13 @@ function renderNode(string $nodeType, object $node, string $innerHtml): string
case NodeType::get(NodeType::CODE)->getValue():
$resultString = "".$innerHtml."";
break;
+ case NodeType::get(NodeType::REFERENCE)->getValue():
+ if(isset($attrs["type"]) && $attrs["type"] == "asset"){
+ $resultString = "
";
+ }else{
+ $resultString = $innerHtml;
+ }
+ break;
default:
$resultString = $innerHtml;
break;
diff --git a/tests/DefaultOptionTest.php b/tests/DefaultOptionTest.php
index 77c241b..4b5d9f9 100644
--- a/tests/DefaultOptionTest.php
+++ b/tests/DefaultOptionTest.php
@@ -121,6 +121,8 @@ public function testShouldReturnMarkTypeHtmlContent(): void
$this->assertEquals("".DefaultOptionTest::$text."", $subscriptString);
$superscriptString = DefaultOptionTest::$defaultRender->renderMark(MarkType::get(MarkType::SUPERSCRIPT), DefaultOptionTest::$text);
$this->assertEquals("".DefaultOptionTest::$text."", $superscriptString);
+ $breakString = DefaultOptionTest::$defaultRender->renderMark(MarkType::get(MarkType::BREAK), DefaultOptionTest::$text);
+ $this->assertEquals("
", $breakString);
}
function testShouldReturnParagraphHtmlForParagraphnode(): void
@@ -312,6 +314,16 @@ function testShouldReturnReferenceHtmlForReferenceNode(): void
$this->assertEquals(DefaultOptionTest::$text, $resultString);
}
+ function testShouldReturnReferenceHtmlForReferenceNodeForAssests(): void
+ {
+ $node = json_decode(AssetReferenceJson);
+
+ $resultString = DefaultOptionTest::$defaultRender->renderNode(NodeType::get(NodeType::REFERENCE)->getValue(), $node, DefaultOptionTest::$text);
+
+ $this->assertEquals(DefaultOptionTest::$text, $resultString);
+ }
+
+
function testShouldTextReferenceHtmlForTextNode(): void
{
$node = json_decode(BlankDocument);