计算机‎ > ‎网络‎ > ‎

Octopress 日常五

发布者:guo rue,发布时间:2016年3月22日 06:13   [ 更新时间:2016年3月22日 06:28 ]
修改 Markdown 文件后缀
Octopress 默认日志文件后缀是 .markdown,但现在大多数 Markdown 文件的后缀是 .md,推荐使用这种更为简洁的后缀。

用文本编辑器打开 Rakefile 文件,
nano Rakefile

找到如下两行代码:
new_post_ext    = "markdown"  # default new post file extension when using the new_post task
new_page_ext    = "markdown"  # default new page file extension when using the new_page task
改为:
new_post_ext    = "md"  # default new post file extension when using the new_post task
new_page_ext    = "md"  # default new page file extension when using the new_page task

保存退出

修改默认 Markdown 解释器
Octopress 默认的 Markdown 解释器是 rdiscount,个人更喜欢 kramdown,支持 Multi Markdown 语法和 LaTeX,对于理工科博客 LaTeX 必不可少,而且据说 kramdown 更快,也是 Github 推荐的 Markdown 解释器。

首先用文本编辑器打开 Gemfile 文件,
nano Gemfile
在文件末尾添加一行:
gem 'kramdown'
保存退出

然后在终端 (Terminal) 执行如下命令:
bundle install

打开 _config.yml 文件,
nano _config.yml
找到:
markdown: rdiscount
rdiscount:
  extensions:
    - autolink
    - footnotes
    - smart

全部注释掉,这样,在每行前面加 # 符号
#markdown: rdiscount
#rdiscount:
#  extensions:
#    - autolink
#    - footnotes
#    - smart
然后跟着加上这一行
markdown: kramdown

保存退出

为了能够显示数学公式,我们需要添加 MathJax 支持,打开文件
nano source/_includes/custom/head.html
添加如下代码:
<!-- MathJax -->
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    tex2jax: {
      inlineMath: [ ['$','$'], ["\\(","\\)"] ],
      processEscapes: true
    }
  });
</script>
<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
      tex2jax: {
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
    });
</script>
<script type="text/x-mathjax-config">
    MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for(i=0; i < all.length; i += 1) {
            all[i].SourceElement().parentNode.className += ' has-jax';
        }
    });
</script>
<script type="text/javascript"
   src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>

这样你就可以使用所有 LaTeX 语法在网页中输入公式了,比如 帖子里 或者页面 正文里加入下面这个公式示例
$$
f'\left( x\right) = \lim _{x\rightarrow 0}\dfrac {f\left( x+\Delta x\right) - f\left( x\right)}{\Delta x}
$$

重新生成网站就能看见了。