notroff 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/notroff +1 -1
- data/lib/yesroff/nr_writer.rb +19 -0
- data/lib/yesroff/odt_parser.rb +44 -5
- data/lib/yesroff/text.rb +27 -4
- metadata +13 -3
- data/lib/notroff/#filter.rb# +0 -27
data/bin/notroff
CHANGED
data/lib/yesroff/nr_writer.rb
CHANGED
@@ -3,6 +3,7 @@ class NRWriter
|
|
3
3
|
|
4
4
|
def initialize
|
5
5
|
@para_style = :body
|
6
|
+
@text_style = :normal
|
6
7
|
@single_line = false
|
7
8
|
end
|
8
9
|
|
@@ -19,6 +20,24 @@ class NRWriter
|
|
19
20
|
@single_line = single_line
|
20
21
|
end
|
21
22
|
|
23
|
+
def switch_text_style(new_style)
|
24
|
+
debug " <<switching to new style #{new_style}>> "
|
25
|
+
return if @text_style == new_style
|
26
|
+
if @text_style != :normal
|
27
|
+
toggle_text_style(@text_style)
|
28
|
+
end
|
29
|
+
if new_style != :normal
|
30
|
+
toggle_text_style(new_style)
|
31
|
+
end
|
32
|
+
@text_style = new_style
|
33
|
+
end
|
34
|
+
|
35
|
+
def toggle_text_style(style)
|
36
|
+
toggle_bold if style == :bold
|
37
|
+
toggle_italic if style == :italic
|
38
|
+
toggle_code if style == :code
|
39
|
+
end
|
40
|
+
|
22
41
|
def end_paragraph
|
23
42
|
puts
|
24
43
|
if @single_line
|
data/lib/yesroff/odt_parser.rb
CHANGED
@@ -2,13 +2,27 @@ require 'rexml/document'
|
|
2
2
|
require 'pp'
|
3
3
|
require 'zip/zipfilesystem'
|
4
4
|
|
5
|
+
DEBUG=true
|
6
|
+
|
7
|
+
def log(*args)
|
8
|
+
$stderr.puts args.join(' ')
|
9
|
+
end
|
10
|
+
|
11
|
+
def debug(*args)
|
12
|
+
#return unless DEBUG
|
13
|
+
puts args.join(' ')
|
14
|
+
end
|
15
|
+
|
5
16
|
class OdtParser
|
17
|
+
|
6
18
|
def initialize(odt_path)
|
19
|
+
log "Reading #{odt_path}..."
|
7
20
|
Zip::ZipFile.open(odt_path ) do |zipfile|
|
8
21
|
zipfile.file.open("content.xml") do |content|
|
9
22
|
@doc = REXML::Document.new(content.read)
|
10
23
|
end
|
11
24
|
end
|
25
|
+
log "Done"
|
12
26
|
|
13
27
|
@writer = NRWriter.new
|
14
28
|
@paras = []
|
@@ -39,23 +53,44 @@ class OdtParser
|
|
39
53
|
ParagraphStyle.new('FT', nil, :body, false),
|
40
54
|
ParagraphStyle.new('IT', nil, :body, false),
|
41
55
|
ParagraphStyle.new('Quotation', nil, :quote, true),
|
56
|
+
|
42
57
|
ParagraphStyle.new('CDT1', nil, :code, false),
|
43
58
|
ParagraphStyle.new('CDT', nil, :code, false),
|
59
|
+
ParagraphStyle.new('CDTX', nil, :code, false),
|
60
|
+
ParagraphStyle.new('C1', nil, :c1, true),
|
61
|
+
ParagraphStyle.new('C2', nil, :c1, true),
|
62
|
+
ParagraphStyle.new('TB', nil, :c1, true),
|
63
|
+
ParagraphStyle.new('Free_20_Form', nil, :c1, true),
|
64
|
+
|
65
|
+
|
66
|
+
ParagraphStyle.new('NLC1', nil, :code, false),
|
67
|
+
ParagraphStyle.new('NLC', nil, :code, false),
|
68
|
+
ParagraphStyle.new('NLCX', nil, :code, false),
|
69
|
+
ParagraphStyle.new('NLPara', nil, :code, false),
|
70
|
+
|
71
|
+
ParagraphStyle.new('TX', nil, :code, false),
|
72
|
+
|
44
73
|
ParagraphStyle.new('HA', nil, :title, true),
|
45
74
|
ParagraphStyle.new('HB', nil, :subtitle, true),
|
46
75
|
ParagraphStyle.new('HC', nil, :sec, true),
|
76
|
+
ParagraphStyle.new('HD', nil, :subsec, true),
|
47
77
|
ParagraphStyle.new('TH', nil, :theading, true),
|
48
78
|
ParagraphStyle.new('LH', nil, :ltitle, true),
|
49
79
|
ParagraphStyle.new('LC', nil, :listing, false),
|
50
80
|
ParagraphStyle.new('LC2', nil, :listing, false),
|
51
81
|
ParagraphStyle.new('LX', nil, :listing, false),
|
52
|
-
|
82
|
+
|
53
83
|
ParagraphStyle.new('BL1', nil, :bullet, true),
|
54
84
|
ParagraphStyle.new('BL', nil, :bullet, true),
|
55
85
|
ParagraphStyle.new('BX', nil, :bullet, true),
|
86
|
+
|
87
|
+
ParagraphStyle.new('NL1', nil, :list, true),
|
88
|
+
ParagraphStyle.new('NL', nil, :list, true),
|
89
|
+
ParagraphStyle.new('NX', nil, :list, true),
|
90
|
+
|
56
91
|
ParagraphStyle.new('BLPara', nil, :bullet, true),
|
57
|
-
ParagraphStyle.new('Quotation_20_Attribution', nil, :attribution, true)
|
58
|
-
|
92
|
+
ParagraphStyle.new('Quotation_20_Attribution', nil, :attribution, true)
|
93
|
+
|
59
94
|
]
|
60
95
|
|
61
96
|
hash = {}
|
@@ -74,6 +109,7 @@ class OdtParser
|
|
74
109
|
end
|
75
110
|
|
76
111
|
def parse_text_styles
|
112
|
+
log "Parsing text styles"
|
77
113
|
styles = REXML::XPath.match(@doc, "//style:style[@style:family='text']")
|
78
114
|
styles.each do |s|
|
79
115
|
attrs = s.attributes
|
@@ -89,6 +125,7 @@ class OdtParser
|
|
89
125
|
end
|
90
126
|
|
91
127
|
def parse_paragraph_styles
|
128
|
+
log "Parsing paragraph styles"
|
92
129
|
styles = REXML::XPath.match(@doc, "//style:style[@style:family='paragraph']")
|
93
130
|
styles.each do |s|
|
94
131
|
attrs = s.attributes
|
@@ -99,6 +136,7 @@ class OdtParser
|
|
99
136
|
end
|
100
137
|
|
101
138
|
def parse_paragraphs
|
139
|
+
log "Parsing paragraphs"
|
102
140
|
results = []
|
103
141
|
paras = REXML::XPath.match(@doc, '//text:p')
|
104
142
|
paras.each do |p|
|
@@ -109,12 +147,13 @@ class OdtParser
|
|
109
147
|
|
110
148
|
def lookup_para_style(name)
|
111
149
|
s = @para_styles[name]
|
112
|
-
|
150
|
+
log "No such para style #{name}" unless s
|
151
|
+
#raise "No such para style #{name}" unless s
|
113
152
|
s
|
114
153
|
end
|
115
154
|
|
116
155
|
def find_or_create_para_style(name)
|
117
|
-
|
156
|
+
return lookup_para_style(name)
|
118
157
|
s = @para_styles[name]
|
119
158
|
unless s
|
120
159
|
STDERR.puts "Warning: no paragraph style named #{name}"
|
data/lib/yesroff/text.rb
CHANGED
@@ -32,9 +32,17 @@ class TextStyle < Style
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def render(w)
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
puts "Rendering style #{self}"
|
36
|
+
|
37
|
+
if @bold
|
38
|
+
w.switch_text_style(:bold)
|
39
|
+
elsif @italic
|
40
|
+
w.switch_text_style(:italic)
|
41
|
+
elsif @code
|
42
|
+
w.switch_text_style(:code)
|
43
|
+
else
|
44
|
+
w.switch_text_style(:normal)
|
45
|
+
end
|
38
46
|
end
|
39
47
|
end
|
40
48
|
|
@@ -66,6 +74,12 @@ class Container
|
|
66
74
|
@contents << content
|
67
75
|
end
|
68
76
|
|
77
|
+
def length
|
78
|
+
l = 0
|
79
|
+
@contents.each {|kid| l += kid.length}
|
80
|
+
l
|
81
|
+
end
|
82
|
+
|
69
83
|
def render(w)
|
70
84
|
#puts "========= rendering #{self.class} size: #{contents.size}"
|
71
85
|
#pp contents
|
@@ -78,6 +92,8 @@ class Span < Container
|
|
78
92
|
attr_accessor :indent
|
79
93
|
|
80
94
|
def render(w)
|
95
|
+
debug "\nrendering span #{self} length #{self.length}"
|
96
|
+
return if self.length == 0
|
81
97
|
style.render(w)
|
82
98
|
w.indent(@indent) if @indent
|
83
99
|
super(w)
|
@@ -101,7 +117,14 @@ class Text
|
|
101
117
|
end
|
102
118
|
|
103
119
|
def render(w)
|
104
|
-
|
120
|
+
text = @text.gsub(/@@/, '\@\@')
|
121
|
+
text = text.gsub(/~~/, '\~\~')
|
122
|
+
text = text.gsub(/!!/, '\!\!')
|
123
|
+
w.text(text)
|
124
|
+
end
|
125
|
+
|
126
|
+
def length
|
127
|
+
@text.length
|
105
128
|
end
|
106
129
|
|
107
130
|
def to_s
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: notroff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,18 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
date: 2012-09-03 00:00:00.000000000Z
|
13
|
-
dependencies:
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rubyzip
|
16
|
+
requirement: &70333341691900 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70333341691900
|
14
25
|
description: NotRoff A simple text to openoffice filter
|
15
26
|
email: russ@russolsen.com
|
16
27
|
executables:
|
@@ -33,7 +44,6 @@ files:
|
|
33
44
|
- spec/text_spec.rb
|
34
45
|
- spec/type_assigner_spec.rb
|
35
46
|
- spec/with_commands.nr
|
36
|
-
- lib/notroff/#filter.rb#
|
37
47
|
- lib/notroff/#io.rb#
|
38
48
|
- lib/notroff/code_scrubber.rb
|
39
49
|
- lib/notroff/command_processor.rb
|
data/lib/notroff/#filter.rb#
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
class Filter
|
2
|
-
def process(paragraphs)
|
3
|
-
paragraphs.find_all {|p| included?(p)}
|
4
|
-
end
|
5
|
-
|
6
|
-
def included?(paragraph)
|
7
|
-
true
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
class IncludedFilter < Filter
|
12
|
-
def included?(paragraph)
|
13
|
-
paragraph[:included]
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
class RegularExpressionExcludeFilter
|
18
|
-
< Filter
|
19
|
-
def initialize(exclude_re)
|
20
|
-
@exclude_re = exclude_re
|
21
|
-
end
|
22
|
-
|
23
|
-
def included?(paragraph)
|
24
|
-
@exclude_re !~ paragraph
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|