paru 0.2.4.2 → 0.2.4.3
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 +4 -4
- data/lib/paru.rb +8 -20
- data/lib/paru/error.rb +4 -6
- data/lib/paru/filter.rb +144 -110
- data/lib/paru/filter/ast_manipulation.rb +75 -39
- data/lib/paru/filter/attr.rb +72 -36
- data/lib/paru/filter/block.rb +14 -8
- data/lib/paru/filter/block_quote.rb +12 -9
- data/lib/paru/filter/bullet_list.rb +6 -6
- data/lib/paru/filter/citation.rb +51 -25
- data/lib/paru/filter/cite.rb +29 -20
- data/lib/paru/filter/code.rb +41 -24
- data/lib/paru/filter/code_block.rb +36 -21
- data/lib/paru/filter/definition_list.rb +19 -15
- data/lib/paru/filter/definition_list_item.rb +30 -17
- data/lib/paru/filter/div.rb +29 -21
- data/lib/paru/filter/document.rb +73 -46
- data/lib/paru/filter/emph.rb +6 -6
- data/lib/paru/filter/empty_block.rb +17 -13
- data/lib/paru/filter/empty_inline.rb +24 -17
- data/lib/paru/filter/header.rb +38 -23
- data/lib/paru/filter/image.rb +13 -11
- data/lib/paru/filter/inline.rb +21 -10
- data/lib/paru/filter/line_block.rb +6 -6
- data/lib/paru/filter/line_break.rb +6 -6
- data/lib/paru/filter/link.rb +33 -21
- data/lib/paru/filter/list.rb +26 -17
- data/lib/paru/filter/list_attributes.rb +53 -32
- data/lib/paru/filter/markdown.rb +102 -59
- data/lib/paru/filter/math.rb +65 -38
- data/lib/paru/filter/meta.rb +26 -16
- data/lib/paru/filter/meta_blocks.rb +12 -9
- data/lib/paru/filter/meta_bool.rb +6 -6
- data/lib/paru/filter/meta_inlines.rb +12 -9
- data/lib/paru/filter/meta_list.rb +6 -6
- data/lib/paru/filter/meta_map.rb +49 -33
- data/lib/paru/filter/meta_string.rb +6 -6
- data/lib/paru/filter/meta_value.rb +22 -14
- data/lib/paru/filter/node.rb +204 -129
- data/lib/paru/filter/note.rb +31 -20
- data/lib/paru/filter/null.rb +6 -6
- data/lib/paru/filter/ordered_list.rb +34 -18
- data/lib/paru/filter/para.rb +20 -13
- data/lib/paru/filter/plain.rb +21 -12
- data/lib/paru/filter/quoted.rb +27 -18
- data/lib/paru/filter/raw_block.rb +32 -19
- data/lib/paru/filter/raw_inline.rb +40 -22
- data/lib/paru/filter/small_caps.rb +7 -6
- data/lib/paru/filter/soft_break.rb +6 -6
- data/lib/paru/filter/space.rb +6 -6
- data/lib/paru/filter/span.rb +28 -18
- data/lib/paru/filter/str.rb +29 -18
- data/lib/paru/filter/strikeout.rb +6 -6
- data/lib/paru/filter/strong.rb +6 -6
- data/lib/paru/filter/subscript.rb +6 -6
- data/lib/paru/filter/superscript.rb +6 -6
- data/lib/paru/filter/table.rb +51 -29
- data/lib/paru/filter/table_row.rb +21 -14
- data/lib/paru/filter/target.rb +29 -15
- data/lib/paru/filter/version.rb +23 -14
- data/lib/paru/pandoc.rb +165 -111
- data/lib/paru/pandoc_options.yaml +3 -3
- data/lib/paru/selector.rb +176 -153
- metadata +2 -3
- data/lib/paru/filter/alignment.rb +0 -30
data/lib/paru/filter/str.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright 2015, 2016 Huub de Beer <Huub@heerdebeer.org>
|
2
|
+
# Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
|
3
3
|
#
|
4
4
|
# This file is part of Paru
|
5
5
|
#
|
@@ -17,26 +17,37 @@
|
|
17
17
|
# along with Paru. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#++
|
19
19
|
module Paru
|
20
|
-
|
21
|
-
|
20
|
+
module PandocFilter
|
21
|
+
require_relative "./inline"
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
def initialize value
|
26
|
-
@string = value
|
27
|
-
end
|
23
|
+
# A Str node represents a string
|
24
|
+
class Str < Inline
|
28
25
|
|
29
|
-
|
30
|
-
|
31
|
-
|
26
|
+
# Create a new Str node based on the value
|
27
|
+
#
|
28
|
+
# @param value [String]
|
29
|
+
def initialize(value)
|
30
|
+
@string = value
|
31
|
+
end
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
# The AST contents
|
34
|
+
def ast_contents()
|
35
|
+
@string
|
36
|
+
end
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
38
|
+
# Has the Str node a string value? Of course!
|
39
|
+
#
|
40
|
+
# @return [Boolean] true
|
41
|
+
def has_string?()
|
42
|
+
true
|
43
|
+
end
|
44
|
+
|
45
|
+
# Has the Str node inline contents?
|
46
|
+
#
|
47
|
+
# @return [Boolean] false
|
48
|
+
def has_inline?()
|
49
|
+
false
|
50
|
+
end
|
51
|
+
end
|
40
52
|
end
|
41
|
-
end
|
42
53
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright 2015, 2016 Huub de Beer <Huub@heerdebeer.org>
|
2
|
+
# Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
|
3
3
|
#
|
4
4
|
# This file is part of Paru
|
5
5
|
#
|
@@ -17,12 +17,12 @@
|
|
17
17
|
# along with Paru. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#++
|
19
19
|
module Paru
|
20
|
-
|
21
|
-
|
20
|
+
module PandocFilter
|
21
|
+
require_relative "./inline"
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
# A Strikeout inline node
|
24
|
+
class Strikeout < Inline
|
25
|
+
end
|
25
26
|
end
|
26
|
-
end
|
27
27
|
end
|
28
28
|
|
data/lib/paru/filter/strong.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright 2015, 2016 Huub de Beer <Huub@heerdebeer.org>
|
2
|
+
# Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
|
3
3
|
#
|
4
4
|
# This file is part of Paru
|
5
5
|
#
|
@@ -17,12 +17,12 @@
|
|
17
17
|
# along with Paru. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#++
|
19
19
|
module Paru
|
20
|
-
|
21
|
-
|
20
|
+
module PandocFilter
|
21
|
+
require_relative "./inline"
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
# A Strong inline node
|
24
|
+
class Strong < Inline
|
25
|
+
end
|
25
26
|
end
|
26
|
-
end
|
27
27
|
end
|
28
28
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright 2015, 2016 Huub de Beer <Huub@heerdebeer.org>
|
2
|
+
# Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
|
3
3
|
#
|
4
4
|
# This file is part of Paru
|
5
5
|
#
|
@@ -17,12 +17,12 @@
|
|
17
17
|
# along with Paru. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#++
|
19
19
|
module Paru
|
20
|
-
|
21
|
-
|
20
|
+
module PandocFilter
|
21
|
+
require_relative "./inline"
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
# A Subscript inline node
|
24
|
+
class Subscript < Inline
|
25
|
+
end
|
25
26
|
end
|
26
|
-
end
|
27
27
|
end
|
28
28
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright 2015, 2016 Huub de Beer <Huub@heerdebeer.org>
|
2
|
+
# Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
|
3
3
|
#
|
4
4
|
# This file is part of Paru
|
5
5
|
#
|
@@ -17,12 +17,12 @@
|
|
17
17
|
# along with Paru. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#++
|
19
19
|
module Paru
|
20
|
-
|
21
|
-
|
20
|
+
module PandocFilter
|
21
|
+
require_relative "./inline"
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
# A Superscript inline node
|
24
|
+
class Superscript < Inline
|
25
|
+
end
|
25
26
|
end
|
26
|
-
end
|
27
27
|
end
|
28
28
|
|
data/lib/paru/filter/table.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright 2015, 2016 Huub de Beer <Huub@heerdebeer.org>
|
2
|
+
# Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
|
3
3
|
#
|
4
4
|
# This file is part of Paru
|
5
5
|
#
|
@@ -17,37 +17,59 @@
|
|
17
17
|
# along with Paru. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#++
|
19
19
|
module Paru
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
module PandocFilter
|
21
|
+
require_relative "./block"
|
22
|
+
require_relative "./inline"
|
23
|
+
|
24
|
+
# The allignment of a table column
|
25
|
+
ALIGNMENTS = ["AlignLeft", "AlignRight", "AlignCenter", "AlignDefault"]
|
24
26
|
|
25
|
-
|
27
|
+
# A Table node represents a table with an inline caption, column
|
28
|
+
# definition, widths, headers, and rows.
|
29
|
+
#
|
30
|
+
# @!attribute caption
|
31
|
+
# @return [Inline]
|
32
|
+
#
|
33
|
+
# @!attribute alignment
|
34
|
+
# @return [ALIGNMENTS]
|
35
|
+
#
|
36
|
+
# @!attribute column_widths
|
37
|
+
# @return [Float]
|
38
|
+
#
|
39
|
+
# @!attribute headers
|
40
|
+
# @return [TableRow]
|
41
|
+
#
|
42
|
+
# @!attribute rows
|
43
|
+
# @return [Array<TableRow>]
|
44
|
+
class Table < Block
|
45
|
+
attr_accessor :caption, :alignment, :column_widths, :headers, :rows
|
26
46
|
|
27
|
-
|
28
|
-
|
29
|
-
|
47
|
+
# Create a new Table based on the contents
|
48
|
+
#
|
49
|
+
# @param contents [Array]
|
50
|
+
def initialize(contents)
|
51
|
+
@caption = Inline.new contents[0]
|
52
|
+
@alignment = contents[1]
|
53
|
+
@column_widths = contents[2]
|
54
|
+
@headers = TableRow.new contents[3]
|
55
|
+
@rows = []
|
56
|
+
contents[4].each do |row_data|
|
57
|
+
@rows.push TableRow.new row_data
|
58
|
+
end
|
59
|
+
end
|
30
60
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
61
|
+
# The AST contents of this Table node
|
62
|
+
#
|
63
|
+
# @return [Array]
|
64
|
+
def ast_contents()
|
65
|
+
[
|
66
|
+
@caption.ast_contents,
|
67
|
+
@alignment,
|
68
|
+
@column_widths,
|
69
|
+
@headers.ast_contents,
|
70
|
+
@rows.map {|row| row.ast_contents}
|
71
|
+
]
|
72
|
+
end
|
39
73
|
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def ast_contents
|
43
|
-
[
|
44
|
-
@caption.ast_contents,
|
45
|
-
@alignment,
|
46
|
-
@column_widths,
|
47
|
-
@headers.ast_contents,
|
48
|
-
@rows.map {|row| row.ast_contents}
|
49
|
-
]
|
50
|
-
end
|
51
74
|
end
|
52
|
-
end
|
53
75
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright 2015, 2016 Huub de Beer <Huub@heerdebeer.org>
|
2
|
+
# Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
|
3
3
|
#
|
4
4
|
# This file is part of Paru
|
5
5
|
#
|
@@ -17,20 +17,27 @@
|
|
17
17
|
# along with Paru. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#++
|
19
19
|
module Paru
|
20
|
-
|
21
|
-
|
20
|
+
module PandocFilter
|
21
|
+
require_relative "./block"
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
23
|
+
# A TableRow node represents a row in a table's head or body
|
24
|
+
class TableRow < Block
|
25
|
+
# Create a new TableRow based on the row_data
|
26
|
+
#
|
27
|
+
# @param row_data [Array]
|
28
|
+
def initialize(row_data)
|
29
|
+
super []
|
30
|
+
row_data.each do |cell|
|
31
|
+
@children.push Block.new cell
|
32
|
+
end
|
33
|
+
end
|
30
34
|
|
31
|
-
|
32
|
-
|
33
|
-
|
35
|
+
# The AST contents of this TableRow
|
36
|
+
#
|
37
|
+
# @return [Array]
|
38
|
+
def ast_contents
|
39
|
+
@children.map {|child| child.ast_contents}
|
40
|
+
end
|
41
|
+
end
|
34
42
|
end
|
35
|
-
end
|
36
43
|
end
|
data/lib/paru/filter/target.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright 2015, 2016 Huub de Beer <Huub@heerdebeer.org>
|
2
|
+
# Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
|
3
3
|
#
|
4
4
|
# This file is part of Paru
|
5
5
|
#
|
@@ -17,21 +17,35 @@
|
|
17
17
|
# along with Paru. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#++
|
19
19
|
module Paru
|
20
|
-
|
20
|
+
module PandocFilter
|
21
|
+
|
22
|
+
# A Target represents the target of a link or image
|
23
|
+
#
|
24
|
+
# @!attribute url
|
25
|
+
# @return [String] the target
|
26
|
+
#
|
27
|
+
# @!attribute title
|
28
|
+
# @return [String] the title of the target
|
29
|
+
class Target
|
30
|
+
attr_accessor :url, :title
|
21
31
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
32
|
+
# Create a new Target based on the contents
|
33
|
+
#
|
34
|
+
# @param contents [Array]
|
35
|
+
def initialize(contents)
|
36
|
+
@url = contents[0]
|
37
|
+
@title = contents[1]
|
38
|
+
end
|
28
39
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
40
|
+
# Create an AST representation of this Target
|
41
|
+
#
|
42
|
+
# @return [Array]
|
43
|
+
def to_ast()
|
44
|
+
[
|
45
|
+
@url,
|
46
|
+
@title
|
47
|
+
]
|
48
|
+
end
|
49
|
+
end
|
35
50
|
end
|
36
|
-
end
|
37
51
|
end
|
data/lib/paru/filter/version.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright 2015, 2016 Huub de Beer <Huub@heerdebeer.org>
|
2
|
+
# Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
|
3
3
|
#
|
4
4
|
# This file is part of Paru
|
5
5
|
#
|
@@ -17,21 +17,30 @@
|
|
17
17
|
# along with Paru. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#++
|
19
19
|
module Paru
|
20
|
-
|
21
|
-
|
20
|
+
module PandocFilter
|
21
|
+
require_relative "./node"
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
23
|
+
# Version is a general Node containing the pandoc-api-version. It has
|
24
|
+
# the format major.minor.revision.sub
|
25
|
+
class Version < Node
|
27
26
|
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
# Create a Version node based on contents
|
28
|
+
#
|
29
|
+
# @param contents [Array<Integer>] a list with api, major, minor,
|
30
|
+
# revision number
|
31
|
+
def initialize(contents)
|
32
|
+
@api, @major, @minor, @revision = contents
|
33
|
+
end
|
31
34
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
+
# The AST type is "pandoc-api-version"
|
36
|
+
def ast_type
|
37
|
+
"pandoc-api-version"
|
38
|
+
end
|
39
|
+
|
40
|
+
# Create an AST representation of this Version
|
41
|
+
def to_ast()
|
42
|
+
[@api, @major, @minor, @revision]
|
43
|
+
end
|
44
|
+
end
|
35
45
|
end
|
36
|
-
end
|
37
46
|
end
|
data/lib/paru/pandoc.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright 2015, 2016 Huub de Beer <Huub@heerdebeer.org>
|
2
|
+
# Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
|
3
3
|
#
|
4
4
|
# This file is part of Paru
|
5
5
|
#
|
@@ -18,134 +18,188 @@
|
|
18
18
|
#++
|
19
19
|
module Paru
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
# Pandoc is a wrapper around the pandoc system. See
|
24
|
-
# <http://pandoc.org/README.html> for details about pandoc. This file is
|
25
|
-
# basically a straightforward translation from command line program to ruby
|
26
|
-
# class
|
27
|
-
|
28
|
-
class Pandoc
|
29
|
-
|
30
|
-
# Gather information about pandoc. It runs `pandoc --version` and extracts
|
31
|
-
# pandoc's version number and default data directory.
|
32
|
-
def self.info
|
33
|
-
output = ''
|
34
|
-
IO.popen('pandoc --version', 'r+') do |p|
|
35
|
-
p.close_write
|
36
|
-
output << p.read
|
37
|
-
end
|
38
|
-
version = output.match(/pandoc (\d+\.\d+.*)$/)[1]
|
39
|
-
data_dir = output.match(/Default user data directory: (.+)$/)[1]
|
40
|
-
|
41
|
-
{
|
42
|
-
:version => version,
|
43
|
-
:data_dir => data_dir
|
44
|
-
}
|
45
|
-
end
|
21
|
+
require "shellwords"
|
22
|
+
require "yaml"
|
46
23
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
24
|
+
# Pandoc is a wrapper around the pandoc document converter. See
|
25
|
+
# <http://pandoc.org/README.html> for details about pandoc. This file is
|
26
|
+
# basically a straightforward translation from the pandoc command line
|
27
|
+
# program to a ruby class, giving a Rubyesque API to work with pandoc.
|
28
|
+
#
|
29
|
+
# @example Convert the markdown string 'hello *world*' to HTML
|
30
|
+
# converter = Paru::Pandoc.new
|
31
|
+
# converter.configure do
|
32
|
+
# from "markdown"
|
33
|
+
# to "html"
|
34
|
+
# end
|
35
|
+
# converter.convert 'hello *world*'
|
36
|
+
#
|
37
|
+
# @example Convert markdown to HTML, written in a more commonly used shorthand
|
38
|
+
# Paru::Pandoc.new do
|
39
|
+
# from markdown
|
40
|
+
# to html
|
41
|
+
# end << 'hello *world*'
|
42
|
+
#
|
43
|
+
#
|
44
|
+
class Pandoc
|
45
|
+
|
46
|
+
# Gather information about pandoc. It runs `pandoc --version` and extracts
|
47
|
+
# pandoc's version number and default data directory.
|
48
|
+
#
|
49
|
+
# @return [Hash] Return a Hash with the :verion and :data_dir of the
|
50
|
+
# pandoc installation
|
51
|
+
def self.info()
|
52
|
+
output = ''
|
53
|
+
IO.popen('pandoc --version', 'r+') do |p|
|
54
|
+
p.close_write
|
55
|
+
output << p.read
|
56
|
+
end
|
57
|
+
version = output.match(/pandoc (\d+\.\d+.*)$/)[1]
|
58
|
+
data_dir = output.match(/Default user data directory: (.+)$/)[1]
|
59
|
+
|
60
|
+
{
|
61
|
+
:version => version,
|
62
|
+
:data_dir => data_dir
|
63
|
+
}
|
64
|
+
end
|
51
65
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
66
|
+
# Create a new Pandoc converter, optionally configured by block
|
67
|
+
#
|
68
|
+
# @param block [Proc] an optional configuration block. See #configure
|
69
|
+
# for how to configure a Pandoc converter
|
70
|
+
def initialize(&block)
|
71
|
+
@options = {}
|
72
|
+
configure(&block) if block_given?
|
73
|
+
end
|
56
74
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
75
|
+
# Configure this Pandoc converter with block. In the block you can
|
76
|
+
# call all pandoc options as methods on this converter. In multi-word
|
77
|
+
# options the dash (-) is replaced by an underscore (_)
|
78
|
+
#
|
79
|
+
# Pandoc has a number of command line options. Most are simple options,
|
80
|
+
# like flags, that can be set only once. Other options can occur more than
|
81
|
+
# once, such as the css option: to add more than one css file to a
|
82
|
+
# generated standalone html file, use the css options once for each
|
83
|
+
# stylesheet to include. Other options do have the pattern key[:value],
|
84
|
+
# which can also occur multiple times, such as metadata.
|
85
|
+
#
|
86
|
+
# All options are specified in a pandoc_options.yaml. If it is an option
|
87
|
+
# that can occur only once, the value of the option in that yaml file is
|
88
|
+
# its default value. If the option can occur multiple times, its value is
|
89
|
+
# an array with one value, the default value.
|
90
|
+
#
|
91
|
+
# @param block [Proc] the options to pandoc
|
92
|
+
# @return [Pandoc] this Pandoc converter
|
93
|
+
#
|
94
|
+
# @example Configure converting HTML to LaTeX with a LaTeX engine
|
95
|
+
# converter.configure do
|
96
|
+
# from 'html'
|
97
|
+
# to 'latex'
|
98
|
+
# latex_engine 'lualatex'
|
99
|
+
# end
|
100
|
+
#
|
101
|
+
def configure(&block)
|
102
|
+
instance_eval(&block)
|
103
|
+
self
|
104
|
+
end
|
69
105
|
|
70
|
-
|
71
|
-
|
72
|
-
|
106
|
+
# Converts input string to output string using the pandoc invocation
|
107
|
+
# configured in this Pandoc instance.
|
108
|
+
#
|
109
|
+
# @param input [String] the input string to convert
|
110
|
+
# @return [String] the converted output string
|
111
|
+
#
|
112
|
+
# The following two examples are the same:
|
113
|
+
#
|
114
|
+
# @example Using convert
|
115
|
+
# output = converter.convert 'this is a *strong* word'
|
116
|
+
#
|
117
|
+
# @example Using <<
|
118
|
+
# output = converter << 'this is a *strong* word'
|
119
|
+
def convert(input)
|
120
|
+
output = ''
|
121
|
+
IO.popen(to_command, 'r+') do |p|
|
122
|
+
p << input
|
123
|
+
p.close_write
|
124
|
+
output << p.read
|
125
|
+
end
|
126
|
+
output
|
127
|
+
end
|
128
|
+
alias << convert
|
129
|
+
|
130
|
+
# Create a string representation of this converter's pandoc command
|
131
|
+
# line invocation. This is useful for debugging purposes.
|
132
|
+
#
|
133
|
+
# @param option_sep [String] the string to separate options with
|
134
|
+
# @return [String] This converter's command line invocation string.
|
135
|
+
def to_command(option_sep = " \\\n\t")
|
136
|
+
"pandoc\t#{to_option_string option_sep}"
|
137
|
+
end
|
73
138
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
139
|
+
private
|
140
|
+
|
141
|
+
def to_option_string(option_sep)
|
142
|
+
options_arr = []
|
143
|
+
@options.each do |option, value|
|
144
|
+
option_string = "--#{option.to_s.gsub '_', '-'}"
|
145
|
+
|
146
|
+
case value
|
147
|
+
when TrueClass then
|
148
|
+
# Flags don't have a value, only its name
|
149
|
+
# For example: --standalone
|
150
|
+
options_arr.push "#{option_string}"
|
151
|
+
when FalseClass then
|
152
|
+
# Skip this option; consider a flag with value false as unset
|
153
|
+
when Array then
|
154
|
+
# This option can occur multiple times: list each with its value.
|
155
|
+
# For example: --css=main.css --css=print.css
|
156
|
+
options_arr.push value.map {|val| "#{option_string}=#{val.to_s.shellescape}"}.join(option_sep)
|
157
|
+
else
|
158
|
+
# All options that aren't flags and can occur only once have the
|
159
|
+
# same pattern: --option=value
|
160
|
+
options_arr.push "#{option_string}=#{value.to_s.shellescape}"
|
161
|
+
end
|
162
|
+
end
|
163
|
+
options_arr.join(option_sep)
|
94
164
|
end
|
95
|
-
end
|
96
|
-
options_arr.join(option_sep)
|
97
|
-
end
|
98
165
|
|
99
|
-
|
100
|
-
|
101
|
-
# once, such as the css option: to add more than one css file to a
|
102
|
-
# generated standalone html file, use the css options once for each
|
103
|
-
# stylesheet to include. Other options do have the pattern key[:value],
|
104
|
-
# which can also occur multiple times, such as metadata.
|
105
|
-
#
|
106
|
-
# All options are specified in a pandoc_options.yaml. If it is an option
|
107
|
-
# that can occur only once, the value of the option in that yaml file is
|
108
|
-
# its default value. If the option can occur multiple times, its value is
|
109
|
-
# an array with one value, the default value.
|
110
|
-
#
|
111
|
-
# For each of these options a method is defined as follows:
|
112
|
-
OPTIONS = YAML.load_file File.join(__dir__, "pandoc_options.yaml")
|
166
|
+
# For each pandoc command line option a method is defined as follows:
|
167
|
+
OPTIONS = YAML.load_file File.join(__dir__, 'pandoc_options.yaml')
|
113
168
|
|
114
|
-
|
115
|
-
|
169
|
+
OPTIONS.keys.each do |option|
|
170
|
+
if OPTIONS[option].is_a? Array then
|
116
171
|
|
117
|
-
|
118
|
-
|
172
|
+
# option can be set multiple times, for example adding multiple css
|
173
|
+
# files
|
119
174
|
|
120
|
-
|
175
|
+
default = OPTIONS[option][0]
|
121
176
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
177
|
+
define_method(option) do |value = default|
|
178
|
+
if @options[option].nil? then
|
179
|
+
@options[option] = []
|
180
|
+
end
|
126
181
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
182
|
+
if value.is_a? Array then
|
183
|
+
@options[option] += value
|
184
|
+
else
|
185
|
+
@options[option].push value
|
186
|
+
end
|
132
187
|
|
133
|
-
|
134
|
-
|
188
|
+
self
|
189
|
+
end
|
135
190
|
|
136
|
-
|
191
|
+
else
|
192
|
+
# option can be set only once, for example a flag or a template
|
137
193
|
|
138
|
-
|
194
|
+
default = OPTIONS[option]
|
195
|
+
define_method(option) do |value = default|
|
196
|
+
@options[option] = value
|
197
|
+
self
|
198
|
+
end
|
139
199
|
|
140
|
-
|
141
|
-
define_method(option) do |value = default|
|
142
|
-
@options[option] = value
|
143
|
-
self
|
200
|
+
end
|
144
201
|
end
|
145
202
|
|
146
|
-
end
|
147
203
|
end
|
148
204
|
|
149
|
-
end
|
150
|
-
|
151
205
|
end
|