oo2md2tex 0.0.16 → 0.0.17
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 +124 -106
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dcefce26c1579dbab1f2ad123c00f5156e28ad2a
|
4
|
+
data.tar.gz: 4ce51bf87b6fee82a67e317be912432eac2b3b2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 463b2a47a0f322fb896898230bc415b7449f52f3ed4f76efba013f01061720e553621cc25a9301d109795c23142c850f701ca1d95203fbffb719d455f15c3216
|
7
|
+
data.tar.gz: b28cb87f9c0c1cbac7c62e5e339b4cb857c3b45b197e4be319eaea23a7b15b7993d93898c7543343271d11861720c65611a82e68c1b4e0be179e378ea09e6245
|
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,116 @@ require 'nokogiri'
|
|
21
21
|
require 'zlib'
|
22
22
|
require 'zip'
|
23
23
|
require 'stringio'
|
24
|
-
require 'awesome_print'
|
25
|
-
require 'pry-byebug'
|
26
24
|
|
27
25
|
module OmniOutliner
|
28
26
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
27
|
+
# Common Classes
|
28
|
+
class ParseContext
|
29
|
+
attr_accessor :parent, :name, :attrs, :column, :lit, :item, :style, :root, :str, :id, :is_root
|
30
|
+
|
31
|
+
def initialize(parent, name, attrs_a)
|
32
|
+
@parent = parent
|
33
|
+
@name = name
|
34
|
+
@column = @lit = @item = @style = @root = @is_root = false
|
35
|
+
@id = nil
|
36
|
+
@str = ""
|
37
|
+
|
38
|
+
@attrs = {}
|
39
|
+
if attrs_a.size != 0
|
40
|
+
attrs_a.each {|k,v| @attrs[k] = v}
|
41
|
+
@id = @attrs["id"] if @attrs.has_key?("id")
|
42
|
+
@is_root = @attrs["is-root"] if @attrs.has_key?("is-root")
|
39
43
|
end
|
44
|
+
end
|
40
45
|
|
41
|
-
|
42
|
-
|
46
|
+
def start_element(name, attrs)
|
47
|
+
@column = name == "column"
|
48
|
+
@item = name == "item"
|
49
|
+
@style = name == "style"
|
50
|
+
@lit = name == "lit"
|
51
|
+
@root = name == "root"
|
52
|
+
if name == "cell"
|
53
|
+
# if it is a hyperlink, use name part as part of output
|
54
|
+
@str += @attrs["name"] if @attrs.has_key?("name")
|
43
55
|
end
|
56
|
+
end
|
44
57
|
|
45
|
-
|
46
|
-
|
47
|
-
@
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
@in_root = true
|
52
|
-
@str = ""
|
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
|
59
|
-
end
|
58
|
+
def end_element(name)
|
59
|
+
if name == "lit"
|
60
|
+
@str += "\n" if in_body_text
|
61
|
+
end
|
62
|
+
if name == "values"
|
63
|
+
@str.gsub(/\n/, '')
|
60
64
|
end
|
65
|
+
end
|
61
66
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
if name == "values"
|
71
|
-
@str.gsub(/\n/, '')
|
72
|
-
puts @str if @in_root
|
73
|
-
@str = ""
|
67
|
+
def in_body_text
|
68
|
+
if @item
|
69
|
+
true
|
70
|
+
elsif @style || @column
|
71
|
+
false
|
72
|
+
else
|
73
|
+
if @in_body_text == nil
|
74
|
+
@in_body_text = @parent.nil? ? false : @parent.in_body_text
|
74
75
|
end
|
76
|
+
@in_body_text
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def characters(s)
|
81
|
+
@str += s if @lit && in_body_text
|
82
|
+
end
|
83
|
+
|
84
|
+
def elevate(context)
|
85
|
+
@str += context.str
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
class DocumentCommon < Nokogiri::XML::SAX::Document
|
90
|
+
def initialize
|
91
|
+
@contexts = []
|
92
|
+
@context = nil
|
93
|
+
super
|
94
|
+
end
|
95
|
+
|
96
|
+
def push_context(name, attrs)
|
97
|
+
@contexts.push(@context)
|
98
|
+
@context = ParseContext.new(@context, name, attrs)
|
99
|
+
end
|
100
|
+
|
101
|
+
def pop_context
|
102
|
+
old_context = @context
|
103
|
+
@context = @contexts.pop
|
104
|
+
@context.elevate(old_context) if @context
|
105
|
+
end
|
106
|
+
|
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
|
+
def characters(s)
|
119
|
+
@context.characters(s)
|
120
|
+
end
|
121
|
+
|
122
|
+
def final_output
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
# Version Dependent Classes for V3
|
127
|
+
#
|
128
|
+
# Format Documenatation can be found at:
|
129
|
+
# https://www.omnigroup.com/namespace/OmniOutliner/xmloutline-v3.dtd
|
130
|
+
class V3
|
131
|
+
class Document < DocumentCommon
|
132
|
+
def final_output
|
133
|
+
puts @context.str
|
75
134
|
end
|
76
135
|
end
|
77
136
|
|
@@ -95,8 +154,13 @@ module OmniOutliner
|
|
95
154
|
super(@file)
|
96
155
|
end
|
97
156
|
end
|
98
|
-
end
|
157
|
+
end
|
99
158
|
|
159
|
+
# Version Dependent Classes for V5
|
160
|
+
#
|
161
|
+
# Format Documenatation can be found at:
|
162
|
+
# https://www.omnigroup.com/namespace/OmniOutliner/xmloutline-v5.rng
|
163
|
+
# https://www.omnigroup.com/namespace/OmniOutliner/xmloutline-editors-v1.rng
|
100
164
|
class V5
|
101
165
|
class Item
|
102
166
|
attr_reader :attrs
|
@@ -119,80 +183,34 @@ module OmniOutliner
|
|
119
183
|
end
|
120
184
|
end
|
121
185
|
|
122
|
-
class Document <
|
186
|
+
class Document < DocumentCommon
|
123
187
|
def initialize
|
124
|
-
@in_column = false
|
125
|
-
@in_lit = false
|
126
|
-
@in_item = false
|
127
|
-
@in_style = false
|
128
|
-
@str = ""
|
129
188
|
@items = {}
|
130
|
-
@id_stack = []
|
131
|
-
@attrs_stack = []
|
132
|
-
@in_items = false
|
133
189
|
super
|
134
190
|
end
|
135
191
|
|
136
|
-
def
|
137
|
-
@str += s if @in_lit && (!@in_style && !@in_column)
|
138
|
-
end
|
139
|
-
|
140
|
-
def start_element(name, attrs_a)
|
141
|
-
if attrs_a.size != 0
|
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
|
192
|
+
def end_element(name)
|
158
193
|
if name == "item"
|
159
|
-
|
160
|
-
|
194
|
+
str = @context.str
|
195
|
+
str.gsub(/\n/, '')
|
196
|
+
@items[@context.id] = Item.new(@context.attrs, str)
|
197
|
+
@context.str = ""
|
161
198
|
end
|
199
|
+
super
|
162
200
|
end
|
163
201
|
|
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
|
202
|
+
def final_output
|
203
|
+
@items.each do |id, item|
|
204
|
+
if item.attrs["is-root"] == "yes"
|
205
|
+
@root = item
|
206
|
+
@root.is_root = true
|
207
|
+
elsif pid = item.attrs["parent-id"]
|
208
|
+
@items[pid].add(item.attrs["rank"], item)
|
209
|
+
else
|
210
|
+
@root.add(item.attrs["rank"], item)
|
193
211
|
end
|
194
|
-
@root.print_all #unless @root.nil?
|
195
212
|
end
|
213
|
+
@root.print_all #unless @root.nil?
|
196
214
|
end
|
197
215
|
end
|
198
216
|
|
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.
|
4
|
+
version: 0.0.17
|
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-
|
11
|
+
date: 2017-06-17 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.0
|
47
|
+
version: '1.0'
|
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.0'
|
55
55
|
description: A barebone Markdown to TeX/LaTeX converter kit via OmniOutliner
|
56
56
|
email: shigeya@wide.ad.jp
|
57
57
|
executables:
|
@@ -92,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
92
|
version: '0'
|
93
93
|
requirements: []
|
94
94
|
rubyforge_project:
|
95
|
-
rubygems_version: 2.6.
|
95
|
+
rubygems_version: 2.6.8
|
96
96
|
signing_key:
|
97
97
|
specification_version: 4
|
98
98
|
summary: oo2text and md2tex
|