rabbit 0.9.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (213) hide show
  1. data/Gemfile +9 -2
  2. data/Rakefile +11 -4
  3. data/TODO +0 -2
  4. data/bin/rabbirack +95 -0
  5. data/bin/rabbit +23 -2
  6. data/bin/rabbiter +9 -0
  7. data/data/locale/en/LC_MESSAGES/rabbit.mo +0 -0
  8. data/data/locale/fr/LC_MESSAGES/rabbit.mo +0 -0
  9. data/data/locale/ja/LC_MESSAGES/rabbit.mo +0 -0
  10. data/doc/_layouts/en.html +1 -1
  11. data/doc/_layouts/ja.html +1 -1
  12. data/doc/_layouts/skeleton.html +1 -1
  13. data/doc/_site/css/rabbit.css +41 -1
  14. data/doc/_site/en/development.html +2 -2
  15. data/doc/_site/en/faq.html +2 -2
  16. data/doc/_site/en/hiki.html +2 -2
  17. data/doc/_site/en/how-to-make/hiki.html +2 -2
  18. data/doc/_site/en/how-to-make/index.html +2 -2
  19. data/doc/_site/en/how-to-make/pdf.html +2 -2
  20. data/doc/_site/en/how-to-make/rd.html +2 -2
  21. data/doc/_site/en/how-to-make/theme.html +2 -2
  22. data/doc/_site/en/index.html +20 -20
  23. data/doc/_site/en/install/homebrew.html +6 -12
  24. data/doc/_site/en/install/index.html +5 -3
  25. data/doc/_site/en/install/macports.html +2 -2
  26. data/doc/_site/en/install/windows.html +2 -2
  27. data/doc/_site/en/news.html +172 -61
  28. data/doc/_site/en/rd.html +2 -2
  29. data/doc/_site/en/sample/hiki/rabbit.html +3 -3
  30. data/doc/_site/en/sample/index.html +2 -2
  31. data/doc/_site/en/sample/rd/rabbit.html +3 -3
  32. data/doc/_site/en/slides.html +2 -2
  33. data/doc/_site/en/usage.html +60 -60
  34. data/doc/_site/en/users.html +2 -2
  35. data/doc/_site/images/screenshots/en/blue-circle.png +0 -0
  36. data/doc/_site/images/screenshots/en/clear-blue-raw.png +0 -0
  37. data/doc/_site/images/screenshots/en/clear-blue.png +0 -0
  38. data/doc/_site/images/screenshots/en/cozmixng-raw.png +0 -0
  39. data/doc/_site/images/screenshots/en/cozmixng.png +0 -0
  40. data/doc/_site/images/screenshots/en/dark-gradation.png +0 -0
  41. data/doc/_site/images/screenshots/en/day-white.png +0 -0
  42. data/doc/_site/images/screenshots/en/debian.png +0 -0
  43. data/doc/_site/images/screenshots/en/green-circle.png +0 -0
  44. data/doc/_site/images/screenshots/en/night-black.png +0 -0
  45. data/doc/_site/images/screenshots/en/rabbit-raw.png +0 -0
  46. data/doc/_site/images/screenshots/en/rabbit.png +0 -0
  47. data/doc/_site/images/screenshots/en/ranguba-raw.png +0 -0
  48. data/doc/_site/images/screenshots/en/ranguba.png +0 -0
  49. data/doc/_site/images/screenshots/en/red-frame.png +0 -0
  50. data/doc/_site/images/screenshots/en/ruby-gnome2.png +0 -0
  51. data/doc/_site/images/screenshots/ja/blue-circle.png +0 -0
  52. data/doc/_site/images/screenshots/ja/clear-blue-raw.png +0 -0
  53. data/doc/_site/images/screenshots/ja/clear-blue.png +0 -0
  54. data/doc/_site/images/screenshots/ja/cozmixng-raw.png +0 -0
  55. data/doc/_site/images/screenshots/ja/cozmixng.png +0 -0
  56. data/doc/_site/images/screenshots/ja/dark-gradation.png +0 -0
  57. data/doc/_site/images/screenshots/ja/day-white.png +0 -0
  58. data/doc/_site/images/screenshots/ja/debian.png +0 -0
  59. data/doc/_site/images/screenshots/ja/green-circle.png +0 -0
  60. data/doc/_site/images/screenshots/ja/night-black.png +0 -0
  61. data/doc/_site/images/screenshots/ja/rabbit-raw.png +0 -0
  62. data/doc/_site/images/screenshots/ja/rabbit.png +0 -0
  63. data/doc/_site/images/screenshots/ja/ranguba-raw.png +0 -0
  64. data/doc/_site/images/screenshots/ja/ranguba.png +0 -0
  65. data/doc/_site/images/screenshots/ja/red-frame.png +0 -0
  66. data/doc/_site/images/screenshots/ja/ruby-gnome2.png +0 -0
  67. data/doc/_site/index.html.en +8 -2
  68. data/doc/_site/index.html.ja +8 -2
  69. data/doc/_site/ja/about.html +2 -2
  70. data/doc/_site/ja/development.html +2 -2
  71. data/doc/_site/ja/faq.html +25 -14
  72. data/doc/_site/ja/hiki.html +2 -2
  73. data/doc/_site/ja/how-to-make/hiki.html +2 -2
  74. data/doc/_site/ja/how-to-make/index.html +2 -2
  75. data/doc/_site/ja/how-to-make/pdf.html +2 -2
  76. data/doc/_site/ja/how-to-make/rd.html +2 -2
  77. data/doc/_site/ja/how-to-make/theme.html +2 -2
  78. data/doc/_site/ja/index.html +2 -2
  79. data/doc/_site/ja/install/homebrew.html +6 -12
  80. data/doc/_site/ja/install/index.html +5 -3
  81. data/doc/_site/ja/install/macports.html +3 -6
  82. data/doc/_site/ja/install/windows.html +2 -2
  83. data/doc/_site/ja/news.html +165 -61
  84. data/doc/_site/ja/rd.html +2 -2
  85. data/doc/_site/ja/sample/hiki/rabbit.html +3 -3
  86. data/doc/_site/ja/sample/index.html +2 -2
  87. data/doc/_site/ja/sample/rd/rabbit.html +3 -3
  88. data/doc/_site/ja/slides.html +2 -2
  89. data/doc/_site/ja/usage.html +60 -69
  90. data/doc/_site/ja/users.html +2 -2
  91. data/doc/css/rabbit.css +41 -1
  92. data/doc/en/index.rd +1 -1
  93. data/doc/en/install/homebrew.rd +2 -11
  94. data/doc/en/install/index.rd +2 -0
  95. data/doc/en/news.rd +117 -3
  96. data/doc/en/sample/hiki/rabbit.hiki +1 -1
  97. data/doc/en/sample/rd/rabbit.rd +1 -1
  98. data/doc/en/usage.rd +12 -17
  99. data/doc/images/screenshots/en/blue-circle.png +0 -0
  100. data/doc/images/screenshots/en/clear-blue-raw.png +0 -0
  101. data/doc/images/screenshots/en/clear-blue.png +0 -0
  102. data/doc/images/screenshots/en/cozmixng-raw.png +0 -0
  103. data/doc/images/screenshots/en/cozmixng.png +0 -0
  104. data/doc/images/screenshots/en/dark-gradation.png +0 -0
  105. data/doc/images/screenshots/en/day-white.png +0 -0
  106. data/doc/images/screenshots/en/debian.png +0 -0
  107. data/doc/images/screenshots/en/green-circle.png +0 -0
  108. data/doc/images/screenshots/en/night-black.png +0 -0
  109. data/doc/images/screenshots/en/rabbit-raw.png +0 -0
  110. data/doc/images/screenshots/en/rabbit.png +0 -0
  111. data/doc/images/screenshots/en/ranguba-raw.png +0 -0
  112. data/doc/images/screenshots/en/ranguba.png +0 -0
  113. data/doc/images/screenshots/en/red-frame.png +0 -0
  114. data/doc/images/screenshots/en/ruby-gnome2.png +0 -0
  115. data/doc/images/screenshots/ja/blue-circle.png +0 -0
  116. data/doc/images/screenshots/ja/clear-blue-raw.png +0 -0
  117. data/doc/images/screenshots/ja/clear-blue.png +0 -0
  118. data/doc/images/screenshots/ja/cozmixng-raw.png +0 -0
  119. data/doc/images/screenshots/ja/cozmixng.png +0 -0
  120. data/doc/images/screenshots/ja/dark-gradation.png +0 -0
  121. data/doc/images/screenshots/ja/day-white.png +0 -0
  122. data/doc/images/screenshots/ja/debian.png +0 -0
  123. data/doc/images/screenshots/ja/green-circle.png +0 -0
  124. data/doc/images/screenshots/ja/night-black.png +0 -0
  125. data/doc/images/screenshots/ja/rabbit-raw.png +0 -0
  126. data/doc/images/screenshots/ja/rabbit.png +0 -0
  127. data/doc/images/screenshots/ja/ranguba-raw.png +0 -0
  128. data/doc/images/screenshots/ja/ranguba.png +0 -0
  129. data/doc/images/screenshots/ja/red-frame.png +0 -0
  130. data/doc/images/screenshots/ja/ruby-gnome2.png +0 -0
  131. data/doc/index.html.en +6 -0
  132. data/doc/index.html.ja +6 -0
  133. data/doc/ja/faq.rd +21 -3
  134. data/doc/ja/install/homebrew.rd +2 -11
  135. data/doc/ja/install/index.rd +2 -0
  136. data/doc/ja/install/macports.rd +1 -6
  137. data/doc/ja/news.rd +109 -3
  138. data/doc/ja/sample/hiki/rabbit.hiki +1 -1
  139. data/doc/ja/sample/rd/rabbit.rd +1 -1
  140. data/doc/ja/usage.rd +11 -29
  141. data/lib/rabbit/canvas.rb +7 -4
  142. data/lib/rabbit/console.rb +1 -1
  143. data/lib/rabbit/div/main-i.erb +1 -1
  144. data/lib/rabbit/div/main.erb +1 -1
  145. data/lib/rabbit/element/base.rb +17 -1
  146. data/lib/rabbit/element/image.rb +1 -0
  147. data/lib/rabbit/element/preformatted.rb +8 -3
  148. data/lib/rabbit/element/syntax-highlighting.rb +15 -0
  149. data/lib/rabbit/element/text-renderer.rb +3 -3
  150. data/lib/rabbit/element/text.rb +0 -12
  151. data/lib/rabbit/element/title-slide.rb +1 -25
  152. data/lib/rabbit/formatter.rb +26 -6
  153. data/lib/rabbit/front.rb +10 -6
  154. data/lib/rabbit/html/template.erb +1 -1
  155. data/lib/rabbit/image.rb +1 -1
  156. data/lib/rabbit/keys.rb +70 -70
  157. data/lib/rabbit/middleware/config.ru +42 -0
  158. data/lib/rabbit/middleware/controller.rb +66 -0
  159. data/lib/rabbit/middleware/public/stylesheets/rabbirack.css +12 -0
  160. data/lib/rabbit/middleware/views/index.haml +13 -0
  161. data/lib/rabbit/middleware/views/layout.haml +8 -0
  162. data/lib/rabbit/parser/ext/aafigure.rb +1 -1
  163. data/lib/rabbit/parser/ext/blockdiag.rb +46 -0
  164. data/lib/rabbit/parser/ext/coderay.rb +66 -0
  165. data/lib/rabbit/parser/ext/emacs.rb +116 -0
  166. data/lib/rabbit/parser/ext/enscript.rb +15 -22
  167. data/lib/rabbit/parser/rd.rb +8 -2
  168. data/lib/rabbit/parser/rd/ext/block-verbatim.rb +53 -16
  169. data/lib/rabbit/parser/wiki.rb +3 -1
  170. data/lib/rabbit/parser/wiki/output.rb +28 -16
  171. data/lib/rabbit/rabbit.rb +7 -1
  172. data/lib/rabbit/renderer/display.rb +14 -2
  173. data/lib/rabbit/renderer/display/clutter-embed.rb +1 -1
  174. data/lib/rabbit/renderer/display/key-handler.rb +12 -12
  175. data/lib/rabbit/soap/base.rb +1 -1
  176. data/lib/rabbit/theme-browser.rb +2 -2
  177. data/lib/rabbit/theme/base/base.rb +7 -0
  178. data/lib/rabbit/theme/default-comment/default-comment.rb +9 -0
  179. data/lib/rabbit/theme/default-comment/property.rb +4 -0
  180. data/lib/rabbit/theme/default-item-mark-setup/default-item-mark-setup.rb +1 -1
  181. data/lib/rabbit/theme/default-slide/default-slide.rb +2 -2
  182. data/lib/rabbit/theme/default-text/default-text.rb +5 -0
  183. data/lib/rabbit/theme/default/default.rb +6 -7
  184. data/lib/rabbit/theme/footer-comment/footer-comment.rb +35 -8
  185. data/lib/rabbit/theme/pdf/pdf.rb +18 -0
  186. data/lib/rabbit/theme/rabbit-powered-by/rabbit-powered-by.rb +1 -1
  187. data/lib/rabbit/theme/syntax-highlighting/property.rb +4 -0
  188. data/lib/rabbit/theme/syntax-highlighting/syntax-highlighting.rb +139 -0
  189. data/lib/rabbit/theme/title-shadow/title-shadow.rb +1 -1
  190. data/lib/rabbit/theme/twitter-comment/twitter-comment.rb +1 -1
  191. data/lib/rabbit/twitter.rb +28 -4
  192. data/lib/rabbit/utils.rb +40 -12
  193. data/po/en/rabbit.po +175 -145
  194. data/po/fr/rabbit.po +180 -149
  195. data/po/ja/rabbit.po +176 -148
  196. data/po/rabbit.pot +175 -145
  197. data/sample/can_rabbit.rd +0 -21
  198. data/sample/rabbit-en.hiki +21 -2
  199. data/sample/rabbit-en.rd +42 -2
  200. data/sample/rabbit-implementation.rd +0 -5
  201. data/sample/rabbit.hiki +19 -16
  202. data/sample/rabbit.rd +42 -11
  203. data/sample/test.hiki +31 -0
  204. data/sample/test.rab +30 -0
  205. metadata +84 -58
  206. data/lib/rabbit/parser/ext/anthy.rb +0 -43
  207. data/lib/rabbit/parser/rd/ext/aafigure.rb +0 -18
  208. data/lib/rabbit/parser/rd/ext/anthy.rb +0 -29
  209. data/lib/rabbit/parser/rd/ext/enscript.rb +0 -24
  210. data/lib/rabbit/parser/rd/ext/tex.rb +0 -24
  211. data/lib/rabbit/source/rwiki.rb +0 -54
  212. data/lib/rabbit/theme/pdf-tortoise-and-hare/pdf-tortoise-and-hare.rb +0 -18
  213. data/lib/rabbit/theme/pdf-tortoise-and-hare/property.rb +0 -3
@@ -0,0 +1,42 @@
1
+ # -*- mode: ruby; coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2011 Kouhei Sutou <kou@clear-code.com>
4
+ #
5
+ # This program is free software; you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation; either version 2 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program; if not, write to the Free Software
17
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
+
19
+ require "drb/drb"
20
+
21
+ require "rabbit/middleware/controller"
22
+
23
+ environment = ENV["RACK_ENV"] || "development"
24
+ case environment
25
+ when "development"
26
+ use Rack::ShowExceptions
27
+ end
28
+
29
+ use Rack::Runtime
30
+ use Rack::ContentLength
31
+
32
+ use Rack::Deflater
33
+ use Rack::ConditionalGet
34
+
35
+ use Rack::Lint
36
+ use Rack::Head
37
+
38
+ rabbit = DRbObject.new_with_uri(ENV["RABBIT_URI"])
39
+ application = Rabbit::Middleware::Controller.new do |controller|
40
+ controller.rabbit = rabbit
41
+ end
42
+ run application
@@ -0,0 +1,66 @@
1
+ # -*- mode: ruby; coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2011 Kouhei Sutou <kou@clear-code.com>
4
+ #
5
+ # This program is free software; you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation; either version 2 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program; if not, write to the Free Software
17
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
+
19
+ require "sinatra/base"
20
+
21
+ module Rabbit
22
+ module Middleware
23
+ class Controller < Sinatra::Base
24
+ attr_accessor :rabbit
25
+
26
+ set :app_file, File.join(File.dirname(__FILE__), "config.ru")
27
+
28
+ layout
29
+
30
+ before do
31
+ content_type("text/html", "charset" => "UTF-8")
32
+ end
33
+
34
+ get "/" do
35
+ haml :index
36
+ end
37
+
38
+ get "/pages/next" do
39
+ @rabbit.move_to_next_if_can
40
+ haml :index
41
+ end
42
+
43
+ get "/pages/previous" do
44
+ @rabbit.move_to_previous_if_can
45
+ haml :index
46
+ end
47
+
48
+ get "/pages/:number" do |number|
49
+ @rabbit.move_to_if_can(number.to_i)
50
+ haml :index
51
+ end
52
+
53
+ def title
54
+ "Rabbit"
55
+ end
56
+
57
+ def slide_title
58
+ current_slide_title = @rabbit.slide_title
59
+ if current_slide_title.respond_to?(:force_encoding)
60
+ current_slide_title.force_encoding("ASCII-8BIT")
61
+ end
62
+ current_slide_title
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,12 @@
1
+ ul,
2
+ ul li
3
+ {
4
+ display: inline;
5
+ }
6
+
7
+ .navi
8
+ {
9
+ font-size: 72px;
10
+ display: block;
11
+ padding: 1em;
12
+ }
@@ -0,0 +1,13 @@
1
+ %ul
2
+ %li
3
+ - if @rabbit.have_next_slide?
4
+ %a(href="/pages/next")
5
+ .navi 次へ
6
+ - else
7
+ .navi 次へ
8
+ %li
9
+ - if @rabbit.have_previous_slide?
10
+ %a(href="/pages/previous")
11
+ .navi 前へ
12
+ - else
13
+ .navi 前へ
@@ -0,0 +1,8 @@
1
+ %html
2
+ %head
3
+ %meta(http-equiv="Content-Type" content="text/html; charset=UTF-8")
4
+ %link(rel="stylesheet" type="text/css" media="all" href="/stylesheets/rabbirack.css")
5
+ %title
6
+ =slide_title
7
+ %body
8
+ =yield
@@ -5,7 +5,7 @@ module Rabbit
5
5
  module_function
6
6
  AVAILABLE_OPTIONS = ["linewidth", "foreground", "fill", "background",
7
7
  "option"]
8
- def make_image_by_aafigure(path, prop, logger)
8
+ def make_image(path, prop, logger)
9
9
  image_file = Tempfile.new("rabbit-image-aafigure")
10
10
  command = ["aafigure",
11
11
  "--type", "svg",
@@ -0,0 +1,46 @@
1
+ module Rabbit
2
+ module Parser
3
+ module Ext
4
+ module BlockDiag
5
+ module_function
6
+ AVAILABLE_FLAG_OPTIONS = ["antialias"]
7
+ # "font" is treated as specially.
8
+ AVAILABLE_VALUE_OPTIONS = []
9
+ def make_image(path, prop, logger)
10
+ image_file = Tempfile.new("rabbit-image-blockdiag")
11
+ command = ["blockdiag",
12
+ "-T", "svg",
13
+ "-o", image_file.path]
14
+ font = find_font(prop)
15
+ command.concat(["-f", font]) if font
16
+ AVAILABLE_FLAG_OPTIONS.each do |name|
17
+ command << "--#{name}" if /\A(?:true|yes)\z/i =~ prop[name].to_s
18
+ end
19
+ AVAILABLE_VALUE_OPTIONS.each do |name|
20
+ command.concat(["--#{name}", prop[name]]) if prop.has_key?(name)
21
+ end
22
+ command << path
23
+ if SystemRunner.run(*command)
24
+ image_file
25
+ else
26
+ format = _("tried blockdiag command: %s")
27
+ additional_info = format % command.inspect
28
+ raise BlockDiagCanNotHandleError.new(command.join(' '),
29
+ additional_info)
30
+ end
31
+ end
32
+
33
+ def find_font(prop)
34
+ font = prop["font"]
35
+ return font if font and File.exist?(font)
36
+ fonts = prop["fonts"]
37
+ return nil if fonts.nil?
38
+ fonts = fonts.split(/\s*,\s*/) if fonts.is_a?(String)
39
+ fonts.find do |font|
40
+ File.exist?(font)
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,66 @@
1
+ require 'coderay'
2
+
3
+ require 'rabbit/utils'
4
+ require 'rabbit/parser/ext/escape'
5
+
6
+ module Rabbit
7
+ module Parser
8
+ module Ext
9
+ module CodeRay
10
+ include GetText
11
+
12
+ module_function
13
+ def highlight(lang, text, logger)
14
+ tokens = ::CodeRay.scan(text.strip, lang.to_sym)
15
+ tokens.encode(RabbitEncoder.new)
16
+ end
17
+
18
+ class RabbitEncoder < ::CodeRay::Encoders::Encoder
19
+ include Element
20
+
21
+ def setup(options)
22
+ super
23
+ @out = SyntaxHighlightingBlock.new
24
+ @elements = [@out]
25
+ end
26
+
27
+ def text_token(text, type=:plain)
28
+ p [:text, type, text] if Utils.syntax_highlighting_debug?
29
+ escaped_text = Escape.escape_meta_character(text)
30
+ text_element = SyntaxHighlightingText.new(Text.new(escaped_text))
31
+ tag_name = type.to_s.gsub(/_/, '-')
32
+ CustomTag.new("syntax-#{tag_name}", text_element)
33
+ end
34
+
35
+ def open_token(kind)
36
+ p [:open, kind] if Utils.syntax_highlighting_debug?
37
+ @out = TextContainer.new
38
+ @elements << @out
39
+ CustomTag.new("syntax-#{kind}")
40
+ end
41
+
42
+ def begin_line(kind)
43
+ p [:begin_line, kind] if Utils.syntax_highlighting_debug?
44
+ nil
45
+ end
46
+
47
+ def end_line(kind)
48
+ p [:end_line, kind] if Utils.syntax_highlighting_debug?
49
+ nil
50
+ end
51
+
52
+ def close_token(kind)
53
+ p [:close, kind] if Utils.syntax_highlighting_debug?
54
+ block = @elements.pop
55
+ @out = @elements.last
56
+ block
57
+ end
58
+
59
+ def finish(options)
60
+ super
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,116 @@
1
+ require 'nokogiri'
2
+
3
+ require 'rabbit/utils'
4
+ require 'rabbit/parser/ext/escape'
5
+
6
+ module Rabbit
7
+ module Parser
8
+ module Ext
9
+ module Emacs
10
+ include Element
11
+ include GetText
12
+
13
+ module_function
14
+ def highlight(text, logger, mode_line=nil)
15
+ src_file = Tempfile.new("rabbit-emacs")
16
+ src_file.open
17
+ src_file.print("#{mode_line}\n") if mode_line
18
+ src_file.print(text)
19
+ src_file.close
20
+ html_file = Tempfile.new("rabbit-emacs-html")
21
+ args = [
22
+ "--batch",
23
+ "--eval",
24
+ "(htmlize-file \"#{src_file.path}\" \"#{html_file.path}\")",
25
+ ]
26
+ if SystemRunner.run("emacs", *args)
27
+ html_file.open
28
+ html_to_rabbit(html_file.read, mode_line, logger)
29
+ else
30
+ nil
31
+ end
32
+ end
33
+
34
+ def html_to_rabbit(html, mode_line, logger)
35
+ html = remove_newline_around_pre(html)
36
+ html = remove_mode_line(html, mode_line)
37
+ node = Nokogiri::HTML(html)
38
+ pre = find_element(node, "pre")
39
+ address = find_element(node, "address")
40
+ element = node_to_rabbit(pre, logger)
41
+ if element
42
+ logger.info(address.text) if address
43
+ element
44
+ else
45
+ nil
46
+ end
47
+ end
48
+
49
+ def remove_newline_around_pre(html)
50
+ html = html.gsub(/<pre([^>]*)>\n/i, '<pre\1>')
51
+ html.gsub(/\n<\/pre>/i, '</pre>')
52
+ end
53
+
54
+ def remove_mode_line(html, mode_line)
55
+ return html if mode_line.nil?
56
+ html.gsub(/<pre([^>]*)>([^\n]+\n)/i) do
57
+ attributes = $1
58
+ mode_line_html = $2
59
+ mode_line_text = mode_line_html.gsub(/<.+?>/, '')
60
+ if mode_line_text.strip == mode_line.strip
61
+ "<pre#{attributes}>"
62
+ else
63
+ "<pre#{attributes}>#{mode_line_html}"
64
+ end
65
+ end
66
+ end
67
+
68
+ def find_element(node, name)
69
+ node.css(name)[0]
70
+ end
71
+
72
+ def node_to_rabbit(node, logger)
73
+ case node.name
74
+ when "pre"
75
+ element = SyntaxHighlightingBlock.new
76
+ node.children.each do |child|
77
+ if child.text?
78
+ element << text_to_rabbit(child.text, "plain")
79
+ else
80
+ child_element = node_to_rabbit(child, logger)
81
+ element << child_element unless child_element.nil?
82
+ end
83
+ end
84
+ element
85
+ when "span"
86
+ p [node.text, node["class"]] if Utils.syntax_highlighting_debug?
87
+ text_to_rabbit(node.text, normalize_class_name(node["class"]))
88
+ else
89
+ format = _("emacs: unsupported element name: %s")
90
+ logger.warn(format % element.name)
91
+ nil
92
+ end
93
+ end
94
+
95
+ def normalize_class_name(name)
96
+ case name
97
+ when "comment-delimiter"
98
+ "comment"
99
+ when "keyword"
100
+ "reserved"
101
+ when "variable-name"
102
+ "variable"
103
+ else
104
+ name
105
+ end
106
+ end
107
+
108
+ def text_to_rabbit(text, type)
109
+ escaped_text = Escape.escape_meta_character(text)
110
+ text_element = SyntaxHighlightingText.new(Text.new(escaped_text))
111
+ CustomTag.new("syntax-#{type}", text_element)
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end
@@ -1,7 +1,4 @@
1
- begin
2
- require 'htree'
3
- rescue LoadError
4
- end
1
+ require 'nokogiri'
5
2
 
6
3
  require 'rabbit/utils'
7
4
  require 'rabbit/parser/ext/escape'
@@ -58,16 +55,12 @@ module Rabbit
58
55
  end
59
56
 
60
57
  def html_to_rabbit(html, logger)
61
- unless defined?(HTree)
62
- logger.warn(_("enscript: can't find HTree library"))
63
- return nil
64
- end
65
- tree = HTree(extract_newline_around_pre(html))
66
- pre = find_element(tree, "pre")
67
- address = find_element(tree, "address")
68
- element = tree_to_rabbit(pre, logger)
58
+ node = Nokogiri::HTML(extract_newline_around_pre(html))
59
+ pre = find_element(node, "pre")
60
+ address = find_element(node, "address")
61
+ element = node_to_rabbit(pre, logger)
69
62
  if element
70
- logger.info(address.extract_text.to_s)
63
+ logger.info(address.text) if address
71
64
  PreformattedBlock.new(element)
72
65
  else
73
66
  nil
@@ -79,18 +72,18 @@ module Rabbit
79
72
  html.gsub(/\n<\/pre>/i, '</pre>')
80
73
  end
81
74
 
82
- def find_element(tree, name)
83
- tree.find_element("{http://www.w3.org/1999/xhtml}#{name}")
75
+ def find_element(node, name)
76
+ node.css(name)[0]
84
77
  end
85
78
 
86
- def tree_to_rabbit(tree, logger)
87
- element = element_to_rabbit(tree, logger)
79
+ def node_to_rabbit(node, logger)
80
+ element = element_to_rabbit(node, logger)
88
81
  return nil if element.nil?
89
- tree.each_child do |child|
82
+ node.children.each do |child|
90
83
  if child.text?
91
- element << Text.new(Escape.escape_meta_character(child.to_s))
84
+ element << Text.new(Escape.escape_meta_character(child.text))
92
85
  else
93
- child_element = tree_to_rabbit(child, logger)
86
+ child_element = node_to_rabbit(child, logger)
94
87
  element << child_element unless child_element.nil?
95
88
  end
96
89
  end
@@ -98,7 +91,7 @@ module Rabbit
98
91
  end
99
92
 
100
93
  def element_to_rabbit(element, logger)
101
- case element.qualified_name
94
+ case element.name
102
95
  when "pre"
103
96
  PreformattedText.new
104
97
  when "b"
@@ -112,7 +105,7 @@ module Rabbit
112
105
  text
113
106
  else
114
107
  format = _("enscript: unsupported element name: %s")
115
- logger.warn(format % element.qualified_name)
108
+ logger.warn(format % element.name)
116
109
  nil
117
110
  end
118
111
  end