\( \newcommand{\ord}[1]{\mathcal{O}\left(#1\right)} \newcommand{\abs}[1]{\lvert #1 \rvert} \newcommand{\floor}[1]{\lfloor #1 \rfloor} \newcommand{\ceil}[1]{\lceil #1 \rceil} \newcommand{\opord}{\operatorname{\mathcal{O}}} \newcommand{\argmax}{\operatorname{arg\,max}} \newcommand{\str}[1]{\texttt{"#1"}} \)

2017年5月12日 星期五

[ Source code beautifier / syntax highlighter ] 在網頁/blog中插入彩色程式碼

先看看結果吧:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#define x first
#define y second
#include<bits/stdc++.h>
using namespace std;
#define X(){\
    sdfgsdfg;\
    sdfgsdfg;\
}
int main(){
    //asdfasdfdfsdfghd\
    asdfasdfasdf\
    asdfasdfsdf
    wchar_t wc;
    cout<<"Jinkela"<<'\n';
    cout<<R"jinkela(
    7122)jinkela";
    cout<<L"adsfasdf"<<endl;
    return 0;
    /*
    asdf
    */
}
這是使用http://hilite.me/ Style=monokai的結果,個人覺得效果不錯,只是raw string和一些比較難實作的東西沒有支援而已,其他的都還算可以

我已經把這個網址加到我的學習連結裡面了,C/C++ syntax highlighter (Style選monokai)那個。用法就是貼上程式碼,設定好語言和style,把產生的html貼在你想貼的位置,蠻簡單的

我在blog中如果程式碼量比較少我覺得沒必要加入模板也會用這個方法來貼code