首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我在Github上使用了Jekyll和Markdown作为我的博客。如何在页面中插入代码标记?

我在Github上使用了Jekyll和Markdown作为我的博客。如何在页面中插入代码标记?
EN

Stack Overflow用户
提问于 2013-04-15 20:31:06
回答 2查看 2.2K关注 0票数 7

我在Github上使用了Jekyll和Markdown作为我的博客。如何在页面中插入代码标记?

我在想我可以使用<pre>标签在我的页面中插入一些代码快照来显示给读者,但是jekyll不喜欢它们。

谁能告诉我一个好的格式化标签,我可以用它在我的页面中插入代码

如果我尝试以下代码:

代码语言:javascript
复制
<pre>
  <code class="ruby">
git clone --mirror git@git.com:project project

cd project

git remote add github git@github.com:username/project.git


In cron Job

cd /pathto/project && git fetch -q && git push -q --mirror github
    </code>
</pre>

我得到了这个错误

我的_config.xml

代码语言:javascript
复制
# This is the default format. 
# For more see: https://github.com/mojombo/jekyll/wiki/Permalinks
permalink: /:categories/:year/:month/:day/:title 

exclude: [".rvmrc", ".rbenv-version", "README.md", "Rakefile", "changelog.md"]
auto: true
pygments: true

# Themes are encouraged to use these universal variables 
# so be sure to set them if your theme uses them.
#
title : xxxx
tagline :xxxx
author :
  name : xxx
  email : jxxx
  github : xxx
  twitter : xx

# The production_url is only used when full-domain names are needed
# such as sitemap.txt 
# Most places will/should use BASE_PATH to make the urls
#
# If you have set a CNAME (pages.github.com) set your custom domain here.
# Else if you are pushing to username.github.com, replace with your username.
# Finally if you are pushing to a GitHub project page, include the project name at the end.
#
production_url : http://johnathanmarksmith.com

# All Jekyll-Bootstrap specific configurations are namespaced into this hash
#
JB :
  version : 0.3.0

  # All links will be namespaced by BASE_PATH if defined.
  # Links in your website should always be prefixed with {{BASE_PATH}}
  # however this value will be dynamically changed depending on your deployment situation.
  #
  # CNAME (http://yourcustomdomain.com)
  #   DO NOT SET BASE_PATH 
  #   (urls will be prefixed with "/" and work relatively)
  #
  # GitHub Pages (http://username.github.com)
  #   DO NOT SET BASE_PATH 
  #   (urls will be prefixed with "/" and work relatively)
  #
  # GitHub Project Pages (http://username.github.com/project-name)
  #
  #   A GitHub Project site exists in the `gh-pages` branch of one of your repositories.
  #  REQUIRED! Set BASE_PATH to: http://username.github.com/project-name
  #
  # CAUTION:
  #   - When in Localhost, your site will run from root "/" regardless of BASE_PATH
  #   - Only the following values are falsy: ["", null, false]
  #   - When setting BASE_PATH it must be a valid url.
  #     This means always setting the protocol (http|https) or prefixing with "/"
  BASE_PATH : false

  # By default, the asset_path is automatically defined relative to BASE_PATH plus the enabled theme.
  # ex: [BASE_PATH]/assets/themes/[THEME-NAME]
  #
  # Override this by defining an absolute path to assets here.
  # ex: 
  #   http://s3.amazonaws.com/yoursite/themes/watermelon
  #   /assets
  #
  ASSET_PATH : false

  # These paths are to the main pages Jekyll-Bootstrap ships with.
  # Some JB helpers refer to these paths; change them here if needed.
  #
  archive_path: /archive.html
  categories_path : /categories.html
  tags_path : /tags.html
  atom_path : /atom.xml
  rss_path : /rss.xml

  # Settings for comments helper
  # Set 'provider' to the comment provider you want to use.
  # Set 'provider' to false to turn commenting off globally.
  #
  comments :
    provider : disqus
    disqus :
      short_name : jekyllbootstrap
    livefyre :
      site_id : 123
    intensedebate :
      account : 123abc
    facebook :
      appid : 123
      num_posts: 5
      width: 580
      colorscheme: light

  # Settings for analytics helper
  # Set 'provider' to the analytics provider you want to use.
  # Set 'provider' to false to turn analytics off globally.
  #        
  analytics :
    provider : google 
    google : 
        tracking_id : 'UA-123-12'
    getclicky :
      site_id : 
    mixpanel :
        token : '_MIXPANEL_TOKEN_'

  # Settings for sharing helper. 
  # Sharing is for things like tweet, plusone, like, reddit buttons etc.
  # Set 'provider' to the sharing provider you want to use.
  # Set 'provider' to false to turn sharing off globally.
  #
  sharing :
    provider : false

  # Settings for all other include helpers can be defined by creating 
  # a hash with key named for the given helper. ex:
  #
  #   pages_list :
  #     provider : "custom"   
  #
  # Setting any helper's provider to 'custom' will bypass the helper code
  # and include your custom code. Your custom file must be defined at:
  #   ./_includes/custom/[HELPER]
  # where [HELPER] is the name of the helper you are overriding.
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-04-16 08:57:22

如果你所指的“页面”是一个Markdown文件,即扩展名是.md或.markdown,那么你需要使用标准的Markdown语法:

对于inline code,使用反引号,如下所示:inline code

对于block code,每行缩进4个空格:

代码语言:javascript
复制
block
of
code

Jekyll使用像RedCarpet、Maruku或RDiscount这样的Markdown解析器,并没有定义你应该如何格式化你的内容,这是由你正在编写的内容类型设置的,在本例中是Markdown。因此,要查找的地方是code的Markdown语法文档

http://daringfireball.net/projects/markdown/syntax#code

您还可以使用{% highlight %} Liquid语法标记查看语法突出显示:

https://github.com/mojombo/jekyll/wiki/Liquid-Extensions#code-highlighting

希望这能有所帮助!

票数 3
EN

Stack Overflow用户

发布于 2013-04-15 23:56:44

先生,这个怎么样?

代码语言:javascript
复制
~~~ ruby
# This is a test.
def foo
  puts 'foo'
end
~~~

ref

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16015222

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档