This is the repository for a chrome extension that allow users to copy HTML and paste it into Gutenberg.
It is composed of 3 main parts:
/background
The service worker./content
The functionality that copies the HTML and formats it for pasting./wp-plugin
Some modifications that run when using the block editor to make copy/pasting possible.
npm install
Install dependencies.npm build
Compiles JavaScript intobuild
folder.npm test
Run test suites.
In Chrome extensions, the service worker, introduced with Manifest V3, acts as a background script that runs independently of the extension's UI. It handles various background tasks such as event handling, network request management, alarms, and inter-component communication, while being more efficient and secure than the previous background pages. Service workers are event-driven and activate only when needed, which conserves resources and improves performance. This shift enhances the reliability, efficiency, and security of Chrome extensions.
This is the Interface for copying HTML and adding it to the clipboard.
Ideally these modifications would ship with Gutenberg in the future but since this is still experimental, this plugin is loaded when viewing the block editor and we register a block so we can handle raw
transforms. In the future, it would be more ideal to ship this in Gutenberg closer to the source code.
Open Google Chrome and go to the extensions page by either:
- Typing chrome://extensions/ in the address bar, or
- Clicking the three-dot menu in the top-right corner, selecting "More tools," and then "Extensions."
On the extensions page, toggle the "Developer mode" switch in the top-right corner to enable developer mode. This will allow you to load unpacked extensions.
Once developer mode is enabled, three new buttons will appear near the top of the page: "Load unpacked," "Pack extension," and "Update."
- Click the "Load unpacked" button.
- In the file dialog that opens, navigate to the directory where your extension files are located and select it.
You can visit the options page and it should load WordPress playground with a patched version of gutenberg that will handle the pasting.
- Right click on the extension icon
- Select "options"
This won't work:
<ul>
<li><h2>Something</h2></li>
</ul>
Potential Fix: Write our own transform
This won't work:
<a>
<h2>Something</h2>
<p>Content</p>
</a>
Potential Fix: Write our own transform.
This is not working even though there is code that makes it seem like it is.
There isn't a transform for this yet.
True.
I think we'll need a block for this.
If there are alot of DOM elements, it can be slow because it's processing everything all at once. Future problem to fix.