html-to-gutenberg 4.2.6 → 4.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +14 -0
- package/index.ts +837 -408
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -798,7 +798,21 @@ const block = async (
|
|
|
798
798
|
};
|
|
799
799
|
|
|
800
800
|
const getFixedHtml = (html) => {
|
|
801
|
+
function parseStyleString(style) {
|
|
802
|
+
const entries = style.split(';').filter(Boolean).map(rule => {
|
|
803
|
+
const [key, value] = rule.split(':');
|
|
804
|
+
if (!key || !value) return null;
|
|
805
|
+
const camelKey = key.trim().replace(/-([a-z])/g, (_, char) => char.toUpperCase());
|
|
806
|
+
return [camelKey, value.trim()];
|
|
807
|
+
}).filter(Boolean);
|
|
808
|
+
const styleObject = Object.fromEntries(entries);
|
|
809
|
+
return JSON.stringify(styleObject).replace(/"([^"\n]+)":/g, '$1:');
|
|
810
|
+
}
|
|
801
811
|
return html
|
|
812
|
+
.replace(/style="([^"]+)"/g, (_, styleString) => {
|
|
813
|
+
const styleObj = parseStyleString(styleString);
|
|
814
|
+
return `style={${styleObj}}`;
|
|
815
|
+
})
|
|
802
816
|
.replace(/ onChange="{" \(newtext\)=""\>/gi, ' onChange={ (newtext) => ')
|
|
803
817
|
.replace(/\<\/RichText\>/gi, '')
|
|
804
818
|
.replace(/value="{(.*?)}"/gi, 'value={$1}')
|