如何防止Jekyll在突出显示中添加空格?
我现在正在用杰基尔做实验。大多数事情看起来都不错,但Jekyll处理代码高亮显示的方式似乎有缺陷 我用pygments 然后杰基尔似乎用了这样的作品:如何防止Jekyll在突出显示中添加空格?,jekyll,liquid,pygments,Jekyll,Liquid,Pygments,我现在正在用杰基尔做实验。大多数事情看起来都不错,但Jekyll处理代码高亮显示的方式似乎有缺陷 我用pygments 然后杰基尔似乎用了这样的作品: {% highlight python %} #!/usr/bin/env python def wer(r, h): """ {% endhighlight %} 生成类似 <div class="highlight"> <pre> <code class="python">&l
{% highlight python %}
#!/usr/bin/env python
def wer(r, h):
"""
{% endhighlight %}
生成类似
<div class="highlight">
<pre>
<code class="python"><span class="c">#!/usr/bin/env python</span>
<span class="k">def</span> <span class="nf">wer</span><span class="p">(</span><span class="n">r</span><span class="p">,</span> <span class="n">h</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> Calculation of WER with Levenshtein distance.</span>
<span class="sd"> Works only for iterables up to 254 elements (uint8).</span>
<span class="sd"> O(nm) time ans space complexity.</span>
[...]
<span class="n">doctest</span><span class="o">.</span><span class="n">testmod</span><span class="p">()</span>
</code>
</pre>
</div>
#/usr/bin/env python
def wer(r,h):
"""
使用Levenshtein距离计算WER。
仅适用于多达254个元素的iterables(uint8)。
O(nm)时间和空间复杂度。
[...]
doctest.testmod()
看起来像
问题是code
和pre
之间的空白:
#!/usr/bin/env python
import re, fnmatch, os
def removeWhitespace(file_path):
#read file content
with open(file_path) as f:
content = f.read()
#replace whitespace
openingTag = re.compile('<pre>\s*<code', re.DOTALL)
closingTag = re.compile('</code>\s*</pre>', re.DOTALL)
if re.findall(openingTag, content):
content = re.sub(openingTag, '<pre><code', content)
content = re.sub(closingTag, '</code></pre>', content)
#write without whitespace
with open(file_path,'w') as f:
f.write(content)
# Get all HTML files
files = []
for root, dirnames, filenames in os.walk('.'):
for filename in fnmatch.filter(filenames, '*.html'):
files.append(os.path.join(root, filename))
for filename in files:
removeWhitespace(filename)
我怎么能告诉杰基尔不要在标签之间加空格
- 用这个
- 我的Jekyll版本是
Jekyll 1.3.1
- 在
我发现我的gem位于gem环境中
/var/lib/gems/1.9.1
- 使用
我发现highlight标记在grep-rn“highlight”-exclude dir=site--exclude dir=test*
/var/lib/gems/1.9.1/gems/jekyll-1.3.1/lib/jekyll/tags/highlight.rb中被解析
- 由于这可能是一个杰基尔虫,我补充说
现在出现了奇怪的部分:
highlight.rb
似乎没有在
和
之间添加任何空格,这与样式表有关
#!/usr/bin/env python
import re, fnmatch, os
def removeWhitespace(file_path):
#read file content
with open(file_path) as f:
content = f.read()
#replace whitespace
openingTag = re.compile('<pre>\s*<code', re.DOTALL)
closingTag = re.compile('</code>\s*</pre>', re.DOTALL)
if re.findall(openingTag, content):
content = re.sub(openingTag, '<pre><code', content)
content = re.sub(closingTag, '</code></pre>', content)
#write without whitespace
with open(file_path,'w') as f:
f.write(content)
# Get all HTML files
files = []
for root, dirnames, filenames in os.walk('.'):
for filename in fnmatch.filter(filenames, '*.html'):
files.append(os.path.join(root, filename))
for filename in files:
removeWhitespace(filename)
我能够使用默认设置在我的测试环境中构建您的示例页面,没有任何问题*
尝试将以下内容添加到style.css
*我唯一的问题是它抱怨了下面这句话
是一个静态博客生成器。
这个问题是由液体引起的,液体是Jekyll的模板引擎(参见液体和Jekyll的模板引擎)
当前(12.12.2013)对这个问题的答案是:你不能阻止Jekyll添加这些空格
但解决根本问题的方法是在编译完所有页面后删除空白。为此,我编写了以下Python脚本:
!/usr/bin/env python
导入re、fnmatch、os
def removeWhitespace(文件路径):
#读取文件内容
打开(文件路径)为f时:
content=f.read()
#替换空白
openingTag=re.compile('\s*否,这不会解决问题(请参阅最新版本)好的。我将尝试更多的调整。这肯定是CSS问题,而不是Jekyll问题。当你删除
和
之间的空格时,你会发现添加的空格是个问题。有些东西添加了这个空格,我认为它是Jekyll。请删除你的“答案”"因为它没有回答我的问题。当我在示例页面上查看源代码时,我没有看到任何多余的空格。另外,正如我所说,使用默认样式在我的测试安装上构建页面时没有任何问题。我添加了一个代码行的图像。请看一看。它肯定在那里。我看了你的。只是出于好奇泰,为什么你在你的标记文件中使用HTML标记?为什么你不使用标记?我目前正在尝试从WordPress迁移到Jekyll。原因很简单,我以前有HTML。我目前不确定是否要切换。使用HTML的一个优点是我知道语法。Jekyll确实支持HTML文件。如果你打算使用pu在您的帖子中重新使用HTML,我建议您将文件扩展名从.markdown
更改为.HTML
。这样您的帖子就不会通过markdown处理器发送。谢谢您的提醒。由于markdown可能是另一个错误源,我已切换到.HTML
文件。问题仍然存在。我也尝试过将文件扩展名更改为.html
,但这并没有解决任何问题。我还将您的帖子转换为markdown,这仍然会产生相同的错误。由于在这两种情况下
和
标记之间都添加了空格,我认为这是处理器和{%highlight bash%}
标记的问题。