paru 0.2.5c → 0.2.5f
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/do-pandoc.rb +5 -5
- data/bin/pandoc2yaml.rb +23 -58
- data/lib/paru.rb +1 -5
- data/lib/paru/error.rb +0 -2
- data/lib/paru/filter.rb +46 -30
- data/lib/paru/filter/ast_manipulation.rb +0 -1
- data/lib/paru/filter/attr.rb +0 -1
- data/lib/paru/filter/block.rb +2 -2
- data/lib/paru/filter/block_quote.rb +2 -2
- data/lib/paru/filter/bullet_list.rb +2 -2
- data/lib/paru/filter/citation.rb +2 -2
- data/lib/paru/filter/cite.rb +8 -4
- data/lib/paru/filter/code.rb +11 -3
- data/lib/paru/filter/code_block.rb +5 -3
- data/lib/paru/filter/definition_list.rb +2 -2
- data/lib/paru/filter/definition_list_item.rb +4 -4
- data/lib/paru/filter/div.rb +5 -3
- data/lib/paru/filter/document.rb +47 -16
- data/lib/paru/filter/emph.rb +2 -2
- data/lib/paru/filter/empty_block.rb +3 -3
- data/lib/paru/filter/empty_inline.rb +2 -2
- data/lib/paru/filter/header.rb +6 -3
- data/lib/paru/filter/horizontal_rule.rb +6 -6
- data/lib/paru/filter/image.rb +2 -3
- data/lib/paru/filter/inline.rb +5 -2
- data/lib/paru/filter/inner_markdown.rb +85 -0
- data/lib/paru/filter/line_block.rb +8 -2
- data/lib/paru/filter/line_break.rb +2 -2
- data/lib/paru/filter/link.rb +4 -5
- data/lib/paru/filter/list.rb +8 -6
- data/lib/paru/filter/math.rb +2 -2
- data/lib/paru/filter/meta.rb +15 -4
- data/lib/paru/filter/meta_blocks.rb +2 -2
- data/lib/paru/filter/meta_bool.rb +2 -3
- data/lib/paru/filter/meta_inlines.rb +4 -2
- data/lib/paru/filter/meta_list.rb +2 -3
- data/lib/paru/filter/meta_map.rb +10 -142
- data/lib/paru/filter/meta_string.rb +1 -1
- data/lib/paru/filter/meta_value.rb +5 -4
- data/lib/paru/filter/metadata.rb +114 -0
- data/lib/paru/filter/node.rb +130 -11
- data/lib/paru/filter/note.rb +3 -4
- data/lib/paru/filter/null.rb +2 -2
- data/lib/paru/filter/ordered_list.rb +5 -5
- data/lib/paru/filter/para.rb +4 -2
- data/lib/paru/filter/plain.rb +4 -2
- data/lib/paru/filter/quoted.rb +2 -2
- data/lib/paru/filter/raw_block.rb +5 -3
- data/lib/paru/filter/raw_inline.rb +2 -3
- data/lib/paru/filter/small_caps.rb +2 -2
- data/lib/paru/filter/soft_break.rb +2 -2
- data/lib/paru/filter/space.rb +2 -2
- data/lib/paru/filter/span.rb +3 -4
- data/lib/paru/filter/str.rb +2 -2
- data/lib/paru/filter/strikeout.rb +2 -2
- data/lib/paru/filter/strong.rb +2 -2
- data/lib/paru/filter/subscript.rb +2 -2
- data/lib/paru/filter/superscript.rb +2 -2
- data/lib/paru/filter/table.rb +3 -3
- data/lib/paru/filter/table_row.rb +2 -2
- data/lib/paru/filter/target.rb +0 -1
- data/lib/paru/filter/version.rb +2 -2
- data/lib/paru/filter_error.rb +25 -0
- data/lib/paru/pandoc.rb +3 -4
- data/lib/paru/pandoc2yaml.rb +71 -0
- data/lib/paru/selector.rb +2 -4
- metadata +6 -3
- data/lib/paru/filter/markdown.rb +0 -150
@@ -16,10 +16,10 @@
|
|
16
16
|
# You should have received a copy of the GNU General Public License
|
17
17
|
# along with Paru. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#++
|
19
|
+
require_relative "./inline.rb"
|
20
|
+
|
19
21
|
module Paru
|
20
22
|
module PandocFilter
|
21
|
-
require_relative "./inline"
|
22
|
-
|
23
23
|
# A Superscript inline node
|
24
24
|
class Superscript < Inline
|
25
25
|
end
|
data/lib/paru/filter/table.rb
CHANGED
@@ -16,11 +16,11 @@
|
|
16
16
|
# You should have received a copy of the GNU General Public License
|
17
17
|
# along with Paru. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#++
|
19
|
+
require_relative "./block.rb"
|
20
|
+
require_relative "./inline.rb"
|
21
|
+
|
19
22
|
module Paru
|
20
23
|
module PandocFilter
|
21
|
-
require_relative "./block"
|
22
|
-
require_relative "./inline"
|
23
|
-
|
24
24
|
# The allignment of a table column
|
25
25
|
ALIGNMENTS = ["AlignLeft", "AlignRight", "AlignCenter", "AlignDefault"]
|
26
26
|
|
@@ -16,10 +16,10 @@
|
|
16
16
|
# You should have received a copy of the GNU General Public License
|
17
17
|
# along with Paru. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#++
|
19
|
+
require_relative "./block.rb"
|
20
|
+
|
19
21
|
module Paru
|
20
22
|
module PandocFilter
|
21
|
-
require_relative "./block"
|
22
|
-
|
23
23
|
# A TableRow node represents a row in a table's head or body
|
24
24
|
class TableRow < Block
|
25
25
|
# Create a new TableRow based on the row_data
|
data/lib/paru/filter/target.rb
CHANGED
data/lib/paru/filter/version.rb
CHANGED
@@ -16,10 +16,10 @@
|
|
16
16
|
# You should have received a copy of the GNU General Public License
|
17
17
|
# along with Paru. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#++
|
19
|
+
require_relative "./node.rb"
|
20
|
+
|
19
21
|
module Paru
|
20
22
|
module PandocFilter
|
21
|
-
require_relative "./node"
|
22
|
-
|
23
23
|
# Version is a general Node containing the pandoc-api-version. It has
|
24
24
|
# the format major.minor.revision.sub
|
25
25
|
class Version < Node
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright 2015, 2016, 2017 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 "./error.rb"
|
20
|
+
|
21
|
+
module Paru
|
22
|
+
# A FilterError raised when there is an error while running a filter.
|
23
|
+
class FilterError < Error
|
24
|
+
end
|
25
|
+
end
|
data/lib/paru/pandoc.rb
CHANGED
@@ -16,11 +16,10 @@
|
|
16
16
|
# You should have received a copy of the GNU General Public License
|
17
17
|
# along with Paru. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#++
|
19
|
-
|
20
|
-
|
21
|
-
require "shellwords"
|
22
|
-
require "yaml"
|
19
|
+
require "shellwords"
|
20
|
+
require "yaml"
|
23
21
|
|
22
|
+
module Paru
|
24
23
|
# Pandoc is a wrapper around the pandoc document converter. See
|
25
24
|
# <http://pandoc.org/README.html> for details about pandoc. The Pandoc
|
26
25
|
# class is basically a straightforward translation from the pandoc command
|
@@ -0,0 +1,71 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright 2015, 2016, 2017 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 "json"
|
20
|
+
require_relative "./pandoc.rb"
|
21
|
+
|
22
|
+
module Paru
|
23
|
+
# Utility class to extract YAML metadata form a markdown file in pandoc's
|
24
|
+
# own markdown format.
|
25
|
+
class Pandoc2Yaml
|
26
|
+
# Paru converters:
|
27
|
+
# Note. When converting metadata back to the pandoc markdown format, you have
|
28
|
+
# to use the option "standalone", otherwise the metadata is skipped
|
29
|
+
|
30
|
+
# Converter from pandoc's markdown to pandoc's AST JSON
|
31
|
+
PANDOC_2_JSON = Paru::Pandoc.new {from "markdown"; to "json"}
|
32
|
+
|
33
|
+
# Converter from pandoc's AST JSON back to pandoc. Note the
|
34
|
+
# 'standalone' property, which is needed to output the metadata as
|
35
|
+
# well.
|
36
|
+
JSON_2_PANDOC = Paru::Pandoc.new {from "json"; to "markdown"; standalone}
|
37
|
+
|
38
|
+
# When converting a pandoc document to JSON, or vice versa, the JSON object
|
39
|
+
# has the following three properties:
|
40
|
+
|
41
|
+
# Pandoc-type API version key
|
42
|
+
VERSION = "pandoc-api-version"
|
43
|
+
# Meta block key
|
44
|
+
META = "meta"
|
45
|
+
# Content's blocks key
|
46
|
+
BLOCKS = "blocks"
|
47
|
+
|
48
|
+
# Extract the YAML metadata from input document
|
49
|
+
#
|
50
|
+
# @param input_document [String] path to input document
|
51
|
+
# @return [String] YAML metadata from input document on STDOUT
|
52
|
+
def self.extract_metadata input_document
|
53
|
+
json = JSON.parse(PANDOC_2_JSON << File.read(input_document))
|
54
|
+
yaml = ""
|
55
|
+
|
56
|
+
version, metadata = json.values_at(VERSION, META)
|
57
|
+
|
58
|
+
if not metadata.empty? then
|
59
|
+
metadata_document = {
|
60
|
+
VERSION => version,
|
61
|
+
META => metadata,
|
62
|
+
BLOCKS => []
|
63
|
+
}
|
64
|
+
|
65
|
+
yaml = JSON_2_PANDOC << JSON.generate(metadata_document)
|
66
|
+
end
|
67
|
+
|
68
|
+
yaml
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/lib/paru/selector.rb
CHANGED
@@ -16,16 +16,14 @@
|
|
16
16
|
# You should have received a copy of the GNU General Public License
|
17
17
|
# along with Paru. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#++
|
19
|
-
|
20
|
-
require_relative './filter'
|
21
|
-
require_relative './error'
|
19
|
+
require_relative './error'
|
22
20
|
|
21
|
+
module Paru
|
23
22
|
# SelectorParseError is thrown when there is an error parsing a selector
|
24
23
|
# used in a filter.
|
25
24
|
class SelectorParseError < Error
|
26
25
|
end
|
27
26
|
|
28
|
-
|
29
27
|
# A Selector models a relationship between Pandoc AST nodes, such as
|
30
28
|
# parent-child or sibling. Selectors in paru are like CSS selectors, but
|
31
29
|
# more limited because the Pandoc AST is quite simple.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paru
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5f
|
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: 2017-
|
11
|
+
date: 2017-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Use Pandoc (http://www.pandoc.org) with ruby
|
14
14
|
email: Huub@heerdebeer.org
|
@@ -43,12 +43,12 @@ files:
|
|
43
43
|
- lib/paru/filter/horizontal_rule.rb
|
44
44
|
- lib/paru/filter/image.rb
|
45
45
|
- lib/paru/filter/inline.rb
|
46
|
+
- lib/paru/filter/inner_markdown.rb
|
46
47
|
- lib/paru/filter/line_block.rb
|
47
48
|
- lib/paru/filter/line_break.rb
|
48
49
|
- lib/paru/filter/link.rb
|
49
50
|
- lib/paru/filter/list.rb
|
50
51
|
- lib/paru/filter/list_attributes.rb
|
51
|
-
- lib/paru/filter/markdown.rb
|
52
52
|
- lib/paru/filter/math.rb
|
53
53
|
- lib/paru/filter/meta.rb
|
54
54
|
- lib/paru/filter/meta_blocks.rb
|
@@ -58,6 +58,7 @@ files:
|
|
58
58
|
- lib/paru/filter/meta_map.rb
|
59
59
|
- lib/paru/filter/meta_string.rb
|
60
60
|
- lib/paru/filter/meta_value.rb
|
61
|
+
- lib/paru/filter/metadata.rb
|
61
62
|
- lib/paru/filter/node.rb
|
62
63
|
- lib/paru/filter/note.rb
|
63
64
|
- lib/paru/filter/null.rb
|
@@ -80,7 +81,9 @@ files:
|
|
80
81
|
- lib/paru/filter/table_row.rb
|
81
82
|
- lib/paru/filter/target.rb
|
82
83
|
- lib/paru/filter/version.rb
|
84
|
+
- lib/paru/filter_error.rb
|
83
85
|
- lib/paru/pandoc.rb
|
86
|
+
- lib/paru/pandoc2yaml.rb
|
84
87
|
- lib/paru/pandoc_options.yaml
|
85
88
|
- lib/paru/selector.rb
|
86
89
|
homepage: https://heerdebeer.org/Software/markdown/paru/
|
data/lib/paru/filter/markdown.rb
DELETED
@@ -1,150 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
# Copyright 2015, 2016, 2017 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
|
-
module Paru
|
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"
|
25
|
-
|
26
|
-
# A Paru::Pandoc converter from JSON to markdown
|
27
|
-
AST2MARKDOWN = Paru::Pandoc.new do
|
28
|
-
from "json"
|
29
|
-
to "markdown"
|
30
|
-
end
|
31
|
-
|
32
|
-
# A Paru::Pandoc converter from markdown to JSON
|
33
|
-
MARKDOWN2JSON = Paru::Pandoc.new do
|
34
|
-
from "markdown"
|
35
|
-
to "json"
|
36
|
-
end
|
37
|
-
|
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
|
46
|
-
|
47
|
-
# Set the markdown representation of this Node: replace this Node
|
48
|
-
# by the Node represented by the markdown string. If an inline
|
49
|
-
# node is being replaced and the replacement has more than one
|
50
|
-
# paragraph, only the contents of the first paragraph is used
|
51
|
-
#
|
52
|
-
# @param markdown [String] the markdown string to replace this
|
53
|
-
# Node
|
54
|
-
#
|
55
|
-
# @example Replacing all horizontal lines by a Plain node saying "hi"
|
56
|
-
# Paru::Filter.run do
|
57
|
-
# with "HorizontalLine" do |line|
|
58
|
-
# line.outer_markdown = "hi"
|
59
|
-
# end
|
60
|
-
# end
|
61
|
-
#
|
62
|
-
def outer_markdown=(markdown)
|
63
|
-
json = MARKDOWN2JSON << markdown
|
64
|
-
temp_doc = PandocFilter::Document.from_JSON json
|
65
|
-
|
66
|
-
if not has_parent? or is_root?
|
67
|
-
@children = temp_doc.children
|
68
|
-
else
|
69
|
-
# replace current node by new nodes
|
70
|
-
# There is a difference between inline and block nodes
|
71
|
-
current_index = parent.find_index self
|
72
|
-
|
73
|
-
# By default, pandoc creates a Block level node when
|
74
|
-
# converting a string. However, if the original is a
|
75
|
-
# inline level node, so should its replacement node(s) be.
|
76
|
-
# Only using first block node (paragraph?)
|
77
|
-
if is_inline?
|
78
|
-
temp_doc = temp_doc.children.first
|
79
|
-
|
80
|
-
if not temp_doc.children.all? {|node| node.is_inline?}
|
81
|
-
raise Error.new "Cannot replace the inline level node represented by '#{outer_markdown}' with markdown that converts to block level nodes: '#{markdown}'."
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|
85
|
-
|
86
|
-
index = current_index
|
87
|
-
temp_doc.each do |child|
|
88
|
-
index += 1
|
89
|
-
parent.insert index, child
|
90
|
-
end
|
91
|
-
# Remove the original node
|
92
|
-
parent.remove_at current_index
|
93
|
-
end
|
94
|
-
|
95
|
-
end
|
96
|
-
|
97
|
-
# Get the markdown representation of this Node's children
|
98
|
-
#
|
99
|
-
# @return [String] the inner markdown representation of this Node
|
100
|
-
#
|
101
|
-
# @example Replace all occurrences of "hello" by "world" in all paragraphs
|
102
|
-
# Paru::Filter.run do
|
103
|
-
# with "Para" do |p|
|
104
|
-
# p.inner_markdown = p.inner_markdown.gsub "hello", "world"
|
105
|
-
# end
|
106
|
-
# end
|
107
|
-
#
|
108
|
-
def inner_markdown()
|
109
|
-
temp_doc = PandocFilter::Document.fragment @children
|
110
|
-
AST2MARKDOWN << temp_doc.to_JSON
|
111
|
-
end
|
112
|
-
|
113
|
-
# Replace this Node's children with the Nodes represented by the
|
114
|
-
# markdown string
|
115
|
-
#
|
116
|
-
# @param markdown [String] the markdown string to replace this
|
117
|
-
# Node's children
|
118
|
-
#
|
119
|
-
# @example Replace all occurrences of "hello" by "world" in all paragraphs
|
120
|
-
# Paru::Filter.run do
|
121
|
-
# with "Para" do |p|
|
122
|
-
# p.inner_markdown = p.inner_markdown.gsub "hello", "world"
|
123
|
-
# end
|
124
|
-
# end
|
125
|
-
#
|
126
|
-
def inner_markdown=(markdown)
|
127
|
-
if has_string?
|
128
|
-
@string = markdown
|
129
|
-
else
|
130
|
-
if markdown.empty?
|
131
|
-
@children = []
|
132
|
-
else
|
133
|
-
json = MARKDOWN2JSON << markdown
|
134
|
-
temp_doc = PandocFilter::Document.from_JSON json
|
135
|
-
temp_doc.children.each {|c| c.parent = @parent}
|
136
|
-
|
137
|
-
if has_inline?
|
138
|
-
@children = temp_doc.children.first.children
|
139
|
-
elsif has_block?
|
140
|
-
@children = temp_doc.children
|
141
|
-
else
|
142
|
-
# Unknown; what to do here?
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|