How to support scrolling when using pygments with Jekyll

我们两清 提交于 2019-11-29 02:19:56

问题


Is it possible to use horizontal scrolling rather than text wrapping in a code section highlughted with pygments when working in Jekyll.

Source of document:

{% highlight bash %}

Full thread dump OpenJDK Client VM (19.0-b09 mixed mode, sharing):

"Attach Listener" daemon prio=10 tid=0x0a482400 nid=0x5105 waiting on condition [0x00000000]
java.lang.Thread.State: RUNNABLE
....
{% endhighlight %}

Generated page (Notice the hex address being wrapped rather than scrolled):


回答1:


Find your highlight.css at: /PROJECT_ROOT/assets/themes/THEME_NAME/css/highlight.css

and add this line at the end:

pre { white-space: pre; overflow: auto; }

Thanks @manatwork for the solution.




回答2:


this answer deals specifically with using pygments and jekyll on github pages

the highlighting is generated thusly:

<div class="highlight">
  <pre>
    <code>
      ... pygments highlighting spans ...
    </code>
  </pre>
</div>

the css that will get you where you want is:

// -- selector prefixed to the wrapper div for collision prevention

.highlight pre code * {
  white-space: nowrap;    // this sets all children inside to nowrap
}

.highlight pre {
  overflow-x: auto;       // this sets the scrolling in x
}

.highlight pre code {
  white-space: pre;       // forces <code> to respect <pre> formatting
}



回答3:


I was using Jekyll and Twitter Bootstrap, and the following is what worked for me in the end:

.highlight pre {
    word-wrap: normal;
}

.highlight pre code {
    white-space: pre;
}



回答4:


As for me, using the latest and greates Jekyll & highlighter releases, this nailed the issue:

/* Make code block overflow */
.highlight pre {
  display: inline-block;
}


来源:https://stackoverflow.com/questions/11093233/how-to-support-scrolling-when-using-pygments-with-jekyll

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!