paru 0.2.4.2 → 0.2.4.3
Sign up to get free protection for your applications and to get access to all the features.
- 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/image.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,17 +17,19 @@
|
|
17
17
|
# along with Paru. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#++
|
19
19
|
module Paru
|
20
|
-
|
20
|
+
module PandocFilter
|
21
21
|
|
22
|
-
|
22
|
+
require_relative "./link"
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
24
|
+
# An Image has an attribute object, a caption, and a target
|
25
|
+
class Image < Link
|
26
|
+
|
27
|
+
# Although Image is defined to be inline, probably because in HTML it
|
28
|
+
# can be an inline element, often it acts like a block element.
|
29
|
+
# @return [Boolean] true
|
30
|
+
def can_act_as_both_block_and_inline?
|
31
|
+
true
|
32
|
+
end
|
33
|
+
end
|
31
34
|
end
|
32
|
-
end
|
33
35
|
end
|
data/lib/paru/filter/inline.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
|
#
|
@@ -20,18 +20,29 @@ module Paru
|
|
20
20
|
module PandocFilter
|
21
21
|
require_relative "./node"
|
22
22
|
|
23
|
+
# An Inline node
|
24
|
+
# @see http://hackage.haskell.org/package/pandoc-types-1.17.0.4/docs/Text-Pandoc-Definition.html#t:Inline
|
23
25
|
class Inline < Node
|
24
|
-
def initialize contents
|
25
|
-
super contents, true
|
26
|
-
end
|
27
26
|
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
# Create a new Inline node with contents
|
28
|
+
# @param contents [Array] the contents of this inline node
|
29
|
+
def initialize(contents)
|
30
|
+
super contents, true
|
31
|
+
end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
33
|
+
# Is this Inline node inline? Of course!
|
34
|
+
#
|
35
|
+
# @return [Boolean] true
|
36
|
+
def is_inline?()
|
37
|
+
true
|
38
|
+
end
|
39
|
+
|
40
|
+
# Has this Inline node inline contents? Of course!
|
41
|
+
#
|
42
|
+
# @return [Boolean] true
|
43
|
+
def has_inline?()
|
44
|
+
true
|
45
|
+
end
|
35
46
|
end
|
36
47
|
end
|
37
48
|
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,11 +17,11 @@
|
|
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 "./list.rb"
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
# A LineBlock is a List of Lists of Inline nodes
|
24
|
+
class LineBlock < List
|
25
|
+
end
|
25
26
|
end
|
26
|
-
end
|
27
27
|
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,11 +17,11 @@
|
|
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 "./empty_inline"
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
# A LineBreak is an empty inline element
|
24
|
+
class LineBreak < EmptyInline
|
25
|
+
end
|
25
26
|
end
|
26
|
-
end
|
27
27
|
end
|
data/lib/paru/filter/link.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,30 +17,42 @@
|
|
17
17
|
# along with Paru. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#++
|
19
19
|
module Paru
|
20
|
-
|
20
|
+
module PandocFilter
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
require_relative "./inline"
|
23
|
+
require_relative "./attr"
|
24
|
+
require_relative "./target"
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
# A Link node has an attribute object, an Inline description and a
|
27
|
+
# target
|
28
|
+
#
|
29
|
+
# @!attribute attr
|
30
|
+
# @return [Attr]
|
31
|
+
#
|
32
|
+
# @!attribute targer
|
33
|
+
# @return [Target]
|
34
|
+
class Link < Inline
|
35
|
+
attr_accessor :attr, :target
|
29
36
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
37
|
+
# Create a new Link node with contents
|
38
|
+
#
|
39
|
+
# @param contents [Array] an array with attributes, description,
|
40
|
+
# and target information
|
41
|
+
def initialize(contents)
|
42
|
+
@attr = Attr.new contents[0]
|
43
|
+
super contents[1]
|
44
|
+
@target = Target.new contents[2]
|
45
|
+
end
|
35
46
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
47
|
+
# Create an AST representation of this Link node
|
48
|
+
def ast_contents
|
49
|
+
[
|
50
|
+
@attr.to_ast,
|
51
|
+
super,
|
52
|
+
@target.to_ast
|
53
|
+
]
|
54
|
+
end
|
43
55
|
|
56
|
+
end
|
44
57
|
end
|
45
|
-
end
|
46
58
|
end
|
data/lib/paru/filter/list.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,24 +17,33 @@
|
|
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 List node is a base node for various List node types
|
24
|
+
class List < Block
|
25
|
+
|
26
|
+
# Create a new List node based on contents
|
27
|
+
#
|
28
|
+
# @param contents [Array] the contents of the list
|
29
|
+
def initialize contents
|
30
|
+
super []
|
31
|
+
contents.each do |item|
|
32
|
+
@children.push Block.new item
|
33
|
+
end
|
34
|
+
end
|
30
35
|
|
31
|
-
|
32
|
-
|
33
|
-
|
36
|
+
# Create an AST representation of this List node
|
37
|
+
def ast_contents
|
38
|
+
@children.map {|child| child.ast_contents}
|
39
|
+
end
|
34
40
|
|
35
|
-
|
36
|
-
|
37
|
-
|
41
|
+
# Has this List node block contents?
|
42
|
+
#
|
43
|
+
# @return [Boolean] true
|
44
|
+
def has_block?
|
45
|
+
true
|
46
|
+
end
|
47
|
+
end
|
38
48
|
end
|
39
|
-
end
|
40
49
|
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,39 +17,60 @@
|
|
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
|
+
# ListAttributes represent the attributes of a list.
|
22
|
+
#
|
23
|
+
# @see http://hackage.haskell.org/package/pandoc-types-1.17.0.4/docs/Text-Pandoc-Definition.html#t:ListAttributes
|
24
|
+
#
|
25
|
+
# @!attribute start
|
26
|
+
# @return [Integer]
|
27
|
+
#
|
28
|
+
# @!attribute number_style
|
29
|
+
# @return [STYLES]
|
30
|
+
#
|
31
|
+
# @!attribute number_delim
|
32
|
+
# @return [DELIMS]
|
33
|
+
class ListAttributes
|
34
|
+
|
35
|
+
# The various styles of list numbers
|
36
|
+
STYLES = [
|
37
|
+
"DefaultStyle",
|
38
|
+
"Example",
|
39
|
+
"Decimal",
|
40
|
+
"LowerRoman",
|
41
|
+
"UpperRoman",
|
42
|
+
"LowerAlpha",
|
43
|
+
"UpperAlpha"
|
44
|
+
]
|
22
45
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
"UpperAlpha"
|
31
|
-
]
|
32
|
-
DELIMS = [
|
33
|
-
"DefaultDelim",
|
34
|
-
"Period",
|
35
|
-
"OneParen",
|
36
|
-
"TwoParens"
|
37
|
-
]
|
46
|
+
# The various delimeters of list numbers
|
47
|
+
DELIMS = [
|
48
|
+
"DefaultDelim",
|
49
|
+
"Period",
|
50
|
+
"OneParen",
|
51
|
+
"TwoParens"
|
52
|
+
]
|
38
53
|
|
39
|
-
|
40
|
-
def initialize attributes
|
41
|
-
@start = attributes[0]
|
42
|
-
@number_style = attributes[1]
|
43
|
-
@number_delim = attributes[2]
|
44
|
-
end
|
54
|
+
attr_accessor :start, :number_style, :number_delim
|
45
55
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
56
|
+
# Create a new ListAttribute object with attributes
|
57
|
+
#
|
58
|
+
# @param attributes [Array] an array with start, number style, and
|
59
|
+
# number delimeter
|
60
|
+
def initialize(attributes)
|
61
|
+
@start = attributes[0]
|
62
|
+
@number_style = attributes[1]
|
63
|
+
@number_delim = attributes[2]
|
64
|
+
end
|
65
|
+
|
66
|
+
# Create an AST representation of this ListAttributes object
|
67
|
+
def to_ast()
|
68
|
+
[
|
69
|
+
@start,
|
70
|
+
@number_style,
|
71
|
+
@number_delim
|
72
|
+
]
|
73
|
+
end
|
74
|
+
end
|
53
75
|
end
|
54
|
-
end
|
55
76
|
end
|
data/lib/paru/filter/markdown.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,74 +17,117 @@
|
|
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
|
+
# A mixin to add inner_markdown and outer_markdown properties to Nodes
|
22
|
+
module Markdown
|
23
|
+
require_relative "../pandoc"
|
24
|
+
require_relative "./document"
|
22
25
|
|
23
|
-
|
24
|
-
|
26
|
+
# A Paru::Pandoc converter from JSON to markdown
|
27
|
+
AST2MARKDOWN = Paru::Pandoc.new do
|
28
|
+
from "json"
|
29
|
+
to "markdown"
|
30
|
+
end
|
25
31
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
32
|
+
# A Paru::Pandoc converter from markdown to JSON
|
33
|
+
MARKDOWN2JSON = Paru::Pandoc.new do
|
34
|
+
from "markdown"
|
35
|
+
to "json"
|
36
|
+
end
|
30
37
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
38
|
+
# Get the markdown representation of this Node, including the Node
|
39
|
+
# itself.
|
40
|
+
#
|
41
|
+
# @return [String] the outer markdown representation of this Node
|
42
|
+
def outer_markdown()
|
43
|
+
temp_doc = PandocFilter::Document.fragment [self]
|
44
|
+
AST2MARKDOWN << temp_doc.to_JSON
|
45
|
+
end
|
35
46
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
47
|
+
# Set the markdown representation of this Node: replace this Node
|
48
|
+
# by the Node represented by the markdown string
|
49
|
+
#
|
50
|
+
# @param markdown [String] the markdown string to replace this
|
51
|
+
# Node
|
52
|
+
#
|
53
|
+
# @example Replacing all horizontal lines by a Plain node saying "hi"
|
54
|
+
# Paru::Filter.run do
|
55
|
+
# with "HorizontalLine" do |line|
|
56
|
+
# line.outer_markdown = "hi"
|
57
|
+
# end
|
58
|
+
# end
|
59
|
+
#
|
60
|
+
def outer_markdown=(markdown)
|
61
|
+
json = MARKDOWN2JSON << markdown
|
62
|
+
temp_doc = PandocFilter::Document.from_JSON json
|
40
63
|
|
41
|
-
|
42
|
-
|
43
|
-
|
64
|
+
if not has_parent? or is_root?
|
65
|
+
@children = temp_doc.children
|
66
|
+
else
|
67
|
+
# replace current node by new nodes
|
68
|
+
# There is a difference between inline and block nodes
|
69
|
+
current_index = parent.find_index self
|
70
|
+
index = current_index
|
71
|
+
temp_doc.each do |child|
|
72
|
+
index += 1
|
73
|
+
parent.insert index, child
|
74
|
+
end
|
75
|
+
# Remove the original node
|
76
|
+
parent.remove_at current_index
|
77
|
+
end
|
44
78
|
|
45
|
-
|
46
|
-
@children = temp_doc.children
|
47
|
-
else
|
48
|
-
# replace current node by new nodes
|
49
|
-
# There is a difference between inline and block nodes
|
50
|
-
current_index = parent.find_index self
|
51
|
-
index = current_index
|
52
|
-
temp_doc.each do |child|
|
53
|
-
index += 1
|
54
|
-
parent.insert index, child
|
55
|
-
end
|
56
|
-
# Remove the original node
|
57
|
-
parent.remove_at current_index
|
58
|
-
end
|
59
|
-
|
60
|
-
end
|
79
|
+
end
|
61
80
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
81
|
+
# Get the markdown representation of this Node's children
|
82
|
+
#
|
83
|
+
# @return [String] the inner markdown representation of this Node
|
84
|
+
#
|
85
|
+
# @example Replace all occurrences of "hello" by "world" in all paragraphs
|
86
|
+
# Paru::Filter.run do
|
87
|
+
# with "Para" do |p|
|
88
|
+
# p.inner_markdown = p.inner_markdown.gsub "hello", "world"
|
89
|
+
# end
|
90
|
+
# end
|
91
|
+
#
|
92
|
+
def inner_markdown()
|
93
|
+
temp_doc = PandocFilter::Document.fragment @children
|
94
|
+
AST2MARKDOWN << temp_doc.to_JSON
|
95
|
+
end
|
66
96
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
97
|
+
# Replace this Node's children with the Nodes represented by the
|
98
|
+
# markdown string
|
99
|
+
#
|
100
|
+
# @param markdown [String] the markdown string to replace this
|
101
|
+
# Node's children
|
102
|
+
#
|
103
|
+
# @example Replace all occurrences of "hello" by "world" in all paragraphs
|
104
|
+
# Paru::Filter.run do
|
105
|
+
# with "Para" do |p|
|
106
|
+
# p.inner_markdown = p.inner_markdown.gsub "hello", "world"
|
107
|
+
# end
|
108
|
+
# end
|
109
|
+
#
|
110
|
+
def inner_markdown=(markdown)
|
111
|
+
if has_string?
|
112
|
+
@string = markdown
|
113
|
+
else
|
114
|
+
if markdown.empty?
|
115
|
+
@children = []
|
116
|
+
else
|
117
|
+
json = MARKDOWN2JSON << markdown
|
118
|
+
temp_doc = PandocFilter::Document.from_JSON json
|
119
|
+
temp_doc.children.each {|c| c.parent = @parent}
|
77
120
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
121
|
+
if has_inline?
|
122
|
+
@children = temp_doc.children[0].children
|
123
|
+
elsif has_block?
|
124
|
+
@children = temp_doc.children
|
125
|
+
else
|
126
|
+
# Unknown; what to do here?
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
84
130
|
end
|
85
|
-
end
|
86
131
|
end
|
87
|
-
end
|
88
132
|
end
|
89
|
-
end
|
90
133
|
end
|