Code blocks
  • 25 May 2022
  • 1 Minute zum Lesen
  • Mitwirkende
  • Dunkel
    Licht
  • pdf

Code blocks

  • Dunkel
    Licht
  • pdf

There is no German content available for this article, You are viewing the fallback version (English).

Document 360 uses Prism.js for syntax highlighting, and supports syntax highlighting in code blocks for languages like:

  • HTML
  • C#
  • Java
  • JavaScript
  • XML
  • JSON
  • CSS
  • SQL
  • Python
  • Markdown
  • PHP
  • PowerShell
  • Text

For a complete list of supported languages, see Prism's Supported Languages documentation.


Creating code blocks in Markdown editor

In the Markdown editor, you can use two methods to create fenced code blocks.

  1. Using triple backticks ``` before and after the included code snippet.

To apply a language's specific syntax highlighting, include the language shortcode (see list below) after the first 3 backticks.

For example:

```csharp
[your code snippet]
```

  1. Using Insert codeblock tool from the formatting toolbar on the editor

Explanatory GIF to add a code block in the Markdown editor

2_ScreenGIF_Adding_codeblock_Mardown

Creating code blocks in WYSIWYG(HTML)

In the WYSIWYG editor, you can create a code block by clicking the code block icon and selecting your desired language.

Explanatory GIF to add a code block in the WYSIWYG editor(HTML editor)

1_ScreenGIF_Adding_codeblock_WYSIWYG editor

Language shortcodes

  • C: c
  • C++: cpp, c++
  • C#: csharp
  • CSS: css
  • CoffeeScript: coffeescript
  • HTML: html
  • JSON: json
  • Java: java
  • JavaScript: javascript, js
  • Objective-C: objective-c, obj-c, objc
  • Objective-C++: objc++
  • PHP: php
  • Perl: perl, pl
  • Python 3: python3, py3
  • Python: python, py
  • Ruby: ruby, rb
  • Snobol: snobol
  • XML: xml

Indentation and code blocks

Any text indented at least 4 spaces will be treated as a code block. This is helpful for longer code snippets. This code will not be syntax-highlighted, but instead will be shown as plain text.

The following code block is created using indents instead of backticks.

def test():
    logging.error('Test failed')

Code block examples

C# block

using System;
namespace HelloWorld
{
    class Hello 
    {
        static void Main() 
        {
            Console.WriteLine("Hello World!");

            // Keep the console window open in debug mode.
            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }
    }
}

Javascript block

function $initHighlight(block, cls) {
try {
if (cls.search(/\bno\-highlight\b/) != -1)
return process(block, true, 0x0F) +
` class="${cls}"`;
} catch (e) {
/* handle exception */
} 
export $initHighlight;

XML block

<book id="bk101">
      <author>Gambardella, Matthew</author>
      <title>XML Developer's Guide</title>
      <genre>Computer</genre>
      <price>44.95</price>
      <publish_date>2000-10-01</publish_date>
      <description>An in-depth look at creating applications 
      with XML.</description>
   </book>

JSON block

{
    "one": 2,
    "three": {
        "point_1": "point_2",
        "point_3": 3.4
    },
    "list": [
        "one",
        "two",
        "three"
    ]
}

PowerShell block

$user = Read-Host "Enter Username"
$pass = Read-Host "Enter Password" -AsSecureString

Ruby block

require 'redcarpet'
markdown = Redcarpet.new("Hello World!")
puts markdown.to_html

War dieser Artikel hilfreich?

What's Next