Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undo issue related to editorjs #16

Closed
sos-productions opened this issue Aug 24, 2020 · 2 comments
Closed

Undo issue related to editorjs #16

sos-productions opened this issue Aug 24, 2020 · 2 comments
Labels
🚫 wontfix This will not be worked on

Comments

@sos-productions
Copy link

sos-productions commented Aug 24, 2020

As Undo plugin need an inital state
`
function initUndo() {

    undo = new Undo({editor});
      
    editor.save().then((outputData) => {
        //console.log('Article data: ', outputData) //strong tags are washed where are they are allowed in config
        var initialData=outputData
        undo.initialize(initialData.blocks);
    }).catch((error) => {
        console.log('Saving failed: ', error)
    });
}

`

and in my paragaph plugin config, I have

paragraph: {
text: {
type: "string",
allowedTags: "i,b,u,a[href],strong,em,br,br,dt,dl,embed,ol,li,ul"
}
}
but edtor sanitize at least strong tag (and I guess others too) on editor.save()
/**
* Saving example
*/

    saveButton.addEventListener('click',(e) => {
            editor.save().then((savedData) => {
                alert(savedData.toSource()) //<strong> dissaper
            });
    }); 

`

so when I undo, I got only text with br tag preserved in paragraph

@Jmzp
Copy link
Contributor

Jmzp commented Aug 24, 2020

Hi @sos-productions, can you provide me with the sample text that you use?

@sos-productions
Copy link
Author

sos-productions commented Aug 25, 2020

Hi @Jmzp,

I just created a paragraph with some styling like strong, I took the chapter 3 of the excellent https://www.theepochtimes.com/c-how-the-specter-of-communism-is-ruling-our-world ...choose
the table of content loaded in editorjs is seen as a paragraph which json is
---8<--------------
{
type : 'paragraph',
data : {
text : text:<strong>Introduction</strong><br><strong>1. The Rise of Totalitarian Communism</strong><br>\na. The Soviet Communists\u2019 Rise to Power<br>\nb. The Chinese Communist Party\u2019s Power Grab<br><strong>2. The Brutality of Communist Rule</strong><br>\na. Soviet Communist Atrocities<br>\n\u2013 Killing by Famine<br>\n\u2013 The Gulags: Europe\u2019s First Concentration Camps<br>\n\u2013 The Great Terror Against the Soviet Elite<br>\nb. The CCP\u2019s Deadly Campaigns<br>\n\u2013 The Great Chinese Famine<br>\n\u2013 The Cultural Revolution: Slaughter and Cultural Genocide<br>\n\u2013 Unprecedented Evil: The Persecution of Falun Gong<br><strong>3. A Century of Killing</strong><br><strong>References</strong>
}
}
-----8<-------------------

As I told you, if make a little change on the paragraph and undo , it is was washing all the tags including strong.
due to the call this.editor.save().then((savedData) => {

Now I fixed it with 4 steps:

  1. a patch on editor.js I submitted here Handles extra parameter sanitizeDisable for saving block(s) codex-team/editor.js#1281 , waiting
    to be approved.
  2. I rebuild the editor with ./build helper script
  3. in index.js of Undo plugin. lin 81, I set editor.save(true) this time
  4. I rebuilt too Undo Plugin

and it works like a charm.

@juanhurtado10 juanhurtado10 removed the bug label Sep 8, 2021
@juanhurtado10 juanhurtado10 added the 🚫 wontfix This will not be worked on label Sep 8, 2021
SanGeeky pushed a commit that referenced this issue Jul 22, 2022
* Create node.js.yml

* Apply the suggested corrections in the ci setup

* Apply additional suggested corrections

* Add the possible solution to the problem reported by GitHub

* Add another possible solution to the problem reported by GitHub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚫 wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants