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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/oo2text +124 -106
  3. metadata +7 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1f66a21735bad0d49f64f38ccb929b6689889320
4
- data.tar.gz: ea9b18b7b1a9635b372f7d7f5e654d6b39f6a3c9
3
+ metadata.gz: dcefce26c1579dbab1f2ad123c00f5156e28ad2a
4
+ data.tar.gz: 4ce51bf87b6fee82a67e317be912432eac2b3b2a
5
5
  SHA512:
6
- metadata.gz: 7bfb984938eb696d137939e85be91e4c91bc6a0413d24180d20b074917c53f4668c5750311cec448a244ce8ace8631da4d516f4f72edb318e83785589e05a384
7
- data.tar.gz: 84bdb11e919e10560144bc05d78f8b2b21f40c1cb735bee69113219e3c7a480403f7c6bb4479e1aff5da8fcf8cfca4757332780b29d0daa28ace01e2264f0b90
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
- class V3
30
- class Document < Nokogiri::XML::SAX::Document
31
- def initialize
32
- @in_column = false
33
- @in_lit = false
34
- @in_item = false
35
- @in_style = false
36
- @in_root = false
37
- @str = ""
38
- super
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
- def characters(s)
42
- @str += s if @in_lit && (!@in_style && !@in_column)
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
- def start_element(name, attrs)
46
- @in_column = true if name == "column"
47
- @in_item = true if name == "item"
48
- @in_style = true if name == "style"
49
- @in_lit = true if name == "lit"
50
- if name == "root"
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
- 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
- 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 # v3
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 < Nokogiri::XML::SAX::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 characters(s)
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
- @id_stack.push(@id)
160
- @attrs_stack.push(@attrs)
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 end_element(name)
165
- if name == "item"
166
- @id = @id_stack.pop
167
- @attrs = @attrs_stack.pop
168
- end
169
- @in_column = false if name == "column"
170
- @in_style = false if name == "style"
171
- if name == "item"
172
- @in_item = false
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.16
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-12 00:00:00.000000000 Z
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.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.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.11
95
+ rubygems_version: 2.6.8
96
96
  signing_key:
97
97
  specification_version: 4
98
98
  summary: oo2text and md2tex