| Class | HtmlBlock |
| In: |
lib/webgen/content.rb
|
| Parent: | Object |
A single block within a page file. The content of the block gets automatically parsed for HTML headers with the id attribute set and converts them into sections for later use.
| SECTION_REGEXP | = | /<h([123456])(?:>|\s([^>]*)>)(.*?)<\/h\1\s*>/i | ||
| ATTR_REGEXP | = | /\s*(\w+)\s*=\s*('|")([^\2]+)\2\s*/ |
| content | [R] | The content of the block. |
| name | [R] | The name of the block. |
| sections | [R] | The parsed sections as array of Section objects. |
# File lib/webgen/content.rb, line 82
82: def self.parse_sections( content )
83: sections = []
84: stack = []
85: content.scan( SECTION_REGEXP ).each do |level,attrs,title|
86: next if attrs.nil?
87: id_attr = attrs.scan( ATTR_REGEXP ).find {|name,sep,value| name == 'id'}
88: next if id_attr.nil?
89: id = id_attr[2]
90:
91: section = Section.new( level.to_i, id, title )
92: success = false
93: while !success
94: if stack.empty?
95: sections << section
96: stack << section
97: success = true
98: elsif stack.last.level < section.level
99: stack.last.subsections << section
100: stack << section
101: success = true
102: else
103: stack.pop
104: end
105: end
106: end
107: sections
108: end