editor-js / code

Code Tool for Editor.js 2.0
MIT License
71 stars 52 forks source link

Characters are replaced by HTML entities #19

Closed polyrainbow closed 4 years ago

polyrainbow commented 4 years ago

In v2.4.1, reserved HTML characters like <>& are replaced by HTML entities on saving data.

Here's a code sandbox to quickly reproduce the issue: https://codesandbox.io/s/peaceful-dhawan-wz02y?file=/index.js

Steps to reproduce:

  1. Create code block
  2. Type reserved HTML characters like "<>&"
  3. Click on "Save and load"

The code block's content changes and displays the HTML entities of the characters.

alcarazzam commented 4 years ago

Fixed in #20

gopumon commented 4 years ago

Is there any workaround till next release??

erBhushanPawar commented 4 years ago

You can use this code for getting it fixed, call it after save block returns the data

fixCodeBlocks(blocks) {
    let codeBlockIndex = 0;
    const els = document.getElementsByClassName('ce-code__textarea') as any || [];
    blocks.map(x => {

      if (x.type === 'code') {
        x.data.code = els[codeBlockIndex++].value
      }
      return x;
    })
    return blocks;
}