oo2md2tex 0.0.17 → 0.1.2

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 -32
  3. metadata +10 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: dcefce26c1579dbab1f2ad123c00f5156e28ad2a
4
- data.tar.gz: 4ce51bf87b6fee82a67e317be912432eac2b3b2a
2
+ SHA256:
3
+ metadata.gz: dc832543f020810fa7a596cc9b594f59c4653615554aa45ab18e14acd63cc09d
4
+ data.tar.gz: 342ee375b6bc9d9c45bfb99b787d02651ec73b43f2cdbfa8b59a4b7ff5f96b52
5
5
  SHA512:
6
- metadata.gz: 463b2a47a0f322fb896898230bc415b7449f52f3ed4f76efba013f01061720e553621cc25a9301d109795c23142c850f701ca1d95203fbffb719d455f15c3216
7
- data.tar.gz: b28cb87f9c0c1cbac7c62e5e339b4cb857c3b45b197e4be319eaea23a7b15b7993d93898c7543343271d11861720c65611a82e68c1b4e0be179e378ea09e6245
6
+ metadata.gz: 519745ae071798cde6d66818edd0f849daa01f5e1410cfd0fdaf59d62568d8410035d51f7f2ff543b6b6cf818a0fcc7d6980a90906746849e104074b1804b887
7
+ data.tar.gz: 7385ac0f860ef7db202a717957d82534ab652f60cd3f9dfeada09fb2b399653692377c7558abe2688cc4253b340e7024d9d0303d1f348498363b372fd1787d1e
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,21 +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
- @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
178
194
  end
179
195
 
180
196
  def print_all
197
+ puts "%% " + parent_chain.join(" < ") + " (#{@rank}) #{@attrs}\n" if $DBG
181
198
  puts @text unless @is_root
182
199
  @children.keys.sort.each {|k| @children[k].print_all}
183
200
  end
@@ -189,14 +206,18 @@ module OmniOutliner
189
206
  super
190
207
  end
191
208
 
209
+ def start_element(name, attrs)
210
+ push_context(name, attrs)
211
+ @context.start_element(name, attrs)
212
+ end
213
+
192
214
  def end_element(name)
215
+ @context.end_element(name)
193
216
  if name == "item"
194
- str = @context.str
195
- str.gsub(/\n/, '')
196
- @items[@context.id] = Item.new(@context.attrs, str)
197
- @context.str = ""
217
+ @items[@context.id] = Item.new(@context.attrs, @context.str + "\n")
198
218
  end
199
- super
219
+ pop_context
220
+ final_output if name == "outline"
200
221
  end
201
222
 
202
223
  def final_output
@@ -205,9 +226,9 @@ module OmniOutliner
205
226
  @root = item
206
227
  @root.is_root = true
207
228
  elsif pid = item.attrs["parent-id"]
208
- @items[pid].add(item.attrs["rank"], item)
229
+ @items[pid].add_child(item)
209
230
  else
210
- @root.add(item.attrs["rank"], item)
231
+ @root.add_child(item)
211
232
  end
212
233
  end
213
234
  @root.print_all #unless @root.nil?
@@ -237,7 +258,7 @@ module OmniOutliner
237
258
  super(@file) if @file
238
259
  end
239
260
  end
240
- end # v3
261
+ end # v5
241
262
  end
242
263
 
243
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.17
4
+ version: 0.1.2
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-17 00:00:00.000000000 Z
11
+ date: 2021-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redcarpet
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.1'
19
+ version: 3.5.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2.1'
26
+ version: 3.5.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: nokogiri
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.0'
47
+ version: '1.3'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.0'
54
+ version: '1.3'
55
55
  description: A barebone Markdown to TeX/LaTeX converter kit via OmniOutliner
56
56
  email: shigeya@wide.ad.jp
57
57
  executables:
@@ -76,7 +76,7 @@ homepage: http://github.com/shigeya/oo2md2tex
76
76
  licenses:
77
77
  - ISC
78
78
  metadata: {}
79
- post_install_message:
79
+ post_install_message:
80
80
  rdoc_options: []
81
81
  require_paths:
82
82
  - lib
@@ -91,9 +91,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
91
  - !ruby/object:Gem::Version
92
92
  version: '0'
93
93
  requirements: []
94
- rubyforge_project:
95
- rubygems_version: 2.6.8
96
- signing_key:
94
+ rubygems_version: 3.0.3
95
+ signing_key:
97
96
  specification_version: 4
98
97
  summary: oo2text and md2tex
99
98
  test_files: []