oreillymedia / HTMLBook

Let's write books in HTML!
http://oreillymedia.github.io/HTMLBook
MIT License
650 stars 100 forks source link

Adding support for code-listing line numbering #201

Closed sandersk closed 8 years ago

sandersk commented 8 years ago

Added handling to toggle on line numbering for code listings, e.g., change the following:

<pre data-type="programlisting" data-line-numbering="numbered">if css_filename
  options[:css_filename] ||= css_filename
  open(css_filename, "w") {|css_file| css_file.write(result)}
  nil
else
  result
end</pre>

to:

<pre data-type="programlisting" data-line-numbering="numbered"><span class="line-number">1 </span>if css_filename
<span class="line-number">2 </span>  options[:css_filename] ||= css_filename
<span class="line-number">3 </span>  open(css_filename, "w") {|css_file| css_file.write(result)}
<span class="line-number">4 </span>  nil
<span class="line-number">5 </span>else
<span class="line-number">6 </span>  result
<span class="line-number">7 </span>end</pre>

Line numbering can be turned on in one of two ways:

<xsl:param name="number.code.lines" select="1"/>

All line numbers are wrapped in <span class="line-number"> to facilitate styling via CSS if desired.