oo2md2tex 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+ #
4
+ # Copyright (c)2012 Shigeya Suzuki
5
+ #
6
+ # Permission to use, copy, modify, and/or distribute this software for any
7
+ # purpose with or without fee is hereby granted, provided that the above
8
+ # copyright notice and this permission notice appear in all copies.
9
+ #
10
+ # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
+ # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
+ # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
+ # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
+ # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
+ # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16
+ # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
+ #
18
+
19
+ require 'optparse'
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
+ #####
26
+
27
+ opts = {
28
+ :ja_commma_subst_tm => false,
29
+ :ja_commma_subst_cp => false
30
+ }
31
+
32
+ ARGV.options do |o|
33
+ o.banner = "#{$0} [options] [markdown_file(s)]"
34
+ o.separator "Options:"
35
+
36
+ o.on("--no-commma-subst", "-N", "No comma/period substitution [JA]") do
37
+ opts[:ja_comma_subst_cp] = false
38
+ opts[:ja_comma_subst_tm] = false
39
+ end
40
+
41
+ o.on("--subst-to-comma-period", "-C", "Substitute to comma/period [JA]") do
42
+ opts[:ja_comma_subst_cp] = true
43
+ opts[:ja_comma_subst_tm] = false
44
+ end
45
+
46
+ o.on("--subst-to-ten-maru", "-T", "Substitute to ten/maru [JA]") do
47
+ opts[:ja_comma_subst_cp] = false
48
+ opts[:ja_comma_subst_tm] = true
49
+ end
50
+
51
+ o.parse!
52
+ end
53
+
54
+ #####
55
+
56
+ def text_tweak(str, opts)
57
+ str.tr!('、。', ',. ') if opts[:ja_comma_subst_cp]
58
+ str.tr!(',. ', '、。') if opts[:ja_comma_subst_tm]
59
+ str
60
+ end
61
+
62
+ puts text_tweak(ARGF.read, opts)
63
+
data/bin/md2tex CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- # -*- mode: ruby -*-
2
+ # -*- coding: utf-8 -*-
3
3
  #
4
4
  # Copyright (c)2012 Shigeya Suzuki
5
5
  #
@@ -23,10 +23,26 @@ end
23
23
  $script_base_dir = File.dirname(__FILE__)+"/../lib"
24
24
  $:.unshift($script_base_dir)
25
25
 
26
+ require 'optparse'
26
27
  require 'redcarpet'
27
28
  require 'markdown_to_tex'
28
29
 
29
- processor = MarkdownToTeX::Processor.new
30
+ #####
31
+
32
+ opts = {
33
+ :git => true
34
+ }
35
+
36
+ ARGV.options do |o|
37
+ o.banner = "#{$0} [options] [Markdown_File(s)]"
38
+ o.separator "Options:"
39
+ o.on("--no-git", "-G", "without running git") { opts[:git] = false }
40
+ o.parse!
41
+ end
42
+
43
+ #####
44
+
45
+ processor = MarkdownToTeX::Processor.new(opts)
30
46
 
31
47
  all = ""
32
48
  ARGV.each do |f|
@@ -25,41 +25,44 @@ module MarkdownToTeX
25
25
  :git_describe,
26
26
  :run_stamp
27
27
 
28
- def initialize
28
+ def initialize(options)
29
+ @options = options
29
30
  @run_stamp = DateTime.now.to_s
31
+ if @options[:git]
32
+ IO.popen("git branch -v --no-abbrev").each do |l|
33
+ if l =~ /(\*|.)\s+(\S+)\s+([0-9a-f]+)\s(.*)/
34
+ if $1 == "*"
35
+ @git_branch_name = $2
36
+ @git_wd_hash_long = $3
37
+ @git_wd_hash = @git_wd_hash_long[0,6]
38
+ @git_commit_line = $4
39
+ @git_commit_line.gsub!(/\#/, '\#')
40
+ @git_commit_line.gsub!(/\%/, '\%')
41
+ @git_commit_line.gsub!(/\[ahead.*\] /, '')
42
+ @git_status = @git_wd_hash + ": " + @git_commit_line
43
+ @git_status_long = @git_commit_line + '\\\\\\\\' + @git_wd_hash_long + '\\\\\\\\' + @git_branch_name
44
+ end
45
+ end
46
+ end
30
47
 
31
- IO.popen("git branch -v --no-abbrev").each do |l|
32
- if l =~ /(\*|.)\s+(\S+)\s+([0-9a-f]+)\s(.*)/
33
- if $1 == "*"
34
- @git_branch_name = $2
35
- @git_wd_hash_long = $3
36
- @git_wd_hash = @git_wd_hash_long[0,6]
37
- @git_commit_line = $4
38
- @git_commit_line.gsub!(/\#/, '\#')
39
- @git_commit_line.gsub!(/\%/, '\%')
40
- @git_commit_line.gsub!(/\[ahead.*\] /, '')
41
- @git_status = @git_wd_hash + ": " + @git_commit_line
42
- @git_status_long = @git_commit_line + '\\\\\\\\' + @git_wd_hash_long + '\\\\\\\\' + @git_branch_name
43
- end
44
- end
45
- end
46
-
48
+ @git_describe = "(no names found for git describe)"
47
49
 
48
- @git_describe = "(no names found for git describe)"
49
-
50
- IO.popen("git describe --dirty --long").each do |l|
51
- if l =~ /(.*)/
52
- @git_describe = $1
53
- end
54
- end
50
+ IO.popen("git describe --dirty --long").each do |l|
51
+ if l =~ /(.*)/
52
+ @git_describe = $1
53
+ end
54
+ end
55
55
 
56
- @macros = {
57
- "__OO2_RUN_STAMP__" => @run_stamp,
58
- "__OO2_GIT_DESCRIBE__" => @git_describe,
59
- "__OO2_GIT_STATUS__" => @git_status,
60
- "__OO2_GIT_STATUS_LONG__" => @git_status_long,
61
- "__OO2_GIT_HASH_LONG__" => @git_wd_hash_long
62
- }
56
+ @macros = {
57
+ "__OO2_RUN_STAMP__" => @run_stamp,
58
+ "__OO2_GIT_DESCRIBE__" => @git_describe,
59
+ "__OO2_GIT_STATUS__" => @git_status,
60
+ "__OO2_GIT_STATUS_LONG__" => @git_status_long,
61
+ "__OO2_GIT_HASH_LONG__" => @git_wd_hash_long
62
+ }
63
+ else
64
+ @macros = { }
65
+ end
63
66
  end
64
67
 
65
68
  def process(text)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oo2md2tex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-11 00:00:00.000000000 Z
12
+ date: 2012-10-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redcarpet
@@ -58,6 +58,7 @@ files:
58
58
  - lib/markdown_to_tex.rb
59
59
  - bin/oo2text
60
60
  - bin/md2tex
61
+ - bin/ja-ten-maru-normalize
61
62
  - Format.md
62
63
  homepage: http://github.com/shigeya/oo2md2tex
63
64
  licenses: