Repository navigation
How to Preserve Inline Styles When Importing HTML from Another WYSIWYG Editor? #6826
Replies: 2 comments
|
GrapesJS parses inline styles into the CSS Composer by design If you need the exported HTML to have styles inline again, I believe you can use the "inlineCss" approach from "grapesjs-preset-newsletter", but I didn't try it myself In silex.me I added a "publish" button to do similar things / poat processing. Maybe https://www.npmjs.com/package/juice can be useful |
|
There is a legacy configuration that keeps the imported declarations inline, but it needs both options: const editor = grapesjs.init({
container: '#gjs',
storageManager: false, // for this example
avoidInlineStyle: false,
forceClass: false,
});
editor.setComponents(`
<p style="color: red; font-size: 20px; text-align: center;">
Sample text
</p>
`);
console.log(editor.getHtml());
I tested this with GrapesJS 0.23.8 in Chrome. With both options disabled, The caveat is that Also, “keep the declarations inline” is different from preserving the original HTML exactly. GrapesJS parses and serializes it: whitespace in the The described behavior was checked in a local Chrome fixture. The source and local browser-fixture checks are described above. |
Uh oh!
There was an error while loading. Please reload this page.
I have an existing WYSIWYG editor where the content is saved as HTML with styles applied directly as inline CSS.
For example, the saved content looks like:
When I load this saved HTML into GrapesJS, the inline styles are removed from the elements or converted into CSS rules managed by GrapesJS.
Since the HTML is generated and saved by another WYSIWYG editor, I need to preserve the existing inline styles exactly as they are when importing the content into GrapesJS.
Is there a recommended GrapesJS configuration or approach to:
styleattributes on imported elements.color,font-size,text-align,background, etc. remain associated with the original elements.For example, I would like this:
to remain with its inline styles after importing into GrapesJS, rather than having the styles moved into the GrapesJS CSS Composer.
What is the recommended way to handle this when importing HTML from another WYSIWYG editor?
All reactions