class Snippeteer::LiquidHighlightScanner
A very simple parser for Jekyll pages that tries to extract code from Liquid highlight tags and partition it by language. Should just work as long as you don't give it nested highlight blocks or something like that.
Constants
- ENDHIGHLIGHT
- HIGHLIGHT
Public Class Methods
new(doc)
click to toggle source
# File lib/snippeteer.rb, line 120 def initialize(doc) @lines = doc.lines.each @snips = [] end
scan(doc)
click to toggle source
# File lib/snippeteer.rb, line 116 def self.scan(doc) new(doc).scan end
Public Instance Methods
scan()
click to toggle source
# File lib/snippeteer.rb, line 125 def scan unhighlit rescue StopIteration @snips end
Private Instance Methods
highlit(lang)
click to toggle source
# File lib/snippeteer.rb, line 132 def highlit(lang) snip = Snippet.new lang, "" until (l = @lines.next) =~ ENDHIGHLIGHT snip.code += l end @snips << snip unhighlit end
unhighlit()
click to toggle source
# File lib/snippeteer.rb, line 141 def unhighlit until (l = @lines.next) =~ HIGHLIGHT; end highlit Lang.find $1 end