jsp嵌入的md文本是经过html encode的,因此md文本内的html标签不会被解析
以下一段在div内的md文本(HTML encoded)
1 | <div id="container"> |
在浏览器中,内部的<code>
标签不会被解析,同时不保留换行符:

browser.png
分别使用innerHTML,innerText和textContent提取id为container的div元素内部的md文本

compare.png
- innerHTML提取的文本保留换行和转义字符
- innerText提取的文本不保留换行,且进行了html decode
- textContent提取的文本保留换行,且进行了html decode
根据具体业务场景进行选择(当前选择3)
补充:
innerText是IE遗留属性,不建议使用
innerText和textContent都会将文本进行decode,因此可以用于解码:
1 | function htmlDecode(text) { |