105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
# File 'lib/markascend/parser.rb', line 105
def parse_hx
hx = @src.scan /h[1-6](\#\w+(-\w+)*)?\ /
return unless hx
hx.strip!
if @env.sandbox
if @env.toc
id = "-#{@env.toc.size}"
end
else
if hx.size > 2
id = hx[3..-1]
elsif @env.toc
id = "-#{@env.toc.size}"
end
end
if id
id_attr = %Q{ id="#{id}"}
end
hx = hx[0...2]
@out << "<#{hx}#{id_attr}>"
line, block = scan_line_and_block
if line
out = []
LineUnit.new(@env, line, block).parse(out)
out.pop if out.last == :"<br>"
out.each do |token|
@out << token
end
if id and @env.toc
@env.toc[id] = [hx[1].to_i, out.join]
end
end
@out << "</#{hx}>"
@src.scan /\ *\n/ if (!block or block.empty?)
true
end
|