From 36d36b7fa209de54e9b3120b79c7a9e81516fbc7 Mon Sep 17 00:00:00 2001 From: Renatho De Carli Rosa Date: Mon, 8 Mar 2021 14:07:20 -0300 Subject: [PATCH 1/2] Add lodash unescape dependency --- package-lock.json | 23 +++++++++++++---------- package.json | 1 + 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index ebad81e..97407c3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4369,6 +4369,11 @@ "resolved": "https://registry.npmjs.org/lodash.tail/-/lodash.tail-4.1.1.tgz", "integrity": "sha1-0jM6NtnncXyK0vfKyv7HwytERmQ=" }, + "lodash.unescape": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/lodash.unescape/-/lodash.unescape-4.0.1.tgz", + "integrity": "sha1-vyJJiGzlFM2hEvrpIYzcBlIR/Jw=" + }, "log-symbols": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-2.2.0.tgz", @@ -4449,6 +4454,14 @@ "safe-buffer": "^5.1.2" } }, + "mem": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/mem/-/mem-1.1.0.tgz", + "integrity": "sha1-Xt1StIXKHZAP5kiVUFOZoN+kX3Y=", + "requires": { + "mimic-fn": "^1.0.0" + } + }, "memory-fs": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/memory-fs/-/memory-fs-0.4.1.tgz", @@ -6859,16 +6872,6 @@ "execa": "^0.7.0", "lcid": "^1.0.0", "mem": "^1.1.0" - }, - "dependencies": { - "mem": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/mem/-/mem-4.0.0.tgz", - "integrity": "sha512-WQxG/5xYc3tMbYLXoXPm81ET2WDULiU5FxbuIoNbJqLOOI8zehXFdZuiUEgfdrU2mVB1pxBZUGlYORSrpuJreA==", - "requires": { - "mimic-fn": "^1.0.0" - } - } } }, "path-type": { diff --git a/package.json b/package.json index 4bb1cd7..89f80ed 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "@wordpress/escape-html": "1.9.0", "cgb-scripts": "1.23.0", "classnames": "2.2.6", + "lodash.unescape": "4.0.1", "npm-force-resolutions": "0.0.3" }, "resolutions": { From 38cbf3f1b7892d895b182886a69c4f7f30cb9ba4 Mon Sep 17 00:00:00 2001 From: Renatho De Carli Rosa Date: Mon, 8 Mar 2021 14:07:54 -0300 Subject: [PATCH 2/2] Update block transform to escape/unescape --- src/code-block/transforms.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/code-block/transforms.js b/src/code-block/transforms.js index 03ed7ad..fc1a42a 100644 --- a/src/code-block/transforms.js +++ b/src/code-block/transforms.js @@ -1,4 +1,6 @@ import { createBlock } from '@wordpress/blocks'; +import { escapeHTML } from '@wordpress/escape-html'; +import unescape from 'lodash.unescape'; export default { from: [ @@ -35,7 +37,7 @@ export default { type: 'block', blocks: [ 'core/code' ], transform: ( { content } ) => { - return createBlock( 'syntaxhighlighter/code', { content } ); + return createBlock( 'syntaxhighlighter/code', { content: unescape( content ) } ); }, }, ], @@ -44,7 +46,7 @@ export default { type: 'block', blocks: [ 'core/code' ], transform: ( { content } ) => { - return createBlock( 'core/code', { content } ); + return createBlock( 'core/code', { content: escapeHTML( content ) } ); }, }, ],