Class: Kramdown::Converter::Html
- Inherits:
-
Base
- Object
- Base
- Kramdown::Converter::Html
- Defined in:
- lib/kramdown-respec.rb
Overview
class HtmlRESPEC < Html
Instance Method Summary collapse
-
#convert_header(el, indent) ⇒ Object
def convert_root(el, indent) result = super # Close the last sections that remain opened current_header_level = 2 while @respec_last_header_level > current_header_level result = “</section>nn” @respec_last_header_level -= 1 end result “</section>nn” end.
-
#convert_root(el, indent) ⇒ Object
Initialize the HTML converter with the given Kramdown document
doc
. -
#initialize(root, options) ⇒ Html
constructor
Initialize the HTML converter with the given Kramdown document
doc
.
Constructor Details
#initialize(root, options) ⇒ Html
Initialize the HTML converter with the given Kramdown document doc
.
245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/kramdown-respec.rb', line 245 def initialize(root, ) super @footnote_counter = @footnote_start = @options[:footnote_nr] @footnotes = [] @footnotes_by_name = {} @footnote_location = nil @toc = [] @toc_code = nil @indent = 2 @stack = [] @respec_first_section = true @respec_last_header_level = 0 end |
Instance Method Details
#convert_header(el, indent) ⇒ Object
def convert_root(el, indent)
result = super
# Close the last sections that remain opened
current_header_level = 2
while @respec_last_header_level > current_header_level
result += "</section>\n\n"
@respec_last_header_level -= 1
end
result + "</section>\n\n"
end
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
# File 'lib/kramdown-respec.rb', line 301 def convert_header(el, indent) res = "" current_header_level = el.[:level] if @respec_first_section @respec_first_section = false @respec_last_header_level = current_header_level else if @respec_last_header_level < current_header_level @respec_last_header_level = current_header_level else while @respec_last_header_level > current_header_level res += "#{' ' * indent}</section>\n\n" @respec_last_header_level -= 1 end res += "#{' ' * indent}</section>\n\n" end end if el.[:respec_section] res += "#{' ' * indent}<section#{html_attributes(el.[:respec_section])}>\n" else res += "#{' ' * indent}<section>\n" end # res + super attr = el.attr.dup if @options[:auto_ids] && !attr['id'] attr['id'] = generate_id(el.[:raw_text]) end @toc << [el.[:level], attr['id'], el.children] if attr['id'] && in_toc?(el) level = output_header_level(el.[:level]) res + format_as_block_html("h#{level}", attr, inner(el, indent), indent) end |
#convert_root(el, indent) ⇒ Object
Initialize the HTML converter with the given Kramdown document doc
. def initialize(root, options)
super
@respec_first_section = true
@respec_last_header_level = 0
end
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
# File 'lib/kramdown-respec.rb', line 265 def convert_root(el, indent) result = inner(el, indent) if @footnote_location result.sub!(/#{@footnote_location}/, footnote_content.gsub(/\\/, "\\\\\\\\")) else result << footnote_content end if @toc_code toc_tree = generate_toc_tree(@toc, @toc_code[0], @toc_code[1] || {}) text = if toc_tree.children.size > 0 convert(toc_tree, 0) else '' end result.sub!(/#{@toc_code.last}/, text.gsub(/\\/, "\\\\\\\\")) end # Close the last sections that remain opened current_header_level = 2 while @respec_last_header_level > current_header_level result += "</section>\n\n" @respec_last_header_level -= 1 end result + "</section>\n\n" result end |