paru 0.4.0 → 0.4.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6bd7fc4981bbeea705d0508b939feff4a5d25db290ece4d07f55079286af2bfd
4
- data.tar.gz: cce99e0d42ba67d9b96904a75bd94f879b22dd52a5ac0709672640d72ecd99b5
3
+ metadata.gz: cd33d3d1738034e8ffeb4edcf0430d51f8f0dc05f23511535a4ba3e33c923d23
4
+ data.tar.gz: c430452f484459c451088ad84db7b603748ed67b3397250c6ad0e1c1773fb89d
5
5
  SHA512:
6
- metadata.gz: bb519fe72d960fd0802aea39cbe049471838c69f72edd8fc471af0c7e928da005e0562668146f4c058551fa79d243e02b73018aa2aeceb7a838c42bb5f8335f2
7
- data.tar.gz: 44cacdd22f7159c69c6ab0eec5960a04f3ec223806451075b78be0921749512bff799d8a0262a63edc6b944186f778e9d3c0549b967b7870b95fab2b460cdab5
6
+ metadata.gz: 89f884fd65ffa81c1be750c5d5ad82d96805c81cfedd3d52c9481e817f9d3cdc47d4a4c79f8d396264d18e9ac4d5dc574e7e5a720ce288a38441eefbc32649e7
7
+ data.tar.gz: 3c12fd5b577195595dec08a398a01dcec4d1297b41a97768fa3077b13c224a385aa0eec624275b98c2db5a938a12efccdc6cfc984f968331ddaf1b6b98c9bf48
@@ -16,7 +16,7 @@ parser = OptionParser.new do |opts|
16
16
  end
17
17
 
18
18
  opts.on("-v", "--version", "Show version") do
19
- puts "do-pandoc.rb is part of paru version 0.2.3"
19
+ puts "do-pandoc.rb is part of paru version 0.4.1"
20
20
  exit
21
21
  end
22
22
  end
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright 2015, 2016, 2017, 2018, 2019 Huub de Beer <Huub@heerdebeer.org>
2
+ # Copyright 2015, 2016, 2017, 2018, 2019, 2020 Huub de Beer <Huub@heerdebeer.org>
3
3
  #
4
4
  # This file is part of Paru
5
5
  #
@@ -18,5 +18,5 @@
18
18
  #++
19
19
  module Paru
20
20
  # Paru's current version
21
- VERSION = [0, 4, 0, 0]
21
+ VERSION = [0, 4, 1, 2]
22
22
  end
@@ -39,6 +39,12 @@ module Paru
39
39
  "Header",
40
40
  "HorizontalRule",
41
41
  "Table",
42
+ "TableHead",
43
+ "TableFoot",
44
+ "TableBody",
45
+ "Row",
46
+ "Cell",
47
+ "Caption",
42
48
  "Div",
43
49
  "Null"
44
50
  ]
@@ -47,6 +53,7 @@ module Paru
47
53
  PANDOC_INLINE = [
48
54
  "Str",
49
55
  "Emph",
56
+ "Underline",
50
57
  "Strong",
51
58
  "Strikeout",
52
59
  "Superscript",
@@ -0,0 +1,65 @@
1
+ #--
2
+ # Copyright 2020 Huub de Beer <Huub@heerdebeer.org>
3
+ #
4
+ # This file is part of Paru
5
+ #
6
+ # Paru is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Paru is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+ require_relative "./block.rb"
20
+ require_relative "./short_caption.rb"
21
+
22
+ module Paru
23
+ module PandocFilter
24
+ # A table's caption, can contain an optional short caption
25
+ class Caption < Block
26
+ attr_accessor :short
27
+
28
+ # Create a new Caption based on the contents
29
+ #
30
+ # @param contents [Array]
31
+ def initialize(contents)
32
+ if contents[0].nil?
33
+ @short = nil
34
+ else
35
+ @short = ShortCaption.new contents[0]
36
+ end
37
+ super(contents[1])
38
+ end
39
+
40
+ # Does this Caption have a short caption?
41
+ #
42
+ # @return [Boolean]
43
+ def has_short?()
44
+ not @short.nil?
45
+ end
46
+
47
+ # Has this node a block?
48
+ #
49
+ # @return [Boolean] true
50
+ def has_block?
51
+ true
52
+ end
53
+
54
+ # The AST contents of this Caption node
55
+ #
56
+ # @return [Array]
57
+ def ast_contents()
58
+ [
59
+ if has_short? then @short.to_ast else nil end,
60
+ @children.map {|row| row.to_ast}
61
+ ]
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,67 @@
1
+ #--
2
+ # Copyright 2020 Huub de Beer <Huub@heerdebeer.org>
3
+ #
4
+ # This file is part of Paru
5
+ #
6
+ # Paru is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Paru is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+ require_relative "./block.rb"
20
+ require_relative "./value.rb"
21
+
22
+ module Paru
23
+ module PandocFilter
24
+ # A Cell node represents a cell in a table's head, body, or foot
25
+ #
26
+ # @!attribute attr
27
+ # @return Attr
28
+ #
29
+ # @!attribute alignment
30
+ # @return Value containing a String, one of AlignRight, AlignLeft,
31
+ # AlignCenter, or AlignDefault.
32
+ #
33
+ # @!attribute rowspan
34
+ # @return Value containing an Integer
35
+ #
36
+ # @!attribute colspan
37
+ # @return Value containing an Integer
38
+ class Cell < Block
39
+ attr_accessor :attr, :alignment, :rowspan, :colspan
40
+
41
+ # Create a new Cell based on the row_data
42
+ #
43
+ # @param contents [Array]
44
+ def initialize(contents)
45
+ @attr = Attr.new contents[0]
46
+ @alignment = Value.new contents[1]
47
+ @rowspan = Value.new contents[2]
48
+ @colspan = Value.new contents[3]
49
+
50
+ super contents[4]
51
+ end
52
+
53
+ # The AST contents of this Cell
54
+ #
55
+ # @return [Array]
56
+ def ast_contents
57
+ [
58
+ @attr.to_ast,
59
+ @alignment.to_ast,
60
+ @rowspan.to_ast,
61
+ @colspan.to_ast,
62
+ @children.map {|child| child.to_ast}
63
+ ]
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,84 @@
1
+ #--
2
+ # Copyright 2020 Huub de Beer <Huub@heerdebeer.org>
3
+ #
4
+ # This file is part of Paru
5
+ #
6
+ # Paru is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Paru is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+ require_relative "./value.rb"
20
+
21
+ module Paru
22
+ module PandocFilter
23
+ # The allignment of a table column
24
+ ALIGNMENTS = ["AlignLeft", "AlignRight", "AlignCenter", "AlignDefault"]
25
+
26
+ # The default width of a column
27
+ COL_WIDTH_DEFAULT = "ColWidthDefault"
28
+
29
+ # Default value for a column specification: left aligned with default
30
+ # width
31
+ DEFAULT_COLSPEC = [{"t": "AlignLeft"}, {"t": COL_WIDTH_DEFAULT}]
32
+
33
+ # ColSpec represents a colspec definition for a table column. It contains an alignment and the column's width.
34
+ #
35
+ # @see https://hackage.haskell.org/package/pandoc-types-1.21/docs/Text-Pandoc-Definition.html#t:ColSpec
36
+ #
37
+ # @!attribute alignment
38
+ # @return [String]
39
+ #
40
+ # @!attribute width
41
+ # @return [Double|COL_WIDTH_DEFAULT]
42
+ class ColSpec
43
+ attr_accessor :alignment, :width
44
+
45
+ # Create a new ColSpec object
46
+ #
47
+ # @param contents [Array = DEFAULT_COLSPEC] the attributes as a pair of [alignment, width]
48
+ def initialize(contents = DEFAULT_COLSPEC)
49
+ @alignment = Value.new contents[0]
50
+ @width = Value.new contents[1]
51
+ end
52
+
53
+ # Set the width
54
+ #
55
+ # @param [String|Integer|Float] new_width the new width. If it is
56
+ # "ColWidthDefault", it uses the default value.
57
+ def width=(new_width)
58
+ if new_width == "ColWidthDefault" then
59
+ @width = Value.new({"t": new_width})
60
+ else
61
+ @width = Value.new({"t": "ColWidth", "c": new_width})
62
+ end
63
+ end
64
+
65
+ # Set the alignment
66
+ #
67
+ # @param [String] new_alignment the new alignment.
68
+ def alignment=(new_alignment)
69
+ @alignment.value = new_alignment
70
+ end
71
+
72
+ # Convert this attributes object to an AST representation
73
+ #
74
+ # @return [Array] Array containing id, class name list, and
75
+ # key-value pair list
76
+ def to_ast
77
+ [
78
+ @alignment.to_ast,
79
+ @width.to_ast
80
+ ]
81
+ end
82
+ end
83
+ end
84
+ end
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
2
+ # Copyright 2015, 2016, 2017, 2020 Huub de Beer <Huub@heerdebeer.org>
3
3
  #
4
4
  # This file is part of Paru
5
5
  #
@@ -36,7 +36,7 @@ module Paru
36
36
 
37
37
  # The current pandoc type version
38
38
  # @see https://hackage.haskell.org/package/pandoc-types
39
- CURRENT_PANDOC_VERSION = [1, 20]
39
+ CURRENT_PANDOC_VERSION = [1, 21]
40
40
 
41
41
  # Each file that is being filtered by pandoc is represented by a root
42
42
  # Document. It is the root node of the AST of the document in the file.
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
2
+ # Copyright 2015, 2016, 2017, 2020 Huub de Beer <Huub@heerdebeer.org>
3
3
  #
4
4
  # This file is part of Paru
5
5
  #
@@ -17,7 +17,6 @@
17
17
  # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
18
  #++
19
19
  require_relative "../pandoc.rb"
20
-
21
20
  require_relative './ast_manipulation.rb'
22
21
 
23
22
  module Paru
@@ -26,12 +25,12 @@ module Paru
26
25
  # A Paru::Pandoc converter from JSON to markdown
27
26
  AST2MARKDOWN = Paru::Pandoc.new do
28
27
  from "json"
29
- to "markdown"
28
+ to "markdown-smart"
30
29
  end
31
30
 
32
31
  # A Paru::Pandoc converter from markdown to JSON
33
32
  MARKDOWN2JSON = Paru::Pandoc.new do
34
- from "markdown"
33
+ from "markdown+smart"
35
34
  to "json"
36
35
  end
37
36
 
@@ -64,7 +63,11 @@ module Paru
64
63
  require_relative './plain.rb'
65
64
  require_relative './raw_block.rb'
66
65
  require_relative './table.rb'
67
- require_relative './table_row.rb'
66
+ require_relative './caption.rb'
67
+ require_relative './table_head.rb'
68
+ require_relative './table_foot.rb'
69
+ require_relative './row.rb'
70
+ require_relative './cell.rb'
68
71
 
69
72
  # Inline level nodes
70
73
  require_relative './cite.rb'
@@ -88,6 +91,8 @@ module Paru
88
91
  require_relative './str.rb'
89
92
  require_relative './subscript.rb'
90
93
  require_relative './superscript.rb'
94
+ require_relative './short_caption.rb'
95
+ require_relative './underline.rb'
91
96
 
92
97
  # Metadata level nodes
93
98
  require_relative './meta_blocks.rb'
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
2
+ # Copyright 2015, 2016, 2017, 2020 Huub de Beer <Huub@heerdebeer.org>
3
3
  #
4
4
  # This file is part of Paru
5
5
  #
@@ -17,32 +17,51 @@
17
17
  # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
18
  #++
19
19
  require_relative "./block.rb"
20
+ require_relative "./cell.rb"
20
21
 
21
22
  module Paru
22
23
  module PandocFilter
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
24
+
25
+ # A Row node represents a row in a table's head or body
26
+ #
27
+ # @!attribute attr
28
+ # @return Attr
29
+ #
30
+ # @!attribute cells
31
+ # @return [Block]
32
+ class Row < Block
33
+ attr_accessor :attr
34
+
35
+ # Create a new Row based on the row_data
26
36
  #
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
37
+ # @param contents [Array = []] the contents of
38
+ # this Row node
39
+ def initialize(contents = [])
40
+ @attr = Attr.new contents[0]
41
+ super contents[1]
42
+ end
43
+
44
+ # The cells of this row
45
+ #
46
+ # @return [Array<Cell>]
47
+ def cells()
48
+ @children
33
49
  end
34
50
 
35
- # The AST contents of this TableRow
51
+ # The AST contents of this Row
36
52
  #
37
53
  # @return [Array]
38
54
  def ast_contents
39
- @children.map {|child| child.ast_contents}
55
+ [
56
+ @attr.to_ast,
57
+ @children.map {|child| child.to_ast}
58
+ ]
40
59
  end
41
60
 
42
- # Convert this TableRow to an array of markdown strings, one for
61
+ # Convert this Row to an array of markdown strings, one for
43
62
  # each cell
44
63
  #
45
- # @return [String[]] An Array representation of this TableRow.
64
+ # @return [String[]] An Array representation of this Row.
46
65
  def to_array()
47
66
  @children.map do |cell|
48
67
  cell.children.map{|c| c.markdown.strip}.join("\n")
@@ -0,0 +1,27 @@
1
+ #--
2
+ # Copyright 2020 Huub de Beer <Huub@heerdebeer.org>
3
+ #
4
+ # This file is part of Paru
5
+ #
6
+ # Paru is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Paru is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+ require_relative "./inline.rb"
20
+
21
+ module Paru
22
+ module PandocFilter
23
+ # A ShortCaption used in a table's caption.
24
+ class ShortCaption < Inline
25
+ end
26
+ end
27
+ end
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
2
+ # Copyright 2015, 2016, 2017, 2020 Huub de Beer <Huub@heerdebeer.org>
3
3
  #
4
4
  # This file is part of Paru
5
5
  #
@@ -19,44 +19,46 @@
19
19
  require "csv"
20
20
  require_relative "./block.rb"
21
21
  require_relative "./inline.rb"
22
+ require_relative "./caption.rb"
23
+ require_relative "./col_spec.rb"
24
+ require_relative "./row.rb"
25
+ require_relative "./table_head.rb"
26
+ require_relative "./table_foot.rb"
27
+ require_relative "./table_body.rb"
22
28
 
23
29
  module Paru
24
30
  module PandocFilter
25
- # The allignment of a table column
26
- ALIGNMENTS = ["AlignLeft", "AlignRight", "AlignCenter", "AlignDefault"]
27
31
 
28
32
  # A Table node represents a table with an inline caption, column
29
33
  # definition, widths, headers, and rows.
30
34
  #
31
35
  # @!attribute caption
32
- # @return [Inline]
36
+ # @return Caption
37
+ #
38
+ # @!attribute attr
39
+ # @return Attr
33
40
  #
34
- # @!attribute alignment
35
- # @return [ALIGNMENTS]
41
+ # @!attribute colspec
42
+ # @return [ColSpec]
36
43
  #
37
- # @!attribute column_widths
38
- # @return [Float]
39
- #
40
- # @!attribute headers
41
- # @return [TableRow]
42
- #
43
- # @!attribute rows
44
- # @return [Array<TableRow>]
44
+ # @!attribute head
45
+ # @return [TableHead]
46
+ #
47
+ # @!attribute foot
48
+ # @return [TableHead]
45
49
  class Table < Block
46
- attr_accessor :caption, :alignment, :column_widths, :headers, :rows
50
+ attr_accessor :caption, :attr, :colspec, :head, :foot
47
51
 
48
52
  # Create a new Table based on the contents
49
53
  #
50
54
  # @param contents [Array]
51
55
  def initialize(contents)
52
- @caption = Inline.new contents[0]
53
- @alignment = contents[1]
54
- @column_widths = contents[2]
55
- @headers = TableRow.new contents[3]
56
- @children = []
57
- contents[4].each do |row_data|
58
- @children.push TableRow.new row_data
59
- end
56
+ @attr = Attr.new contents[0]
57
+ @caption = Caption.new contents[1]["c"]
58
+ @colspec = contents[2].map {|p| ColSpec.new p}
59
+ @head = TableHead.new contents[3]["c"]
60
+ super contents[4]
61
+ @foot = TableFoot.new contents[5]["c"]
60
62
  end
61
63
 
62
64
  # The AST contents of this Table node
@@ -64,11 +66,12 @@ module Paru
64
66
  # @return [Array]
65
67
  def ast_contents()
66
68
  [
67
- @caption.ast_contents,
68
- @alignment,
69
- @column_widths,
70
- @headers.ast_contents,
71
- @children.map {|row| row.ast_contents}
69
+ @attr.to_ast,
70
+ @caption.to_ast,
71
+ @colspec.map {|c| c.to_ast},
72
+ @head.to_ast,
73
+ @children.map {|c| c.to_ast},
74
+ @foot.to_ast,
72
75
  ]
73
76
  end
74
77
 
@@ -82,14 +85,19 @@ module Paru
82
85
  # represented by their markdown strings.
83
86
  def to_array(**config)
84
87
  headers = if config.has_key? :headers then config[:headers] else false end
88
+ footers = if config.has_key? :footers then config[:footers] else false end
85
89
 
86
90
  data = []
87
91
  if headers then
88
- data.push @headers.to_array
92
+ data.concat @head.to_array
89
93
  end
90
94
 
91
95
  @children.each do |row|
92
- data.push row.to_array
96
+ data.concat row.to_array
97
+ end
98
+
99
+ if footers then
100
+ data.concat @foot.to_array
93
101
  end
94
102
 
95
103
  data
@@ -113,53 +121,53 @@ module Paru
113
121
  # @param config [Hash] configuration of the list.
114
122
  # properties:
115
123
  # :headers [Boolean] True if data includes headers on first
116
- # row
124
+ # row. Defailts to false.
117
125
  # :caption [String] The table's caption
118
- # :alignment [String[]] An array with alignments for each
119
- # column. Should have an alignment for all columns. Defaults
120
- # to "AlignLeft"
121
- # :widhts [Number[]] An array with column widths. Should have
122
- # a width for all columns. Use 0 for no set width. Defaults to
123
- # 0
126
+ # :footers [Boolean] True if data includes footers on last row,
127
+ # default to false.
124
128
  #
125
129
  # @return [Table]
126
130
  def self.from_array(data, **config)
127
- return Table.new [[],[],[],[],[]] if data.empty?
128
-
129
- headers = if config.has_key? :headers then
130
- config[:headers]
131
- else
132
- false
133
- end
134
- caption = if config.has_key? :caption then
135
- Block.from_markdown(config[:caption]).ast_contents
136
- else
137
- []
138
- end
139
-
140
- alignment = if config.has_key? :alignment then
141
- config[:alignment].map {|a| {"t" => "#{a}"}}
142
- else
143
- data.first.map {|_| {"t"=>"AlignLeft"}}
144
- end
145
-
146
- widths = if config.has_key? :widths then
147
- config[:widths]
148
- else
149
- data.first.map {|_| 0}
150
- end
151
-
152
- header = []
153
- rows = data
154
- if headers then
155
- header = data.first
156
- header = header.map {|cell| [Block.from_markdown(cell).to_ast]}
157
- rows = data.slice(1..-1)
131
+ # With the updated Table definition, it has become complicated
132
+ # to construct a table manually. It has gotten easier to just
133
+ # construct a string containing a table in Pandoc's markdown and
134
+ # load that. I did remove setting alignments and column widths,
135
+ # though, because that is a bit of a hassle to get right.
136
+
137
+ markdown_table = ""
138
+ header = ""
139
+ footer = ""
140
+
141
+ if config.has_key? :headers and config[:headers] then
142
+ head_row = data.first
143
+ header += head_row.join(" \t") + "\n"
144
+ header += head_row.map {|s| s.gsub(/./, "-") + "-"}.join("\t") + "\n"
145
+ data = data.slice(1..-1)
158
146
  end
159
-
160
- rows = rows.map {|row| row.map {|cell| [Block.from_markdown(cell).to_ast]}}
161
147
 
162
- Table.new [caption, alignment, widths, header, rows]
148
+ if config.has_key? :footers and config[:footers] then
149
+ foot_row = data.first
150
+ footer += foot_row.join(" \t") + "\n"
151
+ footer += foot_row.map {|s| s.gsub(/./, "-") + "-"}.join("\t") + "\n"
152
+ data = data.slice(0, -2)
153
+ end
154
+
155
+ data.each do |row|
156
+ markdown_table += row.join(" \t") + "\n"
157
+ end
158
+
159
+ markdown_table = header + markdown_table + footer
160
+
161
+ if config.has_key? :caption then
162
+ markdown_table += "\n"
163
+ markdown_table += ": #{config[:caption]}\n"
164
+ end
165
+
166
+ table = Block.new []
167
+ table.markdown = markdown_table
168
+ table = table.children.first
169
+
170
+ table
163
171
  end
164
172
 
165
173
 
@@ -0,0 +1,87 @@
1
+ #--
2
+ # Copyright 2015, 2016, 2017, 2020 Huub de Beer <Huub@heerdebeer.org>
3
+ #
4
+ # This file is part of Paru
5
+ #
6
+ # Paru is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Paru is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+ require_relative "./block.rb"
20
+ require_relative "./row.rb"
21
+ require_relative "./value.rb"
22
+
23
+ module Paru
24
+ module PandocFilter
25
+ # A TableBody node represents a row in a table's head or body
26
+ #
27
+ # @!attribute attr
28
+ # @return Attr
29
+ #
30
+ # @!attribute rowheadcolumns
31
+ # @return Value containing an Integer indicating the number of head
32
+ # columns.
33
+ #
34
+ # @!attribute rowheadercolums
35
+ # @return [Row]
36
+ #
37
+ # @!attribute rows
38
+ # @return [Row]
39
+ class TableBody < Block
40
+ attr_accessor :attr, :rowheadcolumnspec, :rowheadercolumns
41
+
42
+ # Create a new TableBody
43
+ #
44
+ # @param contents [Array] The contents of this TableBody
45
+ def initialize(contents)
46
+ @attr = Attr.new contents[0]
47
+ @rowheadcolumns = Value.new contents[1]
48
+ @rowheadercolumns = contents[2].map {|r| Row.new r}
49
+
50
+ super []
51
+ contents[3].each do |row|
52
+ @children.push Row.new row["c"]
53
+ end
54
+ end
55
+
56
+ # The rows in this TableBody
57
+ #
58
+ # @return [Array<Row>]
59
+ def rows()
60
+ @children
61
+ end
62
+
63
+ # The AST contents of this TableBody
64
+ #
65
+ # @return [Array]
66
+ def ast_contents
67
+ [
68
+ @attr.to_ast,
69
+ @rowheadcolumns.to_ast,
70
+ @rowheadercolumns.map {|r| r.to_ast},
71
+ @children.map {|child| child.to_ast}
72
+ ]
73
+ end
74
+
75
+ # Convert this table end to a 2D table of markdown strings for each
76
+ # cell
77
+ #
78
+ # @return [String[][]] This Table as a 2D array of cells
79
+ # represented by their markdown strings.
80
+ def to_array()
81
+ @children.map do |row|
82
+ row.to_array
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,71 @@
1
+ #--
2
+ # Copyright 2020 Huub de Beer <Huub@heerdebeer.org>
3
+ #
4
+ # This file is part of Paru
5
+ #
6
+ # Paru is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Paru is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+ require "csv"
20
+ require_relative "./block.rb"
21
+
22
+ module Paru
23
+ module PandocFilter
24
+
25
+ # A TableEnd node is the base class for the TableHead and TableFoot
26
+ # nodes. It has attributes and one or more rows.
27
+ #
28
+ # @!attribute attr
29
+ # @return Attr
30
+ #
31
+ # @!attribute rows
32
+ # @return [Row]
33
+ class TableEnd < Block
34
+ attr_accessor :attr
35
+
36
+ # Create a new TableEnd based on the contents
37
+ #
38
+ # @param contents [Array]
39
+ def initialize(contents)
40
+ @attr = Attr.new contents[0]
41
+ super contents[1]
42
+ end
43
+
44
+ def rows()
45
+ @children
46
+ end
47
+
48
+ # The AST contents of this Table node
49
+ #
50
+ # @return [Array]
51
+ def ast_contents()
52
+ [
53
+ @attr.to_ast,
54
+ @children.map {|row| row.to_ast},
55
+ ]
56
+ end
57
+
58
+ # Convert this table end to a 2D table of markdown strings for each
59
+ # cell
60
+ #
61
+ # @return [String[][]] This Table as a 2D array of cells
62
+ # represented by their markdown strings.
63
+ def to_array()
64
+ @children.map do |row|
65
+ row.to_array
66
+ end
67
+ end
68
+
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,28 @@
1
+ #--
2
+ # Copyright 2020 Huub de Beer <Huub@heerdebeer.org>
3
+ #
4
+ # This file is part of Paru
5
+ #
6
+ # Paru is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Paru is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+ require_relative "./table_end.rb"
20
+
21
+ module Paru
22
+ module PandocFilter
23
+
24
+ # A TableFoot node represents the heading of a table.
25
+ class TableFoot < TableEnd
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ #--
2
+ # Copyright 2020 Huub de Beer <Huub@heerdebeer.org>
3
+ #
4
+ # This file is part of Paru
5
+ #
6
+ # Paru is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Paru is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+ require_relative "./table_end.rb"
20
+
21
+ module Paru
22
+ module PandocFilter
23
+
24
+ # A TableHead node represents the heading of a table.
25
+ class TableHead < TableEnd
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,27 @@
1
+ #--
2
+ # Copyright 2020 Huub de Beer <Huub@heerdebeer.org>
3
+ #
4
+ # This file is part of Paru
5
+ #
6
+ # Paru is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Paru is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+ require_relative "./inline.rb"
20
+
21
+ module Paru
22
+ module PandocFilter
23
+ # A Underline inline node
24
+ class Underline < Inline
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,108 @@
1
+ #--
2
+ # Copyright 2020 Huub de Beer <Huub@heerdebeer.org>
3
+ #
4
+ # This file is part of Paru
5
+ #
6
+ # Paru is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Paru is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+ require_relative "./node.rb"
20
+ require_relative "../filter_error.rb"
21
+
22
+ module Paru
23
+ module PandocFilter
24
+
25
+ # Values without value are encoded in their type name.
26
+ VALUE_ENCODED_IN_TYPE_NAME = :value_encoded_in_type_name
27
+
28
+ # A Value node that represents some sort of metadata about block or
29
+ # inline nodes
30
+ class Value < Node
31
+
32
+ # Create a new Value with contents. Also indicate if this node has
33
+ # inline children or block children.
34
+ #
35
+ # @param contents [Array<pandoc node in JSON> = []] the contents of
36
+ # this node
37
+ def initialize(contents)
38
+ @type = contents["t"]
39
+
40
+ if contents.has_key? "c" then
41
+ @value = contents["c"]
42
+ else
43
+ @value = VALUE_ENCODED_IN_TYPE_NAME
44
+ end
45
+ end
46
+
47
+ # Get the encoded value
48
+ #
49
+ # @return [Any]
50
+ def value()
51
+ if type_encodes_value? then
52
+ @type
53
+ else
54
+ @value
55
+ end
56
+ end
57
+
58
+ # Set the encoded value
59
+ #
60
+ # @param [Any] new_value
61
+ def value=(new_value)
62
+ if type_encodes_value? then
63
+ @type = new_value
64
+ else
65
+ @value = new_value
66
+ end
67
+ end
68
+
69
+ # Is this node a block?
70
+ #
71
+ # @return [Boolean] false
72
+ def is_block?
73
+ false
74
+ end
75
+
76
+ # Is this node an inline node?
77
+ #
78
+ # @return [Boolean] false
79
+ def is_inline?
80
+ false
81
+ end
82
+
83
+ # The AST type of this Node
84
+ #
85
+ # @return [String]
86
+ def ast_type()
87
+ @type
88
+ end
89
+
90
+
91
+
92
+ # Create an AST representation of this Node
93
+ #
94
+ # @return [Hash]
95
+ def to_ast()
96
+ return {
97
+ "t" => ast_type,
98
+ "c" => if type_encodes_value? then nil else @value end
99
+ }
100
+ end
101
+
102
+ @private
103
+ def type_encodes_value?()
104
+ return @value == VALUE_ENCODED_IN_TYPE_NAME
105
+ end
106
+ end
107
+ end
108
+ end
@@ -92,8 +92,8 @@ module Paru
92
92
  # directory. This method is typically used in scripts that use Paru to
93
93
  # automate the use of pandoc.
94
94
  #
95
- # @return [Hash{:version => String, :data_dir => String}] Pandoc's
96
- # version, such as "1.17.0.4" and the data directory, such as "/home/huub/.pandoc".
95
+ # @return [Hash{:version => Array<Integer>, :data_dir => String}] Pandoc's
96
+ # version, such as "[2.10.1]" and the data directory, such as "/home/huub/.pandoc".
97
97
  def self.info()
98
98
  @@info
99
99
  end
@@ -226,9 +226,13 @@ module Paru
226
226
  throw Error.new "Unable to run pandoc via command '#{@@pandoc_exec} --version': #{err.message}"
227
227
  end
228
228
 
229
- version = version_string.match(/pandoc.* (\d+\.\d+.*)$/)[1]
229
+ version = version_string
230
+ .match(/pandoc.* (\d+\.\d+.*)$/)[1]
231
+ .split(".")
232
+ .map {|s| s.to_i}
233
+ major_version, minor_version = version
230
234
 
231
- if "2.7" <= version then
235
+ if major_version >= 2 and minor_version >= 7 then
232
236
  # Pandoc version 2.7 introduced a new default data dir to comply
233
237
  # with XDG Base Directory Specification
234
238
  xdg_data_dir, old_data_dir = version_string.match(/Default user data directory: (.+)$/)[1].split(" or ")
@@ -254,8 +258,6 @@ module Paru
254
258
  }
255
259
 
256
260
  # Load the options for the appropriate major version of pandoc
257
- major_version = @@info[:version].split(".").first.to_i
258
-
259
261
  if not [1, 2].include? major_version
260
262
  throw Error.new "Unknown major pandoc version: '#{major_version}'. Expected the major version to be '1' or '2'. Please check the pandoc path: '#{@@pandoc_exec}'."
261
263
  # defaults to version 1
@@ -50,7 +50,7 @@ file_scope: true
50
50
  filter: [""]
51
51
  lua_filter: [""]
52
52
  metadata: [""]
53
- metadata-file: [""]
53
+ metadata_file: [""]
54
54
  preserve_tabs: true
55
55
  tab_stop: 4
56
56
  track_changes: "accept"
@@ -68,20 +68,21 @@ eol: "native"
68
68
  dpi: 96
69
69
  wrap: "auto"
70
70
  columns: 78
71
- strip-comments: true
71
+ strip_comments: true
72
72
  toc: true
73
73
  table_of_contents: true
74
74
  toc_depth: 3
75
75
  strip_comments: true
76
76
  no_highlight: true
77
77
  highlight_style: ""
78
- print-highlight-style: ""
78
+ print_highlight_style: ""
79
79
  syntax_definition: ""
80
80
  include_in_header: [""]
81
81
  include_before_body: [""]
82
82
  include_after_body: [""]
83
83
  resource_path: ""
84
84
  request_header: ""
85
+ no_check_certificate: false
85
86
  #####
86
87
  # Options affecting specific writers
87
88
  #####
@@ -109,7 +110,7 @@ epub_metadata: ""
109
110
  epub_embed_font: ""
110
111
  epub_chapter_level: 1
111
112
  epub_subdirectory: ""
112
- ipynb-output: "best"
113
+ ipynb_output: "best"
113
114
  pdf_engine: "pdflatex"
114
115
  pdf_engine_opt: [""]
115
116
  #####
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paru
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Huub de Beer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-25 00:00:00.000000000 Z
11
+ date: 2020-07-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Use Pandoc (http://www.pandoc.org) with ruby
13
+ description: Control pandoc with Ruby and write pandoc filters in Ruby
14
14
  email: Huub@heerdebeer.org
15
15
  executables:
16
16
  - pandoc2yaml.rb
@@ -28,10 +28,13 @@ files:
28
28
  - lib/paru/filter/block.rb
29
29
  - lib/paru/filter/block_quote.rb
30
30
  - lib/paru/filter/bullet_list.rb
31
+ - lib/paru/filter/caption.rb
32
+ - lib/paru/filter/cell.rb
31
33
  - lib/paru/filter/citation.rb
32
34
  - lib/paru/filter/cite.rb
33
35
  - lib/paru/filter/code.rb
34
36
  - lib/paru/filter/code_block.rb
37
+ - lib/paru/filter/col_spec.rb
35
38
  - lib/paru/filter/definition_list.rb
36
39
  - lib/paru/filter/definition_list_item.rb
37
40
  - lib/paru/filter/div.rb
@@ -68,6 +71,8 @@ files:
68
71
  - lib/paru/filter/quoted.rb
69
72
  - lib/paru/filter/raw_block.rb
70
73
  - lib/paru/filter/raw_inline.rb
74
+ - lib/paru/filter/row.rb
75
+ - lib/paru/filter/short_caption.rb
71
76
  - lib/paru/filter/small_caps.rb
72
77
  - lib/paru/filter/soft_break.rb
73
78
  - lib/paru/filter/space.rb
@@ -78,8 +83,13 @@ files:
78
83
  - lib/paru/filter/subscript.rb
79
84
  - lib/paru/filter/superscript.rb
80
85
  - lib/paru/filter/table.rb
81
- - lib/paru/filter/table_row.rb
86
+ - lib/paru/filter/table_body.rb
87
+ - lib/paru/filter/table_end.rb
88
+ - lib/paru/filter/table_foot.rb
89
+ - lib/paru/filter/table_head.rb
82
90
  - lib/paru/filter/target.rb
91
+ - lib/paru/filter/underline.rb
92
+ - lib/paru/filter/value.rb
83
93
  - lib/paru/filter/version.rb
84
94
  - lib/paru/filter_error.rb
85
95
  - lib/paru/pandoc.rb
@@ -99,7 +109,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
99
109
  requirements:
100
110
  - - ">="
101
111
  - !ruby/object:Gem::Version
102
- version: '2.4'
112
+ version: '2.5'
103
113
  required_rubygems_version: !ruby/object:Gem::Requirement
104
114
  requirements:
105
115
  - - ">="