Sometimes you may want to display code for your readers to copy and paste from an article. Here's how:
- Select Code View in your WYSIWYG editor.
- Paste the code you want to display into the code view.
- If you're using our default syntax highlighter, wrap the code using the following format:
<pre><code data-language="language"></code></pre>
tags.- If you're using a custom syntax highlighter, most of those use code class="language-xxxx" or a similar format. Check with the syntax highlighter you're using!
- Replace "language" with the language of the code. For example, the code block below will highlight Javascript syntax:
And produce this treatment using the default syntax highlighting:<pre> <code data-language="javascript"> <script> alert("Hello, World!"); </script> </code> </pre>
Scripts and other HTML
If you're adding code wrapped in <script> tags, encode the greater than and less than signs around the opening and closing script tags so that the code doesn't execute (as is shown above). Use this online tool to encode your script. Be sure to check the box to Encode the less than and greater than sign.