我想知道如何在呈现的 Markdown 代码块中显示行号,特别是如何为 Ghost 博客平台执行此操作。如果您还可以让它根据语言为代码着色(以类似于 GitHub 和其他人所做的方式),那就更好了。谢谢!
最佳答案
This post mentions (2013 年 10 月 11 日):
I just realized Ghost is already supporting the GitHub-Markdown extension.
So basically you can just include as for example Google Code Prettify by adding the following line below {{! The main JavaScript file for Casper }} into:
/content/themes/casperdefault.hbs
.
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js">
</script>
And use the following GitHub markdown in Ghost:
```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”中阅读更多内容,其中解释了如何添加行号:
You can use the
linenums
class to turn on line numbering.
If your code doesn't start at line number 1, you can add a colon and a line number to the end of that class as inlinenums
.
但是,我还没有测试该类是否真的在生成的 <code>
的属性中。元素。
```prettyprint lang-ruby linenumber xxxx
关于javascript - Ghost 代码 Markdown block 中的行号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19481549/