2017-10-04 38 views
0

我正嘗試在我的gh頁面博客上創建一些代碼塊,但我遇到了一些問題。問題使用GFM在Jekyll中創建圍柵代碼塊

這是在我的_config.yml

#Stuff I have added 
highlight: rouge 
markdown: kramdown 

kramdown: 
    input: GFM 
    highlighter: rouge 

現在我試圖如下運行這段代碼,

~~~ 
Is this really how code should be represented? 

Answer = NO!!! 
~~~ 

但這

enter image description here

請幫幫忙,我只想要好的圍欄代碼結構謝謝!

+2

什麼是理想的輸出創造圍欄代碼塊?你沒有指定任何語言,並沒有代碼,所以我沒有看到任何問題的方式工作 – marcanuy

+0

我希望代碼有一個很好的圍欄結構,但(如圖所示)我目前的設置就好像它在行代碼中看起來很糟糕。 –

+0

「好圍欄結​​構」是什麼意思? '柵欄'是_source_中的'〜'字符(或者某些變體中的字符),與原來的使用縮進代碼的Markdown規範不同(它有時可能有點難以用於複製/粘貼等) )。 – matt

回答

0

它沒有顯示源代碼的圍欄,因爲沒有源代碼

如果不指定任何東西,然後它會使用:

<div class="highlighter-rouge"><pre class="highlight"><code> 
Is this really how code should be represented? 

Answer = NO!!! 
</code></pre> 
</div> 

你總是要定製使用像highlighter-rouge生成的類的輸出選項。

在另一方面,如果你指定語言:

~~~ html 
<html> 
<body> 
<p>Is this really how code should be represented?</p> 
<div>Answer = NO!!!</div> 
</body> 
</html> 
~~~ 

那麼它會產生更多的spific造型:

<div class="language-html highlighter-rouge"><pre class="highlight"><code><span class="nt">&lt;html&gt;</span> 
<span class="nt">&lt;body&gt;</span> 
<span class="nt">&lt;p&gt;</span>Is this really how code should be represented?<span class="nt">&lt;/p&gt;</span> 
<span class="nt">&lt;div&gt;</span>Answer = NO!!!<span class="nt">&lt;/div&gt;</span> 
<span class="nt">&lt;/body&gt;</span> 
<span class="nt">&lt;/html&gt;</span> 
</code></pre> 
</div> 

如果您仍然無法看到任何默認的語法高亮,那麼包含這些類的css就會丟失,典型的Jekyll自帶_syntax-highlighting.scss,它已經包含了它們,但是你可以使用你想要的配色方案,例如默認的主題使用這個:https://github.com/jekyll/minima/blob/master/_sass/minima/_syntax-highlighting.scss

或者你可以安裝任何你想要的高棉主題:https://github.com/jneen/rouge/tree/master/lib/rouge/themes

$ rougify foo.rb 
$ rougify style monokai.sublime > syntax.css 
0

嘗試用三重反引號```代替了三重波浪線~~~

 
``` 
Is this really how code should be represented in GFM? 

Answer = YEP!!! 
``` 
+0

不,我已經嘗試過使用'''和~~~以及沒有GFM的redcarpet和kramdown。所有的結果都給我提供了與我的代碼一樣的總體逐行柵欄。 –

+0

如果@marcanuy的更新答案不能解決您的問題,您需要發佈一個公共鏈接到您的回購站,以便人們可以嘗試重現這種情況。否則,這隻會​​最終成爲一個XY問題 – ashmaroli