Rendering Plaintext as HTML maintaining whitespace – without

前端 未结 4 1731
情深已故
情深已故 2021-02-14 08:02

Given any arbitrary text file full of printable characters, how can this be converted to HTML that would be rendered exactly the same (with the following requirements)?

4条回答
  •  孤独总比滥情好
    2021-02-14 08:13

    Is is very simple if you use jQuery library in your project.

    Just one line ,Add asHTml extenstion to String Class and :

    var plain='<a> i am text plain </a>'
    plain.asHtml();
    /* ' i am text plain ' */
    

    DEMO :http://jsfiddle.net/abdennour/B6vGG/3/

    Note : You will not have to access to DoM . Just use builder design pattern of jQuery $('')

提交回复
热议问题