oo2md2tex 0.0.16 → 0.1.1
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 +5 -5
- data/bin/oo2text +146 -107
- metadata +10 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0bfe76ef9a4dd526a424517e533d25bcf183515df636b5e5848f6fe8c9da6cb2
|
4
|
+
data.tar.gz: caccf3c26215eecc14ada4976dbabd523c29a6fd27cbad99c8e1967d6df97e78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3f016aa645bd80c93459baefaba36e8d8e9598eb6bf884a249a672425e606b31b7ddc0aeaab62a0a0772e0ad8cdad2daa409a7bbaa234037aa6132fe3a78903
|
7
|
+
data.tar.gz: 83d104a2a91d0e6925c0e24b7409daadf2da1b2fdd2c4f9aed324ce06dd7ed65233f53559139a01d2d5c0d63a1443c5e8145ade1141d7abc8fd72697278b1044
|
data/bin/oo2text
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# -*- mode: ruby -*-
|
3
3
|
#
|
4
|
-
# Copyright (c)2012 Shigeya Suzuki
|
4
|
+
# Copyright (c)2012,2017 Shigeya Suzuki
|
5
5
|
#
|
6
6
|
# Permission to use, copy, modify, and/or distribute this software for any
|
7
7
|
# purpose with or without fee is hereby granted, provided that the above
|
@@ -21,57 +21,118 @@ require 'nokogiri'
|
|
21
21
|
require 'zlib'
|
22
22
|
require 'zip'
|
23
23
|
require 'stringio'
|
24
|
-
|
25
|
-
|
24
|
+
|
25
|
+
$OO2DBG = false
|
26
|
+
require 'awesome_print' if $OO2DBG
|
27
|
+
require 'pry-byebug' if $OO2DBG
|
26
28
|
|
27
29
|
module OmniOutliner
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
31
|
+
# Common Classes
|
32
|
+
class ParseContext
|
33
|
+
attr_accessor :parent, :name, :attrs, :column, :lit, :item, :style, :root, :str, :id, :is_root
|
34
|
+
|
35
|
+
def initialize(parent, name, attrs_a)
|
36
|
+
@parent = parent
|
37
|
+
@name = name
|
38
|
+
@column = @lit = @item = @style = @root = @is_root = false
|
39
|
+
@id = nil
|
40
|
+
@str = ""
|
41
|
+
|
42
|
+
@attrs = {}
|
43
|
+
if attrs_a.size != 0
|
44
|
+
attrs_a.each {|k,v| @attrs[k] = v}
|
45
|
+
@id = @attrs["id"] if @attrs.has_key?("id")
|
46
|
+
@is_root = @attrs["is-root"] if @attrs.has_key?("is-root")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def start_element(name, attrs)
|
51
|
+
@column = name == "column"
|
52
|
+
@item = name == "item"
|
53
|
+
@style = name == "style"
|
54
|
+
@lit = name == "lit"
|
55
|
+
@root = name == "root"
|
56
|
+
if name == "cell"
|
57
|
+
# if it is a hyperlink, use name part as part of output
|
58
|
+
@str += @attrs["name"] if @attrs.has_key?("name")
|
39
59
|
end
|
60
|
+
end
|
40
61
|
|
41
|
-
|
42
|
-
|
62
|
+
def end_element(name)
|
63
|
+
if name == "values"
|
64
|
+
@str.gsub(/\n/, '')
|
43
65
|
end
|
66
|
+
end
|
44
67
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
@
|
53
|
-
end
|
54
|
-
if name == "cell"
|
55
|
-
# if it is a hyperlink, use name part as part of output
|
56
|
-
if n = attrs.find{|a| a[0] == "name"}
|
57
|
-
@str += n[1]
|
58
|
-
end
|
68
|
+
def in_body_text
|
69
|
+
if @item
|
70
|
+
true
|
71
|
+
elsif @style || @column
|
72
|
+
false
|
73
|
+
else
|
74
|
+
if @in_body_text == nil
|
75
|
+
@in_body_text = @parent.nil? ? false : @parent.in_body_text
|
59
76
|
end
|
77
|
+
@in_body_text
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def characters(s)
|
82
|
+
@str += s if @lit && in_body_text
|
83
|
+
end
|
84
|
+
|
85
|
+
def elevate(context)
|
86
|
+
@str += context.str
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
class DocumentCommon < Nokogiri::XML::SAX::Document
|
91
|
+
def initialize
|
92
|
+
@context = ParseContext.new(nil, "ROOT", {})
|
93
|
+
@contexts = [@context]
|
94
|
+
super
|
95
|
+
end
|
96
|
+
|
97
|
+
def push_context(name, attrs)
|
98
|
+
@contexts.push(@context)
|
99
|
+
@context = ParseContext.new(@context, name, attrs)
|
100
|
+
end
|
101
|
+
|
102
|
+
def pop_context
|
103
|
+
old_context = @context
|
104
|
+
@context = @contexts.pop
|
105
|
+
@context.elevate(old_context) if @context
|
106
|
+
end
|
107
|
+
|
108
|
+
def characters(s)
|
109
|
+
@context.characters(s)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
# Version Dependent Classes for V3
|
114
|
+
#
|
115
|
+
# Format Documenatation can be found at:
|
116
|
+
# https://www.omnigroup.com/namespace/OmniOutliner/xmloutline-v3.dtd
|
117
|
+
class V3
|
118
|
+
class Document < DocumentCommon
|
119
|
+
def start_element(name, attrs)
|
120
|
+
push_context(name, attrs)
|
121
|
+
@context.start_element(name, attrs)
|
60
122
|
end
|
61
123
|
|
62
124
|
def end_element(name)
|
63
|
-
@in_column = false if name == "column"
|
64
|
-
@in_item = false if name == "item"
|
65
|
-
@in_style = false if name == "style"
|
66
|
-
if name == "lit"
|
67
|
-
@str += "\n"
|
68
|
-
@in_lit = false
|
69
|
-
end
|
70
125
|
if name == "values"
|
71
|
-
@str.gsub(/\n/, '')
|
72
|
-
|
73
|
-
@str = ""
|
126
|
+
@context.str.gsub!(/\n/, '')
|
127
|
+
@context.str += "\n"
|
74
128
|
end
|
129
|
+
@context.end_element(name)
|
130
|
+
pop_context
|
131
|
+
final_output if name == "outline"
|
132
|
+
end
|
133
|
+
|
134
|
+
def final_output
|
135
|
+
puts @context.str
|
75
136
|
end
|
76
137
|
end
|
77
138
|
|
@@ -95,104 +156,82 @@ module OmniOutliner
|
|
95
156
|
super(@file)
|
96
157
|
end
|
97
158
|
end
|
98
|
-
end
|
159
|
+
end
|
99
160
|
|
161
|
+
# Version Dependent Classes for V5
|
162
|
+
#
|
163
|
+
# Format Documenatation can be found at:
|
164
|
+
# https://www.omnigroup.com/namespace/OmniOutliner/xmloutline-v5.rng
|
165
|
+
# https://www.omnigroup.com/namespace/OmniOutliner/xmloutline-editors-v1.rng
|
100
166
|
class V5
|
101
167
|
class Item
|
102
|
-
attr_reader :attrs
|
103
|
-
attr_accessor :is_root
|
168
|
+
attr_reader :attrs, :rank, :id, :parent_id
|
169
|
+
attr_accessor :is_root, :parent
|
104
170
|
|
105
171
|
def initialize(attrs, text)
|
106
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
|
107
179
|
@text = text
|
108
180
|
@children = {}
|
109
181
|
end
|
110
182
|
|
111
|
-
def
|
112
|
-
rank =
|
113
|
-
|
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
|
114
194
|
end
|
115
195
|
|
116
196
|
def print_all
|
197
|
+
puts "%% " + parent_chain.join(" < ") + " (#{@rank}) #{@attrs}\n" if $DBG
|
117
198
|
puts @text unless @is_root
|
118
199
|
@children.keys.sort.each {|k| @children[k].print_all}
|
119
200
|
end
|
120
201
|
end
|
121
202
|
|
122
|
-
class Document <
|
203
|
+
class Document < DocumentCommon
|
123
204
|
def initialize
|
124
|
-
@in_column = false
|
125
|
-
@in_lit = false
|
126
|
-
@in_item = false
|
127
|
-
@in_style = false
|
128
|
-
@str = ""
|
129
205
|
@items = {}
|
130
|
-
@id_stack = []
|
131
|
-
@attrs_stack = []
|
132
|
-
@in_items = false
|
133
206
|
super
|
134
207
|
end
|
135
208
|
|
136
|
-
def
|
137
|
-
|
209
|
+
def start_element(name, attrs)
|
210
|
+
push_context(name, attrs)
|
211
|
+
@context.start_element(name, attrs)
|
138
212
|
end
|
139
213
|
|
140
|
-
def
|
141
|
-
|
142
|
-
@attrs = {}
|
143
|
-
attrs_a.each {|k,v| @attrs[k] = v}
|
144
|
-
@id = @attrs["id"] if @attrs.has_key?("id")
|
145
|
-
@is_root = @attrs["is-root"] if @attrs.has_key?("is-root")
|
146
|
-
end
|
147
|
-
@in_column = true if name == "column"
|
148
|
-
@in_style = true if name == "style"
|
149
|
-
@in_lit = true if name == "lit"
|
150
|
-
@in_item = true if name == "item"
|
151
|
-
@in_items = true if name == "items"
|
152
|
-
if name == "cell"
|
153
|
-
# if it is a hyperlink, use name part as part of output
|
154
|
-
if @attrs.has_key?("name")
|
155
|
-
@str += @attrs["name"]
|
156
|
-
end
|
157
|
-
end
|
214
|
+
def end_element(name)
|
215
|
+
@context.end_element(name)
|
158
216
|
if name == "item"
|
159
|
-
|
160
|
-
@attrs_stack.push(@attrs)
|
217
|
+
@items[@context.id] = Item.new(@context.attrs, @context.str + "\n")
|
161
218
|
end
|
219
|
+
pop_context
|
220
|
+
final_output if name == "outline"
|
162
221
|
end
|
163
222
|
|
164
|
-
def
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
@str.gsub(/\n/, '')
|
174
|
-
@items[@id] = Item.new(@attrs, @str)
|
175
|
-
@str = ""
|
176
|
-
end
|
177
|
-
if name == "lit"
|
178
|
-
@str += "\n" if @in_items
|
179
|
-
@in_lit = false
|
180
|
-
end
|
181
|
-
if name == "outline" # final output
|
182
|
-
@root = nil
|
183
|
-
puts "#{@items.count} items"
|
184
|
-
@items.each do |id, item|
|
185
|
-
if item.attrs["is-root"] == "yes"
|
186
|
-
@root = item
|
187
|
-
@root.is_root = true
|
188
|
-
elsif pid = item.attrs["parent-id"]
|
189
|
-
@items[pid].add(item.attrs["rank"], item)
|
190
|
-
else
|
191
|
-
@root.add(item.attrs["rank"], item)
|
192
|
-
end
|
223
|
+
def final_output
|
224
|
+
@items.each do |id, item|
|
225
|
+
if item.attrs["is-root"] == "yes"
|
226
|
+
@root = item
|
227
|
+
@root.is_root = true
|
228
|
+
elsif pid = item.attrs["parent-id"]
|
229
|
+
@items[pid].add_child(item)
|
230
|
+
else
|
231
|
+
@root.add_child(item)
|
193
232
|
end
|
194
|
-
@root.print_all #unless @root.nil?
|
195
233
|
end
|
234
|
+
@root.print_all #unless @root.nil?
|
196
235
|
end
|
197
236
|
end
|
198
237
|
|
@@ -219,7 +258,7 @@ module OmniOutliner
|
|
219
258
|
super(@file) if @file
|
220
259
|
end
|
221
260
|
end
|
222
|
-
end #
|
261
|
+
end # v5
|
223
262
|
end
|
224
263
|
|
225
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.
|
4
|
+
version: 0.1.1
|
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:
|
11
|
+
date: 2021-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redcarpet
|
@@ -42,16 +42,16 @@ dependencies:
|
|
42
42
|
name: rubyzip
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 1.
|
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.
|
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
|
-
|
95
|
-
|
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: []
|