Grunt-ngdocs的语法高亮显示功能

时间:2014-12-03 13:28:39

标签: angularjs syntax-highlighting jsdoc

我不知道是否出现了问题或者它尚未得到支持,但我希望看到代码块如下:

```
var example = 3;
```

在要突出显示的文档中。
如何修复/添加此功能?

2 个答案:

答案 0 :(得分:1)

我使用highlightjsjQuery livequery plugin

解决了这个问题

Gruntfile.js中的我的ngdocs部分现在看起来像这样:

options: {
  html5Mode: false,
  scripts: [
    'bower_components/jquery/dist/jquery.js',
    'js/jquery.livequery.min.js',
    'angular.js',
    'js/helpers/ngdocs.js',
    'bower_components/highlightjs/highlight.pack.js'
  ],
  styles: [
    'bower_components/highlightjs/styles/atelier-forest.dark.css'
  ]

我的js / helpers / ngdocs.js看起来像这样:

'use strict';

/* global $, hljs */
$(function () {
    $('pre code').livequery(
        function() {
            hljs.highlightBlock(this);
        });

});

答案 1 :(得分:0)

解决方法:

标记模块用于 grunt-ngdocs grunt-ngdocs\node_modules\marked\lib)。 由于grunt-ngdocs使用 angular-bootstrap-prettify (BTW使用 google-code-prettify ),因此它足以调整标记< / em>稍微为了产生<pre class="prettyprint linenums">...</pre>而不是<pre>...</pre>
所以在Renderer.prototype.code函数(我的版本中的第757行),return语句可以像这样改变:

  • return '<pre class="prettyprint linenums"><code>' ...
  • return '<pre class="prettyprint linenums"><code class="' ...

清洁解决方案:

ngDocs 似乎用<pre>..</pre>替换所有<pre class="prettyprint linenums">...</pre>块(第266行,第v0.2.6段)。因此,我们可以直接在文档中使用```块,而不是使用markdown ```代码<pre>...</pre>块。