jsp嵌入的md文本是经过html encode的,因此md文本内的html标签不会被解析
以下一段在div内的md文本(HTML encoded)
1 2 3 4 5 6 7 8 9 10 11
|
<div id="container"> # h1 title ## h2 title ### h3 title
<code> console.log("Hello World!"); </code>
-  </div>
|
在浏览器中,内部的
<code>
标签不会被解析,同时不保留换行符:
innerHTML提取的文本保留换行和转义字符
innerText提取的文本不保留换行,且进行了html decode
textContent提取的文本保留换行,且进行了html decode
根据具体业务场景进行选择(当前选择3)
innerText是IE遗留属性,不建议使用
innerText和textContent都会将文本进行decode,因此可以用于解码:
1 2 3 4 5 6 7
|
function htmlDecode(text) { var temp = document.createElement("div"); temp.innerHTML = text; var output = temp.innerText || temp.textContent; temp = null; return output; }
|