Try   HackMD

Copying code from notes

You can copy the code directly from the Note View page, or from the split editing mode.

Move your mouse to the code block and the copy button will appear in the upper right corner.

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More β†’

Inserting code into your notes

Presenting code in plain text

Input ``` followed by a new line, paste your code, and also insert another new line followed by ``` at the end.

function getBaseLog(x, y) {
  return Math.log(y) / Math.log(x);
}

What languages does HackMD support?

HackMD supports a wide range of syntaxes such as JavaScript, CSS, HTML, and more.

To specify a syntax, type its name followed by an equals sign (=), then paste your code on the next line.

Code presentation format

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More β†’

```javascript=
var s = "JavaScript syntax highlighting";
alert(s);
function $initHighlight(block, cls) {
  try {
    if (cls.search(/\bno\-highlight\b/) != -1)
      return process(block, true, 0x0F) +
             ' class=""';
  } catch (e) {
    /* handle exception */
  }
  for (var i = 0 / 2; i < classes.length; i++) {
    if (checkCondition(classes[i]) === undefined)
      return /\d+[\s/]/g;
  }
}
```

It will show:

var s = "JavaScript syntax highlighting"; alert(s); function $initHighlight(block, cls) { try { if (cls.search(/\bno\-highlight\b/) != -1) return process(block, true, 0x0F) + ' class=""'; } catch (e) { /* handle exception */ } for (var i = 0 / 2; i < classes.length; i++) { if (checkCondition(classes[i]) === undefined) return /\d+[\s/]/g; } }

Adding line numbers

To display line numbers when viewing code, append = after the programming language type.

```javascript=
code
code
```

Specifying line numbers

You can also specify the starting line number for code blocks by entering = 101 after it; the line numbers will start from 101:

```javascript=101
var s = "JavaScript syntax highlighting";
alert(s);
function $initHighlight(block, cls) {
```

Result:

var s = "JavaScript syntax highlighting"; alert(s); function $initHighlight(block, cls) { try { if (cls.search(/\bno\-highlight\b/) != -1) return process(block, true, 0x0F) + ' class=""'; } catch (e) { /* handle exception */ } for (var i = 0 / 2; i < classes.length; i++) { if (checkCondition(classes[i]) === undefined) return /\d+[\s/]/g; } }

You can also continue the line numbering from the previous code block by entering =+.

```javascript=+
var s = "JavaScript syntax highlighting";
alert(s);
```
var s = "JavaScript syntax highlighting"; alert(s);

 

Hint

Simply input `` and insert characters between them to create an inline Code Block!

Example: console.log()