9

私は現在、Jekyll を試しています。ほとんどのものは問題ないように見えますが、Jekyll がコードの強調表示を処理する方法にはバグがあるようです。

顔料を使用しています。

次に、Jekyll は次のようなピースを使用しているようです。

{% 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>

次のように見えます

ここに画像の説明を入力

ここに画像の説明を入力

code問題はとの間の空白preです:

ここに画像の説明を入力

これらのタグの間に空白を入れないように Jekyll に指示するにはどうすればよいですか?

バグハンティング

  • 私のJekyllバージョンはjekyll 1.3.1.
  • gem environment、私の宝石が にあることがわかりました/var/lib/gems/1.9.1
  • ハイライトタグが解析されること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
  • これは Jekyll のバグかもしれないので、Issue 1801を追加しました

と の間に空白highlight.rbを追加しないようです。<pre><code>

4

2 に答える 2

4

この問題は、Jekyll のテンプレート エンジンである Liquid が原因で発生します ( Liquid のIssue 216およびJekyll のIssue 1806を参照)。

この質問に対する現在 (2013 年 12 月 12 日) の回答は次のとおりです。

しかし、根本的な問題を解決するには、すべてのページがコンパイルされた後に空白を削除します。そのために、次の Python スクリプトを作成しました。

#!/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)
于 2013-12-11T23:44:19.470 に答える