-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathrhg_textile_converter.rb
More file actions
59 lines (50 loc) · 1.64 KB
/
rhg_textile_converter.rb
File metadata and controls
59 lines (50 loc) · 1.64 KB
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
require "jekyll/converters/textile"
module Jekyll::Converters
class RhgTextile < Textile
safe true
# set this :low before "jekyll serve" when you want to use only Jekyll::Converters::Textile
priority :high
RHG_CODE_RE = /`([^`]+)`/
RHG_IMAGE_RE = /^!(.+\.(?:jpg|png))\((.+)\)!/
def convert(content)
# try to enable the <code> syntax of the original RubyForge project,
# but not fully.
lines = content.lines
skips = []
skips << "cvs diff parse.y" # chapter 11
skips << "69 EXPR_DOT, /*" # chapter 11
content = lines.map do |line|
unless skips.any? {|s| line.include? s }
line = line.gsub(RHG_CODE_RE) { "<code>#{$1}</code>" }
end
# this applies the markup of the original book and
# fixes improper markups of the generated htmls at the same time.
if line =~ /^▼ /
line = %{<p class="caption">#{line.rstrip}</p>\n}
end
line
end.join
# try to apply the style for images of the original book
figc = 0
no_figc = content.include? %{class="image"}
content.gsub!(RHG_IMAGE_RE) do |m|
figc += 1
src, title = $~[1..2]
alt = "(" + src.split(".").first.split("_").last + ")"
title = "Figure #{figc}: #{title}" unless no_figc
out = <<-EOS
<p class="image">
<img src="#{src}" alt="#{alt}"><br>
#{title}
</p>
EOS
end
super content
end
unless Jekyll::Converter.respond_to? :descendants
# simulate Jekyll::Converter.inherited
Jekyll::Converter.subclasses << self
Jekyll::Converter.subclasses.sort!
end
end
end