GrapesJS / components-custom-code

GrapesJS component for the embed of custom code
https://grapesjs.com/demo.html
BSD 3-Clause "New" or "Revised" License
74 stars 45 forks source link

Prevent Quote Marks being converted #12

Closed adamwpe closed 1 year ago

adamwpe commented 3 years ago

If you type in a quote mark:

image

When it gets converted to html, it's no longer a quote mark.

image

Is there a way to prevent this?

It does not happen if I rap it around with a script tag, but obviously, it won't be rendered.

I see that you can override the commandCustomCode I can override the 'handleSave' command, like so

'grapesjs-custom-code': {
                    commandCustomCode: {
                        handleSave: function() {
                            const { editor, target } = this;
                            const code = this.getCodeViewer().getContent();
                            console.log(code);
                            target.set(this.keyCustomCode,code);
                            editor.Modal.close();
                        }
                    }
                },

and the code variable is correct, but not too sure how target.set works since it looks like it is using backbone.js.

mhowey commented 2 years ago

@adamwpe - did you ever find a solution to this? I'm also looking to change how GrapesJS converts quotes.

Zunaib commented 2 years ago

Hey did anyone resolve this ?

kamalrohra commented 2 years ago

Even I face the same issue

hussein-khamis commented 2 years ago

Has anyone found any solution?

Zaxcoding commented 1 year ago

Depending how you're using the editor, you can modify the response from editor.getHtml to unescape the single quotes. For instance:

const html = editor.getHtml({ cleanId: true });
const unescapedHtml = html.replace(/'/g, "'");

@artf I think a good solution could be to include configurations for the editor to allow us to choose which of these escape sequences we want to include out of the ones in the escape mixin (or allow us to override this escape method entirely).

artf commented 1 year ago

This shouldn't be an issue anymore from this grapesjs release https://github.com/GrapesJS/grapesjs/releases/tag/v0.20.2

Anyway, for anybody who wants to update the escape logic, the proper way would be to update the textnode component model (eg. the toHTML/__escapeContent method)