diff --git a/composer.json b/composer.json index d18e7096..1e56644d 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,8 @@ "galbar/jsonpath": "^3.0", "guzzlehttp/guzzle": "^7.8", "kevinrob/guzzle-cache-middleware": "^6.0", - "psr/log": "^3.0" + "psr/log": "^3.0", + "erusev/parsedown": "^1.7" }, "require-dev": { "automattic/vipwpcs": "^3.0", diff --git a/composer.lock b/composer.lock index 30eb5bdb..c874275a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,58 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "ec0e3eb63268ad2bfb2057581f9e6915", + "content-hash": "b203ff35836cad6613c8d26e735378fe", "packages": [ + { + "name": "erusev/parsedown", + "version": "1.7.4", + "source": { + "type": "git", + "url": "https://github.com/erusev/parsedown.git", + "reference": "cb17b6477dfff935958ba01325f2e8a2bfa6dab3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/erusev/parsedown/zipball/cb17b6477dfff935958ba01325f2e8a2bfa6dab3", + "reference": "cb17b6477dfff935958ba01325f2e8a2bfa6dab3", + "shasum": "" + }, + "require": { + "ext-mbstring": "*", + "php": ">=5.3.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.8.35" + }, + "type": "library", + "autoload": { + "psr-0": { + "Parsedown": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Emanuil Rusev", + "email": "hello@erusev.com", + "homepage": "http://erusev.com" + } + ], + "description": "Parser for Markdown.", + "homepage": "http://parsedown.org", + "keywords": [ + "markdown", + "parser" + ], + "support": { + "issues": "https://github.com/erusev/parsedown/issues", + "source": "https://github.com/erusev/parsedown/tree/1.7.x" + }, + "time": "2019-12-30T22:54:17+00:00" + }, { "name": "galbar/jsonpath", "version": "3.0", diff --git a/docs/extending/query.md b/docs/extending/query.md index 447722c8..e514d83e 100644 --- a/docs/extending/query.md +++ b/docs/extending/query.md @@ -68,14 +68,9 @@ The `get_input_schema` method defines the input data expected by the query. The - `type`: The type of the override. Supported values are `query_var` and `url`. - `target`: The targeted entity for the override (e.g., the query or URL variable that contains the overridde). - `type` (required): The type of the input variable. Supported types are: - - `base64` - - `boolean` - - `button_url` - - `image_alt` - - `image_url` - `number` - - `currency` - `string` + - `id` #### Example @@ -101,7 +96,17 @@ The `get_output_schema` method defines how to extract data from the API response - `name` (optional): The human-friendly display name of the output variable. - `default_value` (optional): The default value for the output variable. - `path` (required): A [JSONPath](https://jsonpath.com/) expression to extract the variable value. - - `type` (required): The type of the output variable. Supported types are `string`, `number`, and `boolean`. + - `type` (required): The type of the output variable. Supported types are - + - `id` + - `base64` + - `boolean` + - `number` + - `string` + - `button_url` + - `image_url` + - `image_alt` + - `currency` + - `markdown` #### Example diff --git a/inc/Config/QueryRunner/QueryRunner.php b/inc/Config/QueryRunner/QueryRunner.php index 9ccf78e0..1e1229fe 100644 --- a/inc/Config/QueryRunner/QueryRunner.php +++ b/inc/Config/QueryRunner/QueryRunner.php @@ -5,6 +5,7 @@ use Exception; use GuzzleHttp\RequestOptions; use JsonPath\JsonObject; +use Parsedown; use RemoteDataBlocks\Config\QueryContext\HttpQueryContext; use RemoteDataBlocks\HttpClient\HttpClient; use WP_Error; @@ -259,6 +260,9 @@ protected function get_field_value( array|string $field_value, array $mapping ): case 'html': return $field_value_single; + case 'markdown': + return Parsedown::instance()->text( $field_value_single ); + case 'currency': $currency_symbol = $mapping['prefix'] ?? '$'; return sprintf( '%s%s', $currency_symbol, number_format( (float) $field_value_single, 2 ) ); diff --git a/inc/Editor/BlockPatterns/BlockPatterns.php b/inc/Editor/BlockPatterns/BlockPatterns.php index e2160aec..78a95414 100644 --- a/inc/Editor/BlockPatterns/BlockPatterns.php +++ b/inc/Editor/BlockPatterns/BlockPatterns.php @@ -108,6 +108,7 @@ public static function register_default_block_pattern( string $block_name, strin ]; break; + case 'markdown': case 'base64': case 'currency': $bindings['paragraphs'][] = [ diff --git a/inc/REST/AuthController.php b/inc/REST/AuthController.php index aa68c416..21f8fb83 100644 --- a/inc/REST/AuthController.php +++ b/inc/REST/AuthController.php @@ -8,7 +8,6 @@ use WP_REST_Response; use WP_Error; -defined( 'ABSPATH' ) || exit(); defined( 'ABSPATH' ) || exit(); /** diff --git a/src/blocks/remote-data-container/config/constants.ts b/src/blocks/remote-data-container/config/constants.ts index 64441c8b..e2383378 100644 --- a/src/blocks/remote-data-container/config/constants.ts +++ b/src/blocks/remote-data-container/config/constants.ts @@ -15,5 +15,5 @@ export const REMOTE_DATA_REST_API_URL = getRestUrl(); export const CONTAINER_CLASS_NAME = getClassName( 'container' ); export const IMAGE_FIELD_TYPES = [ 'image_alt', 'image_url' ]; -export const TEXT_FIELD_TYPES = [ 'number', 'base64', 'currency', 'string' ]; +export const TEXT_FIELD_TYPES = [ 'number', 'base64', 'currency', 'string', 'markdown' ]; export const BUTTON_FIELD_TYPES = [ 'button_url' ]; diff --git a/src/data-sources/airtable/constants.ts b/src/data-sources/airtable/constants.ts index b90d9641..0c61d6d2 100644 --- a/src/data-sources/airtable/constants.ts +++ b/src/data-sources/airtable/constants.ts @@ -4,7 +4,6 @@ export const AIRTABLE_STRING_TYPES = Object.freeze( 'multilineText', 'email', 'phoneNumber', - 'richText', 'barcode', 'singleSelect', 'date', @@ -32,7 +31,6 @@ export const SUPPORTED_AIRTABLE_TYPES = Object.freeze( [ 'multilineText', 'email', 'phoneNumber', - 'richText', 'barcode', 'singleSelect', 'multipleSelects', @@ -55,6 +53,8 @@ export const SUPPORTED_AIRTABLE_TYPES = Object.freeze( [ 'createdBy', 'lastModifiedBy', 'singleCollaborator', + // Markdown types + 'richText', // Other types 'multipleCollaborators', 'currency', diff --git a/src/data-sources/airtable/utils.ts b/src/data-sources/airtable/utils.ts index d4129fd8..bd9ee097 100644 --- a/src/data-sources/airtable/utils.ts +++ b/src/data-sources/airtable/utils.ts @@ -28,6 +28,9 @@ export const getAirtableOutputQueryMappingValue = ( } switch ( field.type ) { + case 'richText': + return { ...baseField, type: 'markdown' }; + case 'currency': return { ...baseField,