oo2md2tex 0.0.18 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +5 -5
  2. data/bin/oo2text +53 -33
  3. metadata +16 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 51dcd05d8ba14f620580f79c30ec4affea5b3c89
4
- data.tar.gz: 6038b3084acaed875cdbad5b905895853b956f3b
2
+ SHA256:
3
+ metadata.gz: b21885d146e82b9311a26ed13a0100ea10d7a8df659a3948eba3cec5ecb2d37b
4
+ data.tar.gz: 4fedeff1701b3151b1dfc9f1935677d6300846d42e7d38b821f36911b46d698e
5
5
  SHA512:
6
- metadata.gz: 0710d42c8c84375ea3ab87f2325c8bccf2ce39f73b67fdb38a1c56ddbaae7fa70079362bb9a7af1be35fd05ce5240544264590257fcbae6c760e1a73c234c830
7
- data.tar.gz: '064208e1b1b84f32d77c1634137bf921a26fcd5d29e6112d7066866885776be12989c284efdb53b5f8d6f61b2831b52d790099371318e44e6253146815635869'
6
+ metadata.gz: fcff80582b49e59abb42a2278db2f86958d99f06d0d85cc928e281378a1d66511620a7b702d5c717d0b7bd9850ee4ad6100864e311798d18121b5148e0494d63
7
+ data.tar.gz: f937197b8429c20a8d359fe8872897086c66bad81b8461399c4f18683bbd5db33a5b3c9214b09e2abd9c7c584c7a09885e77c313397c0786c8babc91ffb64ab3
data/bin/oo2text CHANGED
@@ -22,6 +22,10 @@ require 'zlib'
22
22
  require 'zip'
23
23
  require 'stringio'
24
24
 
25
+ $OO2DBG = false
26
+ require 'awesome_print' if $OO2DBG
27
+ require 'pry-byebug' if $OO2DBG
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,9 +226,9 @@ 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
214
234
  @root.print_all #unless @root.nil?
@@ -238,7 +258,7 @@ module OmniOutliner
238
258
  super(@file) if @file
239
259
  end
240
260
  end
241
- end # v3
261
+ end # v5
242
262
  end
243
263
 
244
264
  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.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shigeya Suzuki
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-20 00:00:00.000000000 Z
11
+ date: 2021-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redcarpet
@@ -16,14 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.1'
19
+ version: '3.5'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 3.5.1
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
27
  - - "~>"
25
28
  - !ruby/object:Gem::Version
26
- version: '2.1'
29
+ version: '3.5'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 3.5.1
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: nokogiri
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +50,14 @@ dependencies:
44
50
  requirements:
45
51
  - - "~>"
46
52
  - !ruby/object:Gem::Version
47
- version: '1.0'
53
+ version: '1.3'
48
54
  type: :runtime
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
51
57
  requirements:
52
58
  - - "~>"
53
59
  - !ruby/object:Gem::Version
54
- version: '1.0'
60
+ version: '1.3'
55
61
  description: A barebone Markdown to TeX/LaTeX converter kit via OmniOutliner
56
62
  email: shigeya@wide.ad.jp
57
63
  executables:
@@ -76,7 +82,7 @@ homepage: http://github.com/shigeya/oo2md2tex
76
82
  licenses:
77
83
  - ISC
78
84
  metadata: {}
79
- post_install_message:
85
+ post_install_message:
80
86
  rdoc_options: []
81
87
  require_paths:
82
88
  - lib
@@ -91,9 +97,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
97
  - !ruby/object:Gem::Version
92
98
  version: '0'
93
99
  requirements: []
94
- rubyforge_project:
95
- rubygems_version: 2.6.11
96
- signing_key:
100
+ rubygems_version: 3.2.3
101
+ signing_key:
97
102
  specification_version: 4
98
103
  summary: oo2text and md2tex
99
104
  test_files: []