ConvertersLesson 39Free preview
Text to HTML
This lesson is part of Web Developer Tools · All levels
Summary
Text to HTML converts plain text into HTML pieces that are ready to be displayed, generally by wrapping paragraphs using the p tag and new line with br. Special characters such as <, >, and & must be evaporated so as not to be considered markup. The blank line is usually used as a paragraph separator. If the text is from the user, do not paste it raw into the innerHTML because of the risk of injection.
Key points
- The normal text is broken down into paragraphs based on the blank lines
- New line in paragraph can be converted to tag br
- Characters <, >, and & must be escaped
- Use textContent or escaping when displaying user input
- HTML results should be checked to ensure that the paragraph structure is consistent.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.