pandoku 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/pandoku.rb +1 -1
- data/lib/pandoku/document.rb +10 -8
- data/lib/pandoku/format.rb +4 -8
- data/lib/pandoku/formats/html.rb +47 -43
- data/lib/pandoku/formats/markdown.rb +11 -11
- data/lib/pandoku/formats/odt.rb +33 -7
- data/lib/pandoku/formats/rst.rb +27 -0
- metadata +2 -1
data/lib/pandoku.rb
CHANGED
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/pandoku/format'
|
|
3
3
|
|
4
4
|
# %w<markdown rst html latex
|
5
5
|
# context man mediawiki texinfo docbook opendocument odt s5 rtf>.each do |f|
|
6
|
-
%w<markdown html>.each do |f|
|
6
|
+
%w<markdown rst html odt>.each do |f|
|
7
7
|
require "#{File.dirname(__FILE__)}/pandoku/formats/#{f}"
|
8
8
|
end
|
9
9
|
|
data/lib/pandoku/document.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/format'
|
2
2
|
|
3
3
|
module Pandoku
|
4
|
-
PANDOC_PATH = 'pandoc'
|
4
|
+
PANDOC_PATH = ENV['PANDOC_PATH'] || 'pandoc'
|
5
5
|
|
6
6
|
class Document
|
7
7
|
attr_reader :format, :text
|
@@ -16,16 +16,18 @@ module Pandoku
|
|
16
16
|
|
17
17
|
# Makes a command string to execute Pandoc.
|
18
18
|
def command_for(format)
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
commands = [PANDOC_PATH, '-f', self.format.class.name,
|
20
|
+
'-t', format.class.name]
|
21
|
+
commands += self.format.cliopts
|
22
|
+
commands += format.cliopts
|
23
|
+
escapeshellarg = lambda do |arg|
|
24
|
+
"'" + arg.to_s.gsub(/[^\\]'/) {|s| %<#{s.chars.first}\\'> } + "'"
|
25
|
+
end
|
26
|
+
commands.select {|v| v }.collect(&escapeshellarg).join(' ')
|
25
27
|
end
|
26
28
|
|
27
29
|
# Compiles the document to given +format+.
|
28
|
-
# If a second argument +io+ is true
|
30
|
+
# If a second argument +io+ is +true+, returns +IO+ instead of +String+.
|
29
31
|
def compile(format, io = false)
|
30
32
|
unless format.is_a?(OutputFormat)
|
31
33
|
raise TypeError, 'format must be OutputFormat'
|
data/lib/pandoku/format.rb
CHANGED
@@ -21,13 +21,9 @@ module Pandoku
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def cliopts
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
@options.select {|k, v| v } \
|
28
|
-
.collect {|p| %<--#{p[0].gsub('_', '-')}> +
|
29
|
-
(p[1] != true ? %<=#{p[1]}> : '') } \
|
30
|
-
.join(' ')
|
24
|
+
self.options.select {|k, v| v } \
|
25
|
+
.collect {|p| %<--#{p[0].to_s.gsub('_', '-')}> +
|
26
|
+
(p[1] != true ? %<=#{p[1]}> : '') }
|
31
27
|
end
|
32
28
|
end
|
33
29
|
|
@@ -39,7 +35,7 @@ module Pandoku
|
|
39
35
|
|
40
36
|
module OutputFormat
|
41
37
|
# Compiles the given +document+ to the format.
|
42
|
-
# If a second argument +io+ is true
|
38
|
+
# If a second argument +io+ is +true+, returns +IO+ instead of +String+.
|
43
39
|
def compile(document, io = false)
|
44
40
|
cin, cout, cerr = Open3.popen3(document.command_for(self))
|
45
41
|
cin.print(document.text)
|
data/lib/pandoku/formats/html.rb
CHANGED
@@ -5,49 +5,53 @@ module Pandoku::Formats
|
|
5
5
|
#
|
6
6
|
# == Available Options
|
7
7
|
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
8
|
+
# <tt>:standalone</tt>:: Produce output with an appropriate header and footer.
|
9
|
+
# <tt>:parse_raw</tt>:: Parse untranslatable HTML codes as raw HTML,
|
10
|
+
# instead of ignoring them.
|
11
|
+
# <tt>latexmathml</tt>::
|
12
|
+
# Use LaTeXMathML to display embedded TeX math in HTML output.
|
13
|
+
# To insert a link to a local copy of the <b>LaTeXMathML.js</b> script,
|
14
|
+
# provide a URL string. If just <tt>true</tt> is provided, the contents
|
15
|
+
# of the script will be inserted directly into the HTML header.
|
16
|
+
# <tt>:jsmath</tt>::
|
17
|
+
# Use jsMath to display embedded TeX math in HTML output.
|
18
|
+
# The URL should point to the jsMath load script; if provided,
|
19
|
+
# it will be linked to in the header of standalone HTML documents.
|
20
|
+
# <tt>:gladtex</tt>::
|
21
|
+
# Enclose TeX math in +<eq>+ tags in HTML output.
|
22
|
+
# These can then be processed by gladTeX to produce links
|
23
|
+
# to images of the typeset formulas.
|
24
|
+
# <tt>:mimetex</tt>::
|
25
|
+
# Render TeX math using the mimeTeX CGI script. If URL is not specified,
|
26
|
+
# it is assumed that the script is at <b>/cgi-bin/mimetex.cgi</b>.
|
27
|
+
# <tt>:no_wrap</tt>:: Disable text wrapping in output.
|
28
|
+
# (Default is to wrap text.)
|
29
|
+
# <tt>:sanitize_html</tt>::
|
30
|
+
# Sanitizes HTML using a whitelist. Unsafe tags are replaced by
|
31
|
+
# HTML comments; unsafe attributes are omitted. URIs in links and
|
32
|
+
# images are also checked against a whitelist of URI schemes.
|
33
|
+
# <tt>:email_obfuscation</tt> <i>(<tt>nil</tt>|<tt>:javascript</tt>|<tt>:references</tt>)</i>::
|
34
|
+
# Specify a method for obfuscating <tt>mailto:</tt> links
|
35
|
+
# in HTML documents.
|
36
|
+
# * <tt>:nil</tt> leaves <tt>mailto:</tt> links as they are.
|
37
|
+
# * <tt>:javascript</tt> obfuscates them using javascript.
|
38
|
+
# * <tt>:references</tt> obfuscates them by printing their letters
|
39
|
+
# as decimal or hexadecimal character references.
|
40
|
+
# If <tt>:strict => true</tt> is specified, references is
|
41
|
+
# used regardless of the presence of this option.
|
42
|
+
# <tt>:toc</tt>:: Include an automatically generated table of contents.
|
43
|
+
# <tt>:css</tt>:: Link to a CSS style sheet.
|
44
|
+
# The pathname of the style sheet goes value.
|
45
|
+
# <tt>:include_in_header</tt>::
|
46
|
+
# Include contents of the given filename at the end of the header.
|
47
|
+
# Implies <tt>:standalone</tt>.
|
48
|
+
# <tt>:include_before_body</tt>:: Include contents of the given filename
|
49
|
+
# at the beginning of the document body.
|
50
|
+
# <tt>:include_after_body</tt>:: Include contents of the given filename
|
51
|
+
# at the end of the document body.
|
52
|
+
# <tt>:custom_header</tt>::
|
53
|
+
# Use contents of the given filename as the document header.
|
54
|
+
# Implies <tt>:standalone</tt>.
|
51
55
|
class HTML < Pandoku::Format
|
52
56
|
include Pandoku::InputFormat, Pandoku::OutputFormat
|
53
57
|
|
@@ -5,17 +5,17 @@ module Pandoku::Formats
|
|
5
5
|
#
|
6
6
|
# == Available Options
|
7
7
|
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
8
|
+
# <tt>:strict</tt>:: Use strict syntax, with no extensions or variants.
|
9
|
+
# <tt>:reference_links</tt>:: Use reference-style links,
|
10
|
+
# rather than inline links, in writing.
|
11
|
+
# <tt>:smart</tt>:: Use smart quotes, dashes, and ellipses.
|
12
|
+
# <tt>:no_wrap</tt>:: Disable text wrapping in output.
|
13
|
+
# (Default is to wrap text.)
|
14
|
+
# <tt>:sanitize_html</tt>::
|
15
|
+
# Sanitizes HTML using a whitelist. Unsafe tags are replaced by
|
16
|
+
# HTML comments; unsafe attributes are omitted. URIs in links and
|
17
|
+
# images are also checked against a whitelist of URI schemes.
|
18
|
+
# <tt>:toc</tt>:: Include an automatically generated table of contents.
|
19
19
|
class Markdown < Pandoku::Format
|
20
20
|
include Pandoku::InputFormat, Pandoku::OutputFormat
|
21
21
|
|
data/lib/pandoku/formats/odt.rb
CHANGED
@@ -1,27 +1,53 @@
|
|
1
|
+
require 'tempfile'
|
1
2
|
require File.dirname(File.dirname(__FILE__)) + '/format'
|
2
3
|
|
3
4
|
module Pandoku::Formats
|
4
5
|
# ODT (OpenOffice text document) format.
|
5
|
-
|
6
|
-
|
6
|
+
#
|
7
|
+
# == Available Options
|
8
|
+
#
|
9
|
+
# <tt>:toc</tt>:: Include an automatically generated table of contents.
|
10
|
+
class ODT < Pandoku::Format
|
11
|
+
include Pandoku::OutputFormat
|
7
12
|
|
8
13
|
def self.name
|
9
14
|
:odt
|
10
15
|
end
|
11
16
|
|
17
|
+
def self.default_options
|
18
|
+
{ :toc => false }
|
19
|
+
end
|
20
|
+
|
12
21
|
def cliopts
|
13
|
-
@tmpfile = @tmpfile ||
|
14
|
-
"--output=#{@tmpfile}
|
22
|
+
@tmpfile = @tmpfile || _tmpfile
|
23
|
+
super + ["--output=#{@tmpfile}"]
|
15
24
|
end
|
16
25
|
|
17
|
-
|
18
|
-
|
26
|
+
# Compiles the given +document+ to the format.
|
27
|
+
# If a second argument +file+ is +true+, returns +File+ instead of +String+.
|
28
|
+
#
|
29
|
+
# *Note* that it creates a temporary file for the result.
|
30
|
+
# If +file+ is +false+, the temporary file become deleted.
|
31
|
+
def compile(document, file = false)
|
32
|
+
@tmpfile = _tmpfile
|
33
|
+
ps = IO.popen(document.command_for(self), 'w')
|
34
|
+
ps.print(document.text)
|
35
|
+
ps.close
|
36
|
+
f = File.new(@tmpfile, 'r')
|
37
|
+
return f if file
|
38
|
+
result = f.read
|
39
|
+
f.close
|
40
|
+
File.unlink(@tmpfile)
|
41
|
+
return result
|
19
42
|
end
|
20
43
|
|
21
44
|
private
|
22
45
|
|
23
46
|
def _tmpfile
|
24
|
-
|
47
|
+
f = Tempfile.new('pandoku')
|
48
|
+
path = f.path
|
49
|
+
f.close(false)
|
50
|
+
path
|
25
51
|
end
|
26
52
|
end
|
27
53
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.dirname(File.dirname(__FILE__)) + '/format'
|
2
|
+
|
3
|
+
module Pandoku::Formats
|
4
|
+
# reStructuredText format. http://docutils.sourceforge.net/rst.html
|
5
|
+
#
|
6
|
+
# == Available Options
|
7
|
+
#
|
8
|
+
# <tt>:reference_links</tt>:: Use reference-style links,
|
9
|
+
# rather than inline links, in writing.
|
10
|
+
# <tt>:no_wrap</tt>:: Disable text wrapping in output.
|
11
|
+
# (Default is to wrap text.)
|
12
|
+
# <tt>:toc</tt>:: Include an instruction to create table of contents.
|
13
|
+
class ReStructuredText < Pandoku::Format
|
14
|
+
include Pandoku::InputFormat, Pandoku::OutputFormat
|
15
|
+
|
16
|
+
def self.name
|
17
|
+
:rst
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.default_options
|
21
|
+
{ :reference_links => false, :no_wrap => false, :toc => false }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Aliases.
|
26
|
+
ReST = RST = reStructuredText = ReStructuredText
|
27
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pandoku
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: "0.
|
4
|
+
version: "0.2"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hong, MinHee
|
@@ -25,6 +25,7 @@ files:
|
|
25
25
|
- lib/pandoku.rb
|
26
26
|
- lib/pandoku/formats/odt.rb
|
27
27
|
- lib/pandoku/formats/html.rb
|
28
|
+
- lib/pandoku/formats/rst.rb
|
28
29
|
- lib/pandoku/formats/markdown.rb
|
29
30
|
- lib/pandoku/document.rb
|
30
31
|
- lib/pandoku/format.rb
|