redcloth-formatters-docbook 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.textile +22 -0
- data/Rakefile +2 -0
- data/lib/redcloth-formatters-docbook.rb +4 -0
- data/lib/redcloth-formatters-docbook/formatters/docbook.rb +358 -0
- data/lib/redcloth-formatters-docbook/textile_doc.rb +19 -0
- data/lib/redcloth-formatters-docbook/version.rb +7 -0
- data/redcloth-formatters-docbook.gemspec +24 -0
- data/spec/docbook_spec.rb +61 -0
- data/spec/fixtures/bibliography.textile +23 -0
- data/spec/fixtures/bibliography.xml +30 -0
- data/spec/fixtures/chapters.textile +25 -0
- data/spec/fixtures/chapters.xml +38 -0
- data/spec/fixtures/cover.textile +13 -0
- data/spec/fixtures/cover.xml +19 -0
- data/spec/fixtures/footnotes.textile +10 -0
- data/spec/fixtures/footnotes.xml +12 -0
- data/spec/fixtures/hello.textile +5 -0
- data/spec/fixtures/hello.xml +11 -0
- data/spec/fixtures/lists.textile +11 -0
- data/spec/fixtures/lists.xml +23 -0
- data/spec/fixtures/phrase.textile +21 -0
- data/spec/fixtures/phrase.xml +39 -0
- data/spec/fixtures/source.textile +17 -0
- data/spec/fixtures/source.xml +32 -0
- data/spec/fixtures/tables.textile +9 -0
- data/spec/fixtures/tables.xml +46 -0
- data/spec/helpers.rb +9 -0
- metadata +145 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.textile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The gem extends "RedCloth":http://www.redcloth.org with a DocBook formatter.
|
2
|
+
|
3
|
+
It might be used in conjunction with "Booky":http://www.https://github.com/southdesign/booky to create fully blown PDFs out of textiles.
|
4
|
+
|
5
|
+
h2. Install
|
6
|
+
|
7
|
+
Simply run @gem install redcloth-formatters-docbook@
|
8
|
+
|
9
|
+
h2. Usage
|
10
|
+
|
11
|
+
bc.. require 'rubygems'
|
12
|
+
require 'RedCloth'
|
13
|
+
require 'redcloth-formatters-docbook'
|
14
|
+
|
15
|
+
textile = File.open("your.textile", 'rb') { |f| f.read }
|
16
|
+
docbook = RedCloth.new(textile).to_docbook
|
17
|
+
puts docbook
|
18
|
+
=> "
|
19
|
+
<?xml version="1.0" encoding="utf-8"?>
|
20
|
+
<book xmlns="http://docbook.org/ns/docbook" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xl="http://www.w3.org/1999/xlink" version="5.0">
|
21
|
+
<para>Hello</para>
|
22
|
+
</book>"
|
data/Rakefile
ADDED
@@ -0,0 +1,358 @@
|
|
1
|
+
module RedCloth::Formatters::Docbook
|
2
|
+
|
3
|
+
@@stack = []
|
4
|
+
@@footnotes = {}
|
5
|
+
|
6
|
+
# cover
|
7
|
+
def title(opts)
|
8
|
+
options = parse_css(opts[:style])
|
9
|
+
reference_id = ""
|
10
|
+
reference_id = " xml:id=\"#{options[:id]}\"" if options[:id]
|
11
|
+
out = ""
|
12
|
+
out += close_level("section4")
|
13
|
+
out += close_level("section3")
|
14
|
+
out += close_level("section2")
|
15
|
+
out += close_level("chapter")
|
16
|
+
out += close_level("preface")
|
17
|
+
out += close_level("title")
|
18
|
+
out += "\n#{"\t" * @@stack.size}<info#{reference_id}>\n"
|
19
|
+
out += "#{"\t" * @@stack.size}\t<title>#{opts[:text]}</title>\n"
|
20
|
+
open_level("title", "#{"\t" * @@stack.size}</info>\n\n")
|
21
|
+
out
|
22
|
+
end
|
23
|
+
|
24
|
+
def subtitle(opts)
|
25
|
+
"#{"\t" * @@stack.size}<subtitle>#{opts[:text]}</subtitle>\n"
|
26
|
+
end
|
27
|
+
|
28
|
+
def author(opts)
|
29
|
+
first, last = opts[:text].split(" ")
|
30
|
+
"#{"\t" * @@stack.size}<author><firstname>#{first}</firstname><surname>#{last}</surname></author>\n"
|
31
|
+
end
|
32
|
+
|
33
|
+
def copyright(opts)
|
34
|
+
split = opts[:text].split(",")
|
35
|
+
year = split.first
|
36
|
+
holder = split.slice(1, split.length - 1).join(",").strip
|
37
|
+
"#{"\t" * @@stack.size}<copyright><year>#{year}</year><holder>#{holder}</holder></copyright>\n"
|
38
|
+
end
|
39
|
+
|
40
|
+
# preface
|
41
|
+
def h0(opts)
|
42
|
+
options = parse_css(opts[:style])
|
43
|
+
reference_id = ""
|
44
|
+
reference_id = " xml:id=\"#{options[:id]}\"" if options[:id]
|
45
|
+
out = ""
|
46
|
+
out += close_level("section4")
|
47
|
+
out += close_level("section3")
|
48
|
+
out += close_level("section2")
|
49
|
+
out += close_level("chapter")
|
50
|
+
out += close_level("preface")
|
51
|
+
out += close_level("title")
|
52
|
+
out += "#{"\t" * @@stack.size}<preface#{reference_id}>\n\n"
|
53
|
+
out += "#{"\t" * @@stack.size}\t<title>#{opts[:text]}</title>\n"
|
54
|
+
open_level("preface", "#{"\t" * @@stack.size}</preface>\n\n")
|
55
|
+
out
|
56
|
+
end
|
57
|
+
|
58
|
+
# chapter
|
59
|
+
def h1(opts)
|
60
|
+
options = parse_css(opts[:style])
|
61
|
+
reference_id = ""
|
62
|
+
reference_id = " xml:id=\"#{options[:id]}\"" if options[:id]
|
63
|
+
out = ""
|
64
|
+
out += close_level("section4")
|
65
|
+
out += close_level("section3")
|
66
|
+
out += close_level("section2")
|
67
|
+
out += close_level("chapter")
|
68
|
+
out += close_level("preface")
|
69
|
+
out += close_level("title")
|
70
|
+
out += "#{"\t" * @@stack.size}<chapter xmlns='http://docbook.org/ns/docbook' xmlns:xi='http://www.w3.org/2001/XInclude' version='5.0'#{reference_id}>\n\n"
|
71
|
+
out += "#{"\t" * @@stack.size}\t<title>#{opts[:text]}</title>\n"
|
72
|
+
open_level("chapter", "#{"\t" * @@stack.size}</chapter>\n\n")
|
73
|
+
out
|
74
|
+
end
|
75
|
+
|
76
|
+
# section 1
|
77
|
+
def h2(opts)
|
78
|
+
options = parse_css(opts[:style])
|
79
|
+
reference_id = ""
|
80
|
+
reference_id = " xml:id=\"#{options[:id]}\"" if options[:id]
|
81
|
+
out = ""
|
82
|
+
out += close_level("section4")
|
83
|
+
out += close_level("section3")
|
84
|
+
out += close_level("section2")
|
85
|
+
out += "\n"
|
86
|
+
out += "#{"\t" * @@stack.size}<section#{reference_id}>\n"
|
87
|
+
out += "#{"\t" * @@stack.size}\t<title>#{opts[:text]}</title>\n"
|
88
|
+
open_level("section2", "#{"\t" * @@stack.size}</section>\n")
|
89
|
+
out
|
90
|
+
end
|
91
|
+
|
92
|
+
# section 2
|
93
|
+
def h3(opts)
|
94
|
+
options = parse_css(opts[:style])
|
95
|
+
reference_id = ""
|
96
|
+
reference_id = " xml:id=\"#{options[:id]}\"" if options[:id]
|
97
|
+
out = ""
|
98
|
+
out += close_level("section4")
|
99
|
+
out += close_level("section3")
|
100
|
+
out += "\n"
|
101
|
+
out += "#{"\t" * @@stack.size}<section#{reference_id}>\n"
|
102
|
+
out += "#{"\t" * @@stack.size}\t<title>#{opts[:text]}</title>\n"
|
103
|
+
open_level("section3", "#{"\t" * @@stack.size}</section>\n")
|
104
|
+
out
|
105
|
+
end
|
106
|
+
|
107
|
+
# section 3
|
108
|
+
def h4(opts)
|
109
|
+
options = parse_css(opts[:style])
|
110
|
+
reference_id = ""
|
111
|
+
reference_id = " xml:id=\"#{options[:id]}\"" if options[:id]
|
112
|
+
out = ""
|
113
|
+
out += close_level("section4")
|
114
|
+
out += "\n"
|
115
|
+
out += "#{"\t" * @@stack.size}<section#{reference_id}>\n"
|
116
|
+
out += "#{"\t" * @@stack.size}\t<title>#{opts[:text]}</title>\n"
|
117
|
+
open_level("section4", "#{"\t" * @@stack.size}</section>\n")
|
118
|
+
out
|
119
|
+
end
|
120
|
+
|
121
|
+
# para
|
122
|
+
def p(opts)
|
123
|
+
"#{"\t" * @@stack.size}<para>#{opts[:text]}</para>\n"
|
124
|
+
end
|
125
|
+
|
126
|
+
# lists
|
127
|
+
def ul_open(opt)
|
128
|
+
"\n#{"\t" * @@stack.size}<itemizedlist>\n"
|
129
|
+
end
|
130
|
+
|
131
|
+
def ul_close(opt)
|
132
|
+
"#{"\t" * @@stack.size}</itemizedlist>\n"
|
133
|
+
end
|
134
|
+
|
135
|
+
def ol_open(opt)
|
136
|
+
"\n#{"\t" * @@stack.size}<orderedlist>\n"
|
137
|
+
end
|
138
|
+
|
139
|
+
def ol_close(opt)
|
140
|
+
"#{"\t" * @@stack.size}</orderedlist>\n"
|
141
|
+
end
|
142
|
+
|
143
|
+
def li_open(opts)
|
144
|
+
"#{"\t" * @@stack.size}\t<listitem><para>#{opts[:text]}"
|
145
|
+
end
|
146
|
+
|
147
|
+
def li_close(opts=nil)
|
148
|
+
"</para></listitem>#{opts[:text]}\n"
|
149
|
+
end
|
150
|
+
|
151
|
+
@@table_headers = nil
|
152
|
+
|
153
|
+
# tables
|
154
|
+
def table_open(opts)
|
155
|
+
options = parse_css(opts[:style])
|
156
|
+
options[:align] ||= 'left'
|
157
|
+
@@table_headers = options[:cols].to_i
|
158
|
+
out = "\n"
|
159
|
+
out += "#{"\t" * @@stack.size}<table frame='all'>\n"
|
160
|
+
out += "#{"\t" * @@stack.size}\t<title>#{options[:name]}</title>\n\n"
|
161
|
+
out += "#{"\t" * @@stack.size}\t<tgroup cols='#{options[:cols]}' align='#{options[:align]}' colsep='1' rowsep='1'>\n"
|
162
|
+
out += "#{"\t" * @@stack.size}\t\t<thead>\n"
|
163
|
+
out
|
164
|
+
end
|
165
|
+
|
166
|
+
def table_close(opts)
|
167
|
+
"#{"\t" * @@stack.size}\t\t</tbody>\n#{"\t" * @@stack.size}\t</tgroup>\n</table>\n"
|
168
|
+
end
|
169
|
+
|
170
|
+
def th(opts)
|
171
|
+
"\t<tr#{pba(opts)}>\n"
|
172
|
+
end
|
173
|
+
|
174
|
+
def tr_open(opts)
|
175
|
+
"#{"\t" * @@stack.size}\t\t\t<row>\n"
|
176
|
+
end
|
177
|
+
|
178
|
+
def tr_close(opts)
|
179
|
+
out = "#{"\t" * @@stack.size}\t\t\t</row>\n"
|
180
|
+
|
181
|
+
if @@table_headers == 0
|
182
|
+
out += "#{"\t" * @@stack.size}\t\t</thead>\n#{"\t" * @@stack.size}\t\t<tbody>\n"
|
183
|
+
@@table_headers = nil
|
184
|
+
end
|
185
|
+
|
186
|
+
out
|
187
|
+
end
|
188
|
+
|
189
|
+
def td(opts)
|
190
|
+
@@table_headers -= 1 if opts[:th]
|
191
|
+
"#{"\t" * @@stack.size}\t\t\t\t<entry>#{opts[:text].strip}</entry>\n"
|
192
|
+
end
|
193
|
+
|
194
|
+
|
195
|
+
# footnotes
|
196
|
+
def footno(opts)
|
197
|
+
opts[:id] ||= opts[:text]
|
198
|
+
"<footnote><para>#{@@footnotes[opts[:id]]}</para></footnote>"
|
199
|
+
end
|
200
|
+
|
201
|
+
def fn(opts)
|
202
|
+
@@footnotes[opts[:id]] = opts[:text]
|
203
|
+
""
|
204
|
+
end
|
205
|
+
|
206
|
+
# phrase
|
207
|
+
def i(opts)
|
208
|
+
"<emphasis>#{opts[:text]}</emphasis>"
|
209
|
+
end
|
210
|
+
alias :em :i
|
211
|
+
|
212
|
+
def b(opts)
|
213
|
+
"<emphasis role=\"bold\">#{opts[:text]}</emphasis>"
|
214
|
+
end
|
215
|
+
alias :strong :b
|
216
|
+
|
217
|
+
def br(opts)
|
218
|
+
""
|
219
|
+
end
|
220
|
+
|
221
|
+
def cite(opts)
|
222
|
+
"<citation xl:href=\"##{opts[:text]}\">#{opts[:text]}</citation>"
|
223
|
+
end
|
224
|
+
|
225
|
+
def code(opts)
|
226
|
+
return opts[:text] if opts[:block]
|
227
|
+
"<code>#{opts[:text]}</code>"
|
228
|
+
end
|
229
|
+
|
230
|
+
def link(opts)
|
231
|
+
"<link xl:href=\"#{opts[:href]}\">#{opts[:name]}</link>"
|
232
|
+
end
|
233
|
+
|
234
|
+
def image(opts)
|
235
|
+
title = opts[:title]
|
236
|
+
id = title.split(" ").join(".")
|
237
|
+
|
238
|
+
out = "\n"
|
239
|
+
out += "<figure xml:id=\"#{id}\">\n"
|
240
|
+
out += "<title>#{title}</title>\n"
|
241
|
+
out += "<mediaobject>\n"
|
242
|
+
out += "\t<imageobject><imagedata fileref=\"#{opts[:src]}\" format=\"PNG\" /></imageobject>\n"
|
243
|
+
out += "</mediaobject>\n"
|
244
|
+
out += "</figure>\n"
|
245
|
+
out
|
246
|
+
end
|
247
|
+
|
248
|
+
def bq_open(opts)
|
249
|
+
opts[:block] = true
|
250
|
+
options = parse_css(opts[:style])
|
251
|
+
out = "<blockquote>\n"
|
252
|
+
out += "\t<attribution>#{options[:by]}</attribution>\n" if options[:by]
|
253
|
+
out
|
254
|
+
end
|
255
|
+
|
256
|
+
def bq_close(opts)
|
257
|
+
"</blockquote>\n"
|
258
|
+
end
|
259
|
+
|
260
|
+
# source
|
261
|
+
def bc_open(opts)
|
262
|
+
opts[:block] = true
|
263
|
+
options = parse_css(opts[:style])
|
264
|
+
id = options[:name].split(" ").join(".")
|
265
|
+
out = "<para>\n"
|
266
|
+
out += "\t<example xml:id=\"#{id}\">\n"
|
267
|
+
out += "\t<title>#{options[:name]}</title>\n"
|
268
|
+
out += "\t<programlisting width=\"100%\">\n"
|
269
|
+
out
|
270
|
+
end
|
271
|
+
|
272
|
+
def bc_close(opts)
|
273
|
+
out = "</programlisting>\n"
|
274
|
+
out += "\t</example>\n"
|
275
|
+
out += "</para>\n"
|
276
|
+
out
|
277
|
+
end
|
278
|
+
|
279
|
+
def self.close_all_levels text = ""
|
280
|
+
return "" if @@stack.empty?
|
281
|
+
begin
|
282
|
+
entry = @@stack.pop
|
283
|
+
text += "\n#{entry[:tag]}"
|
284
|
+
end while !@@stack.empty?
|
285
|
+
text
|
286
|
+
end
|
287
|
+
|
288
|
+
def self.open_book
|
289
|
+
out = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
|
290
|
+
out += "<book xmlns=\"http://docbook.org/ns/docbook\" xmlns:xi=\"http://www.w3.org/2001/XInclude\" xmlns:xl=\"http://www.w3.org/1999/xlink\" version=\"5.0\">\n"
|
291
|
+
out
|
292
|
+
end
|
293
|
+
|
294
|
+
def self.close_book
|
295
|
+
self.close_all_levels + "\n</book>"
|
296
|
+
end
|
297
|
+
|
298
|
+
private
|
299
|
+
|
300
|
+
def parse_css css
|
301
|
+
options = {}
|
302
|
+
begin
|
303
|
+
css = css.split ";"
|
304
|
+
css.each do |css|
|
305
|
+
key, value = css.split ":"
|
306
|
+
options[key.strip.to_sym] = value.strip
|
307
|
+
end
|
308
|
+
rescue
|
309
|
+
end
|
310
|
+
options
|
311
|
+
end
|
312
|
+
|
313
|
+
def close_level(type)
|
314
|
+
last = @@stack.last
|
315
|
+
return "" if last.nil?
|
316
|
+
if last[:type] == type
|
317
|
+
return @@stack.pop[:tag]
|
318
|
+
end
|
319
|
+
""
|
320
|
+
end
|
321
|
+
|
322
|
+
def open_level(type, tag)
|
323
|
+
@@stack << { :type => type, :tag => tag }
|
324
|
+
end
|
325
|
+
|
326
|
+
# escapement for regular HTML (not in PRE tag)
|
327
|
+
def escape(text)
|
328
|
+
html_esc(text)
|
329
|
+
end
|
330
|
+
|
331
|
+
# escapement for HTML in a PRE tag
|
332
|
+
def escape_pre(text)
|
333
|
+
html_esc(text, :html_escape_preformatted)
|
334
|
+
end
|
335
|
+
|
336
|
+
# escaping for HTML attributes
|
337
|
+
def escape_attribute(text)
|
338
|
+
html_esc(text, :html_escape_attributes)
|
339
|
+
end
|
340
|
+
|
341
|
+
def after_transform(text)
|
342
|
+
text.chomp!
|
343
|
+
end
|
344
|
+
|
345
|
+
|
346
|
+
def before_transform(text)
|
347
|
+
|
348
|
+
end
|
349
|
+
|
350
|
+
def method_missing(method, opts)
|
351
|
+
opts[:text] || ""
|
352
|
+
end
|
353
|
+
|
354
|
+
def formatter_methods
|
355
|
+
singleton_methods.map! {|method| method.to_sym }
|
356
|
+
end
|
357
|
+
|
358
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module RedCloth
|
2
|
+
class TextileDoc
|
3
|
+
|
4
|
+
#
|
5
|
+
# Generates DocBook from the Textile contents.
|
6
|
+
#
|
7
|
+
# RedCloth.new( "And then? She *fell*!" ).to_docbook
|
8
|
+
# #=> "<para>And then? She fell!</para>"
|
9
|
+
#
|
10
|
+
def to_docbook( *rules )
|
11
|
+
apply_rules(rules)
|
12
|
+
|
13
|
+
docbook = RedCloth::Formatters::Docbook.open_book
|
14
|
+
docbook += to(RedCloth::Formatters::Docbook)
|
15
|
+
docbook += RedCloth::Formatters::Docbook.close_book
|
16
|
+
docbook
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "redcloth-formatters-docbook/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "redcloth-formatters-docbook"
|
7
|
+
s.version = Redcloth::Formatters::Docbook::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Thomas Fankhauser"]
|
10
|
+
s.email = ["tommylefunk@googlemail.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{RedCloth DocBook Formatter}
|
13
|
+
s.description = %q{Allows RedCloth to convert .textiles to Docbook XMLs}
|
14
|
+
|
15
|
+
s.rubyforge_project = "redcloth-formatters-docbook"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency "RedCloth", "~> 4.2.8"
|
23
|
+
s.add_development_dependency "rspec", "~> 2.6"
|
24
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'RedCloth'
|
2
|
+
require 'redcloth-formatters-docbook'
|
3
|
+
require 'spec/helpers'
|
4
|
+
|
5
|
+
describe Redcloth::Formatters::Docbook do
|
6
|
+
|
7
|
+
it "basic command available" do
|
8
|
+
textile = File.open("spec/fixtures/hello.textile", 'rb') { |f| f.read }
|
9
|
+
docbook = File.open("spec/fixtures/hello.xml", 'rb') { |f| f.read }
|
10
|
+
RedCloth.new(textile).to_docbook.docbook_strip.should eql(docbook.docbook_strip)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "chapters with sections" do
|
14
|
+
textile = File.open("spec/fixtures/chapters.textile", 'rb') { |f| f.read }
|
15
|
+
docbook = File.open("spec/fixtures/chapters.xml", 'rb') { |f| f.read }
|
16
|
+
RedCloth.new(textile).to_docbook.docbook_strip.should eql(docbook.docbook_strip)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "lists" do
|
20
|
+
textile = File.open("spec/fixtures/lists.textile", 'rb') { |f| f.read }
|
21
|
+
docbook = File.open("spec/fixtures/lists.xml", 'rb') { |f| f.read }
|
22
|
+
RedCloth.new(textile).to_docbook.docbook_strip.should eql(docbook.docbook_strip)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "tables" do
|
26
|
+
textile = File.open("spec/fixtures/tables.textile", 'rb') { |f| f.read }
|
27
|
+
docbook = File.open("spec/fixtures/tables.xml", 'rb') { |f| f.read }
|
28
|
+
RedCloth.new(textile).to_docbook.docbook_strip.should eql(docbook.docbook_strip)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "footnotes" do
|
32
|
+
textile = File.open("spec/fixtures/footnotes.textile", 'rb') { |f| f.read }
|
33
|
+
docbook = File.open("spec/fixtures/footnotes.xml", 'rb') { |f| f.read }
|
34
|
+
RedCloth.new(textile).to_docbook.docbook_strip.should eql(docbook.docbook_strip)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "phrase" do
|
38
|
+
textile = File.open("spec/fixtures/phrase.textile", 'rb') { |f| f.read }
|
39
|
+
docbook = File.open("spec/fixtures/phrase.xml", 'rb') { |f| f.read }
|
40
|
+
RedCloth.new(textile).to_docbook.docbook_strip.should eql(docbook.docbook_strip)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "source" do
|
44
|
+
textile = File.open("spec/fixtures/source.textile", 'rb') { |f| f.read }
|
45
|
+
docbook = File.open("spec/fixtures/source.xml", 'rb') { |f| f.read }
|
46
|
+
RedCloth.new(textile).to_docbook.docbook_strip.should eql(docbook.docbook_strip)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "bibliography" do
|
50
|
+
textile = File.open("spec/fixtures/bibliography.textile", 'rb') { |f| f.read }
|
51
|
+
docbook = File.open("spec/fixtures/bibliography.xml", 'rb') { |f| f.read }
|
52
|
+
RedCloth.new(textile).to_docbook.docbook_strip.should eql(docbook.docbook_strip)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "cover" do
|
56
|
+
textile = File.open("spec/fixtures/cover.textile", 'rb') { |f| f.read }
|
57
|
+
docbook = File.open("spec/fixtures/cover.xml", 'rb') { |f| f.read }
|
58
|
+
RedCloth.new(textile).to_docbook.docbook_strip.should eql(docbook.docbook_strip)
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
h1. Bibliography
|
2
|
+
|
3
|
+
h2. Referencing
|
4
|
+
|
5
|
+
Look at ??BernersLee?? for more information.
|
6
|
+
|
7
|
+
Look at ??Coleman?? for more information.
|
8
|
+
|
9
|
+
h2. Bibliography
|
10
|
+
|
11
|
+
h3{id:BernersLee}. Tim Berners Lee: The Web Reinvented
|
12
|
+
|
13
|
+
Addison Wesley 2003
|
14
|
+
|
15
|
+
Page 20-40
|
16
|
+
|
17
|
+
h3{id:Coleman}. Jones Coleman: Cummulated Chaos
|
18
|
+
|
19
|
+
Wembley 2003
|
20
|
+
|
21
|
+
Page 20-40
|
22
|
+
|
23
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<book xmlns="http://docbook.org/ns/docbook" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xl="http://www.w3.org/1999/xlink" version="5.0">
|
3
|
+
|
4
|
+
<chapter xmlns='http://docbook.org/ns/docbook' xmlns:xi='http://www.w3.org/2001/XInclude' version='5.0'>
|
5
|
+
<title>Bibliography</title>
|
6
|
+
<section>
|
7
|
+
<title>Referencing</title>
|
8
|
+
<para>Look at <citation xl:href="#BernersLee">BernersLee</citation> for more information.</para>
|
9
|
+
<para>Look at <citation xl:href="#Coleman">Coleman</citation> for more information.</para>
|
10
|
+
</section>
|
11
|
+
|
12
|
+
<section>
|
13
|
+
<title>Bibliography</title>
|
14
|
+
|
15
|
+
<section xml:id="BernersLee">
|
16
|
+
<title>Tim Berners Lee: The Web Reinvented</title>
|
17
|
+
<para>Addison Wesley 2003</para>
|
18
|
+
<para>Page 20-40</para>
|
19
|
+
</section>
|
20
|
+
|
21
|
+
<section xml:id="Coleman">
|
22
|
+
<title>Jones Coleman: Cummulated Chaos</title>
|
23
|
+
<para>Wembley 2003</para>
|
24
|
+
<para>Page 20-40</para>
|
25
|
+
</section>
|
26
|
+
|
27
|
+
</section>
|
28
|
+
</chapter>
|
29
|
+
|
30
|
+
</book>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
h1. Chapter 1
|
2
|
+
|
3
|
+
Some chapter text
|
4
|
+
|
5
|
+
h2. Sub Heading 1
|
6
|
+
|
7
|
+
Some sub text
|
8
|
+
|
9
|
+
h3. SubSub Heading 1
|
10
|
+
|
11
|
+
Some text
|
12
|
+
|
13
|
+
h4. SubSubSub Heading 1
|
14
|
+
|
15
|
+
Some more text
|
16
|
+
|
17
|
+
h2. Sub Heading 2
|
18
|
+
|
19
|
+
Some more sub text sub text
|
20
|
+
|
21
|
+
Even Some more sub text sub text
|
22
|
+
|
23
|
+
h1. Chapter 2
|
24
|
+
|
25
|
+
A little text
|
@@ -0,0 +1,38 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<book xmlns="http://docbook.org/ns/docbook" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xl="http://www.w3.org/1999/xlink" version="5.0">
|
3
|
+
|
4
|
+
<chapter xmlns='http://docbook.org/ns/docbook' xmlns:xi='http://www.w3.org/2001/XInclude' version='5.0'>
|
5
|
+
|
6
|
+
<title>Chapter 1</title>
|
7
|
+
<para>Some chapter text</para>
|
8
|
+
|
9
|
+
<section>
|
10
|
+
<title>Sub Heading 1</title>
|
11
|
+
<para>Some sub text</para>
|
12
|
+
|
13
|
+
<section>
|
14
|
+
<title>SubSub Heading 1</title>
|
15
|
+
<para>Some text</para>
|
16
|
+
|
17
|
+
<section>
|
18
|
+
<title>SubSubSub Heading 1</title>
|
19
|
+
<para>Some more text</para>
|
20
|
+
</section>
|
21
|
+
|
22
|
+
</section>
|
23
|
+
</section>
|
24
|
+
|
25
|
+
<section>
|
26
|
+
<title>Sub Heading 2</title>
|
27
|
+
<para>Some more sub text sub text</para>
|
28
|
+
<para>Even Some more sub text sub text</para>
|
29
|
+
</section>
|
30
|
+
|
31
|
+
</chapter>
|
32
|
+
|
33
|
+
<chapter xmlns='http://docbook.org/ns/docbook' xmlns:xi='http://www.w3.org/2001/XInclude' version='5.0'>
|
34
|
+
<title>Chapter 2</title>
|
35
|
+
<para>A little text</para>
|
36
|
+
</chapter>
|
37
|
+
|
38
|
+
</book>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<book xmlns="http://docbook.org/ns/docbook" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xl="http://www.w3.org/1999/xlink" version="5.0">
|
3
|
+
|
4
|
+
<info>
|
5
|
+
<title>Super Social Everybody</title>
|
6
|
+
<subtitle>How to Survive in the Social Web</subtitle>
|
7
|
+
<author><firstname>Thomas</firstname><surname>Fankhauser</surname></author>
|
8
|
+
<copyright>
|
9
|
+
<year>2010</year>
|
10
|
+
<holder>Norman Walsh, All rights reserved.</holder>
|
11
|
+
</copyright>
|
12
|
+
</info>
|
13
|
+
|
14
|
+
<preface>
|
15
|
+
<title>Foreword</title>
|
16
|
+
<para>This is the place for the foreword</para>
|
17
|
+
</preface>
|
18
|
+
|
19
|
+
</book>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<book xmlns="http://docbook.org/ns/docbook" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xl="http://www.w3.org/1999/xlink" version="5.0">
|
3
|
+
<chapter xmlns='http://docbook.org/ns/docbook' xmlns:xi='http://www.w3.org/2001/XInclude' version='5.0'>
|
4
|
+
|
5
|
+
<title>Footnotes</title>
|
6
|
+
|
7
|
+
<section>
|
8
|
+
<title>Basic</title>
|
9
|
+
<para>This sentence<footnote><para>Sentence is a collection of words</para></footnote> needs a footnote<footnote><para>A note at the food of the page</para></footnote>.</para>
|
10
|
+
</section>
|
11
|
+
</chapter>
|
12
|
+
</book>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<book xmlns="http://docbook.org/ns/docbook" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xl="http://www.w3.org/1999/xlink" version="5.0">
|
3
|
+
|
4
|
+
<chapter xmlns='http://docbook.org/ns/docbook' xmlns:xi='http://www.w3.org/2001/XInclude' version='5.0'>
|
5
|
+
<title>Hello</title>
|
6
|
+
<section>
|
7
|
+
<title>Basic</title>
|
8
|
+
<para>Hello</para>
|
9
|
+
</section>
|
10
|
+
</chapter>
|
11
|
+
</book>
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<book xmlns="http://docbook.org/ns/docbook" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xl="http://www.w3.org/1999/xlink" version="5.0">
|
3
|
+
|
4
|
+
<chapter xmlns='http://docbook.org/ns/docbook' xmlns:xi='http://www.w3.org/2001/XInclude' version='5.0'>
|
5
|
+
<title>Lists</title>
|
6
|
+
<section>
|
7
|
+
<title>Basic</title>
|
8
|
+
|
9
|
+
<itemizedlist>
|
10
|
+
<listitem><para>A bullet list 1</para></listitem>
|
11
|
+
<listitem><para>A bullet list 2</para></listitem>
|
12
|
+
<listitem><para>A bullet list 3</para></listitem>
|
13
|
+
</itemizedlist>
|
14
|
+
|
15
|
+
<orderedlist>
|
16
|
+
<listitem><para>A numbered list 1</para></listitem>
|
17
|
+
<listitem><para>A numbered list 2</para></listitem>
|
18
|
+
<listitem><para>A numbered list 3</para></listitem>
|
19
|
+
</orderedlist>
|
20
|
+
|
21
|
+
</section>
|
22
|
+
</chapter>
|
23
|
+
</book>
|
@@ -0,0 +1,21 @@
|
|
1
|
+
h1. Phrases
|
2
|
+
|
3
|
+
h2. Basic
|
4
|
+
|
5
|
+
I _believe_ every word.
|
6
|
+
|
7
|
+
I __believe__ every word.
|
8
|
+
|
9
|
+
This is a *bold* sentence.
|
10
|
+
|
11
|
+
This is a **bold** sentence.
|
12
|
+
|
13
|
+
??LKing?? was said by Martin Luther King.
|
14
|
+
|
15
|
+
Simply run @rake db:migrate@ to install everything.
|
16
|
+
|
17
|
+
Simply got to "Google":http://www.google.com and search.
|
18
|
+
|
19
|
+
!../images/image.png(A great image)!
|
20
|
+
|
21
|
+
bq{by: Martin Luther King}. I have a dream. The dream is great. It will come true!
|
@@ -0,0 +1,39 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<book xmlns="http://docbook.org/ns/docbook" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xl="http://www.w3.org/1999/xlink" version="5.0">
|
3
|
+
|
4
|
+
<chapter xmlns='http://docbook.org/ns/docbook' xmlns:xi='http://www.w3.org/2001/XInclude' version='5.0'>
|
5
|
+
<title>Phrases</title>
|
6
|
+
<section>
|
7
|
+
<title>Basic</title>
|
8
|
+
|
9
|
+
<para>I <emphasis>believe</emphasis> every word.</para>
|
10
|
+
|
11
|
+
<para>I <emphasis>believe</emphasis> every word.</para>
|
12
|
+
|
13
|
+
<para>This is a <emphasis role="bold">bold</emphasis> sentence.</para>
|
14
|
+
|
15
|
+
<para>This is a <emphasis role="bold">bold</emphasis> sentence.</para>
|
16
|
+
|
17
|
+
<para><citation xl:href="#LKing">LKing</citation> was said by Martin Luther King.</para>
|
18
|
+
|
19
|
+
<para>Simply run <code>rake db:migrate</code> to install everything.</para>
|
20
|
+
|
21
|
+
<para>Simply got to <link xl:href="http://www.google.com">Google</link> and search.</para>
|
22
|
+
|
23
|
+
<para>
|
24
|
+
<figure xml:id="A.great.image">
|
25
|
+
<title>A great image</title>
|
26
|
+
<mediaobject>
|
27
|
+
<imageobject><imagedata fileref="../images/image.png" format="PNG" /></imageobject>
|
28
|
+
</mediaobject>
|
29
|
+
</figure>
|
30
|
+
</para>
|
31
|
+
|
32
|
+
<blockquote>
|
33
|
+
<attribution>Martin Luther King</attribution>
|
34
|
+
<para>I have a dream. The dream is great. It will come true!</para>
|
35
|
+
</blockquote>
|
36
|
+
|
37
|
+
</section>
|
38
|
+
</chapter>
|
39
|
+
</book>
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<book xmlns="http://docbook.org/ns/docbook" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xl="http://www.w3.org/1999/xlink" version="5.0">
|
3
|
+
|
4
|
+
<chapter xmlns='http://docbook.org/ns/docbook' xmlns:xi='http://www.w3.org/2001/XInclude' version='5.0'>
|
5
|
+
<title>Source Code</title>
|
6
|
+
<section>
|
7
|
+
<title>Basic</title>
|
8
|
+
|
9
|
+
<para>some text</para>
|
10
|
+
|
11
|
+
<para>
|
12
|
+
<example xml:id="Ruby.Car.Class">
|
13
|
+
<title>Ruby Car Class</title>
|
14
|
+
<programlisting width="100%">
|
15
|
+
class Car
|
16
|
+
|
17
|
+
def start_engine
|
18
|
+
end
|
19
|
+
|
20
|
+
def stop_engine
|
21
|
+
end
|
22
|
+
|
23
|
+
end</programlisting>
|
24
|
+
</example>
|
25
|
+
</para>
|
26
|
+
|
27
|
+
<para>Another paragraph</para>
|
28
|
+
|
29
|
+
</section>
|
30
|
+
</chapter>
|
31
|
+
|
32
|
+
</book>
|
@@ -0,0 +1,46 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<book xmlns="http://docbook.org/ns/docbook" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xl="http://www.w3.org/1999/xlink" version="5.0">
|
3
|
+
|
4
|
+
<chapter xmlns='http://docbook.org/ns/docbook' xmlns:xi='http://www.w3.org/2001/XInclude' version='5.0'>
|
5
|
+
|
6
|
+
<title>Tables</title>
|
7
|
+
|
8
|
+
<section>
|
9
|
+
<title>Basic</title>
|
10
|
+
|
11
|
+
<table frame='all'>
|
12
|
+
<title>Attendees</title>
|
13
|
+
|
14
|
+
<tgroup cols='3' align='left' colsep='1' rowsep='1'>
|
15
|
+
<thead>
|
16
|
+
<row>
|
17
|
+
<entry>Name</entry>
|
18
|
+
<entry>Age</entry>
|
19
|
+
<entry>Sex</entry>
|
20
|
+
</row>
|
21
|
+
</thead>
|
22
|
+
<tbody>
|
23
|
+
<row>
|
24
|
+
<entry>Joan</entry>
|
25
|
+
<entry>24</entry>
|
26
|
+
<entry>F</entry>
|
27
|
+
</row>
|
28
|
+
<row>
|
29
|
+
<entry>Archie</entry>
|
30
|
+
<entry>29</entry>
|
31
|
+
<entry>M</entry>
|
32
|
+
</row>
|
33
|
+
<row>
|
34
|
+
<entry>Bello</entry>
|
35
|
+
<entry>45</entry>
|
36
|
+
<entry>F</entry>
|
37
|
+
</row>
|
38
|
+
</tbody>
|
39
|
+
</tgroup>
|
40
|
+
</table>
|
41
|
+
</section>
|
42
|
+
|
43
|
+
</chapter>
|
44
|
+
|
45
|
+
|
46
|
+
</book>
|
data/spec/helpers.rb
ADDED
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: redcloth-formatters-docbook
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Thomas Fankhauser
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-10-17 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: RedCloth
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 39
|
30
|
+
segments:
|
31
|
+
- 4
|
32
|
+
- 2
|
33
|
+
- 8
|
34
|
+
version: 4.2.8
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rspec
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 15
|
46
|
+
segments:
|
47
|
+
- 2
|
48
|
+
- 6
|
49
|
+
version: "2.6"
|
50
|
+
type: :development
|
51
|
+
version_requirements: *id002
|
52
|
+
description: Allows RedCloth to convert .textiles to Docbook XMLs
|
53
|
+
email:
|
54
|
+
- tommylefunk@googlemail.com
|
55
|
+
executables: []
|
56
|
+
|
57
|
+
extensions: []
|
58
|
+
|
59
|
+
extra_rdoc_files: []
|
60
|
+
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- README.textile
|
65
|
+
- Rakefile
|
66
|
+
- lib/redcloth-formatters-docbook.rb
|
67
|
+
- lib/redcloth-formatters-docbook/formatters/docbook.rb
|
68
|
+
- lib/redcloth-formatters-docbook/textile_doc.rb
|
69
|
+
- lib/redcloth-formatters-docbook/version.rb
|
70
|
+
- redcloth-formatters-docbook.gemspec
|
71
|
+
- spec/docbook_spec.rb
|
72
|
+
- spec/fixtures/bibliography.textile
|
73
|
+
- spec/fixtures/bibliography.xml
|
74
|
+
- spec/fixtures/chapters.textile
|
75
|
+
- spec/fixtures/chapters.xml
|
76
|
+
- spec/fixtures/cover.textile
|
77
|
+
- spec/fixtures/cover.xml
|
78
|
+
- spec/fixtures/footnotes.textile
|
79
|
+
- spec/fixtures/footnotes.xml
|
80
|
+
- spec/fixtures/hello.textile
|
81
|
+
- spec/fixtures/hello.xml
|
82
|
+
- spec/fixtures/lists.textile
|
83
|
+
- spec/fixtures/lists.xml
|
84
|
+
- spec/fixtures/phrase.textile
|
85
|
+
- spec/fixtures/phrase.xml
|
86
|
+
- spec/fixtures/source.textile
|
87
|
+
- spec/fixtures/source.xml
|
88
|
+
- spec/fixtures/tables.textile
|
89
|
+
- spec/fixtures/tables.xml
|
90
|
+
- spec/helpers.rb
|
91
|
+
has_rdoc: true
|
92
|
+
homepage: ""
|
93
|
+
licenses: []
|
94
|
+
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
hash: 3
|
106
|
+
segments:
|
107
|
+
- 0
|
108
|
+
version: "0"
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
none: false
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
hash: 3
|
115
|
+
segments:
|
116
|
+
- 0
|
117
|
+
version: "0"
|
118
|
+
requirements: []
|
119
|
+
|
120
|
+
rubyforge_project: redcloth-formatters-docbook
|
121
|
+
rubygems_version: 1.4.2
|
122
|
+
signing_key:
|
123
|
+
specification_version: 3
|
124
|
+
summary: RedCloth DocBook Formatter
|
125
|
+
test_files:
|
126
|
+
- spec/docbook_spec.rb
|
127
|
+
- spec/fixtures/bibliography.textile
|
128
|
+
- spec/fixtures/bibliography.xml
|
129
|
+
- spec/fixtures/chapters.textile
|
130
|
+
- spec/fixtures/chapters.xml
|
131
|
+
- spec/fixtures/cover.textile
|
132
|
+
- spec/fixtures/cover.xml
|
133
|
+
- spec/fixtures/footnotes.textile
|
134
|
+
- spec/fixtures/footnotes.xml
|
135
|
+
- spec/fixtures/hello.textile
|
136
|
+
- spec/fixtures/hello.xml
|
137
|
+
- spec/fixtures/lists.textile
|
138
|
+
- spec/fixtures/lists.xml
|
139
|
+
- spec/fixtures/phrase.textile
|
140
|
+
- spec/fixtures/phrase.xml
|
141
|
+
- spec/fixtures/source.textile
|
142
|
+
- spec/fixtures/source.xml
|
143
|
+
- spec/fixtures/tables.textile
|
144
|
+
- spec/fixtures/tables.xml
|
145
|
+
- spec/helpers.rb
|