class Kramdown::Converter::Rfc2629

def convert_codeblock(el, indent, opts)

def convert_codeblock(el, indent, opts)
  # el.attr['anchor'] ||= saner_generate_id(el.value) -- no longer in 1.0.6
  result = el.value
  gi = el.attr.delete('gi')
  blockclass = el.attr.delete('class')
  if blockclass == 'language-tbreak'
    result = result.lines.map {|line| [line.chomp, 0]}
    spaceind = 0
    result.each_with_index {|pair, index|
      if pair[0] == ''
        result[spaceind][1] += 1
        pair[0] = nil unless index == spaceind
      else
        spaceind = index
      end
    }
    # $stderr.puts(result.inspect)
    result = result.map {|line, space|
      "<![CDATA[#{line.gsub(/^\s+/) {|s| "\u00A0" * s.size}}]]><vspace blankLines=\"#{space}\"/>" if line
    }.compact.join("\n")
    "#{' '*indent}<t>#{result}</t>\n"
  else
    artwork_attr = {}
    t = nil
    if blockclass
      classes = blockclass.split(' ')
      classes.each do |cl|
        if md = cl.match(/\Alanguage-(.*)/)
          t = artwork_attr["type"] = md[1] # XXX overwrite
        else
          $stderr.puts "*** Unimplemented codeblock class: #{cl}"
        end
      end
    end
    # compensate for XML2RFC idiosyncrasy by insisting on a blank line
    unless el.attr.delete('tight')
      result[0,0] = "\n" unless result[0,1] == "\n"
    end
    el.attr.each do |k, v|
      if md = k.match(/\A(?:artwork|sourcecode)-(.*)/)
        el.attr.delete(k)
        artwork_attr[md[1]] = v
      end
    end
    case t
    when "aasvg", "ditaa", "goat",
         "math", "math-asciitex", "mermaid",  "mscgen",
         "plantuml", "plantuml-utxt",
         "protocol", "protocol-aasvg", "protocol-goat",
         "railroad", "railroad-utf8"
      if gi
        warn "*** Can't set GI #{gi} for composite SVG artset"
      end
      result, result1 = memoize(:svg_tool_process, t,
                                artwork_attr.delete("svg-options"),
                                artwork_attr.delete("txt-options"),
                                result)
      retart = mk_artwork(artwork_attr, "ascii-art",
                          "<![CDATA[#{result}#{result =~ /\n\Z/ ? '' : "\n"}]]>")
      if result1          # nest TXT in artset with SVG
        retsvg = mk_artwork(artwork_attr, "svg",
                            result1.sub(/.*?<svg/m, "<svg"))
        retart = "<artset>#{retsvg}#{retart}</artset>"
      end
      "#{' '*indent}<figure#{el_html_attributes(el)}>#{retart}</figure>\n"
    else
      gi ||= (
        if !$options.v3 || !t || ARTWORK_TYPES.include?(t) || artwork_attr["align"]
          "artwork"
        else
          "sourcecode"
        end
      )
      loc_str =
        if anchor = el.attr['anchor']
          "##{anchor}"
        elsif lineno = el.options[:location]
          "#{correct_location(lineno)}"
        else
          "UNKNOWN"
        end
      preprocs = el.attr.delete("pre")
      checks = el.attr.delete("check")
      postprocs = el.attr.delete("post")
      case t
      when "cbor"
        warn "** There is no sourcecode-type “cbor”."
        warn "**   Do you mean “cbor-diag” (diagnostic notation)"
        warn "**   or “cbor-pretty” (annotated hex-dump)?"
      when "json"
        checks ||= "json"
      when /\A(.*)-from-yaml\z/
        t = $1
        preprocs ||= "yaml2json"
      end
      preprocs = (preprocs || '').split("-")
      checks = (checks || '').split("-")
      postprocs = (postprocs || '').split("-")
      result = sourcecode_checkproc(preprocs, checks, postprocs, loc_str, result)
      "#{' '*indent}<figure#{el_html_attributes(el)}><#{gi}#{html_attributes(artwork_attr)}><![CDATA[#{result}#{result =~ /\n\Z/ ? '' : "\n"}]]></#{gi}></figure>\n"
    end
  end
end