html-to-gutenberg 4.2.6 → 4.2.8
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 +15 -0
- package/index.ts +837 -408
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -798,7 +798,22 @@ 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
|
+
let [key, value] = rule.split(':');
|
|
804
|
+
if (!key || !value) return null;
|
|
805
|
+
key = key.trim().replace(/^[-\s]+/, '');
|
|
806
|
+
const camelKey = key.replace(/-([a-z])/g, (_, char) => char.toUpperCase());
|
|
807
|
+
return [camelKey, value.trim()];
|
|
808
|
+
}).filter(Boolean);
|
|
809
|
+
const styleObject = Object.fromEntries(entries);
|
|
810
|
+
return JSON.stringify(styleObject).replace(/"([^"\n]+)":/g, '$1:');
|
|
811
|
+
}
|
|
801
812
|
return html
|
|
813
|
+
.replace(/style="([^"]+)"/g, (_, styleString) => {
|
|
814
|
+
const styleObj = parseStyleString(styleString);
|
|
815
|
+
return `style={${styleObj}}`;
|
|
816
|
+
})
|
|
802
817
|
.replace(/ onChange="{" \(newtext\)=""\>/gi, ' onChange={ (newtext) => ')
|
|
803
818
|
.replace(/\<\/RichText\>/gi, '')
|
|
804
819
|
.replace(/value="{(.*?)}"/gi, 'value={$1}')
|