讓你網站文章中的程式碼漂亮起來 – Code Prettifier

Bycodeant

讓你網站文章中的程式碼漂亮起來 – Code Prettifier

想要在網站上發表文章時,如果遇上了程式碼的段落,排版起來總是會有點頭大,最好用的當然還是 < pre > 標籤,但是要完全做到程式碼的高亮突顯效果就不是很容易的。以前流行過的 XOOPS 這套 CMS 裏面就有很好的程式碼內容高亮突顯套件,但是現在也有一個簡單易用的選擇 :Google Code Prettify

https://github.com/google/code-prettify

使用上非常簡單,首先添加一行 Code 引入 Javascript:

<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js" async="async"></script>

然後在有程式碼內容的使用下面的範例編輯即可:

<pre class="prettyprint">........</pre>

下面示範一下 C 語言的效果:

void geo_ip_city (char *ip_str, IP_INFO *ip_info)
{
	GeoIP       *gi  = NULL;
	GeoIPRecord *gir = NULL;

	gi = GeoIP_open("/root/GeoIP/GeoLiteCity.dat", GEOIP_INDEX_CACHE);
	if (gi == NULL) {
		printf("Error opening database\n");
		return;
	}
	
	gir = GeoIP_record_by_name(gi, (const char *)ip_str);
	if (gir != NULL) {
		//printf("%s\n%s\n%s\n%s\n", ip_str, _mk_NA(gir->country_code), _mk_NA(GeoIP_region_name_by_code(gir->country_code, gir->region)), _mk_NA(gir->city));
		snprintf(ip_info->country, IP_COUNTRY_LENGTH, "%s", _mk_NA(gir->country_code));
		snprintf(ip_info->city, IP_CITY_LENGTH, "%s, %s", _mk_NA(GeoIP_region_name_by_code(gir->country_code, gir->region)), _mk_NA(gir->city));
		GeoIPRecord_delete(gir);
	}

	GeoIP_delete(gi);
	return;
} 

 真的是好物,一用就愛上。

About the author

codeant administrator

Leave a Reply