Download
We're evolving to serve you better! This current forum has transitioned to read-only mode. For new discussions, support, and engagement, we've moved to GitHub Discussions.

The WYSIWYG editor is removing common white space and adding non breakable space

  • #7776
    Avatar photo[anonymous]

    Hey there, The editor is removing my common white space and replacing it with non-breakable space, I can’t use that because my site has c programs as its content, I’m hosting a site to explain programming language. So if someone copies my code it won’t run in a compiler due to this issue. So is there a workaround for this?

    #7899
    Avatar photo[anonymous]

    Hi,

    I think that the only solution is to write custom helper in your theme which will remove all non-breaking spaces and replace them with white spaces.

    BTW did you tried to use block editor or markdown editor? The same issue occurs?

    #7901
    Avatar photo[anonymous]

    Thanks for your reply, But I did some tinkering and wrote a custom js function to replace the non-breaking white space written by the editor and replace it with common white space as it is being copied, for anyone looking for the code.

    <script>
    function copyCode() {
    var Text = document.getElementById(‘code-wrap’).innerText;
    var results = Text.replace(/ /gi,” “);
    navigator.clipboard.writeText(results);
    }
    </script>