File: render_man.rb

package info (click to toggle)
ruby-redcarpet 3.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 360 kB
  • sloc: ansic: 4,595; ruby: 261; makefile: 4
file content (65 lines) | stat: -rw-r--r-- 1,186 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
module Redcarpet
  module Render
    class ManPage < Base

      def normal_text(text)
        text.gsub('-', '\\-').strip
      end

      def block_code(code, language)
        "\n.nf\n#{normal_text(code)}\n.fi\n"
      end

      def codespan(code)
        block_code(code, nil)
      end

      def header(title, level)
        case level
        when 1
          "\n.TH #{title}\n"

        when 2
          "\n.SH #{title}\n"

        when 3
          "\n.SS #{title}\n"
        end
      end

      def double_emphasis(text)
        "\\fB#{text}\\fP"
      end

      def emphasis(text)
        "\\fI#{text}\\fP"
      end

      def linebreak
        "\n.LP\n"
      end

      def paragraph(text)
        "\n.TP\n#{text}\n"
      end

      def list(content, list_type)
        case list_type
        when :ordered
          "\n\n.nr step 0 1\n#{content}\n"
        when :unordered
          "\n.\n#{content}\n"
        end
      end

      def list_item(content, list_type)
        case list_type
        when :ordered
          ".IP \\n+[step]\n#{content.strip}\n"
        when :unordered
          ".IP \\[bu] 2 \n#{content.strip}\n"
        end
      end
    end
  end
end