rabbit 0.9.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +9 -2
- data/Rakefile +11 -4
- data/TODO +0 -2
- data/bin/rabbirack +95 -0
- data/bin/rabbit +23 -2
- data/bin/rabbiter +9 -0
- data/data/locale/en/LC_MESSAGES/rabbit.mo +0 -0
- data/data/locale/fr/LC_MESSAGES/rabbit.mo +0 -0
- data/data/locale/ja/LC_MESSAGES/rabbit.mo +0 -0
- data/doc/_layouts/en.html +1 -1
- data/doc/_layouts/ja.html +1 -1
- data/doc/_layouts/skeleton.html +1 -1
- data/doc/_site/css/rabbit.css +41 -1
- data/doc/_site/en/development.html +2 -2
- data/doc/_site/en/faq.html +2 -2
- data/doc/_site/en/hiki.html +2 -2
- data/doc/_site/en/how-to-make/hiki.html +2 -2
- data/doc/_site/en/how-to-make/index.html +2 -2
- data/doc/_site/en/how-to-make/pdf.html +2 -2
- data/doc/_site/en/how-to-make/rd.html +2 -2
- data/doc/_site/en/how-to-make/theme.html +2 -2
- data/doc/_site/en/index.html +20 -20
- data/doc/_site/en/install/homebrew.html +6 -12
- data/doc/_site/en/install/index.html +5 -3
- data/doc/_site/en/install/macports.html +2 -2
- data/doc/_site/en/install/windows.html +2 -2
- data/doc/_site/en/news.html +172 -61
- data/doc/_site/en/rd.html +2 -2
- data/doc/_site/en/sample/hiki/rabbit.html +3 -3
- data/doc/_site/en/sample/index.html +2 -2
- data/doc/_site/en/sample/rd/rabbit.html +3 -3
- data/doc/_site/en/slides.html +2 -2
- data/doc/_site/en/usage.html +60 -60
- data/doc/_site/en/users.html +2 -2
- data/doc/_site/images/screenshots/en/blue-circle.png +0 -0
- data/doc/_site/images/screenshots/en/clear-blue-raw.png +0 -0
- data/doc/_site/images/screenshots/en/clear-blue.png +0 -0
- data/doc/_site/images/screenshots/en/cozmixng-raw.png +0 -0
- data/doc/_site/images/screenshots/en/cozmixng.png +0 -0
- data/doc/_site/images/screenshots/en/dark-gradation.png +0 -0
- data/doc/_site/images/screenshots/en/day-white.png +0 -0
- data/doc/_site/images/screenshots/en/debian.png +0 -0
- data/doc/_site/images/screenshots/en/green-circle.png +0 -0
- data/doc/_site/images/screenshots/en/night-black.png +0 -0
- data/doc/_site/images/screenshots/en/rabbit-raw.png +0 -0
- data/doc/_site/images/screenshots/en/rabbit.png +0 -0
- data/doc/_site/images/screenshots/en/ranguba-raw.png +0 -0
- data/doc/_site/images/screenshots/en/ranguba.png +0 -0
- data/doc/_site/images/screenshots/en/red-frame.png +0 -0
- data/doc/_site/images/screenshots/en/ruby-gnome2.png +0 -0
- data/doc/_site/images/screenshots/ja/blue-circle.png +0 -0
- data/doc/_site/images/screenshots/ja/clear-blue-raw.png +0 -0
- data/doc/_site/images/screenshots/ja/clear-blue.png +0 -0
- data/doc/_site/images/screenshots/ja/cozmixng-raw.png +0 -0
- data/doc/_site/images/screenshots/ja/cozmixng.png +0 -0
- data/doc/_site/images/screenshots/ja/dark-gradation.png +0 -0
- data/doc/_site/images/screenshots/ja/day-white.png +0 -0
- data/doc/_site/images/screenshots/ja/debian.png +0 -0
- data/doc/_site/images/screenshots/ja/green-circle.png +0 -0
- data/doc/_site/images/screenshots/ja/night-black.png +0 -0
- data/doc/_site/images/screenshots/ja/rabbit-raw.png +0 -0
- data/doc/_site/images/screenshots/ja/rabbit.png +0 -0
- data/doc/_site/images/screenshots/ja/ranguba-raw.png +0 -0
- data/doc/_site/images/screenshots/ja/ranguba.png +0 -0
- data/doc/_site/images/screenshots/ja/red-frame.png +0 -0
- data/doc/_site/images/screenshots/ja/ruby-gnome2.png +0 -0
- data/doc/_site/index.html.en +8 -2
- data/doc/_site/index.html.ja +8 -2
- data/doc/_site/ja/about.html +2 -2
- data/doc/_site/ja/development.html +2 -2
- data/doc/_site/ja/faq.html +25 -14
- data/doc/_site/ja/hiki.html +2 -2
- data/doc/_site/ja/how-to-make/hiki.html +2 -2
- data/doc/_site/ja/how-to-make/index.html +2 -2
- data/doc/_site/ja/how-to-make/pdf.html +2 -2
- data/doc/_site/ja/how-to-make/rd.html +2 -2
- data/doc/_site/ja/how-to-make/theme.html +2 -2
- data/doc/_site/ja/index.html +2 -2
- data/doc/_site/ja/install/homebrew.html +6 -12
- data/doc/_site/ja/install/index.html +5 -3
- data/doc/_site/ja/install/macports.html +3 -6
- data/doc/_site/ja/install/windows.html +2 -2
- data/doc/_site/ja/news.html +165 -61
- data/doc/_site/ja/rd.html +2 -2
- data/doc/_site/ja/sample/hiki/rabbit.html +3 -3
- data/doc/_site/ja/sample/index.html +2 -2
- data/doc/_site/ja/sample/rd/rabbit.html +3 -3
- data/doc/_site/ja/slides.html +2 -2
- data/doc/_site/ja/usage.html +60 -69
- data/doc/_site/ja/users.html +2 -2
- data/doc/css/rabbit.css +41 -1
- data/doc/en/index.rd +1 -1
- data/doc/en/install/homebrew.rd +2 -11
- data/doc/en/install/index.rd +2 -0
- data/doc/en/news.rd +117 -3
- data/doc/en/sample/hiki/rabbit.hiki +1 -1
- data/doc/en/sample/rd/rabbit.rd +1 -1
- data/doc/en/usage.rd +12 -17
- data/doc/images/screenshots/en/blue-circle.png +0 -0
- data/doc/images/screenshots/en/clear-blue-raw.png +0 -0
- data/doc/images/screenshots/en/clear-blue.png +0 -0
- data/doc/images/screenshots/en/cozmixng-raw.png +0 -0
- data/doc/images/screenshots/en/cozmixng.png +0 -0
- data/doc/images/screenshots/en/dark-gradation.png +0 -0
- data/doc/images/screenshots/en/day-white.png +0 -0
- data/doc/images/screenshots/en/debian.png +0 -0
- data/doc/images/screenshots/en/green-circle.png +0 -0
- data/doc/images/screenshots/en/night-black.png +0 -0
- data/doc/images/screenshots/en/rabbit-raw.png +0 -0
- data/doc/images/screenshots/en/rabbit.png +0 -0
- data/doc/images/screenshots/en/ranguba-raw.png +0 -0
- data/doc/images/screenshots/en/ranguba.png +0 -0
- data/doc/images/screenshots/en/red-frame.png +0 -0
- data/doc/images/screenshots/en/ruby-gnome2.png +0 -0
- data/doc/images/screenshots/ja/blue-circle.png +0 -0
- data/doc/images/screenshots/ja/clear-blue-raw.png +0 -0
- data/doc/images/screenshots/ja/clear-blue.png +0 -0
- data/doc/images/screenshots/ja/cozmixng-raw.png +0 -0
- data/doc/images/screenshots/ja/cozmixng.png +0 -0
- data/doc/images/screenshots/ja/dark-gradation.png +0 -0
- data/doc/images/screenshots/ja/day-white.png +0 -0
- data/doc/images/screenshots/ja/debian.png +0 -0
- data/doc/images/screenshots/ja/green-circle.png +0 -0
- data/doc/images/screenshots/ja/night-black.png +0 -0
- data/doc/images/screenshots/ja/rabbit-raw.png +0 -0
- data/doc/images/screenshots/ja/rabbit.png +0 -0
- data/doc/images/screenshots/ja/ranguba-raw.png +0 -0
- data/doc/images/screenshots/ja/ranguba.png +0 -0
- data/doc/images/screenshots/ja/red-frame.png +0 -0
- data/doc/images/screenshots/ja/ruby-gnome2.png +0 -0
- data/doc/index.html.en +6 -0
- data/doc/index.html.ja +6 -0
- data/doc/ja/faq.rd +21 -3
- data/doc/ja/install/homebrew.rd +2 -11
- data/doc/ja/install/index.rd +2 -0
- data/doc/ja/install/macports.rd +1 -6
- data/doc/ja/news.rd +109 -3
- data/doc/ja/sample/hiki/rabbit.hiki +1 -1
- data/doc/ja/sample/rd/rabbit.rd +1 -1
- data/doc/ja/usage.rd +11 -29
- data/lib/rabbit/canvas.rb +7 -4
- data/lib/rabbit/console.rb +1 -1
- data/lib/rabbit/div/main-i.erb +1 -1
- data/lib/rabbit/div/main.erb +1 -1
- data/lib/rabbit/element/base.rb +17 -1
- data/lib/rabbit/element/image.rb +1 -0
- data/lib/rabbit/element/preformatted.rb +8 -3
- data/lib/rabbit/element/syntax-highlighting.rb +15 -0
- data/lib/rabbit/element/text-renderer.rb +3 -3
- data/lib/rabbit/element/text.rb +0 -12
- data/lib/rabbit/element/title-slide.rb +1 -25
- data/lib/rabbit/formatter.rb +26 -6
- data/lib/rabbit/front.rb +10 -6
- data/lib/rabbit/html/template.erb +1 -1
- data/lib/rabbit/image.rb +1 -1
- data/lib/rabbit/keys.rb +70 -70
- data/lib/rabbit/middleware/config.ru +42 -0
- data/lib/rabbit/middleware/controller.rb +66 -0
- data/lib/rabbit/middleware/public/stylesheets/rabbirack.css +12 -0
- data/lib/rabbit/middleware/views/index.haml +13 -0
- data/lib/rabbit/middleware/views/layout.haml +8 -0
- data/lib/rabbit/parser/ext/aafigure.rb +1 -1
- data/lib/rabbit/parser/ext/blockdiag.rb +46 -0
- data/lib/rabbit/parser/ext/coderay.rb +66 -0
- data/lib/rabbit/parser/ext/emacs.rb +116 -0
- data/lib/rabbit/parser/ext/enscript.rb +15 -22
- data/lib/rabbit/parser/rd.rb +8 -2
- data/lib/rabbit/parser/rd/ext/block-verbatim.rb +53 -16
- data/lib/rabbit/parser/wiki.rb +3 -1
- data/lib/rabbit/parser/wiki/output.rb +28 -16
- data/lib/rabbit/rabbit.rb +7 -1
- data/lib/rabbit/renderer/display.rb +14 -2
- data/lib/rabbit/renderer/display/clutter-embed.rb +1 -1
- data/lib/rabbit/renderer/display/key-handler.rb +12 -12
- data/lib/rabbit/soap/base.rb +1 -1
- data/lib/rabbit/theme-browser.rb +2 -2
- data/lib/rabbit/theme/base/base.rb +7 -0
- data/lib/rabbit/theme/default-comment/default-comment.rb +9 -0
- data/lib/rabbit/theme/default-comment/property.rb +4 -0
- data/lib/rabbit/theme/default-item-mark-setup/default-item-mark-setup.rb +1 -1
- data/lib/rabbit/theme/default-slide/default-slide.rb +2 -2
- data/lib/rabbit/theme/default-text/default-text.rb +5 -0
- data/lib/rabbit/theme/default/default.rb +6 -7
- data/lib/rabbit/theme/footer-comment/footer-comment.rb +35 -8
- data/lib/rabbit/theme/pdf/pdf.rb +18 -0
- data/lib/rabbit/theme/rabbit-powered-by/rabbit-powered-by.rb +1 -1
- data/lib/rabbit/theme/syntax-highlighting/property.rb +4 -0
- data/lib/rabbit/theme/syntax-highlighting/syntax-highlighting.rb +139 -0
- data/lib/rabbit/theme/title-shadow/title-shadow.rb +1 -1
- data/lib/rabbit/theme/twitter-comment/twitter-comment.rb +1 -1
- data/lib/rabbit/twitter.rb +28 -4
- data/lib/rabbit/utils.rb +40 -12
- data/po/en/rabbit.po +175 -145
- data/po/fr/rabbit.po +180 -149
- data/po/ja/rabbit.po +176 -148
- data/po/rabbit.pot +175 -145
- data/sample/can_rabbit.rd +0 -21
- data/sample/rabbit-en.hiki +21 -2
- data/sample/rabbit-en.rd +42 -2
- data/sample/rabbit-implementation.rd +0 -5
- data/sample/rabbit.hiki +19 -16
- data/sample/rabbit.rd +42 -11
- data/sample/test.hiki +31 -0
- data/sample/test.rab +30 -0
- metadata +84 -58
- data/lib/rabbit/parser/ext/anthy.rb +0 -43
- data/lib/rabbit/parser/rd/ext/aafigure.rb +0 -18
- data/lib/rabbit/parser/rd/ext/anthy.rb +0 -29
- data/lib/rabbit/parser/rd/ext/enscript.rb +0 -24
- data/lib/rabbit/parser/rd/ext/tex.rb +0 -24
- data/lib/rabbit/source/rwiki.rb +0 -54
- data/lib/rabbit/theme/pdf-tortoise-and-hare/pdf-tortoise-and-hare.rb +0 -18
- 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
|
@@ -5,7 +5,7 @@ module Rabbit
|
|
5
5
|
module_function
|
6
6
|
AVAILABLE_OPTIONS = ["linewidth", "foreground", "fill", "background",
|
7
7
|
"option"]
|
8
|
-
def
|
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
|
-
|
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
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
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.
|
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(
|
83
|
-
|
75
|
+
def find_element(node, name)
|
76
|
+
node.css(name)[0]
|
84
77
|
end
|
85
78
|
|
86
|
-
def
|
87
|
-
element = element_to_rabbit(
|
79
|
+
def node_to_rabbit(node, logger)
|
80
|
+
element = element_to_rabbit(node, logger)
|
88
81
|
return nil if element.nil?
|
89
|
-
|
82
|
+
node.children.each do |child|
|
90
83
|
if child.text?
|
91
|
-
element << Text.new(Escape.escape_meta_character(child.
|
84
|
+
element << Text.new(Escape.escape_meta_character(child.text))
|
92
85
|
else
|
93
|
-
child_element =
|
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.
|
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.
|
108
|
+
logger.warn(format % element.name)
|
116
109
|
nil
|
117
110
|
end
|
118
111
|
end
|