JiHong88 / suneditor

Pure javascript based WYSIWYG html editor, with no dependencies.
http://suneditor.com
MIT License
1.77k stars 316 forks source link

Disable Formatting and Use Content As it is in Code View #1256

Open raunakrajvanshi opened 1 year ago

raunakrajvanshi commented 1 year ago

Hi @JiHong88 . Thank you for such a fantastic library. My Usecase is that I have a email template builder made for client where client can paste HTML Content via the Code View. However The Editor is unable to render the UI Properly and images and content go offset. On other HTML Editors online it is viewing correctly. The client cannot add the "se" tags as you had mentioned.

Is there a way I can paste the HTML Without any formatting or checking? Thank you. Do let me know if you need the HTML Content I am trying to address in this issue.

JiHong88 commented 1 year ago

Hi, Please show me that HTML.

cardalda commented 1 year ago

Hi, I have the same problem. Copy + pasting from Monaco Code Editor will copy fragments in HTML. (https://microsoft.github.io/monaco-editor/playground.html)

(You can view the clipboard contents via https://evercoder.github.io/clipboard-inspector/ )

For example, copying image

will result in:

<meta charset='utf-8'><div style="color: #d4d4d4;background-color: #1e1e1e;font-family: Menlo, Monaco, 'Courier New', monospace;font-weight: normal;font-size: 12px;line-height: 18px;white-space: pre;"><div><span style="color: #d4d4d4;">    .</span><span style="color: #d7ba7d;">__se__format__range_code</span><span style="color: #d4d4d4;"> {</span></div><div><span style="color: #d4d4d4;">        </span><span style="color: #9cdcfe;">font-family</span><span style="color: #d4d4d4;">: Menlo, Monaco, </span><span style="color: #d4d4d4;">"</span><span style="color: #ce9178;">Courier New</span><span style="color: #d4d4d4;">"</span><span style="color: #d4d4d4;">, </span><span style="color: #ce9178;">monospace</span><span style="color: #d4d4d4;">;       </span></div></div>

It's important not to trim the lines, otherwise you will lose your indentation.

I tried to create a custom formatter like this:

 formats: ['p', 'div', 'blockquote', 'pre', 'h1','h2', 'h3','h4', 'h5', 'h6', {
        tag     : "div", 
        command : 'range',
        class   : "__se__format__range_code",
        name    : "code",
    }]

with css:

.__se__format__range_code {
    font-family: Menlo, Monaco, "Courier New", monospace;        
    font-weight: normal;
    font-size: 12px;
    font-feature-settings: "liga" 0, "calt" 0;
    font-variation-settings: normal;
    line-height: 18px;
    letter-spacing: 0px;
    background-color: #1e1e1e;        
    white-space: pre-wrap        
}

but this will destroy your indentation, and you cannot paste new fragments into your existing code...

JiHong88 commented 7 months ago

meta tags are not inserted. Is it really necessary?

Try the following options:

attributesWhitelist: {
  all: 'style|class',
}