File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change 1+ require "jekyll/converters/textile"
2+ module Jekyll ::Converters
3+ class RhgTextile < Textile
4+ safe true
5+
6+ # set this :low before "jekyll serve" when you want to use only Jekyll::Converters::Textile
7+ priority :high
8+
9+ RHG_CODE_RE = /`([^`]+)`/
10+ RHG_IMAGE_RE = /^!(.+\. (?:jpg|png))\( (.+)\) !/
11+
12+ def convert ( content )
13+ # try to enable the <code> syntax of the original RubyForge project,
14+ # but not fully.
15+ lines = content . lines
16+ lines . map! { |line | line . gsub ( RHG_CODE_RE ) { "<code>#{ $1} </code>" } }
17+ content = lines . join
18+
19+ # try to apply the style for images of the original book
20+ figc = 0
21+ no_figc = content . include? %{class="image"}
22+ content . gsub! ( RHG_IMAGE_RE ) do |m |
23+ figc += 1
24+ src , title = $~[ 1 ..2 ]
25+ alt = "(" + src . split ( "." ) . first . split ( "_" ) . last + ")"
26+ title = "Figure #{ figc } : #{ title } " unless no_figc
27+ out = <<-EOS
28+ <p class="image">
29+ <img src="#{ src } " alt="#{ alt } "><br>
30+ #{ title }
31+ </p>
32+ EOS
33+ end
34+
35+ super content
36+ end
37+
38+ # simulate Jekyll::Converter.inherited
39+ Jekyll ::Converter . subclasses << self
40+ Jekyll ::Converter . subclasses . sort!
41+ end
42+ end
43+
You can’t perform that action at this time.
0 commit comments