Ghost代码降价块中的行号

时间:2013-10-20 19:03:55

标签: javascript github markdown ghost-blog

我想知道如何在呈现的markdown代码块中显示行号,特别是如何为Ghost博客平台执行此操作。如果您还可以根据语言为代码着色(以类似于GitHub和其他人的方式)。谢谢!

2 个答案:

答案 0 :(得分:13)

This post mentions(2013年10月11日):

  

我刚刚意识到Ghost已经支持GitHub-Markdown扩展。

     

所以基本上你可以通过在{{!下面添加以下行代码来包含Google Code Prettify)。 Casper的主要JavaScript文件}}进入:
  /content/themes/casperdefault.hbs

<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js">    
</script>
  

在Ghost中使用以下GitHub markdown:

```prettyprint lang-ruby require 'redcarpet' markdown = Redcarpet.new("Hello World!") puts markdown.to_html ```

上面的Markdown将生成以下HTML代码,然后由Google Code Prettify进行美化:

<pre>
  <code class="prettyprint lang-ruby">
    require 'redcarpet' 
    markdown = Redcarpet.new("Hello World!") 
    puts markdown.to_html
  </code>
</pre> 

从那里,您可以阅读更多“google-code-prettify”,其中介绍了如何添加行号:

  

您可以使用 linenums 类打开行号   如果您的代码不是从第1行开始,则可以在linenums中添加冒号和行号到该类的末尾。

但是,我还没有测试该类是否实际上属于生成的<code>元素的属性。

```prettyprint lang-ruby linenumber xxxx

答案 1 :(得分:1)

我尝试了一切,但没有任何作用对我来说最后我在底部添加了这些行(suggested by google-code)并且一切都开始工作

<script>
    $(document).ready(function () {            
        $("pre").each(function () {
            if (($(this).html().split(/\n/).length - 1) > 3) {
                $(this).addClass('prettyprint linenums:1');
            }
        });
    });
 </script>

可能对任何人都有帮助!

相关问题