Syntax Highlighter


Pada postingan sebelumnya telah saya jelaskan bahwa saya akan mulai (belajar) menulis tutorial tentang blogging dan script. Saya rasa sebelum saya mulai menuliskan artikel tentang kesemuanya itu, saya akan mereviev sedikit tentang penggunaan syntax highlighter dan sekaligus instalasinya.

Syntax highlighter berfungsi untuk melakukan highlight pada kode tertentu sehingga memudahkan dalam membacanya sekaligus memercantik tampilan blog. Sebagai contoh, di bawah ini adalah hasil dari pekerjaan syntax highlighter untuk kode CSS:

tanpa syntax highlighter (dengan blockquote biasa):

/* Use this with templates/template-twocol.html */
body {
margin-left: 0px;
margin-top: 20px;
margin-right: 0px;
background-color: #000000;
color: #eee;
font-family: Trebuchet MS;
font-size: 12px;
}
a:link {
color: #FF3366;
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #990000;
}
a:hover {
text-decoration: none;
color: #FF0000;
}
a:active {
text-decoration: none;
color: #FF3366;
}



dengan syntax highlighter:


  1. /* Use this with templates/template-twocol.html */
  2. body {
  3. margin-left: 0px;
  4. margin-top: 20px;
  5. margin-right: 0px;
  6. background-color: #000000;
  7. color: #eee;
  8. font-family: Trebuchet MS;
  9. font-size: 12px;
  10. }
  11. a:link {
  12. color: #FF3366;
  13. text-decoration: none;
  14. }
  15. a:visited {
  16. text-decoration: none;
  17. color: #990000;
  18. }
  19. a:hover {
  20. text-decoration: none;
  21. color: #FF0000;
  22. }
  23. a:active {
  24. text-decoration: none;
  25. color: #FF3366;
  26. }


Dapat kita lihat perbedaannya bukan?

nah langsung saja, bagi pengguna Blogspot cara instalasi syntax highlighter sangat mudah. Pertama, download dahulu syntax highlighter generator (untuk blog ini saya menggunakan static syntax highlighter dari relic19 yang cukup menggunakan CSS (bukan javascript) sehingga lebih cepat dan mudah. Download static syntax highlighter maka kita akan mendapatkan generator syntax highlighter yang berfungsi untuk mengubah kode yang kita masukkan menjadi kode HTML.

Selanjutnya, masukkan kode CSS di bawah ini kedalam template blogger (letakkan sebelum kode ]]>).


  1. .dp-highlighter
  2. {
  3. font-family: "Consolas", "Courier New", Courier, mono, serif;
  4. font-size: 12px;
  5. background-color: #E7E5DC;
  6. width: 99%;
  7. overflow: auto;
  8. margin: 18px 0 18px 0 !important;
  9. padding-top: 1px; /* adds a little border on top when controls are hidden */
  10. }

  11. /* clear styles */
  12. .dp-highlighter ol,
  13. .dp-highlighter ol li,
  14. .dp-highlighter ol li span
  15. {
  16. margin: 0;
  17. padding: 0;
  18. border: none;
  19. }

  20. .dp-highlighter a,
  21. .dp-highlighter a:hover
  22. {
  23. background: none;
  24. border: none;
  25. padding: 0;
  26. margin: 0;
  27. }

  28. .dp-highlighter .bar
  29. {
  30. padding-left: 45px;
  31. }

  32. .dp-highlighter.collapsed .bar,
  33. .dp-highlighter.nogutter .bar
  34. {
  35. padding-left: 0px;
  36. }

  37. .dp-highlighter ol
  38. {
  39. list-style: decimal; /* for ie */
  40. background-color: #fff;
  41. margin: 0px 0px 1px 45px !important; /* 1px bottom margin seems to fix occasional Firefox scrolling */
  42. padding: 0px;
  43. color: #5C5C5C;
  44. }

  45. .dp-highlighter.nogutter ol,
  46. .dp-highlighter.nogutter ol li
  47. {
  48. list-style: none !important;
  49. margin-left: 0px !important;
  50. }

  51. .dp-highlighter ol li,
  52. .dp-highlighter .columns div
  53. {
  54. list-style: decimal-leading-zero; /* better look for others, override cascade from OL */
  55. list-style-position: outside !important;
  56. border-left: 3px solid #6CE26C;
  57. background-color: #F8F8F8;
  58. color: #5C5C5C;
  59. padding: 0 3px 0 10px !important;
  60. margin: 0 !important;
  61. line-height: 14px;
  62. }

  63. .dp-highlighter.nogutter ol li,
  64. .dp-highlighter.nogutter .columns div
  65. {
  66. border: 0;
  67. }

  68. .dp-highlighter .columns
  69. {
  70. background-color: #F8F8F8;
  71. color: gray;
  72. overflow: hidden;
  73. width: 100%;
  74. }

  75. .dp-highlighter .columns div
  76. {
  77. padding-bottom: 5px;
  78. }

  79. .dp-highlighter ol li.alt
  80. {
  81. background-color: #FFF;
  82. color: inherit;
  83. }

  84. .dp-highlighter ol li span
  85. {
  86. color: black;
  87. background-color: inherit;
  88. }

  89. /* Adjust some properties when collapsed */

  90. .dp-highlighter.collapsed ol
  91. {
  92. margin: 0px;
  93. }

  94. .dp-highlighter.collapsed ol li
  95. {
  96. display: none;
  97. }

  98. /* Additional modifications when in print-view */

  99. .dp-highlighter.printing
  100. {
  101. border: none;
  102. }

  103. .dp-highlighter.printing .tools
  104. {
  105. display: none !important;
  106. }

  107. .dp-highlighter.printing li
  108. {
  109. display: list-item !important;
  110. }

  111. /* Styles for the tools */

  112. .dp-highlighter .tools
  113. {
  114. padding: 3px 8px 3px 10px;
  115. font: 9px Verdana, Geneva, Arial, Helvetica, sans-serif;
  116. color: silver;
  117. background-color: #f8f8f8;
  118. padding-bottom: 10px;
  119. border-left: 3px solid #6CE26C;
  120. }

  121. .dp-highlighter.nogutter .tools
  122. {
  123. border-left: 0;
  124. }

  125. .dp-highlighter.collapsed .tools
  126. {
  127. border-bottom: 0;
  128. }

  129. .dp-highlighter .tools a
  130. {
  131. font-size: 9px;
  132. color: #a0a0a0;
  133. background-color: inherit;
  134. text-decoration: none;
  135. margin-right: 10px;
  136. }

  137. .dp-highlighter .tools a:hover
  138. {
  139. color: red;
  140. background-color: inherit;
  141. text-decoration: underline;
  142. }

  143. /* About dialog styles */

  144. .dp-about { background-color: #fff; color: #333; margin: 0px; padding: 0px; }
  145. .dp-about table { width: 100%; height: 100%; font-size: 11px; font-family: Tahoma, Verdana, Arial, sans-serif !important; }
  146. .dp-about td { padding: 10px; vertical-align: top; }
  147. .dp-about .copy { border-bottom: 1px solid #ACA899; height: 95%; }
  148. .dp-about .title { color: red; background-color: inherit; font-weight: bold; }
  149. .dp-about .para { margin: 0 0 4px 0; }
  150. .dp-about .footer { background-color: #ECEADB; color: #333; border-top: 1px solid #fff; text-align: right; }
  151. .dp-about .close { font-size: 11px; font-family: Tahoma, Verdana, Arial, sans-serif !important; background-color: #ECEADB; color: #333; width: 60px; height: 22px; }

  152. /* Language specific styles */

  153. .dp-highlighter .comment, .dp-highlighter .comments { color: #008200; background-color: inherit; }
  154. .dp-highlighter .string { color: blue; background-color: inherit; }
  155. .dp-highlighter .keyword { color: #069; font-weight: bold; background-color: inherit; }
  156. .dp-highlighter .preprocessor { color: gray; background-color: inherit; }


Nah, selesai sudah. Untuk menampilkan posting berupa kode semacam CSS atau JavaScript, tinggal melakukan copy & paste dari generator syntax highlighter. dan jika menginginkan tampilan yang berbeda tinggal diedit aja CSS nya. itu saja.


Terimakasih telah membaca..
:)

0 komentar:

Post a Comment