File: hiki_formatter.rb

package info (click to toggle)
hiki 1.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 1,812 kB
  • ctags: 2,033
  • sloc: ruby: 14,572; lisp: 926; sh: 19; makefile: 16
file content (44 lines) | stat: -rw-r--r-- 947 bytes parent folder | download | duplicates (5)
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
# $Id: hiki_formatter.rb,v 1.8 2008-01-06 05:49:30 znz Exp $
# Copyright (C) 2003 TAKEUCHI Hitoshi <hitoshi@namaraii.com>

module Hiki
  class HikiFormatter
    H2_RE = /^<h2>.*<a name=/

    def apply_tdiary_theme(orig_html)
      return orig_html if @conf.mobile_agent?
      section = ''
      title   = ''
      html    = ''

      orig_html.each_line do |line|
        if H2_RE =~ line
          html << tdiary_section(title, section) unless title.empty? && section.empty?
          section = ''
          title = line
        else
          section << line
        end
      end
      html << tdiary_section(title, section)
    end

    private

    def tdiary_section(title, section)
      title = title.strip
      section = section.strip
      return '' if title.empty? && section.empty?
<<"EOS"
<div class="day">
  #{title}
  <div class="body">
    <div class="section">
      #{section}
    </div>
  </div>
</div>
EOS
    end
  end
end