pandoku 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/lib/pandoku.rb +9 -0
- data/lib/pandoku/document.rb +37 -0
- data/lib/pandoku/format.rb +54 -0
- data/lib/pandoku/formats/html.rb +66 -0
- data/lib/pandoku/formats/markdown.rb +31 -0
- data/lib/pandoku/formats/odt.rb +27 -0
- metadata +60 -0
data/lib/pandoku.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/pandoku/document'
|
2
|
+
require File.dirname(__FILE__) + '/pandoku/format'
|
3
|
+
|
4
|
+
# %w<markdown rst html latex
|
5
|
+
# context man mediawiki texinfo docbook opendocument odt s5 rtf>.each do |f|
|
6
|
+
%w<markdown html>.each do |f|
|
7
|
+
require "#{File.dirname(__FILE__)}/pandoku/formats/#{f}"
|
8
|
+
end
|
9
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/format'
|
2
|
+
|
3
|
+
module Pandoku
|
4
|
+
PANDOC_PATH = 'pandoc'
|
5
|
+
|
6
|
+
class Document
|
7
|
+
attr_reader :format, :text
|
8
|
+
|
9
|
+
def initialize(format, text)
|
10
|
+
unless format.is_a?(InputFormat)
|
11
|
+
raise TypeError, 'format must be InputFormat'
|
12
|
+
end
|
13
|
+
@format = format
|
14
|
+
@text = text
|
15
|
+
end
|
16
|
+
|
17
|
+
# Makes a command string to execute Pandoc.
|
18
|
+
def command_for(format)
|
19
|
+
<<-CMD
|
20
|
+
#{PANDOC_PATH} -f #{self.format.class.name}
|
21
|
+
-t #{format.class.name}
|
22
|
+
#{self.format.cliopts}
|
23
|
+
#{format.cliopts}
|
24
|
+
CMD
|
25
|
+
end
|
26
|
+
|
27
|
+
# Compiles the document to given +format+.
|
28
|
+
# If a second argument +io+ is true, returns +IO+ instead of +String+.
|
29
|
+
def compile(format, io = false)
|
30
|
+
unless format.is_a?(OutputFormat)
|
31
|
+
raise TypeError, 'format must be OutputFormat'
|
32
|
+
end
|
33
|
+
format.compile(self, io)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'open3'
|
2
|
+
require File.dirname(__FILE__) + '/document'
|
3
|
+
|
4
|
+
module Pandoku
|
5
|
+
class Format
|
6
|
+
attr_reader :options
|
7
|
+
|
8
|
+
def self.name
|
9
|
+
raise NotImplementedError,
|
10
|
+
'Format.name should be overrided to return Symbol'
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.default_options
|
14
|
+
{}
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(options = {})
|
18
|
+
@options = self.class.default_options
|
19
|
+
keys = @options.keys
|
20
|
+
@options.merge!(Hash[options.select {|k, v| keys.include?(k) }])
|
21
|
+
end
|
22
|
+
|
23
|
+
def cliopts
|
24
|
+
escapeshellarg = lambda do |arg|
|
25
|
+
"'" + arg.gsub(/[^\\]'/) {|s| %<#{s.chars.first}\\'> } + "'"
|
26
|
+
end
|
27
|
+
@options.select {|k, v| v } \
|
28
|
+
.collect {|p| %<--#{p[0].gsub('_', '-')}> +
|
29
|
+
(p[1] != true ? %<=#{p[1]}> : '') } \
|
30
|
+
.join(' ')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
module InputFormat
|
35
|
+
def parse(text)
|
36
|
+
Document.new(self, text)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
module OutputFormat
|
41
|
+
# Compiles the given +document+ to the format.
|
42
|
+
# If a second argument +io+ is true, returns +IO+ instead of +String+.
|
43
|
+
def compile(document, io = false)
|
44
|
+
cin, cout, cerr = Open3.popen3(document.command_for(self))
|
45
|
+
cin.print(document.text)
|
46
|
+
cin.close
|
47
|
+
return cout if io
|
48
|
+
result = cout.read
|
49
|
+
cout.close
|
50
|
+
return result
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require File.dirname(File.dirname(__FILE__)) + '/format'
|
2
|
+
|
3
|
+
module Pandoku::Formats
|
4
|
+
# HTML format.
|
5
|
+
#
|
6
|
+
# == Available Options
|
7
|
+
#
|
8
|
+
# * <tt>:standalone</tt> - Produce output with an appropriate header
|
9
|
+
# and footer.
|
10
|
+
# * <tt>:parse_raw</tt> - Parse untranslatable HTML codes as raw HTML,
|
11
|
+
# instead of ignoring them.
|
12
|
+
# * <tt>latexmathml</tt> - Use LaTeXMathML to display embedded TeX math in
|
13
|
+
# HTML output. To insert a link to a local copy of the <b>LaTeXMathML.js</b>
|
14
|
+
# script, provide a URL string. If just <tt>true</tt> is provided, the
|
15
|
+
# contents of the script will be inserted directly into the HTML header.
|
16
|
+
# * <tt>:jsmath</tt> - Use jsMath to display embedded TeX math in HTML output.
|
17
|
+
# The URL should point to the jsMath load script; if provided,
|
18
|
+
# it will be linked to in the header of standalone HTML documents.
|
19
|
+
# * <tt>:gladtex</tt> - Enclose TeX math in +<eq>+ tags in HTML output.
|
20
|
+
# These can then be processed by gladTeX to produce links
|
21
|
+
# to images of the typeset formulas.
|
22
|
+
# * <tt>:mimetex</tt> - Render TeX math using the mimeTeX CGI script.
|
23
|
+
# If URL is not specified, it is assumed that the script is at
|
24
|
+
# <b>/cgi-bin/mimetex.cgi</b>.
|
25
|
+
# * <tt>:no_wrap</tt> - Disable text wrapping in output.
|
26
|
+
# (Default is to wrap text.)
|
27
|
+
# * <tt>:sanitize_html</tt> - Sanitizes HTML using a whitelist.
|
28
|
+
# Unsafe tags are replaced by HTML comments; unsafe attributes are omitted.
|
29
|
+
# URIs in links and images are also checked against a whitelist of URI
|
30
|
+
# schemes.
|
31
|
+
# * <tt>:email_obfuscation</tt> -
|
32
|
+
# (<tt>nil</tt>|<tt>:javascript</tt>|<tt>:references</tt>)
|
33
|
+
# Specify a method for obfuscating <tt>mailto:</tt> links in HTML documents.
|
34
|
+
# * <tt>:nil</tt> leaves <tt>mailto:</tt> links as they are.
|
35
|
+
# * <tt>:javascript</tt> obfuscates them using javascript.
|
36
|
+
# * <tt>:references</tt> obfuscates them by printing their letters
|
37
|
+
# as decimal or hexadecimal character references.
|
38
|
+
# If <tt>:strict => true</tt> is specified, references is used regardless
|
39
|
+
# of the presence of this option.
|
40
|
+
# * <tt>:toc</tt> - Include an automatically generated table of contents.
|
41
|
+
# * <tt>:css</tt> - Link to a CSS style sheet.
|
42
|
+
# The pathname of the style sheet goes value.
|
43
|
+
# * <tt>:include_in_header</tt> - Include contents of the given filename
|
44
|
+
# at the end of the header. Implies <tt>:standalone</tt>.
|
45
|
+
# * <tt>:include_before_body</tt> - Include contents of the given filename
|
46
|
+
# at the beginning of the document body.
|
47
|
+
# * <tt>:include_after_body</tt> - Include contents of the given filename
|
48
|
+
# at the end of the document body.
|
49
|
+
# * <tt>:custom_header</tt> - Use contents of the given filename as the
|
50
|
+
# document header. Implies <tt>:standalone</tt>.
|
51
|
+
class HTML < Pandoku::Format
|
52
|
+
include Pandoku::InputFormat, Pandoku::OutputFormat
|
53
|
+
|
54
|
+
def self.name
|
55
|
+
:html
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.default_options
|
59
|
+
{ :standalone => false, :parse_raw => false, :latexmathml => nil,
|
60
|
+
:jsmath => nil, :gladtex => false, :mimetex => nil, :no_wrap => false,
|
61
|
+
:sanitize_html => false, :email_obfuscation => false, :toc => false,
|
62
|
+
:css => nil, :include_in_header => nil, :include_before_body => nil,
|
63
|
+
:include_after_body => nil, :custom_header => nil }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.dirname(File.dirname(__FILE__)) + '/format'
|
2
|
+
|
3
|
+
module Pandoku::Formats
|
4
|
+
# Markdown format. http://daringfireball.net/projects/markdown/
|
5
|
+
#
|
6
|
+
# == Available Options
|
7
|
+
#
|
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> - Sanitizes HTML using a whitelist.
|
15
|
+
# Unsafe tags are replaced by HTML comments; unsafe attributes are omitted.
|
16
|
+
# URIs in links and images are also checked against a whitelist of URI
|
17
|
+
# schemes.
|
18
|
+
# * <tt>:toc</tt> - Include an automatically generated table of contents.
|
19
|
+
class Markdown < Pandoku::Format
|
20
|
+
include Pandoku::InputFormat, Pandoku::OutputFormat
|
21
|
+
|
22
|
+
def self.name
|
23
|
+
:markdown
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.default_options
|
27
|
+
{ :strict => false, :reference_links => false, :smart => false,
|
28
|
+
:no_wrap => false, :sanitize_html => false, :toc => false }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.dirname(File.dirname(__FILE__)) + '/format'
|
2
|
+
|
3
|
+
module Pandoku::Formats
|
4
|
+
# ODT (OpenOffice text document) format.
|
5
|
+
class ODT
|
6
|
+
include OutputFormat
|
7
|
+
|
8
|
+
def self.name
|
9
|
+
:odt
|
10
|
+
end
|
11
|
+
|
12
|
+
def cliopts
|
13
|
+
@tmpfile = @tmpfile || self._tmpfile
|
14
|
+
"--output=#{@tmpfile} #{super.cliopts}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def compile(document)
|
18
|
+
@tmpfile = self._tmpfile
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def _tmpfile
|
24
|
+
Dir.tmpdir
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pandoku
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.1"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hong, MinHee
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-08 00:00:00 +09:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Loose Ruby interface for Pandoc, the most powerful markup processor.
|
17
|
+
email: minhee@dahlia.kr
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- lib/pandoku.rb
|
26
|
+
- lib/pandoku/formats/odt.rb
|
27
|
+
- lib/pandoku/formats/html.rb
|
28
|
+
- lib/pandoku/formats/markdown.rb
|
29
|
+
- lib/pandoku/document.rb
|
30
|
+
- lib/pandoku/format.rb
|
31
|
+
has_rdoc: true
|
32
|
+
homepage: http://github.com/dahlia/pandoku
|
33
|
+
licenses: []
|
34
|
+
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: "0"
|
45
|
+
version:
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: "0"
|
51
|
+
version:
|
52
|
+
requirements: []
|
53
|
+
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 1.3.5
|
56
|
+
signing_key:
|
57
|
+
specification_version: 3
|
58
|
+
summary: Loose Ruby interface for Pandoc, the most powerful markup processor.
|
59
|
+
test_files: []
|
60
|
+
|