Skip to content

Conversation

@westonruter
Copy link
Owner

Fixes #84.

This PR renames attributes as follows:

Old New
selectedLines highlightedLines
showLines showLineNumbers

When rendering the block on the frontend, the old attributes will still work.

However, when opening the post editor the old deprecated attributes will need to be re-populated. I didn't implement migration of these old attributes because (1) only showLines is in a current release, (2) there are only 400 active installs of this plugin currently, and (3) I wasn't sure how best to do it on the JS side of things.

@westonruter westonruter requested a review from allejo May 3, 2020 23:57
@westonruter
Copy link
Owner Author

(3) I wasn't sure how best to do it on the JS side of things.

This is what I was trying without luck:

diff --git a/src/index.js b/src/index.js
index 304a5c7..2338a09 100644
--- a/src/index.js
+++ b/src/index.js
@@ -270,6 +270,30 @@ const extendCodeBlockWithSyntaxHighlighting = (settings) => {
 				</pre>
 			);
 		},
+
+		deprecated: [
+			...(settings.deprecated || []),
+			{
+				attributes: {
+					...settings.attributes,
+					language: {
+						type: 'string',
+					},
+					showLines: {
+						type: 'boolean',
+					},
+				},
+				migrate(attributes, innerBlocks) {
+					return [
+						{
+							language: attributes.language,
+							showLineNumbers: attributes.showLines,
+						},
+						innerBlocks,
+					];
+				},
+			},
+		],
 	};
 };

@allejo
Copy link
Contributor

allejo commented May 6, 2020

How does 8561992 work for you?

@westonruter
Copy link
Owner Author

How does 8561992 work for you?

Wow. You did it! I missed the isEligible part. Nice job.

Copy link
Contributor

@allejo allejo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@westonruter westonruter merged commit 92e23b2 into master May 6, 2020
@westonruter westonruter deleted the update/attribute-names branch May 6, 2020 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Confirm identifiers for attributes

3 participants