Try   HackMD

複製筆記中的程式碼

不論在筆記檢視頁、雙欄編輯模式,你都可以直接複製程式碼。

請將滑鼠移動至程式碼區塊,右上角會出現複製按鈕。

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 →

在筆記中貼入程式碼

純文字呈現程式碼

輸入 ``` 後換行貼入程式碼,在結尾處也換行插入 ```

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

HackMD 支援哪些語言?

HackMD 支援非常多程式語言,諸如 javascript、CSS、HTML等等。
在表明程式語言之後輸入 = ,再換行貼入程式碼

程式碼呈現格式

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;
  }
}
```

結果:

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; } }

加上行號

要讓程式碼在瀏覽時有行號,請在程式語言種類之後加上 =

```javascript=
code
code
```

指定行號

您也可以指定開始行號,在 = 之後輸入 101,行號就會從 101 開始:

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

結果:

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; } }

或是可以接續上一個程式碼區塊的行號,使用 =+

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

 

小提示

輸入「`` 」並在中間加入字元,就可以建立行內的 Code Block 了!

範例:console.log()