javascript - Ghost 代码 Markdown block 中的行号

标签 javascript github markdown ghost-blog

我想知道如何在呈现的 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 in linenums.

但是,我还没有测试该类是否真的在生成的 <code> 的属性中。元素。

```prettyprint lang-ruby linenumber xxxx

关于javascript - Ghost 代码 Markdown block 中的行号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19481549/

相关文章:

github - 在 GitHub 中查找我作为作者、审阅者或受让人的 PR

python - Pygments 风格未在 Jekyll 博客中应用

Github页面无法正确显示markdown

css - 删除 Markdown 表内图像的背景颜色

javascript - 将 Canvas 图像作为 multipart/form-data 类型的 Blob 上传到 facebook

javascript - 实时网络音频输入可以在 Ubuntu 上的 Google Chrome 中使用吗?

javascript - 正则表达式不能以 .replace() 的方式工作

javascript - Highcharts 散点标记翻译错误

php - 新的 GitHub Push to Master -> 压缩,发送到 S3

git - 如何访问公共(public) fork 的 GitLens+ 功能?