redcloth-formatters-docbook 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -120,7 +120,7 @@ module RedCloth::Formatters::Docbook
120
120
 
121
121
  # para
122
122
  def p(opts)
123
- "#{"\t" * @@stack.size}<para>#{opts[:text]}</para>\n"
123
+ "#{"\t" * @@stack.size}<para>#{clean_text(opts[:text])}</para>\n"
124
124
  end
125
125
 
126
126
  # lists
@@ -215,7 +215,7 @@ module RedCloth::Formatters::Docbook
215
215
  alias :strong :b
216
216
 
217
217
  def br(opts)
218
- ""
218
+ " "
219
219
  end
220
220
 
221
221
  def cite(opts)
@@ -234,12 +234,14 @@ module RedCloth::Formatters::Docbook
234
234
  def image(opts)
235
235
  title = opts[:title]
236
236
  id = title.split(" ").join(".")
237
+ options = parse_css(opts[:style])
238
+ width = options[:width] || "100%"
237
239
 
238
240
  out = "\n"
239
241
  out += "<figure xml:id=\"#{id}\">\n"
240
242
  out += "<title>#{title}</title>\n"
241
243
  out += "<mediaobject>\n"
242
- out += "\t<imageobject><imagedata fileref=\"#{opts[:src]}\" format=\"PNG\" /></imageobject>\n"
244
+ out += "\t<imageobject><imagedata fileref=\"#{opts[:src]}\" format=\"PNG\" width=\"#{width}\"/></imageobject>\n"
243
245
  out += "</mediaobject>\n"
244
246
  out += "</figure>\n"
245
247
  out
@@ -261,9 +263,8 @@ module RedCloth::Formatters::Docbook
261
263
  def bc_open(opts)
262
264
  opts[:block] = true
263
265
  options = parse_css(opts[:style])
264
- id = options[:name].split(" ").join(".")
265
266
  out = "<para>\n"
266
- out += "\t<example xml:id=\"#{id}\">\n"
267
+ out += "\t<example xml:id=\"#{parse_id(options[:name])}\">\n"
267
268
  out += "\t<title>#{options[:name]}</title>\n"
268
269
  out += "\t<programlisting width=\"100%\">\n"
269
270
  out
@@ -309,6 +310,10 @@ module RedCloth::Formatters::Docbook
309
310
  end
310
311
  options
311
312
  end
313
+
314
+ def parse_id name
315
+ name.gsub(",", "").gsub(".", "").squeeze(" ").strip.gsub(" ", "")
316
+ end
312
317
 
313
318
  def close_level(type)
314
319
  last = @@stack.last
@@ -322,20 +327,24 @@ module RedCloth::Formatters::Docbook
322
327
  def open_level(type, tag)
323
328
  @@stack << { :type => type, :tag => tag }
324
329
  end
330
+
331
+ def clean_text(text)
332
+ text.gsub("\n", " ").gsub("\t", " ").squeeze(" ").strip
333
+ end
325
334
 
326
335
  # escapement for regular HTML (not in PRE tag)
327
336
  def escape(text)
328
- html_esc(text)
337
+ text
329
338
  end
330
339
 
331
340
  # escapement for HTML in a PRE tag
332
341
  def escape_pre(text)
333
- html_esc(text, :html_escape_preformatted)
342
+ text
334
343
  end
335
344
 
336
345
  # escaping for HTML attributes
337
346
  def escape_attribute(text)
338
- html_esc(text, :html_escape_attributes)
347
+ text
339
348
  end
340
349
 
341
350
  def after_transform(text)
@@ -1,7 +1,7 @@
1
1
  module Redcloth
2
2
  module Formatters
3
3
  module Docbook
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.2"
5
5
  end
6
6
  end
7
7
  end
data/spec/docbook_spec.rb CHANGED
@@ -57,5 +57,11 @@ describe Redcloth::Formatters::Docbook do
57
57
  docbook = File.open("spec/fixtures/cover.xml", 'rb') { |f| f.read }
58
58
  RedCloth.new(textile).to_docbook.docbook_strip.should eql(docbook.docbook_strip)
59
59
  end
60
+
61
+ it "formatting" do
62
+ textile = File.open("spec/fixtures/formatting.textile", 'rb') { |f| f.read }
63
+ docbook = File.open("spec/fixtures/formatting.xml", 'rb') { |f| f.read }
64
+ RedCloth.new(textile).to_docbook.docbook_strip.should eql(docbook.docbook_strip)
65
+ end
60
66
 
61
67
  end
@@ -0,0 +1,12 @@
1
+ h1. Hello
2
+
3
+ h2. Basic
4
+
5
+ They're so cool!
6
+
7
+
8
+ This is some text that
9
+ continues in the second line.
10
+
11
+ This is some text that
12
+ continues in the second line.
@@ -0,0 +1,13 @@
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>They're so cool!</para>
9
+ <para>This is some text that continues in the second line.</para>
10
+ <para>This is some text that continues in the second line.</para>
11
+ </section>
12
+ </chapter>
13
+ </book>
@@ -16,6 +16,6 @@ Simply run @rake db:migrate@ to install everything.
16
16
 
17
17
  Simply got to "Google":http://www.google.com and search.
18
18
 
19
- !../images/image.png(A great image)!
19
+ !{width: 90%;}../images/image.png(A great image)!
20
20
 
21
21
  bq{by: Martin Luther King}. I have a dream. The dream is great. It will come true!
@@ -24,7 +24,7 @@
24
24
  <figure xml:id="A.great.image">
25
25
  <title>A great image</title>
26
26
  <mediaobject>
27
- <imageobject><imagedata fileref="../images/image.png" format="PNG" /></imageobject>
27
+ <imageobject><imagedata fileref="../images/image.png" format="PNG" width="90%"/></imageobject>
28
28
  </mediaobject>
29
29
  </figure>
30
30
  </para>
@@ -9,7 +9,7 @@
9
9
  <para>some text</para>
10
10
 
11
11
  <para>
12
- <example xml:id="Ruby.Car.Class">
12
+ <example xml:id="RubyCarClass">
13
13
  <title>Ruby Car Class</title>
14
14
  <programlisting width="100%">
15
15
  class Car
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redcloth-formatters-docbook
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Thomas Fankhauser
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-17 00:00:00 +02:00
18
+ date: 2011-10-18 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -77,6 +77,8 @@ files:
77
77
  - spec/fixtures/cover.xml
78
78
  - spec/fixtures/footnotes.textile
79
79
  - spec/fixtures/footnotes.xml
80
+ - spec/fixtures/formatting.textile
81
+ - spec/fixtures/formatting.xml
80
82
  - spec/fixtures/hello.textile
81
83
  - spec/fixtures/hello.xml
82
84
  - spec/fixtures/lists.textile
@@ -132,6 +134,8 @@ test_files:
132
134
  - spec/fixtures/cover.xml
133
135
  - spec/fixtures/footnotes.textile
134
136
  - spec/fixtures/footnotes.xml
137
+ - spec/fixtures/formatting.textile
138
+ - spec/fixtures/formatting.xml
135
139
  - spec/fixtures/hello.textile
136
140
  - spec/fixtures/hello.xml
137
141
  - spec/fixtures/lists.textile