Handle linebreak generated by Monaco Editor with PHP (& MySQL)

I’ve not been able to handle line-break/new-line/carriage-return on Monaco Editor when processed with PHP (Laravel). I want to store the code to MySQL thereafter.
Eventually, the stored code will be displayed on the Monaco Editor anyway.

What is the best practice to do it?

this doesn’t solve the problem. the tags are broken

$code = preg_replace('/rn|r|n/', 'n', request()->custom_script);



<label for="">Custom Script</label>
<div class="monaco-editor-container" style="height: 250px; border: 1px solid rgb(238, 238, 238);"></div>
<textarea name="custom_script" id="monaco_editor_textarea" style="display: none; white-space: pre-line"></textarea>

window.MonacoValue = '{!! $monacoValue !!}';
require(["vs/editor/editor.main"], function () {
    const monacoEditor = monaco.editor.create(document.querySelector('.monaco-editor-container'), {
        value: window.MonacoValue,
        language: 'html',
        base: 'vs',
        fontSize: "14px",
        minimap: { enabled: false },


    monacoEditor.onKeyDown(debounce(e => {
    }, 500))

Source: JavaSript – Stack Overflow

November 27, 2021
Category : News
Tags: javascript | laravel | monaco-editor | mysql | php

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.