oo2md2tex 0.1.6 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4607a4b601cdd8cc4915ef11331d6967b2f543d12b99065f27703325142c0dbe
4
- data.tar.gz: f536e11320fdcca1c5cc791d3b99d2cb8fa88e077c70e2264658b596307c9230
3
+ metadata.gz: 68bebed3d6cc51b61c48f592122ea2e518da3b126f8bd38f572fccec9609ec98
4
+ data.tar.gz: b7857afae528a8e2c8c8d208d4ed87fe80ba1dab222b93750b87deabfc3a8821
5
5
  SHA512:
6
- metadata.gz: a13471447b718ca701d859d6345c5576771ee5dd89396a824a0afce7db9e7997c8844a81bcdd00750c764f7d220bf903f4cb7403b1d3b15f8809059bec1b802e
7
- data.tar.gz: 5b260c491cc5017c7cbfdf2aad161b75cf964520a04d579579e4978d13e6f538d5d55b73c4799d745b69fcc6abd13423da7ef87b8834b689d1bb2d2f0ff17bad
6
+ metadata.gz: d9e331d5ea8eecb0f28f4c6e5b62fb2842926914f8ed9297211d7b94c74d0415ab00504820d6e9847ea614f6f9a11b860ae4d236b98ace3cd16f2c0db8adbb39
7
+ data.tar.gz: c709a34c324172a969910624820d8eb92472c3b411fc5199b16c5cdf693ad5fb4bd401df0544ef730b6165aae054c6f7f0459f21d5e55102645b21cad3e5511c
data/bin/ja-count CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
3
3
  #
4
4
  # Copyright (c)2014 Shigeya Suzuki
5
5
  #
@@ -16,10 +16,6 @@
16
16
  # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
17
  #
18
18
 
19
- if RUBY_VERSION >= "1.9" # encoding only supported in Ruby 1.9.x
20
- Encoding.default_external = "UTF-8"
21
- end
22
-
23
19
  #####
24
20
 
25
21
  puts "(#{ARGF.read.size} characters)"
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
3
3
  #
4
4
  # Copyright (c)2012 Shigeya Suzuki
5
5
  #
@@ -18,10 +18,6 @@
18
18
 
19
19
  require 'optparse'
20
20
 
21
- if RUBY_VERSION >= "1.9" # encoding only supported in Ruby 1.9.x
22
- Encoding.default_external = "UTF-8"
23
- end
24
-
25
21
  #####
26
22
 
27
23
  opts = {
@@ -54,8 +50,8 @@ end
54
50
  #####
55
51
 
56
52
  def text_tweak(str, opts)
57
- str.tr!('、。', ',.') if opts[:ja_comma_subst_cp]
58
- str.tr!(',. ', '、。') if opts[:ja_comma_subst_tm]
53
+ str = str.tr('、。', ',.') if opts[:ja_comma_subst_cp]
54
+ str = str.tr(',. ', '、。') if opts[:ja_comma_subst_tm]
59
55
  str
60
56
  end
61
57
 
data/bin/md2tex CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
3
3
  #
4
4
  # Copyright (c)2012 Shigeya Suzuki
5
5
  #
@@ -16,10 +16,6 @@
16
16
  # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
17
  #
18
18
 
19
- if RUBY_VERSION >= "1.9" # encoding only supported in Ruby 1.9.x
20
- Encoding.default_external = "UTF-8"
21
- end
22
-
23
19
  $script_base_dir = File.dirname(__FILE__)+"/../lib"
24
20
  $:.unshift($script_base_dir)
25
21
 
@@ -50,10 +46,10 @@ all = processor.process(ARGF.read)
50
46
  puts processor.job_signature
51
47
  puts all
52
48
 
53
- all.gsub!(/%.*/, '')
54
- all.gsub!(/\s+/, ' ')
55
- all.gsub!(/\\(begin|end){[^}]+}/, '')
56
- all.gsub!(/\\([A-Za-z]+)/, '')
57
- all.gsub!(/\s+/, '')
58
- all.gsub!(/\{|\}/, '')
49
+ all = all.gsub(/%.*/, '')
50
+ all = all.gsub(/\s+/, ' ')
51
+ all = all.gsub(/\\(begin|end){[^}]+}/, '')
52
+ all = all.gsub(/\\([A-Za-z]+)/, '')
53
+ all = all.gsub(/\s+/, '')
54
+ all = all.gsub(/\{|\}/, '')
59
55
  puts "% Text length: #{all.size} chars"
data/bin/oo2text CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- # -*- mode: ruby -*-
2
+ # frozen_string_literal: true
3
3
  #
4
4
  # Copyright (c)2012,2017 Shigeya Suzuki
5
5
  #
@@ -17,7 +17,7 @@
17
17
  #
18
18
 
19
19
  require 'optparse'
20
- require 'nokogiri'
20
+ require 'rexml/parsers/sax2parser'
21
21
  require 'zlib'
22
22
  require 'zip'
23
23
  require 'stringio'
@@ -37,7 +37,7 @@ module OmniOutliner
37
37
  @name = name
38
38
  @column = @lit = @item = @style = @root = @is_root = false
39
39
  @id = nil
40
- @str = ""
40
+ @str = +""
41
41
 
42
42
  @attrs = {}
43
43
  if attrs_a.size != 0
@@ -87,11 +87,34 @@ module OmniOutliner
87
87
  end
88
88
  end
89
89
 
90
- class DocumentCommon < Nokogiri::XML::SAX::Document
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
@@ -123,8 +157,7 @@ module OmniOutliner
123
157
 
124
158
  def end_element(name)
125
159
  if name == "values"
126
- @context.str.gsub!(/\n/, '')
127
- @context.str += "\n"
160
+ @context.str = @context.str.gsub(/\n/, '') + "\n"
128
161
  end
129
162
  @context.end_element(name)
130
163
  pop_context
@@ -136,7 +169,7 @@ module OmniOutliner
136
169
  end
137
170
  end
138
171
 
139
- class Parser < Nokogiri::XML::SAX::Parser
172
+ class Parser
140
173
  def initialize(fn)
141
174
  @file = nil
142
175
  if fn =~ /\.oo3$/
@@ -149,11 +182,11 @@ module OmniOutliner
149
182
  else
150
183
  @file = File.open(fn)
151
184
  end
152
- super(Document.new)
185
+ @doc = Document.new
153
186
  end
154
187
 
155
188
  def parse
156
- super(@file)
189
+ @doc.parse_source(@file)
157
190
  end
158
191
  end
159
192
  end
@@ -165,23 +198,25 @@ module OmniOutliner
165
198
  # https://www.omnigroup.com/namespace/OmniOutliner/xmloutline-editors-v1.rng
166
199
  class V5
167
200
  class Item
168
- attr_reader :attrs, :rank, :id, :parent_id
201
+ attr_reader :attrs, :rank, :rank_hex, :seq, :id, :parent_id
169
202
  attr_accessor :is_root, :parent
170
203
 
171
- def initialize(attrs, text)
204
+ def initialize(attrs, text, seq)
172
205
  @attrs = attrs
173
206
  @id = @attrs["id"]
174
207
  @parent = nil
175
208
  @parent_id = @attrs["parent-id"]
176
- @rank = @attrs["rank"]
177
- @rank = "0" if @rank.nil? || @rank == ""
178
- @rank += "00" if @rank.size == 4
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
179
214
  @text = text
180
- @children = {}
215
+ @children = [] # Hash -> Array
181
216
  end
182
217
 
183
218
  def add_child(item)
184
- @children[item.rank.hex] = item
219
+ @children << item
185
220
  item.parent = self
186
221
  end
187
222
 
@@ -196,13 +231,14 @@ module OmniOutliner
196
231
  def print_all
197
232
  puts "%% " + parent_chain.join(" < ") + " (#{@rank}) #{@attrs}\n" if $DBG
198
233
  puts @text unless @is_root
199
- @children.keys.sort.each {|k| @children[k].print_all}
234
+ @children.sort_by {|c| [c.rank_hex, c.seq]}.each {|c| c.print_all}
200
235
  end
201
236
  end
202
237
 
203
238
  class Document < DocumentCommon
204
239
  def initialize
205
240
  @items = {}
241
+ @seq = 0
206
242
  super
207
243
  end
208
244
 
@@ -214,7 +250,8 @@ module OmniOutliner
214
250
  def end_element(name)
215
251
  @context.end_element(name)
216
252
  if name == "item"
217
- @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
218
255
  end
219
256
  pop_context
220
257
  final_output if name == "outline"
@@ -235,7 +272,7 @@ module OmniOutliner
235
272
  end
236
273
  end
237
274
 
238
- class Parser < Nokogiri::XML::SAX::Parser
275
+ class Parser
239
276
  def initialize(fn)
240
277
  @file = nil
241
278
  if fn =~ /\.ooutline$/
@@ -251,11 +288,11 @@ module OmniOutliner
251
288
  @file = ""
252
289
  end
253
290
  end
254
- super(Document.new)
291
+ @doc = Document.new
255
292
  end
256
293
 
257
294
  def parse
258
- super(@file) if @file
295
+ @doc.parse_source(@file) if @file
259
296
  end
260
297
  end
261
298
  end # v5
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Copyright (c)2012 Shigeya Suzuki
3
4
  #
@@ -35,7 +36,7 @@ module MarkdownToTeX
35
36
  @git_branch_name = $2
36
37
  @git_wd_hash_long = $3
37
38
  @git_wd_hash = @git_wd_hash_long[0,6]
38
- @git_commit_line = $4
39
+ @git_commit_line = $4.dup
39
40
  @git_commit_line.gsub!(/\#/, '\#')
40
41
  @git_commit_line.gsub!(/\%/, '\%')
41
42
  @git_commit_line.gsub!(/\[ahead.*\] /, '')
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Copyright (c)2012 Shigeya Suzuki
3
4
  #
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Copyright (c)2012 Shigeya Suzuki
3
4
  #
@@ -24,7 +25,7 @@ module MarkdownToTeX
24
25
 
25
26
  # Process a paragraph
26
27
  def self.process_paragraph(text)
27
- text.gsub!(/\(\((.*)\)\)/, '\\ITEM{\1}') # description format
28
+ text = text.gsub(/\(\((.*)\)\)/, '\\ITEM{\1}') # description format
28
29
  self.reference(text)
29
30
  end
30
31
 
@@ -79,8 +80,9 @@ module MarkdownToTeX
79
80
 
80
81
  def self.label_split(s)
81
82
  label = ""
82
- if s.sub!(/\s*\[([^\]]+)\]/, '')
83
+ if s =~ /\s*\[([^\]]+)\]/
83
84
  label = $1
85
+ s = s.sub(/\s*\[([^\]]+)\]/, '')
84
86
  end
85
87
  [s, label]
86
88
  end
@@ -117,7 +119,7 @@ module MarkdownToTeX
117
119
 
118
120
  def self.process_final(text, macros)
119
121
  # Macro expansions
120
- macros.each {|m, v| text.gsub!(m, v) }
122
+ macros.each {|m, v| text = text.gsub(m, v) }
121
123
  text
122
124
  end
123
125
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'markdown_to_tex/renderer'
2
4
  require_relative 'markdown_to_tex/text_processor'
3
5
  require_relative 'markdown_to_tex/processor'
metadata CHANGED
@@ -1,22 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oo2md2tex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shigeya Suzuki
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2022-02-27 00:00:00.000000000 Z
10
+ date: 2026-06-27 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: redcarpet
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '3.5'
20
16
  - - ">="
21
17
  - !ruby/object:Gem::Version
22
18
  version: 3.5.1
@@ -24,47 +20,44 @@ dependencies:
24
20
  prerelease: false
25
21
  version_requirements: !ruby/object:Gem::Requirement
26
22
  requirements:
27
- - - "~>"
28
- - !ruby/object:Gem::Version
29
- version: '3.5'
30
23
  - - ">="
31
24
  - !ruby/object:Gem::Version
32
25
  version: 3.5.1
33
26
  - !ruby/object:Gem::Dependency
34
- name: nokogiri
27
+ name: rexml
35
28
  requirement: !ruby/object:Gem::Requirement
36
29
  requirements:
37
- - - "~>"
30
+ - - ">="
38
31
  - !ruby/object:Gem::Version
39
- version: 1.13.2
32
+ version: '3.2'
40
33
  type: :runtime
41
34
  prerelease: false
42
35
  version_requirements: !ruby/object:Gem::Requirement
43
36
  requirements:
44
- - - "~>"
37
+ - - ">="
45
38
  - !ruby/object:Gem::Version
46
- version: 1.13.2
39
+ version: '3.2'
47
40
  - !ruby/object:Gem::Dependency
48
41
  name: rubyzip
49
42
  requirement: !ruby/object:Gem::Requirement
50
43
  requirements:
51
- - - "~>"
44
+ - - ">="
52
45
  - !ruby/object:Gem::Version
53
- version: '1.3'
46
+ version: '2.0'
54
47
  type: :runtime
55
48
  prerelease: false
56
49
  version_requirements: !ruby/object:Gem::Requirement
57
50
  requirements:
58
- - - "~>"
51
+ - - ">="
59
52
  - !ruby/object:Gem::Version
60
- version: '1.3'
53
+ version: '2.0'
61
54
  description: A barebone Markdown to TeX/LaTeX converter kit via OmniOutliner
62
55
  email: shigeya@wide.ad.jp
63
56
  executables:
64
- - oo2text
65
- - md2tex
66
- - ja-ten-maru-normalize
67
57
  - ja-count
58
+ - ja-ten-maru-normalize
59
+ - md2tex
60
+ - oo2text
68
61
  extensions: []
69
62
  extra_rdoc_files:
70
63
  - Format.md
@@ -82,7 +75,6 @@ homepage: http://github.com/shigeya/oo2md2tex
82
75
  licenses:
83
76
  - ISC
84
77
  metadata: {}
85
- post_install_message:
86
78
  rdoc_options: []
87
79
  require_paths:
88
80
  - lib
@@ -90,15 +82,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
90
82
  requirements:
91
83
  - - ">="
92
84
  - !ruby/object:Gem::Version
93
- version: '1.9'
85
+ version: '3.1'
94
86
  required_rubygems_version: !ruby/object:Gem::Requirement
95
87
  requirements:
96
88
  - - ">="
97
89
  - !ruby/object:Gem::Version
98
90
  version: '0'
99
91
  requirements: []
100
- rubygems_version: 3.3.7
101
- signing_key:
92
+ rubygems_version: 4.0.10
102
93
  specification_version: 4
103
94
  summary: oo2text and md2tex
104
95
  test_files: []