I am trying to read the content of "PRE" or "CODE" tag of HTML to server side in C#. I am using HTML editor "tinymce". Preview is displayed properly. But when I read it on server side in string variable and the display it in some div. Then all the formatting is lost and code is shown in single line.
我试图在C#中向服务器端读取HTML的“PRE”或“CODE”标记的内容。我正在使用HTML编辑器“tinymce”。预览显示正确。但是当我在服务器端读取字符串变量并将其显示在某个div中时。然后所有格式都丢失,代码以单行显示。
<pre>
<code>
function Panel(element, canClose, closeHandler) {
this.element = element;
this.canClose = canClose;
this.closeHandler = function() {
if (closeHandler) closeHandler()
};
}
</code>
</pre>
1 个解决方案
#1
You need to use the <pre>...</pre>
tags to denote preformatted text, simply embedding in <div>...</div>
tags will ignore all newlines unless you use <br />
to force a new line break
您需要使用
... 标签来表示预先格式化的文本,只需嵌入... 标签将忽略所有换行,除非您使用
强制新的越线
For example, to embed the string in pre tags, you may use:
例如,要将字符串嵌入到预标记中,您可以使用:
string s = tbxTinymce.Text;
s = "<pre>" + s + "</pre>";
divOutput.InnerHtml = s;
#1
You need to use the <pre>...</pre>
tags to denote preformatted text, simply embedding in <div>...</div>
tags will ignore all newlines unless you use <br />
to force a new line break
您需要使用
... 标签来表示预先格式化的文本,只需嵌入... 标签将忽略所有换行,除非您使用
强制新的越线
For example, to embed the string in pre tags, you may use:
例如,要将字符串嵌入到预标记中,您可以使用:
string s = tbxTinymce.Text;
s = "<pre>" + s + "</pre>";
divOutput.InnerHtml = s;