我在Github上使用Jekyll和Markdown作为我的博客.如何在页面中插入代码标签?
例子我以为我可以使用<pre>标签将一些代码捕捉插入我的页面以显示给读者,但是jekyll不喜欢它们.
有人可以告诉我一个好的格式标签,我可以用它在我的页面中插入代码
如果我尝试这个代码:
<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>
Run Code Online (Sandbox Code Playgroud)
我收到这个错误

我的_config.xml
# 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 …Run Code Online (Sandbox Code Playgroud) 使用Redcarpet,当我在我的降价中包含类似下面的内容时,它不会考虑任何换行符或缩进.我在线的末尾尝试了两个空格.代码之间的额外行.似乎没什么用.
```xml
<?xml version="1.0" encoding="UTF-8"?>
<hash>
<money>3</money>
</hash>
```
Run Code Online (Sandbox Code Playgroud)
我知道了:
<?xml version="1.0" encoding="UTF-8"?> <hash> <money>3</money> </hash>
Run Code Online (Sandbox Code Playgroud)
以下是Redcarpet设置:
Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink => true, :space_after_headers => true, :fenced_code_blocks => true, :no_intra_emphasis => true, :lax_html_blocks => true)
Run Code Online (Sandbox Code Playgroud)
我需要做些什么来使线条正确断开并保留缩进,就像在这里或在GitHub上一样?
更新 - 源代码如下:
<pre><code><?xml version="1.0" encoding="UTF-8"?>
<hash>
<money>3</money>
</hash>
</code></pre>
Run Code Online (Sandbox Code Playgroud) 我正在尝试将代码突出显示用于使用jekyll构建的简单博客.我希望能够在markdown中编写的帖子中进行代码突出显示,因此我启用了redcarpet作为标记语言.这很好用,代码在<pre></pre>标签中格式化,代码的所有各种元素都得到相应的类.例如
<span class="n">function</span>
<span class="n">saySomething</span>
<span class="p">()</span>
<span class="p">{</span>
etc.
Run Code Online (Sandbox Code Playgroud)
这很棒但是这并没有给我们实际的突出显示(颜色).所以我想必须有一些css准备好复制和粘贴,这实际上是不同代码元素的样式.还是我完全错过了什么?
我查看了一些突出显示像美化或棱镜这样的库的代码,但这些代码在浏览器中使用javascript进行自己的格式化.但由于redcarpet已经完成了格式化代码的繁重工作,因此不必再进行此操作.
任何提示?
为了使用简单的HTML成功显示代码,我在我的基于Jekyll的博客中添加了Highlight.js,该博客在Github页面上运行
<!--Add Highlight.js https://highlightjs.org/download/ -->
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.0.0/styles/default.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.0.0/highlight.min.js"></script>
<!-- Using Highight.js https://highlightjs.org/usage/-->
<script>
hljs.initHighlightingOnLoad();
</script>Run Code Online (Sandbox Code Playgroud)
我需要显示下面的C#代码,即:<pre> <code class="csharp">和之间的所有内容</code> </pre>:
<pre>
<code class="csharp">
/// <summary>
/// Main class of the project
/// </summary>
class Program
{
/// <summary>
/// Main entry point of the program
/// </summary>
/// <param name="args">Command line args</param>
static void Main(string[] args)
{
//Do stuff
}
} …Run Code Online (Sandbox Code Playgroud)