oo2md2tex 0.2.0 → 0.3.0
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.
- checksums.yaml +4 -4
- data/bin/oo2text +56 -18
- metadata +6 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 68bebed3d6cc51b61c48f592122ea2e518da3b126f8bd38f572fccec9609ec98
|
|
4
|
+
data.tar.gz: b7857afae528a8e2c8c8d208d4ed87fe80ba1dab222b93750b87deabfc3a8821
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d9e331d5ea8eecb0f28f4c6e5b62fb2842926914f8ed9297211d7b94c74d0415ab00504820d6e9847ea614f6f9a11b860ae4d236b98ace3cd16f2c0db8adbb39
|
|
7
|
+
data.tar.gz: c709a34c324172a969910624820d8eb92472c3b411fc5199b16c5cdf693ad5fb4bd401df0544ef730b6165aae054c6f7f0459f21d5e55102645b21cad3e5511c
|
data/bin/oo2text
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
#
|
|
18
18
|
|
|
19
19
|
require 'optparse'
|
|
20
|
-
require '
|
|
20
|
+
require 'rexml/parsers/sax2parser'
|
|
21
21
|
require 'zlib'
|
|
22
22
|
require 'zip'
|
|
23
23
|
require 'stringio'
|
|
@@ -87,11 +87,34 @@ module OmniOutliner
|
|
|
87
87
|
end
|
|
88
88
|
end
|
|
89
89
|
|
|
90
|
-
|
|
90
|
+
# Adapter: translate REXML SAX2 callbacks (uri, localname, qname, attrs-hash)
|
|
91
|
+
# into the parser's (name, attr-pairs) interface used by the Document classes.
|
|
92
|
+
class Sax2Adapter
|
|
93
|
+
def initialize(doc)
|
|
94
|
+
@doc = doc
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def start_element(_uri, _localname, qname, attributes)
|
|
98
|
+
@doc.start_element(qname, attributes.to_a)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def end_element(_uri, _localname, qname)
|
|
102
|
+
@doc.end_element(qname)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def characters(text)
|
|
106
|
+
@doc.characters(text)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def cdata(text)
|
|
110
|
+
@doc.characters(text)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
class DocumentCommon
|
|
91
115
|
def initialize
|
|
92
116
|
@context = ParseContext.new(nil, "ROOT", {})
|
|
93
117
|
@contexts = [@context]
|
|
94
|
-
super
|
|
95
118
|
end
|
|
96
119
|
|
|
97
120
|
def push_context(name, attrs)
|
|
@@ -108,6 +131,17 @@ module OmniOutliner
|
|
|
108
131
|
def characters(s)
|
|
109
132
|
@context.characters(s)
|
|
110
133
|
end
|
|
134
|
+
|
|
135
|
+
# Drive a REXML SAX2 parse from an IO/String source through this document.
|
|
136
|
+
def parse_source(source)
|
|
137
|
+
parser = REXML::Parsers::SAX2Parser.new(source)
|
|
138
|
+
adapter = Sax2Adapter.new(self)
|
|
139
|
+
parser.listen(:start_element) {|*a| adapter.start_element(*a) }
|
|
140
|
+
parser.listen(:end_element) {|*a| adapter.end_element(*a) }
|
|
141
|
+
parser.listen(:characters) {|text| adapter.characters(text) }
|
|
142
|
+
parser.listen(:cdata) {|text| adapter.cdata(text) }
|
|
143
|
+
parser.parse
|
|
144
|
+
end
|
|
111
145
|
end
|
|
112
146
|
|
|
113
147
|
# Version Dependent Classes for V3
|
|
@@ -135,7 +169,7 @@ module OmniOutliner
|
|
|
135
169
|
end
|
|
136
170
|
end
|
|
137
171
|
|
|
138
|
-
class Parser
|
|
172
|
+
class Parser
|
|
139
173
|
def initialize(fn)
|
|
140
174
|
@file = nil
|
|
141
175
|
if fn =~ /\.oo3$/
|
|
@@ -148,11 +182,11 @@ module OmniOutliner
|
|
|
148
182
|
else
|
|
149
183
|
@file = File.open(fn)
|
|
150
184
|
end
|
|
151
|
-
|
|
185
|
+
@doc = Document.new
|
|
152
186
|
end
|
|
153
187
|
|
|
154
188
|
def parse
|
|
155
|
-
|
|
189
|
+
@doc.parse_source(@file)
|
|
156
190
|
end
|
|
157
191
|
end
|
|
158
192
|
end
|
|
@@ -164,23 +198,25 @@ module OmniOutliner
|
|
|
164
198
|
# https://www.omnigroup.com/namespace/OmniOutliner/xmloutline-editors-v1.rng
|
|
165
199
|
class V5
|
|
166
200
|
class Item
|
|
167
|
-
attr_reader :attrs, :rank, :id, :parent_id
|
|
201
|
+
attr_reader :attrs, :rank, :rank_hex, :seq, :id, :parent_id
|
|
168
202
|
attr_accessor :is_root, :parent
|
|
169
203
|
|
|
170
|
-
def initialize(attrs, text)
|
|
204
|
+
def initialize(attrs, text, seq)
|
|
171
205
|
@attrs = attrs
|
|
172
206
|
@id = @attrs["id"]
|
|
173
207
|
@parent = nil
|
|
174
208
|
@parent_id = @attrs["parent-id"]
|
|
175
|
-
@
|
|
176
|
-
@rank = "
|
|
177
|
-
@rank
|
|
209
|
+
@seq = seq # document appearance order (tie-break)
|
|
210
|
+
@rank = @attrs["rank"].to_s
|
|
211
|
+
rank = @rank.empty? ? "0" : @rank # empty rank means first (0)
|
|
212
|
+
rank += "00" if rank.size == 4 # legacy 4-digit -> 6-digit
|
|
213
|
+
@rank_hex = rank.hex
|
|
178
214
|
@text = text
|
|
179
|
-
@children =
|
|
215
|
+
@children = [] # Hash -> Array
|
|
180
216
|
end
|
|
181
217
|
|
|
182
218
|
def add_child(item)
|
|
183
|
-
@children
|
|
219
|
+
@children << item
|
|
184
220
|
item.parent = self
|
|
185
221
|
end
|
|
186
222
|
|
|
@@ -195,13 +231,14 @@ module OmniOutliner
|
|
|
195
231
|
def print_all
|
|
196
232
|
puts "%% " + parent_chain.join(" < ") + " (#{@rank}) #{@attrs}\n" if $DBG
|
|
197
233
|
puts @text unless @is_root
|
|
198
|
-
@children.
|
|
234
|
+
@children.sort_by {|c| [c.rank_hex, c.seq]}.each {|c| c.print_all}
|
|
199
235
|
end
|
|
200
236
|
end
|
|
201
237
|
|
|
202
238
|
class Document < DocumentCommon
|
|
203
239
|
def initialize
|
|
204
240
|
@items = {}
|
|
241
|
+
@seq = 0
|
|
205
242
|
super
|
|
206
243
|
end
|
|
207
244
|
|
|
@@ -213,7 +250,8 @@ module OmniOutliner
|
|
|
213
250
|
def end_element(name)
|
|
214
251
|
@context.end_element(name)
|
|
215
252
|
if name == "item"
|
|
216
|
-
@items[@context.id] = Item.new(@context.attrs, @context.str + "\n")
|
|
253
|
+
@items[@context.id] = Item.new(@context.attrs, @context.str + "\n", @seq)
|
|
254
|
+
@seq += 1
|
|
217
255
|
end
|
|
218
256
|
pop_context
|
|
219
257
|
final_output if name == "outline"
|
|
@@ -234,7 +272,7 @@ module OmniOutliner
|
|
|
234
272
|
end
|
|
235
273
|
end
|
|
236
274
|
|
|
237
|
-
class Parser
|
|
275
|
+
class Parser
|
|
238
276
|
def initialize(fn)
|
|
239
277
|
@file = nil
|
|
240
278
|
if fn =~ /\.ooutline$/
|
|
@@ -250,11 +288,11 @@ module OmniOutliner
|
|
|
250
288
|
@file = ""
|
|
251
289
|
end
|
|
252
290
|
end
|
|
253
|
-
|
|
291
|
+
@doc = Document.new
|
|
254
292
|
end
|
|
255
293
|
|
|
256
294
|
def parse
|
|
257
|
-
|
|
295
|
+
@doc.parse_source(@file) if @file
|
|
258
296
|
end
|
|
259
297
|
end
|
|
260
298
|
end # v5
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: oo2md2tex
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Shigeya Suzuki
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-
|
|
10
|
+
date: 2026-06-27 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: redcarpet
|
|
@@ -24,19 +24,19 @@ dependencies:
|
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
25
|
version: 3.5.1
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
|
-
name:
|
|
27
|
+
name: rexml
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
|
29
29
|
requirements:
|
|
30
30
|
- - ">="
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
|
-
version: '
|
|
32
|
+
version: '3.2'
|
|
33
33
|
type: :runtime
|
|
34
34
|
prerelease: false
|
|
35
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
36
36
|
requirements:
|
|
37
37
|
- - ">="
|
|
38
38
|
- !ruby/object:Gem::Version
|
|
39
|
-
version: '
|
|
39
|
+
version: '3.2'
|
|
40
40
|
- !ruby/object:Gem::Dependency
|
|
41
41
|
name: rubyzip
|
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -89,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
89
89
|
- !ruby/object:Gem::Version
|
|
90
90
|
version: '0'
|
|
91
91
|
requirements: []
|
|
92
|
-
rubygems_version: 4.0.
|
|
92
|
+
rubygems_version: 4.0.10
|
|
93
93
|
specification_version: 4
|
|
94
94
|
summary: oo2text and md2tex
|
|
95
95
|
test_files: []
|