BVB Source Codes

rouge Show html_table.rb Source code

Return Download rouge: download html_table.rb Source code - Download rouge Source code - Type:.rb
  1. # -*- coding: utf-8 -*- #
  2.  
  3. module Rouge
  4.   module Formatters
  5.     class HTMLTable < Formatter
  6.       tag 'html_table'
  7.  
  8.       def initialize(inner, opts={})
  9.         @inner = inner
  10.         @start_line = opts.fetch(:start_line, 1)
  11.         @line_format = opts.fetch(:line_format, '%i')
  12.         @table_class = opts.fetch(:table_class, 'rouge-table')
  13.         @gutter_class = opts.fetch(:gutter_class, 'rouge-gutter')
  14.         @code_class = opts.fetch(:code_class, 'rouge-code')
  15.       end
  16.  
  17.       def style(scope)
  18.         yield "#{scope} .rouge-table { border-spacing: 0 }"
  19.         yield "#{scope} .rouge-gutter { text-align: right }"
  20.       end
  21.  
  22.       def stream(tokens, &b)
  23.         num_lines = 0
  24.         last_val = ''
  25.         formatted = ''
  26.  
  27.         tokens.each do |tok, val|
  28.           last_val = val
  29.           num_lines += val.scan(/\n/).size
  30.           formatted << @inner.span(tok, val)
  31.         end
  32.  
  33.         # add an extra line for non-newline-terminated strings
  34.         if last_val[-1] != "\n"
  35.           num_lines += 1
  36.           @inner.span(Token::Tokens::Text::Whitespace, "\n") { |str| formatted << str }
  37.         end
  38.  
  39.         # generate a string of newline-separated line numbers for the gutter>
  40.         formatted_line_numbers = (@start_line..num_lines+@start_line-1).map do |i|
  41.           sprintf("#{@line_format}", i) << "\n"
  42.         end.join('')
  43.  
  44.         numbers = %(<pre class="lineno">#{formatted_line_numbers}</pre>)
  45.  
  46.         yield %(<table class="#@table_class"><tbody><tr>)
  47.  
  48.         # the "gl" class applies the style for Generic.Lineno
  49.         yield %(<td class="#@gutter_class gl">)
  50.         yield numbers
  51.         yield '</td>'
  52.  
  53.         yield %(<td class="#@code_class"><pre>)
  54.         yield formatted
  55.         yield '</pre></td>'
  56.  
  57.         yield "</tr></tbody></table>\n"
  58.       end
  59.     end
  60.   end
  61. end
  62.  
downloadhtml_table.rb Source code - Download rouge Source code
Related Source Codes/Software:
spring-security-oauth - Support for adding OAuth1(a) and OAuth2 features (... 2017-04-23
Toucan - Fabulous Image Processing in Swift 2017-04-23
CoffeeScriptRedux - 2017-04-23
breakpoint - Really simple media queries in Sa 2017-04-23
libsvm - 2017-04-22
sphinx_rtd_theme - Sphinx theme for readthedocs.org 2017-04-23
BlurEffectForAndroidDesign - Sample to show how to implement blur graphical tri... 2017-04-23
mama2 - Mother plan - all firewood high flame 2017-04-23
JKeyboardPanelSwitch - For resolve the layout conflict when keybord & amp... 2017-04-23
viz.js - A hack to put Graphviz on the web. ... 2017-04-23
browser-diet - 2017-04-30
react-music - Make beats with React! http... 2017-04-30
java-code-styles - IntelliJ IDEA code style settings for Square's Jav... 2017-04-30
swing - A swipeable cards interface. The swipe-left/swipe-... 2017-04-30
qTip2 - qTip2 - Pretty powerful tooltips ... 2017-04-30
jo - JSON output from a shell 2017-04-30
Fluidbox - Replicating and improving the lightbox module seen... 2017-04-30
boto3 - AWS SDK for Python http://a... 2017-04-30
PreloadJS - PreloadJS makes preloading assets & getting ag... 2017-04-29
gotraining - Go Training Class Material : ... 2017-04-29

 Back to top