【问题标题】:google-code-prettify doesn't work for matlab codegoogle-code-prettify 不适用于 matlab 代码
【发布时间】:2013-04-15 21:20:47
【问题描述】:

我正在使用 google-code-prettify 包来突出显示我的 matlab 代码,但是突出显示看起来不像 matlab 样式的着色。我的最小工作示例:

<!DOCTYPE html>
<html>
<head>
   <link href="prettify/prettify.css" type="text/css" rel="stylesheet" />
   <script src="prettify/prettify.js" type="text/javascript"></script>
   <script src="prettify/run_prettify.js" type="text/javascript"></script>
</head>
<body>
      <pre class="prettyprint lang-matlab">
      <code>
      i=1;
      if i==2
         i=1;
      end
      while(1)
         a=5;
      end
      %test comment
      </code>
      </pre>
</body>
</html>

例如,在上面的示例中,%test comment 没有以绿色突出显示,但是一些行被突出显示,例如while 循环。我是不是做错了什么?

【问题讨论】:

    标签: matlab google-code-prettify


    【解决方案1】:

    当您使用run_prettify.js 时,您不需要同时使用prettify.jsprettify.css。只需将?lang=matlab 添加到run_prettify.js URL,它就会加载您需要的所有JS 和CSS。

    http://code.google.com/p/google-code-prettify/wiki/GettingStarted

    你可以加载 JavaScript 吗?和 CSS 用于通过一个 URL 进行美化

    ...

    例如

    <script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?lang=css&skin=sunburst"></script>
    

    指定lang参数也加载CSS语言扩展和皮肤参数加载sunburst皮肤。

    所以你的&lt;head&gt; 应该是这样的

    <head>
       <script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?lang=matlab" type="text/javascript"></script>
    </head>
    

    【讨论】:

      【解决方案2】:

      您需要包含 matlab 语言处理程序:

      <script src="https://google-code-prettify.googlecode.com/svn/trunk/src/lang-matlab.js"></script>
      

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-06
      • 1970-01-01
      • 2013-04-05
      • 1970-01-01
      • 1970-01-01
      • 2010-12-23
      • 1970-01-01
      相关资源
      最近更新 更多