Pygments syntax highlighting in Jekyll without starting a

后端 未结 4 1400
心在旅途
心在旅途 2021-01-21 06:18

If you use Jekyll with the Pygments syntax-highlighting package, it’s possible to write

{% highlight clojure %}
(def something :foobar)
{% endhighlight %}


        
相关标签:
4条回答
  • 2021-01-21 07:02

    You can add a CSS class to any object you put in a post.

    If you define a CSS entry like this:

    .inlined { display:inline; }
    

    You can then add this class to the generated <div> doing this:

    In Clojure, keywords like 
    {% highlight clojure %}:foobar{% endhighlight %}{: .inlined } 
    are prepended by colons.
    

    This works with all kind of objects (tables, images, etc). I can not test it right now, but I think this will solve the issue.

    When you test it, look at the output HTML. You will then find that your <div> now has the class=inlined attribute set.

    0 讨论(0)
  • 2021-01-21 07:06

    My quick workaround was letting Jekyll preprocess the code:

    <div class="highlight">
        <code class="language-css" data-lang="css">…</code>
    </div>
    

    And paste it into a desirable place after replacing divs with spans:

    <span class="highlight">
        <code class="language-css" data-lang="css">…</code>
    </span>    
    
    0 讨论(0)
  • 2021-01-21 07:07

    I think that you can use the nowrap option to prevent Pygments from wrapping the code in a div tag. So your example would become:

    In Clojure, keywords like 
    <span class='highlight'><code class='closure'>
    {% highlight clojure nowrap %}:foobar{% endhighlight %}
    </code></span>
    are prepended by colons.
    
    0 讨论(0)
  • 2021-01-21 07:12

    Two years later, I went ahead and created my own Jekyll plugin to provide inline syntax highlighting. It’s called inline_highlight and it can be used like so:

    In Clojure, keywords like {% ihighlight clojure %}:foobar{% endihighlight %}
    are prepended by colons.
    
    0 讨论(0)
提交回复
热议问题