Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent line-wraps of code blocks using jekyll, kramdown, and rouge

Using kramdown and rouge for markdown syntax-highlighting in a jekyll blog, I'd like to prevent long lines of code from wrapping onto a new line. I'd like to be able to use a horizontal scrollbar to reveal the rest of the content.

Here is the jekyll config:

markdown: kramdown
kramdown:
  input: GFM
  syntax_highlighter: rouge

I'm using the base16.solarized.dark css theme generated by the rougify command.

Here is an example code usage:

```` js
console.log("some code") // and a really really long long long comment which i'd like to not wrap onto the next line
````
like image 586
s2t2 Avatar asked Apr 14 '16 02:04

s2t2


3 Answers

Boostrap is adding a white-space: pre-wrap rule in order to help code block readability.

If you want you code block to avoid this wrap, you can edit your css/data-creative.css and add

pre code{
  white-space: pre;
}
like image 192
David Jacquel Avatar answered Nov 29 '22 23:11

David Jacquel


You have somewhere a CSS rule that for the code element sets white-space: pre-wrap. Add the following rule to override it:

code {
    white-space: pre;
}
like image 36
Alex Palcuie Avatar answered Nov 30 '22 01:11

Alex Palcuie


I solved it like this:

pre {
    ...
    overflow-x: scroll;
}
like image 42
Enes Başpınar Avatar answered Nov 30 '22 01:11

Enes Başpınar