2

I'm using Prettify (from Google Code - https://code.google.com/p/google-code-prettify/). When one adds the linenums attribute then it renders the program using alternating background colors on each line (i.e., it uses "stripes" or "piano keys"). When one removes that attribute Prettify no longer stripes the lines.

Is it possible to get Prettify to stripe source code WITHOUT also adding line numbers?

Kara
  • 6,115
  • 16
  • 50
  • 57
MikeTheTall
  • 3,214
  • 4
  • 31
  • 40

2 Answers2

2

If you look at the themes gallery you'll see that this is affected by the stylesheet, and that there are some with line numbers on every line.


Something like

<style>li.L4, li.L9 { list-style-type: none }</style>

should do it.

The operative part of the default stylesheet is

li.L0,
li.L1,
li.L2,
li.L3,
li.L5,
li.L6,
li.L7,
li.L8 { list-style-type: none }

which turns off list bulleting for all items with index i where (i % 10) ∉ (4,9), hence the li.L4, li.L9 selector fills the gaps.

Mike Samuel
  • 118,113
  • 30
  • 216
  • 245
0

Answer is yes. Mike Samuel's answer seems to misinterpret or ignore the question.

The "piano keys" striping of code (not line numbers) occurs with every other line of text having an alternating background color whenever line numbers are requested. I wanted to turn it off when showing line numbers, but the original questioner wanted to know how to turn it on (like for an Excel spreadsheet) but without showing line numbers. Neither question, however, would seem to have anything to do with the line numbers or the li style directly, hence the confusion.

To fix this, a background-color property can be added; this overrides the striping colors of the numbered prettify commands and allows custom stripes.

An answer to both my problem and the original was eventually found. A style was added to override the current prettify code such as the following. You must still specify linenums in the prettify class but none will be shown:

highlight every 5th line no nums:

<style>
 li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8
   { background:#000022  !important; list-style-type:none !important}
 li.L4,li.L9
   { background:#080833  !important; list-style-type:none !important}
</style>

highlight every 5th line with nums:

 <style>
  li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8
    { background:#000022  !important; list-style-type:decimal !important}
  li.L4,li.L9
    { background:#080833  !important; list-style-type:decimal !important}
 </style>

Important: there is no comma before the curly bracket. If you insert such a comma the style will fail!

Toby Speight
  • 27,591
  • 48
  • 66
  • 103