forked from telerik/winforms-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtabbedCode_generator.rb
More file actions
38 lines (32 loc) · 1.09 KB
/
tabbedCode_generator.rb
File metadata and controls
38 lines (32 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
module Reading
class TabbedCodeGenerator < Jekyll::Generator
def generate(site)
@site = site
@converter = site.getConverterImpl(Jekyll::Converters::Markdown)
site.pages.each do |p|
createTabbedCode(p, p.content)
end
end
def createTabbedCode(page, content)
tab_start = /````\w/
tab_end = /````\s{2,}/
first_index = content.index(tab_start)
last_index = first_index && content.index(tab_end, first_index)
indexes = []
while first_index && !indexes.include?(first_index)
if last_index.nil?
Jekyll.logger.warn "Tabbed Code Error:", "Failed to generate tabbed code in #{page.path}"
end
indexes.push(first_index)
block = encode_liquid(content[first_index..last_index + 4])
block = @converter.convert(block)
content[first_index..last_index + 4] = "<div class='tabbedCode'>" + block + "</div>"
first_index = content.index(tab_start, last_index)
last_index = first_index && content.index(tab_end, last_index + 4)
end
end
def encode_liquid(content)
content = content.gsub("{{", "{{ '{{' }}")
end
end
end