oo2md2tex 0.0.18 → 0.0.19

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/oo2text +54 -33
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 51dcd05d8ba14f620580f79c30ec4affea5b3c89
4
- data.tar.gz: 6038b3084acaed875cdbad5b905895853b956f3b
3
+ metadata.gz: 9083374a98ee729448d3ae40727b77aa2759678b
4
+ data.tar.gz: 1b2c3b5cb0f2ddccc9a38f6694f7e90661451a42
5
5
  SHA512:
6
- metadata.gz: 0710d42c8c84375ea3ab87f2325c8bccf2ce39f73b67fdb38a1c56ddbaae7fa70079362bb9a7af1be35fd05ce5240544264590257fcbae6c760e1a73c234c830
7
- data.tar.gz: '064208e1b1b84f32d77c1634137bf921a26fcd5d29e6112d7066866885776be12989c284efdb53b5f8d6f61b2831b52d790099371318e44e6253146815635869'
6
+ metadata.gz: 6e9075b8a6e9807e107c6a41e58aa1429dbefacc71f6bf92fe1b6b32ec084ab7606801abad1b75821e1da0155ccd83274692c625e75337eba68ee34ca089c054
7
+ data.tar.gz: edf4dc0f7a5ef2b6bf0254fb3fcbc52858786445d101d28cdffad661574c19f076e23ce76525fcbeef713eb051533f4bcc8db18769d86685cb538738f23cc4d9
data/bin/oo2text CHANGED
@@ -22,6 +22,10 @@ require 'zlib'
22
22
  require 'zip'
23
23
  require 'stringio'
24
24
 
25
+ $DBG = true
26
+ require 'awesome_print' if $DBG
27
+ require 'pry-byebug' if $DBG
28
+
25
29
  module OmniOutliner
26
30
 
27
31
  # Common Classes
@@ -56,9 +60,6 @@ module OmniOutliner
56
60
  end
57
61
 
58
62
  def end_element(name)
59
- if name == "lit"
60
- @str += "\n" if in_body_text
61
- end
62
63
  if name == "values"
63
64
  @str.gsub(/\n/, '')
64
65
  end
@@ -88,8 +89,8 @@ module OmniOutliner
88
89
 
89
90
  class DocumentCommon < Nokogiri::XML::SAX::Document
90
91
  def initialize
91
- @contexts = []
92
- @context = nil
92
+ @context = ParseContext.new(nil, "ROOT", {})
93
+ @contexts = [@context]
93
94
  super
94
95
  end
95
96
 
@@ -104,23 +105,9 @@ module OmniOutliner
104
105
  @context.elevate(old_context) if @context
105
106
  end
106
107
 
107
- def start_element(name, attrs)
108
- push_context(name, attrs)
109
- @context.start_element(name, attrs)
110
- end
111
-
112
- def end_element(name)
113
- final_output if name == "outline"
114
- @context.end_element(name)
115
- pop_context
116
- end
117
-
118
108
  def characters(s)
119
109
  @context.characters(s)
120
110
  end
121
-
122
- def final_output
123
- end
124
111
  end
125
112
 
126
113
  # Version Dependent Classes for V3
@@ -129,6 +116,21 @@ module OmniOutliner
129
116
  # https://www.omnigroup.com/namespace/OmniOutliner/xmloutline-v3.dtd
130
117
  class V3
131
118
  class Document < DocumentCommon
119
+ def start_element(name, attrs)
120
+ push_context(name, attrs)
121
+ @context.start_element(name, attrs)
122
+ end
123
+
124
+ def end_element(name)
125
+ if name == "values"
126
+ @context.str.gsub!(/\n/, '')
127
+ @context.str += "\n"
128
+ end
129
+ @context.end_element(name)
130
+ pop_context
131
+ final_output if name == "outline"
132
+ end
133
+
132
134
  def final_output
133
135
  puts @context.str
134
136
  end
@@ -163,22 +165,36 @@ module OmniOutliner
163
165
  # https://www.omnigroup.com/namespace/OmniOutliner/xmloutline-editors-v1.rng
164
166
  class V5
165
167
  class Item
166
- attr_reader :attrs
167
- attr_accessor :is_root
168
+ attr_reader :attrs, :rank, :id, :parent_id
169
+ attr_accessor :is_root, :parent
168
170
 
169
171
  def initialize(attrs, text)
170
172
  @attrs = attrs
173
+ @id = @attrs["id"]
174
+ @parent = nil
175
+ @parent_id = @attrs["parent-id"]
176
+ @rank = @attrs["rank"]
177
+ @rank = "0" if @rank.nil? || @rank == ""
178
+ @rank += "00" if @rank.size == 4
171
179
  @text = text
172
180
  @children = {}
173
181
  end
174
182
 
175
- def add(rank, item)
176
- rank = "0" if rank.nil? || rank == ""
177
- rank += "00" if rank.size == 4
178
- @children[rank.hex] = item
183
+ def add_child(item)
184
+ @children[item.rank.hex] = item
185
+ item.parent = self
186
+ end
187
+
188
+ def parent_chain
189
+ if @parent == nil
190
+ return ["ROOT"]
191
+ else
192
+ @parent.parent_chain + [self.id]
193
+ end
179
194
  end
180
195
 
181
196
  def print_all
197
+ puts "%% " + parent_chain.join(" < ") + " (#{@rank}) #{@attrs}\n" if $DBG
182
198
  puts @text unless @is_root
183
199
  @children.keys.sort.each {|k| @children[k].print_all}
184
200
  end
@@ -190,14 +206,18 @@ module OmniOutliner
190
206
  super
191
207
  end
192
208
 
209
+ def start_element(name, attrs)
210
+ push_context(name, attrs)
211
+ @context.start_element(name, attrs)
212
+ end
213
+
193
214
  def end_element(name)
215
+ @context.end_element(name)
194
216
  if name == "item"
195
- str = @context.str
196
- str.gsub(/\n/, '')
197
- @items[@context.id] = Item.new(@context.attrs, str)
198
- @context.str = ""
217
+ @items[@context.id] = Item.new(@context.attrs, @context.str + "\n")
199
218
  end
200
- super
219
+ pop_context
220
+ final_output if name == "outline"
201
221
  end
202
222
 
203
223
  def final_output
@@ -206,11 +226,12 @@ module OmniOutliner
206
226
  @root = item
207
227
  @root.is_root = true
208
228
  elsif pid = item.attrs["parent-id"]
209
- @items[pid].add(item.attrs["rank"], item)
229
+ @items[pid].add_child(item)
210
230
  else
211
- @root.add(item.attrs["rank"], item)
231
+ @root.add_child(item)
212
232
  end
213
233
  end
234
+ #binding.pry
214
235
  @root.print_all #unless @root.nil?
215
236
  end
216
237
  end
@@ -238,7 +259,7 @@ module OmniOutliner
238
259
  super(@file) if @file
239
260
  end
240
261
  end
241
- end # v3
262
+ end # v5
242
263
  end
243
264
 
244
265
  ARGV.options do |o|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oo2md2tex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.18
4
+ version: 0.0.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shigeya Suzuki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-20 00:00:00.000000000 Z
11
+ date: 2017-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redcarpet