The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Colorize the code tags

Go down

Tutorial Colorize the code tags

Post by Ange Tuteur Fri Nov 20, 2015 12:24 pm

Colorize the code tags

This tutorial will help you with coloring the contents of the code tags just like in the following example :
Colorize the code tags Hljs10

Colorize the code tags 09615110 1. Installing the JavaScript

Firstly, you must create a new script by going to Modules > JavaScript codes management. Make sure JS codes management is enabled and then create a new script with the following settings.

Title : Code syntax highlighter
Placement : In the topics
$(function(){var a=$("dl.codebox dd").find("code, div.cont_code");0!=a.length&&$.ajax({url:"",cache:!0,dataType:"script",success:function(){hljs.configure({useBR:!0});a.each(function(a,b){hljs.highlightBlock(b)})}})});

Save the script when you're finished.

Colorize the code tags 09615110 2. Installing the CSS

Lastly, you need to add a bit of CSS to your stylesheet to color the formatted code. Go to Display > Colors > CSS stylesheet and paste the following CSS rules* :
.hljs {
  display: inline-block;
  padding: 0.5em;
  color: #333;
  background: #f8f8f8;
.diff .hljs-header,
.hljs-javadoc {
  color: #998;
  font-style: italic;
.css .rule .hljs-keyword,
.javascript .hljs-title,
.nginx .hljs-title,
.hljs-status {
  color: #333;
  font-weight: bold;
.ruby .hljs-constant {
  color: #099;
.hljs-tag .hljs-value,
.tex .hljs-formula {
  color: #d14;
.coffeescript .hljs-params,
.scss .hljs-preprocessor {
  color: #900;
  font-weight: bold;
.javascript .hljs-title,
.lisp .hljs-title,
.clojure .hljs-title,
.hljs-subst {
  font-weight: normal;
.hljs-class .hljs-title,
.haskell .hljs-type,
.vhdl .hljs-literal,
.tex .hljs-command {
  color: #458;
  font-weight: bold;
.hljs-tag .hljs-title,
.hljs-rules .hljs-property,
.django .hljs-tag .hljs-keyword {
  color: #000080;
  font-weight: normal;
.lisp .hljs-body {
  color: #008080;
.hljs-regexp {
  color: #009926;
.ruby .hljs-symbol .hljs-string,
.lisp .hljs-keyword,
.tex .hljs-special,
.hljs-prompt {
  color: #990073;
.lisp .hljs-title,
.clojure .hljs-built_in {
  color: #0086b3;
.hljs-cdata {
  color: #999;
  font-weight: bold;
.hljs-deletion {
  background: #fdd;
.hljs-addition {
  background: #dfd;
.diff .hljs-change {
  background: #0086b3;
.hljs-chunk {
  color: #aaa;

Click submit when you're done, and it is now installed ! Yes

*You can preview the other themes here, and the corresponding CSS files via Github.

Ange Tuteur
Ange Tuteur

Male Posts : 13246
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

Back to top Go down

Back to top

- Similar topics

Permissions in this forum:
You cannot reply to topics in this forum