File: h.rb

package info (click to toggle)
ruby-reverse-markdown 3.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 472 kB
  • sloc: ruby: 1,558; makefile: 4
file content (20 lines) | stat: -rw-r--r-- 533 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
module ReverseMarkdown
  module Converters
    class H < Base
      def convert(node, state = {})
        prefix = '#' * node.name[/\d/].to_i
        content = treat_children(node, state).strip
        # Merge lines into one (markdown headings can't span multiple lines)
        content = content.split(/\s*\n\s*/).join(' ')
        "\n#{prefix} #{content}\n"
      end
    end

    register :h1, H.new
    register :h2, H.new
    register :h3, H.new
    register :h4, H.new
    register :h5, H.new
    register :h6, H.new
  end
end