1

In my Angular 1.x application (using ES5) I need to show the user the sample of formatted css and js code on the UI (with indentations, line-breaks, etc.), which the the user will need to copy and paste into his own html file. The sample of code:

<style type='text/css'> html, body { margin: 0 }
.banner {
    display: block;
    position: absolute;
</style>
<script>
window.showSmth = function(item) {
   // some logic here
}
</script>

I've tried to search for some 3rd parties, but no results so far, could someone advice me on this?

4
  • 2
    You can use <pre>tag Commented Nov 21, 2016 at 13:03
  • try this simple integration for better visibility alexgorbatchev.com/SyntaxHighlighter Commented Nov 21, 2016 at 13:05
  • <code>A piece of computer code</code> Commented Nov 21, 2016 at 13:14
  • This looks pretty straight-forward: github.com/pc035860/angular-highlightjs Commented Nov 21, 2016 at 13:27

1 Answer 1

1

In HTML proper, there’s no way short of escaping the characters.

The only solution guaranteed to work everywhere is to escape the code (< and & as &lt; and &amp;, respectively) manually.

  1. Replace the & character with &amp;

  2. Replace the < character with &lt;

  3. Replace the > character with &gt;

  4. Optionally surround your HTML sample with <pre> and/or <code> tags.

Syntax highlighting sites:

rainbows (very Perfect)

prettify

syntaxhighlighter

highlight

JSHighlighter

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.