Add code samples

Sometimes you may want to display code for your readers to copy and paste from an article. Here's how:

  1. Select Code View in your WYSIWYG editor.
  2. Paste the code you want to display into the code view.
  3. If you're using our default syntax highlighter, wrap the code using the following format: <pre><code data-language="language"></code></pre> tags.
    1. 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!
  4. Replace "language" with the language of the code. For example, the code block below will highlight Javascript syntax:
  5. <pre>
        <code data-language="javascript">
            &lt;script&gt;
            alert("Hello, World!");
            &lt;/script&gt;
        </code>
    </pre>
    And produce this treatment using the default syntax highlighting:

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.