oo2md2tex 0.0.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.
- data/Format.md +72 -0
- data/bin/md2tex +48 -0
- data/bin/oo2text +81 -0
- data/lib/markdown_to_tex.rb +19 -0
- data/lib/markdown_to_tex/processor.rb +81 -0
- data/lib/markdown_to_tex/renderer.rb +127 -0
- data/lib/markdown_to_tex/text_processor.rb +131 -0
- metadata +88 -0
data/Format.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# Modified Markdown format for md2tex
|
2
|
+
|
3
|
+
This document describes modified markdown format for md2tex.
|
4
|
+
|
5
|
+
# Interpretation of Markdown to TeX
|
6
|
+
|
7
|
+
md2tex's format a minor extension to John Gruber's [Markdown][markdown] format.
|
8
|
+
|
9
|
+
[markdown]: http://daringfireball.net/projects/markdown/
|
10
|
+
|
11
|
+
To avoid possible incompatibilities, tried to minimize the extension.
|
12
|
+
Followings are the extensions implemented in md2tex.
|
13
|
+
|
14
|
+
Basically, `md2tex` can output either TeX or LaTeX text.
|
15
|
+
|
16
|
+
|
17
|
+
## Section name interpretation
|
18
|
+
|
19
|
+
Markdown's section titles are mapped directly into LaTeX's counterpart.
|
20
|
+
|
21
|
+
If a section name may include `[label]` at the end of title for the label
|
22
|
+
for the given section name. The output will be `\label{LABEL}` appended to the
|
23
|
+
section name.
|
24
|
+
|
25
|
+
LaTeX section command accepts optional _shorter_ title use for the
|
26
|
+
table-of-contents. you can specify this by using vertical bar like
|
27
|
+
this:
|
28
|
+
|
29
|
+
# longer_title | shorter_title [LABEL]
|
30
|
+
|
31
|
+
|
32
|
+
## Comments
|
33
|
+
|
34
|
+
Characters after `%` treated as comments and no interpretations performed,
|
35
|
+
write to output as-is.
|
36
|
+
|
37
|
+
|
38
|
+
## LaTeX environments' items
|
39
|
+
|
40
|
+
Lines prefixed with number, dot and space like `1. ` is treated as a enumerated list item.
|
41
|
+
|
42
|
+
Lines prefixed with dash and space like `- ` is treated as a itemized list. Each of them are translated into `\item ` LaTeX commands.
|
43
|
+
|
44
|
+
Lines start with a text surrounded by double parenthesis like `((TEXT))` is a items with text. This text is translated into `\item[TEXT]` command.
|
45
|
+
|
46
|
+
## Labels/Citations
|
47
|
+
|
48
|
+
References are denoted by `[citation-key]`.
|
49
|
+
Multiple citations are allowed inside a bracket like this: `[cite_a, cite_b, cite_c]`.
|
50
|
+
|
51
|
+
Note that, writing citation with `[cite_a][cite_b]` is confusing to use with regard to Markdown syntax. Either separating these two with `[cite_a]\relax[\cite_b]` or such trick may be possible.
|
52
|
+
|
53
|
+
### Label format
|
54
|
+
|
55
|
+
Labels references are denoted by `[label-name]`. For labels inside the document
|
56
|
+
(non-citations) need to have prefixes.
|
57
|
+
|
58
|
+
- `sec:`
|
59
|
+
- `subsec:`
|
60
|
+
- `subsubsec:`
|
61
|
+
- `fig:` or `figure:`
|
62
|
+
- `tab:` or `table:`
|
63
|
+
|
64
|
+
### Special references
|
65
|
+
|
66
|
+
- `[this:sec]`
|
67
|
+
- `[this:subsec]`
|
68
|
+
- `[this:subsubsec]`
|
69
|
+
- `[prev:sec]` or `[previous:sec]`
|
70
|
+
- `[prev:subsec]` or `[prev:subsec]`
|
71
|
+
- `[prev:subsubsec]` or `[previous:subsubsec]`
|
72
|
+
|
data/bin/md2tex
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- mode: ruby -*-
|
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
|
+
if RUBY_VERSION >= "1.9" # encoding only supported in Ruby 1.9.x
|
20
|
+
Encoding.default_external = "UTF-8"
|
21
|
+
end
|
22
|
+
|
23
|
+
$script_base_dir = File.dirname(__FILE__)+"/../lib"
|
24
|
+
$:.unshift($script_base_dir)
|
25
|
+
|
26
|
+
require 'redcarpet'
|
27
|
+
require 'markdown_to_tex'
|
28
|
+
|
29
|
+
processor = MarkdownToTeX::Processor.new
|
30
|
+
|
31
|
+
all = ""
|
32
|
+
ARGV.each do |f|
|
33
|
+
i = File.read(f)
|
34
|
+
s = processor.process(i)
|
35
|
+
puts processor.job_signature
|
36
|
+
puts s
|
37
|
+
all += s
|
38
|
+
end
|
39
|
+
|
40
|
+
all.gsub!(/%.*/, '')
|
41
|
+
all.gsub!(/\s+/, ' ')
|
42
|
+
all.gsub!(/\\(begin|end){[^}]+}/, '')
|
43
|
+
#all.gsub!(/\\(LL|REP|DEL|REPX|DELX)[^}]+/, '')
|
44
|
+
all.gsub!(/\\([A-Za-z]+)/, '')
|
45
|
+
#all.gsub!(/L:[A-Za-z1-9]+/, '')
|
46
|
+
all.gsub!(/\s+/, '')
|
47
|
+
all.gsub!(/\{|\}/, '')
|
48
|
+
puts "% Text length: #{all.size} chars"
|
data/bin/oo2text
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- mode: ruby -*-
|
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
|
+
require 'nokogiri'
|
21
|
+
require 'zlib'
|
22
|
+
|
23
|
+
module OmniOutliner
|
24
|
+
|
25
|
+
class Document < Nokogiri::XML::SAX::Document
|
26
|
+
def initialize
|
27
|
+
@in_item = false
|
28
|
+
@in_style = false
|
29
|
+
@str = ""
|
30
|
+
super
|
31
|
+
end
|
32
|
+
|
33
|
+
def characters(s)
|
34
|
+
@str += s if @in_item && !@in_style
|
35
|
+
end
|
36
|
+
|
37
|
+
def start_element(name, attrs)
|
38
|
+
@in_item = true if name == "item"
|
39
|
+
@in_style = true if name == "style"
|
40
|
+
end
|
41
|
+
|
42
|
+
def end_element(name)
|
43
|
+
@in_item = false if name == "item"
|
44
|
+
@in_style = false if name == "style"
|
45
|
+
if name == "values"
|
46
|
+
@str.gsub(/\n/, '')
|
47
|
+
puts @str
|
48
|
+
@str = ""
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class Parser < Nokogiri::XML::SAX::Parser
|
54
|
+
def initialize(fn)
|
55
|
+
@file = nil
|
56
|
+
if fn =~ /\.oo3$/
|
57
|
+
fn = "#{fn}/contents.xml"
|
58
|
+
@file = Zlib::GzipReader.new(File.open(fn))
|
59
|
+
else
|
60
|
+
@file = File.open(fn, rm)
|
61
|
+
end
|
62
|
+
super(Document.new)
|
63
|
+
end
|
64
|
+
|
65
|
+
def parse
|
66
|
+
super(@file)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
ARGV.options do |o|
|
73
|
+
o.banner = "ruby #{$0} [options] OmniOutliner-Document-Package"
|
74
|
+
o.separator "Options:"
|
75
|
+
o.parse!
|
76
|
+
end
|
77
|
+
|
78
|
+
ARGV.each do |file|
|
79
|
+
parser = OmniOutliner::Parser.new(file)
|
80
|
+
parser.parse
|
81
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative 'markdown_to_tex/renderer'
|
2
|
+
require_relative 'markdown_to_tex/text_processor'
|
3
|
+
require_relative 'markdown_to_tex/processor'
|
4
|
+
|
5
|
+
#
|
6
|
+
# Copyright (c)2012 Shigeya Suzuki
|
7
|
+
#
|
8
|
+
# Permission to use, copy, modify, and/or distribute this software for any
|
9
|
+
# purpose with or without fee is hereby granted, provided that the above
|
10
|
+
# copyright notice and this permission notice appear in all copies.
|
11
|
+
#
|
12
|
+
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
13
|
+
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
14
|
+
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
15
|
+
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
16
|
+
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
17
|
+
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
18
|
+
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
19
|
+
#
|
@@ -0,0 +1,81 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c)2012 Shigeya Suzuki
|
3
|
+
#
|
4
|
+
# Permission to use, copy, modify, and/or distribute this software for any
|
5
|
+
# purpose with or without fee is hereby granted, provided that the above
|
6
|
+
# copyright notice and this permission notice appear in all copies.
|
7
|
+
#
|
8
|
+
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
9
|
+
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
10
|
+
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
11
|
+
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
12
|
+
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
13
|
+
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
14
|
+
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
15
|
+
#
|
16
|
+
|
17
|
+
require 'date'
|
18
|
+
|
19
|
+
module MarkdownToTeX
|
20
|
+
|
21
|
+
class Processor
|
22
|
+
|
23
|
+
attr_reader :git_branch_name, :git_wd_hash, :git_hash_wd_long,
|
24
|
+
:git_commit_line, :git_status, :git_status_long,
|
25
|
+
:git_describe,
|
26
|
+
:run_stamp
|
27
|
+
|
28
|
+
def initialize
|
29
|
+
@run_stamp = DateTime.now.to_s
|
30
|
+
|
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
|
+
|
47
|
+
|
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
|
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
|
+
}
|
63
|
+
end
|
64
|
+
|
65
|
+
def process(text)
|
66
|
+
@renderer = Redcarpet::Markdown.new(MarkdownToTeX::Renderer)
|
67
|
+
TextProcessor.process_final(@renderer.render(text), @macros)
|
68
|
+
end
|
69
|
+
|
70
|
+
def job_signature; <<-EOS.gsub(/^\s+%/, '%')
|
71
|
+
% oo-tex.rb run at #{@run_stamp}
|
72
|
+
% description: #{@git_describe}
|
73
|
+
% revision: #{@git_wd_hash_long}
|
74
|
+
% commit log:
|
75
|
+
% #{@git_commit_line}
|
76
|
+
EOS
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c)2012 Shigeya Suzuki
|
3
|
+
#
|
4
|
+
# Permission to use, copy, modify, and/or distribute this software for any
|
5
|
+
# purpose with or without fee is hereby granted, provided that the above
|
6
|
+
# copyright notice and this permission notice appear in all copies.
|
7
|
+
#
|
8
|
+
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
9
|
+
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
10
|
+
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
11
|
+
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
12
|
+
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
13
|
+
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
14
|
+
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
15
|
+
#
|
16
|
+
|
17
|
+
module MarkdownToTeX
|
18
|
+
class Renderer < Redcarpet::Render::Base
|
19
|
+
# Block-level calls
|
20
|
+
# If the return value of the method is `nil`, the block
|
21
|
+
# will be skipped.
|
22
|
+
# If the method for a document element is not implemented,
|
23
|
+
# the block will be skipped.
|
24
|
+
#
|
25
|
+
# Example:
|
26
|
+
#
|
27
|
+
# class RenderWithoutCode < Redcarpet::Render::HTML
|
28
|
+
# def block_code(code, language)
|
29
|
+
# nil
|
30
|
+
# end
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
def block_code(code, language)
|
34
|
+
wrap_environment("verbatim", code)
|
35
|
+
end
|
36
|
+
|
37
|
+
## block_quote(quote)
|
38
|
+
## block_html(raw_html)
|
39
|
+
def header(text, header_level)
|
40
|
+
TextProcessor.process_header(text, header_level)
|
41
|
+
end
|
42
|
+
|
43
|
+
## hrule()
|
44
|
+
|
45
|
+
def list(contents, list_type)
|
46
|
+
environment = case list_type
|
47
|
+
when "ordered" then "enumerated"
|
48
|
+
when "unordered" then "itemize"
|
49
|
+
end
|
50
|
+
wrap_environment("itemize", contents)
|
51
|
+
end
|
52
|
+
|
53
|
+
def list_item(text, list_type)
|
54
|
+
"\\item #{text}\n"
|
55
|
+
end
|
56
|
+
|
57
|
+
def paragraph(text)
|
58
|
+
TextProcessor.process_paragraph(text)+"\n\n"
|
59
|
+
end
|
60
|
+
|
61
|
+
## table(header, body)
|
62
|
+
## table_row(content)
|
63
|
+
## table_cell(content, alignment)
|
64
|
+
|
65
|
+
# Span-level calls
|
66
|
+
# A return value of `nil` will not output any data
|
67
|
+
# If the method for a document element is not implemented,
|
68
|
+
# the contents of the span will be copied verbatim
|
69
|
+
def autolink(link, link_type)
|
70
|
+
"{{autolink:<#{link}>, title:<#{title}>, content:<#{content}>}}"
|
71
|
+
end
|
72
|
+
|
73
|
+
def codespan(code)
|
74
|
+
qchar = if code =~ /\+/ then "!" else "+" end
|
75
|
+
"\\verb#{qchar}#{code}#{qchar}"
|
76
|
+
end
|
77
|
+
## double_emphasis(text)
|
78
|
+
## emphasis(text)
|
79
|
+
## image(link, title, alt_text)
|
80
|
+
def linebreak()
|
81
|
+
"\n%\n"
|
82
|
+
end
|
83
|
+
|
84
|
+
def link(link, title, content)
|
85
|
+
"#{content}\\nobreak\\footnote{\\url{#{link}}}"
|
86
|
+
end
|
87
|
+
|
88
|
+
def raw_html(raw_html)
|
89
|
+
raw_html
|
90
|
+
end
|
91
|
+
|
92
|
+
## triple_emphasis(text)
|
93
|
+
## strikethrough(text)
|
94
|
+
## superscript(text)
|
95
|
+
|
96
|
+
# Low level rendering
|
97
|
+
## entity(text)
|
98
|
+
## normal_text(text)
|
99
|
+
|
100
|
+
# Header of the document
|
101
|
+
# Rendered before any another elements
|
102
|
+
def doc_header()
|
103
|
+
"% start-of-output\n"
|
104
|
+
end
|
105
|
+
|
106
|
+
# Footer of the document
|
107
|
+
# Rendered after all the other elements
|
108
|
+
def doc_footer()
|
109
|
+
"\n% end-of-output"
|
110
|
+
end
|
111
|
+
|
112
|
+
# Pre/post-process
|
113
|
+
# Special callback: preprocess or postprocess the whole
|
114
|
+
# document before or after the rendering process begins
|
115
|
+
## preprocess(full_document)
|
116
|
+
## postprocess(full_document)
|
117
|
+
|
118
|
+
|
119
|
+
private
|
120
|
+
def wrap_environment(environment, text)
|
121
|
+
"\\begin{#{environment}}\n"+
|
122
|
+
text +
|
123
|
+
"\\end{#{environment}}\n"
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c)2012 Shigeya Suzuki
|
3
|
+
#
|
4
|
+
# Permission to use, copy, modify, and/or distribute this software for any
|
5
|
+
# purpose with or without fee is hereby granted, provided that the above
|
6
|
+
# copyright notice and this permission notice appear in all copies.
|
7
|
+
#
|
8
|
+
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
9
|
+
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
10
|
+
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
11
|
+
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
12
|
+
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
13
|
+
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
14
|
+
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
15
|
+
#
|
16
|
+
|
17
|
+
module MarkdownToTeX
|
18
|
+
class TextProcessor
|
19
|
+
|
20
|
+
@@tag_namespace = nil
|
21
|
+
@@cite_map = {}
|
22
|
+
@@level_tag = ["chapter", "section", "subsection", "subsubsection"]
|
23
|
+
@@level_shift = 0
|
24
|
+
|
25
|
+
# Process a paragraph
|
26
|
+
def self.process_paragraph(text)
|
27
|
+
text.gsub!(/\(\((.*)\)\)/, '\\ITEM{\1}') # description format
|
28
|
+
self.reference(text)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Citation Handling
|
32
|
+
|
33
|
+
def self.bib_name_map(n)
|
34
|
+
@@cite_map.has_key?(n) ? @@cite_map[n] : n
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.tag_name_map(n)
|
38
|
+
return "" if n == nil
|
39
|
+
if @@tag_namespace == nil or n =~ /#{@@tag_namespace}:/
|
40
|
+
return n
|
41
|
+
end
|
42
|
+
@@tag_namespace + ":" + n
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.label_name_map(n)
|
46
|
+
if @@tag_namespace == nil
|
47
|
+
return bib_name_map(n)
|
48
|
+
end
|
49
|
+
|
50
|
+
if n =~ /(chap|part|sec|subsec|subsubsec|fig|table|eq):(.+)/
|
51
|
+
r = $1 + ":" + self.tag_name_map($2)
|
52
|
+
else
|
53
|
+
r = self.bib_name_map(n)
|
54
|
+
end
|
55
|
+
r
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.ref_name_map(n)
|
59
|
+
self.label_name_map(n)
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.ref_name_map_cite(k)
|
63
|
+
cite = "CITE"
|
64
|
+
text = k.split(/\s*,\s*/).each.map {|kk| self.ref_name_map(kk)}.join(",")
|
65
|
+
if text =~ /"(.*)"/
|
66
|
+
r = "[#{$1}]"
|
67
|
+
else
|
68
|
+
r = "\\#{cite}{#{text}}"
|
69
|
+
end
|
70
|
+
r
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.reference(text)
|
74
|
+
text.
|
75
|
+
gsub(/\[(this|prev|next):(chap|part|sec|subsec|subsubsec|fig|table)\]/) { "\\#{$1}#{$2}KEY{}" }.
|
76
|
+
gsub(/\[((chap|part|sec|subsec|subsubsec|fig|table):[^\]]+)\]/) { "\\#{$2}REF{#{self.ref_name_map($1)}}" }.
|
77
|
+
gsub(/\[([^\]]+)\]/) { self.ref_name_map_cite($1);}
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.label_split(s)
|
81
|
+
label = ""
|
82
|
+
if s.sub!(/\s*\[([^\]]+)\]/, '')
|
83
|
+
label = $1
|
84
|
+
end
|
85
|
+
[s, label]
|
86
|
+
end
|
87
|
+
|
88
|
+
def self.short_desc(s) # map short|long
|
89
|
+
s_short = ""
|
90
|
+
if s =~ /\s*([^\|]+)\s*\|\s*(.+)\s*/
|
91
|
+
s_short = "[#{$1}]"
|
92
|
+
s = $2
|
93
|
+
end
|
94
|
+
[s, s_short]
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.level_tag(d)
|
98
|
+
@@level_tag[d + @@level_shift]
|
99
|
+
end
|
100
|
+
|
101
|
+
# Process a header
|
102
|
+
def self.process_header(text, level)
|
103
|
+
name, label = self.label_split(text)
|
104
|
+
name, name_short = self.short_desc(name)
|
105
|
+
tag = self.level_tag(level)
|
106
|
+
the_label = self.label_name_map(label)
|
107
|
+
star = "" # star ? "*" : ""
|
108
|
+
s = self.comment_line(tag.upcase + ": #{name}")
|
109
|
+
s << "\\#{tag}#{star}#{name_short}{#{name}}"
|
110
|
+
s << "\\label{#{the_label}}" unless label.empty?
|
111
|
+
s << "\n"
|
112
|
+
s
|
113
|
+
end
|
114
|
+
|
115
|
+
|
116
|
+
# Process on whole output text
|
117
|
+
|
118
|
+
def self.process_final(text, macros)
|
119
|
+
# Macro expansions
|
120
|
+
macros.each {|m, v| text.gsub!(m, v) }
|
121
|
+
text
|
122
|
+
end
|
123
|
+
|
124
|
+
def self.comment_line(s)
|
125
|
+
px = (78 - 1 - s.length)
|
126
|
+
px = 1 if px < 1
|
127
|
+
"%" * px + " " + s + "\n"
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: oo2md2tex
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Shigeya Suzuki
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-11 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: redcarpet
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2.1'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.1'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: nokogiri
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '1.5'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '1.5'
|
46
|
+
description: A barebone Markdown to TeX/LaTeX converter kit via OmniOutliner
|
47
|
+
email: shigeya@wide.ad.jp
|
48
|
+
executables:
|
49
|
+
- oo2text
|
50
|
+
- md2tex
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files:
|
53
|
+
- Format.md
|
54
|
+
files:
|
55
|
+
- lib/markdown_to_tex/processor.rb
|
56
|
+
- lib/markdown_to_tex/renderer.rb
|
57
|
+
- lib/markdown_to_tex/text_processor.rb
|
58
|
+
- lib/markdown_to_tex.rb
|
59
|
+
- bin/oo2text
|
60
|
+
- bin/md2tex
|
61
|
+
- Format.md
|
62
|
+
homepage: http://github.com/shigeya/oo2md2tex
|
63
|
+
licenses:
|
64
|
+
- ISC
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ! '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '1.9'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 1.8.24
|
84
|
+
signing_key:
|
85
|
+
specification_version: 3
|
86
|
+
summary: oo2text and md2tex
|
87
|
+
test_files: []
|
88
|
+
has_rdoc:
|