使用Highlight.js突出显示Java语法

时间:2017-05-12 22:26:33

标签: highlight.js

我正在使用highlight.js来设置Java的样式,它会为字符串,关键字和数字生成标记,但不会为类型和文字生成标记。我正在使用highlight.js / 9.11.0。

建议?

参见示例:https://codepen.io/amandaw/pen/bWMraO

CSS

.hljs-variable {
   color: red
 }

.hljs-type {
   color: orange
}
.hljs-literal {
   color: yellow
}

HTML

<pre><code class="java"> 

import java.util.*;

public class Main {
  public static void main(String[] args) throws Exception {
  Date d1 = new Date();
  Calendar cl = Calendar. getInstance();

    cl.setTime(d1);
    System.out.println("today is "+ d1.toString());

    cl. roll(Calendar.MONTH, 100);
    System.out.println("date after a month will be " + cl.getTime().toString() );

    cl. roll(Calendar.HOUR, 70);
    System.out.println("date after 7 hrs will be "+ cl.getTime().toString() );
   }
}

</code></pre>

0 个答案:

没有答案