반응형
How can I use SyntaxHighlihgter
in my web page.
1. Download SyntaxHighlighter
2. Extract all files and upload scripts and styles files to server
3. In your page, add the below scrpit to <head> block
<script type="text/javascript" src="./images/shCore.js"></script>
<script type="text/javascript" src="./images/shLegacy.js"></script>
<script type="text/javascript" src="./images/shBrushBash.js"></script>
<script type="text/javascript" src="./images/shBrushCpp.js"></script>
<script type="text/javascript" src="./images/shBrushDiff.js"></script>
<script type="text/javascript" src="./images/shBrushJava.js"></script>
<script type="text/javascript" src="./images/shBrushJScript.js"></script>
<script type="text/javascript" src="./images/shBrushPlain.js"></script>
<script type="text/javascript" src="./images/shBrushPython.js"></script>
<script type="text/javascript" src="./images/shBrushSql.js"></script>
<script type="text/javascript" src="./images/shBrushXml.js"></script>
<link type="text/css" rel="stylesheet" href="./images/shCore.css">
<link type="text/css" rel="stylesheet" href="./images/shThemeDefault.css">
<script type="text/javascript">
SyntaxHighlighter.all();
</script>
If you change the theme, check this url,
<link type="text/css" rel="stylesheet" href="./images/shThemeEmacs.css">
4. In your page, add the <pre> block with source code as the below
1. Java case :
<pre class="brush:java">
// This is Java highlighter
</pre>
2. C/C++ case :
<pre class="brush:cpp">
// This is cpp highlighter
</pre>
If you use another language, check related script file.
For example, you can find Brush.aliases = ['cpp', 'c'] in shBrushCpp.js for C++.
4. Example :
4.1. Java Case
/* This JNI function will open a sensor calibration. * return a sensor calibration handle for open success, * otherwise, retrun 0 */ JNIEXPORT jint JNICALL psh_calibration_open(JNIEnv *env, jobject jobj, jint sensor_type) { int ret; handle_t cal; if (sensor_type == COMPASS_CAL){ LOGI("PSH_S_C: Start compass calibration"); cal = psh_open_session(SENSOR_CALIBRATION_COMP); if (cal == NULL) { LOGE("PSH_S_C: Can not connect compass_cal"); return 0; } } else { LOGE("PSH_S_C: No this sensor type supported!"); return 0; } cal_param[sensor_type].handle = cal; memset((void*)&cal_param[sensor_type].param, 0, sizeof(struct cmd_calibration_param)); return (int)cal; }
4.2. CPP Case
/* This JNI function will open a sensor calibration. * return a sensor calibration handle for open success, * otherwise, retrun 0 */ JNIEXPORT jint JNICALL psh_calibration_open(JNIEnv *env, jobject jobj, jint sensor_type) { int ret; handle_t cal; if (sensor_type == COMPASS_CAL){ LOGI("PSH_S_C: Start compass calibration"); cal = psh_open_session(SENSOR_CALIBRATION_COMP); if (cal == NULL) { LOGE("PSH_S_C: Can not connect compass_cal"); return 0; } } else { LOGE("PSH_S_C: No this sensor type supported!"); return 0; } cal_param[sensor_type].handle = cal; memset((void*)&cal_param[sensor_type].param, 0, sizeof(struct cmd_calibration_param)); return (int)cal; }
P.S : In mobile browser, do not show theme mode. It just show plain mode.
반응형
댓글