pandoc_object_filters 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +8 -0
- data/lib/pandoc_object_filters.rb +51 -4
- data/lib/pandoc_object_filters/element_helper.rb +106 -0
- data/lib/pandoc_object_filters/v1_16.rb +9 -0
- data/lib/pandoc_object_filters/v1_16/element.rb +62 -0
- data/lib/pandoc_object_filters/v1_16/element/attr.rb +54 -0
- data/lib/pandoc_object_filters/v1_16/element/base.rb +46 -0
- data/lib/pandoc_object_filters/v1_16/element/base_element.rb +17 -0
- data/lib/pandoc_object_filters/{element → v1_16/element}/block.rb +4 -2
- data/lib/pandoc_object_filters/v1_16/element/document.rb +25 -0
- data/lib/pandoc_object_filters/v1_16/element/enum.rb +17 -0
- data/lib/pandoc_object_filters/{element → v1_16/element}/inline.rb +4 -2
- data/lib/pandoc_object_filters/v1_16/element/meta.rb +20 -0
- data/lib/pandoc_object_filters/{element → v1_16/element}/meta_value.rb +4 -2
- data/lib/pandoc_object_filters/v1_16/element/target.rb +18 -0
- data/lib/pandoc_object_filters/v1_17.rb +9 -0
- data/lib/pandoc_object_filters/v1_17/element.rb +63 -0
- data/lib/pandoc_object_filters/v1_17/element/attr.rb +11 -0
- data/lib/pandoc_object_filters/v1_17/element/base.rb +10 -0
- data/lib/pandoc_object_filters/v1_17/element/base_element.rb +11 -0
- data/lib/pandoc_object_filters/v1_17/element/block.rb +11 -0
- data/lib/pandoc_object_filters/v1_17/element/document.rb +28 -0
- data/lib/pandoc_object_filters/v1_17/element/enum.rb +11 -0
- data/lib/pandoc_object_filters/v1_17/element/inline.rb +11 -0
- data/lib/pandoc_object_filters/v1_17/element/leaf.rb +17 -0
- data/lib/pandoc_object_filters/v1_17/element/meta.rb +20 -0
- data/lib/pandoc_object_filters/v1_17/element/meta_value.rb +11 -0
- data/lib/pandoc_object_filters/v1_17/element/target.rb +11 -0
- data/lib/pandoc_object_filters/version.rb +1 -1
- metadata +29 -14
- data/lib/pandoc_object_filters/element.rb +0 -135
- data/lib/pandoc_object_filters/element/attr.rb +0 -43
- data/lib/pandoc_object_filters/element/base.rb +0 -44
- data/lib/pandoc_object_filters/element/base_element.rb +0 -11
- data/lib/pandoc_object_filters/element/document.rb +0 -19
- data/lib/pandoc_object_filters/element/enum.rb +0 -15
- data/lib/pandoc_object_filters/element/meta.rb +0 -18
- data/lib/pandoc_object_filters/element/target.rb +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 871c51f8b724882422047a358762bb3159937fcb
|
4
|
+
data.tar.gz: 6dfecfb0968982b307bdf49155a20c637b6d9adb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91a98c6c032b8ec9989ad97db908fd576f5560968943998388169759a4212e0fb68677659e9e7debf589a21ea3404a6058a68d510ee6b481bd449a719d352f1b
|
7
|
+
data.tar.gz: 662a7d6b9eef279e3d30432798a889b67a92981f8849d350701aaa74acfab9175430f8430fa8459b727a103f2d6d05e33a52d10d859d9ccf4e326c62592c75c2
|
data/.rubocop.yml
CHANGED
@@ -7,9 +7,17 @@ AllCops:
|
|
7
7
|
DisplayCopNames: true
|
8
8
|
TargetRubyVersion: 2.2
|
9
9
|
|
10
|
+
Style/ClassAndModuleCamelCase:
|
11
|
+
Exclude:
|
12
|
+
- lib/**/v*_*
|
13
|
+
- lib/**/v*_*/**/*
|
14
|
+
|
10
15
|
Metrics/LineLength:
|
11
16
|
Max: 120
|
12
17
|
|
18
|
+
Style/Documentation:
|
19
|
+
Enabled: false
|
20
|
+
|
13
21
|
Style/SignalException:
|
14
22
|
EnforcedStyle: only_raise
|
15
23
|
|
@@ -4,12 +4,59 @@
|
|
4
4
|
# See http://pandoc.org/scripting.html
|
5
5
|
# and https://github.com/jgm/pandocfilters
|
6
6
|
# for more information.
|
7
|
+
require "open3"
|
7
8
|
|
8
9
|
module PandocObjectFilters
|
9
|
-
|
10
|
-
autoload :
|
11
|
-
autoload :
|
12
|
-
|
10
|
+
# NOTE: The version refers to the pandoc-types version, not the pandoc version
|
11
|
+
autoload :V1_16, "pandoc_object_filters/v1_16"
|
12
|
+
autoload :V1_17, "pandoc_object_filters/v1_17"
|
13
|
+
|
14
|
+
autoload :ElementHelper, "pandoc_object_filters/element_helper"
|
15
|
+
autoload :Filter, "pandoc_object_filters/filter"
|
16
|
+
autoload :VERSION, "pandoc_object_filters/version"
|
17
|
+
autoload :Walker, "pandoc_object_filters/walker"
|
18
|
+
|
19
|
+
def self.current_pandoc_version
|
20
|
+
@current_pandoc_version ||=
|
21
|
+
begin
|
22
|
+
result, status = Open3.capture2(ENV.fetch("PANDOC_EXE", "pandoc"), "-v")
|
23
|
+
|
24
|
+
unless status.success?
|
25
|
+
raise "Cannot determine Pandoc version! " \
|
26
|
+
"You may point to a valid Pandoc binary via a PANDOC_EXE environment variable."
|
27
|
+
end
|
28
|
+
|
29
|
+
type_version = result[/pandoc-types (\d+\.\d+)(?:\.\d+)*/, 1]
|
30
|
+
type_version = type_version.to_f if type_version
|
31
|
+
|
32
|
+
unless type_version
|
33
|
+
version = result[/pandoc (\d+\.\d+)(?:\.\d+)*/, 1]
|
34
|
+
version = version.to_f if version
|
35
|
+
|
36
|
+
if version < 1.16
|
37
|
+
raise "Pandoc is too old for pandoc_object_filters: #{version}"
|
38
|
+
elsif version < 1.18
|
39
|
+
type_version = 1.16
|
40
|
+
elsif version < 1.19
|
41
|
+
type_version = 1.17
|
42
|
+
else
|
43
|
+
raise "Pandoc is too new for this version of pandoc_object_filters: #{version}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
if type_version < 1.16
|
48
|
+
raise "Pandoc types is too old for pandoc_object_filters: #{version}"
|
49
|
+
elsif type_version < 1.17
|
50
|
+
PandocObjectFilters::V1_16
|
51
|
+
elsif type_version < 1.18
|
52
|
+
PandocObjectFilters::V1_17
|
53
|
+
else
|
54
|
+
raise "Pandoc types is too new for this version of pandoc_object_filters: #{version}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
Element = current_pandoc_version::Element
|
13
60
|
|
14
61
|
def self.filter(input = $stdin, output = $stdout, argv = ARGV, &block)
|
15
62
|
PandocObjectFilters::Filter.new(input, output, argv, &block).filter
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require "pandoc_object_filters"
|
2
|
+
|
3
|
+
module PandocObjectFilters
|
4
|
+
module ElementHelper
|
5
|
+
attr_reader :version
|
6
|
+
|
7
|
+
def version=(value)
|
8
|
+
raise "The version is already defined!" if @version
|
9
|
+
@version = value
|
10
|
+
end
|
11
|
+
|
12
|
+
def autoload_elements(*elements)
|
13
|
+
raise "autoload_elements can only be called once!" if @autoloaded_elements
|
14
|
+
@autoloaded_elements = true
|
15
|
+
elements.each do |element|
|
16
|
+
version_dir = version.name.split("::").last.downcase
|
17
|
+
element_path = element.to_s.gsub(/(\w)([A-Z])/, "\\1_\\2").downcase
|
18
|
+
autoload element, "pandoc_object_filters/#{version_dir}/element/#{element_path}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_ast(object)
|
23
|
+
if object.respond_to?(:to_ast)
|
24
|
+
object.to_ast
|
25
|
+
elsif object.is_a?(Array)
|
26
|
+
object.map { |x| to_ast(x) }
|
27
|
+
elsif object.is_a?(Hash)
|
28
|
+
result = {}
|
29
|
+
object.each { |key, value| result[key] = to_ast(value) }
|
30
|
+
result
|
31
|
+
else
|
32
|
+
object
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_object(object)
|
37
|
+
if object.is_a?(Array)
|
38
|
+
object.map { |x| to_object(x) }
|
39
|
+
elsif object.is_a?(Hash) && object.include?("t")
|
40
|
+
raise "Unknown type: #{object['t']}" unless PandocObjectFilters::Element.const_defined?(object["t"])
|
41
|
+
type = PandocObjectFilters::Element.const_get(object["t"])
|
42
|
+
raise "Invalid type: #{object['t']}" unless type < PandocObjectFilters::Element::BaseElement
|
43
|
+
type.new(to_object(object["c"]))
|
44
|
+
elsif object.is_a?(Hash) && object.include?("unMeta")
|
45
|
+
PandocObjectFilters::Element::Meta.new(to_object(object["unMeta"]))
|
46
|
+
elsif object.is_a?(Hash)
|
47
|
+
result = {}
|
48
|
+
object.each { |key, value| result[key] = to_object(value) }
|
49
|
+
result
|
50
|
+
else
|
51
|
+
object
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def walk(object, &block)
|
56
|
+
PandocObjectFilters::Walker.new(object, &block).walk
|
57
|
+
end
|
58
|
+
|
59
|
+
def walk!(object, &block)
|
60
|
+
PandocObjectFilters::Walker.new(object, &block).walk!
|
61
|
+
end
|
62
|
+
|
63
|
+
def define_elements(*definitions)
|
64
|
+
raise "define_elements can only be called once!" if @defined_elements
|
65
|
+
@defined_elements = true
|
66
|
+
definitions.each do |name, *params|
|
67
|
+
name.freeze
|
68
|
+
|
69
|
+
options =
|
70
|
+
if params.last.is_a?(Hash)
|
71
|
+
params.pop
|
72
|
+
else
|
73
|
+
{}
|
74
|
+
end
|
75
|
+
|
76
|
+
const_set(name, Class.new(version::Element::BaseElement) do
|
77
|
+
(options[:include] || []).each { |mod| include mod }
|
78
|
+
|
79
|
+
if params.size == 1
|
80
|
+
contents_attr params.first
|
81
|
+
else
|
82
|
+
params.each_with_index { |param, index| contents_attr param, index }
|
83
|
+
end
|
84
|
+
|
85
|
+
define_method(:element_name) { name }
|
86
|
+
|
87
|
+
if options[:conversions]
|
88
|
+
private
|
89
|
+
|
90
|
+
define_method(:convert_contents) do
|
91
|
+
@contents = @contents.map.with_index do |x, index|
|
92
|
+
convert_to_type = options[:conversions][params[index]]
|
93
|
+
|
94
|
+
if convert_to_type && !x.is_a?(convert_to_type)
|
95
|
+
convert_to_type.new(x)
|
96
|
+
else
|
97
|
+
x
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require "pandoc_object_filters"
|
2
|
+
|
3
|
+
module PandocObjectFilters
|
4
|
+
module V1_16
|
5
|
+
module Element
|
6
|
+
extend PandocObjectFilters::ElementHelper
|
7
|
+
self.version = PandocObjectFilters::V1_16
|
8
|
+
|
9
|
+
autoload_elements :Attr,
|
10
|
+
:Base,
|
11
|
+
:BaseElement,
|
12
|
+
:Block,
|
13
|
+
:Document,
|
14
|
+
:Enum,
|
15
|
+
:Inline,
|
16
|
+
:Meta,
|
17
|
+
:MetaValue,
|
18
|
+
:Target
|
19
|
+
|
20
|
+
# rubocop:disable Metrics/LineLength
|
21
|
+
define_elements ["MetaMap", :elements, { include: [PandocObjectFilters::V1_16::Element::MetaValue, PandocObjectFilters::V1_16::Element::Enum] }],
|
22
|
+
["MetaList", :elements, { include: [PandocObjectFilters::V1_16::Element::MetaValue, PandocObjectFilters::V1_16::Element::Enum] }],
|
23
|
+
["MetaBool", :value, { include: [PandocObjectFilters::V1_16::Element::MetaValue] }],
|
24
|
+
["MetaString", :value, { include: [PandocObjectFilters::V1_16::Element::MetaValue] }],
|
25
|
+
["MetaInlines", :elements, { include: [PandocObjectFilters::V1_16::Element::MetaValue, PandocObjectFilters::V1_16::Element::Enum] }],
|
26
|
+
["MetaBlocks", :elements, { include: [PandocObjectFilters::V1_16::Element::MetaValue, PandocObjectFilters::V1_16::Element::Enum] }],
|
27
|
+
["Plain", :elements, { include: [PandocObjectFilters::V1_16::Element::Block, PandocObjectFilters::V1_16::Element::Enum] }],
|
28
|
+
["Para", :elements, { include: [PandocObjectFilters::V1_16::Element::Block, PandocObjectFilters::V1_16::Element::Enum] }],
|
29
|
+
["CodeBlock", :attributes, :value, { include: [PandocObjectFilters::V1_16::Element::Block], conversions: { attributes: PandocObjectFilters::V1_16::Element::Attr } }],
|
30
|
+
["RawBlock", :format, :value, { include: [PandocObjectFilters::V1_16::Element::Block] }],
|
31
|
+
["BlockQuote", :elements, { include: [PandocObjectFilters::V1_16::Element::Block, PandocObjectFilters::V1_16::Element::Enum] }],
|
32
|
+
["OrderedList", :attributes, :elements, { include: [PandocObjectFilters::V1_16::Element::Block, PandocObjectFilters::V1_16::Element::Enum] }],
|
33
|
+
["BulletList", :elements, { include: [PandocObjectFilters::V1_16::Element::Block, PandocObjectFilters::V1_16::Element::Enum] }],
|
34
|
+
["DefinitionList", :elements, { include: [PandocObjectFilters::V1_16::Element::Block, PandocObjectFilters::V1_16::Element::Enum] }],
|
35
|
+
["Header", :level, :attributes, :elements, { include: [PandocObjectFilters::V1_16::Element::Block, PandocObjectFilters::V1_16::Element::Enum], conversions: { attributes: PandocObjectFilters::V1_16::Element::Attr } }],
|
36
|
+
["HorizontalRule", { include: [PandocObjectFilters::V1_16::Element::Block] }],
|
37
|
+
["Table", :captions, :alignments, :widths, :headers, :rows, { include: [PandocObjectFilters::V1_16::Element::Block] }],
|
38
|
+
["Div", :attributes, :elements, { include: [PandocObjectFilters::V1_16::Element::Block, PandocObjectFilters::V1_16::Element::Enum], conversions: { attributes: PandocObjectFilters::V1_16::Element::Attr } }],
|
39
|
+
["Null", { include: [PandocObjectFilters::V1_16::Element::Block] }],
|
40
|
+
["Str", :value, { include: [PandocObjectFilters::V1_16::Element::Inline] }],
|
41
|
+
["Emph", :elements, { include: [PandocObjectFilters::V1_16::Element::Inline, PandocObjectFilters::V1_16::Element::Enum] }],
|
42
|
+
["Strong", :elements, { include: [PandocObjectFilters::V1_16::Element::Inline, PandocObjectFilters::V1_16::Element::Enum] }],
|
43
|
+
["Strikeout", :elements, { include: [PandocObjectFilters::V1_16::Element::Inline, PandocObjectFilters::V1_16::Element::Enum] }],
|
44
|
+
["Superscript", :elements, { include: [PandocObjectFilters::V1_16::Element::Inline, PandocObjectFilters::V1_16::Element::Enum] }],
|
45
|
+
["Subscript", :elements, { include: [PandocObjectFilters::V1_16::Element::Inline, PandocObjectFilters::V1_16::Element::Enum] }],
|
46
|
+
["SmallCaps", :elements, { include: [PandocObjectFilters::V1_16::Element::Inline, PandocObjectFilters::V1_16::Element::Enum] }],
|
47
|
+
["Quoted", :type, :elements, { include: [PandocObjectFilters::V1_16::Element::Inline, PandocObjectFilters::V1_16::Element::Enum] }],
|
48
|
+
["Cite", :citations, :elements, { include: [PandocObjectFilters::V1_16::Element::Inline, PandocObjectFilters::V1_16::Element::Enum] }],
|
49
|
+
["Code", :attributes, :value, { include: [PandocObjectFilters::V1_16::Element::Inline], conversions: { attributes: PandocObjectFilters::V1_16::Element::Attr } }],
|
50
|
+
["Space", { include: [PandocObjectFilters::V1_16::Element::Inline] }],
|
51
|
+
["SoftBreak", { include: [PandocObjectFilters::V1_16::Element::Inline] }],
|
52
|
+
["LineBreak", { include: [PandocObjectFilters::V1_16::Element::Inline] }],
|
53
|
+
["Math", :type, :value, { include: [PandocObjectFilters::V1_16::Element::Inline] }],
|
54
|
+
["RawInline", :format, :value, { include: [PandocObjectFilters::V1_16::Element::Inline] }],
|
55
|
+
["Link", :attributes, :elements, :target, { include: [PandocObjectFilters::V1_16::Element::Inline, PandocObjectFilters::V1_16::Element::Enum], conversions: { attributes: PandocObjectFilters::V1_16::Element::Attr, target: PandocObjectFilters::V1_16::Element::Target } }],
|
56
|
+
["Image", :attributes, :elements, :target, { include: [PandocObjectFilters::V1_16::Element::Inline, PandocObjectFilters::V1_16::Element::Enum], conversions: { attributes: PandocObjectFilters::V1_16::Element::Attr, target: PandocObjectFilters::V1_16::Element::Target } }],
|
57
|
+
["Note", :elements, { include: [PandocObjectFilters::V1_16::Element::Inline, PandocObjectFilters::V1_16::Element::Enum] }],
|
58
|
+
["Span", :attributes, :elements, { include: [PandocObjectFilters::V1_16::Element::Inline, PandocObjectFilters::V1_16::Element::Enum], conversions: { attributes: PandocObjectFilters::V1_16::Element::Attr } }]
|
59
|
+
# rubocop:enable Metrics/LineLength
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require "pandoc_object_filters"
|
2
|
+
|
3
|
+
module PandocObjectFilters
|
4
|
+
module V1_16
|
5
|
+
module Element
|
6
|
+
class Attr < PandocObjectFilters::V1_16::Element::Base
|
7
|
+
module Behavior
|
8
|
+
def self.included(other)
|
9
|
+
other.contents_attr :identifier, 0
|
10
|
+
other.contents_attr :classes, 1
|
11
|
+
other.contents_attr :key_values, 2
|
12
|
+
other.extend ClassMethods
|
13
|
+
end
|
14
|
+
|
15
|
+
module ClassMethods
|
16
|
+
def build(options = {})
|
17
|
+
id = options.fetch(:identifier, "")
|
18
|
+
classes = options.fetch(:classes, [])
|
19
|
+
key_values = options.fetch(:key_values, [])
|
20
|
+
|
21
|
+
key_values = key_values.to_a if key_values.is_a?(Hash)
|
22
|
+
|
23
|
+
new([id, classes, key_values])
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def [](key)
|
28
|
+
# NOTE: While this pseudo Hash implementations are inefficient, they
|
29
|
+
# guarantee any changes to key_values will be honored, which would be
|
30
|
+
# difficult if the key_values were cached in a Hash
|
31
|
+
result = key_values.find { |pair| pair.first == key } || []
|
32
|
+
result[1]
|
33
|
+
end
|
34
|
+
|
35
|
+
def []=(key, value)
|
36
|
+
found = key_values.find { |pair| pair.first == key }
|
37
|
+
|
38
|
+
if found
|
39
|
+
found[1] = value
|
40
|
+
else
|
41
|
+
key_values << [key, value]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def include?(key)
|
46
|
+
!!key_values.find { |pair| pair.first == key }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
include Behavior
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "pandoc_object_filters"
|
2
|
+
|
3
|
+
module PandocObjectFilters
|
4
|
+
module V1_16
|
5
|
+
module Element
|
6
|
+
class Base
|
7
|
+
attr_accessor :contents
|
8
|
+
|
9
|
+
def self.contents_attr(name, index = nil)
|
10
|
+
if index
|
11
|
+
define_method(name) { contents[index] }
|
12
|
+
define_method("#{name}=") { |value| contents[index] = value }
|
13
|
+
else
|
14
|
+
define_method(name) { contents }
|
15
|
+
define_method("#{name}=") { |value| @contents = value }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(contents = [])
|
20
|
+
@contents = contents
|
21
|
+
convert_contents if respond_to?(:convert_contents, true)
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_ast
|
25
|
+
PandocObjectFilters::Element.to_ast(contents)
|
26
|
+
end
|
27
|
+
|
28
|
+
def inspect
|
29
|
+
to_ast.inspect
|
30
|
+
end
|
31
|
+
|
32
|
+
def ==(other)
|
33
|
+
self.class == other.class && contents == other.contents
|
34
|
+
end
|
35
|
+
|
36
|
+
def walk(&block)
|
37
|
+
PandocObjectFilters::Element.walk(self, &block)
|
38
|
+
end
|
39
|
+
|
40
|
+
def walk!(&block)
|
41
|
+
PandocObjectFilters::Element.walk!(self, &block)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "pandoc_object_filters"
|
2
|
+
|
3
|
+
module PandocObjectFilters
|
4
|
+
module V1_16
|
5
|
+
module Element
|
6
|
+
class BaseElement < PandocObjectFilters::V1_16::Element::Base
|
7
|
+
module Behavior
|
8
|
+
def to_ast
|
9
|
+
{ "t" => element_name, "c" => PandocObjectFilters::Element.to_ast(contents) }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
include Behavior
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "pandoc_object_filters"
|
2
|
+
|
3
|
+
module PandocObjectFilters
|
4
|
+
module V1_16
|
5
|
+
module Element
|
6
|
+
class Document < PandocObjectFilters::V1_16::Element::Base
|
7
|
+
module Behavior
|
8
|
+
attr_reader :meta
|
9
|
+
|
10
|
+
def initialize(ast)
|
11
|
+
object = PandocObjectFilters::Element.to_object(ast)
|
12
|
+
@meta = object[0]
|
13
|
+
@contents = object[1]
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_ast
|
17
|
+
[meta.to_ast, PandocObjectFilters::Element.to_ast(contents)]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
include Behavior
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "pandoc_object_filters"
|
2
|
+
|
3
|
+
module PandocObjectFilters
|
4
|
+
module V1_16
|
5
|
+
module Element
|
6
|
+
class Meta < PandocObjectFilters::V1_16::Element::Base
|
7
|
+
include PandocObjectFilters::V1_16::Element::Enum
|
8
|
+
alias elements contents
|
9
|
+
|
10
|
+
def initialize(contents = {})
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_ast
|
15
|
+
{ "unMeta" => PandocObjectFilters::Element.to_ast(contents) }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "pandoc_object_filters"
|
2
|
+
|
3
|
+
module PandocObjectFilters
|
4
|
+
module V1_16
|
5
|
+
module Element
|
6
|
+
class Target < PandocObjectFilters::V1_16::Element::Base
|
7
|
+
module Behavior
|
8
|
+
def self.included(other)
|
9
|
+
other.contents_attr :url, 0
|
10
|
+
other.contents_attr :title, 1
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
include Behavior
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require "pandoc_object_filters"
|
2
|
+
|
3
|
+
module PandocObjectFilters
|
4
|
+
module V1_17
|
5
|
+
module Element
|
6
|
+
extend PandocObjectFilters::ElementHelper
|
7
|
+
self.version = PandocObjectFilters::V1_17
|
8
|
+
|
9
|
+
autoload_elements :Attr,
|
10
|
+
:Base,
|
11
|
+
:BaseElement,
|
12
|
+
:Block,
|
13
|
+
:Document,
|
14
|
+
:Enum,
|
15
|
+
:Inline,
|
16
|
+
:Leaf,
|
17
|
+
:Meta,
|
18
|
+
:MetaValue,
|
19
|
+
:Target
|
20
|
+
|
21
|
+
# rubocop:disable Metrics/LineLength
|
22
|
+
define_elements ["MetaMap", :elements, { include: [PandocObjectFilters::V1_17::Element::MetaValue, PandocObjectFilters::V1_17::Element::Enum] }],
|
23
|
+
["MetaList", :elements, { include: [PandocObjectFilters::V1_17::Element::MetaValue, PandocObjectFilters::V1_17::Element::Enum] }],
|
24
|
+
["MetaBool", :value, { include: [PandocObjectFilters::V1_17::Element::MetaValue] }],
|
25
|
+
["MetaString", :value, { include: [PandocObjectFilters::V1_17::Element::MetaValue] }],
|
26
|
+
["MetaInlines", :elements, { include: [PandocObjectFilters::V1_17::Element::MetaValue, PandocObjectFilters::V1_17::Element::Enum] }],
|
27
|
+
["MetaBlocks", :elements, { include: [PandocObjectFilters::V1_17::Element::MetaValue, PandocObjectFilters::V1_17::Element::Enum] }],
|
28
|
+
["Plain", :elements, { include: [PandocObjectFilters::V1_17::Element::Block, PandocObjectFilters::V1_17::Element::Enum] }],
|
29
|
+
["Para", :elements, { include: [PandocObjectFilters::V1_17::Element::Block, PandocObjectFilters::V1_17::Element::Enum] }],
|
30
|
+
["CodeBlock", :attributes, :value, { include: [PandocObjectFilters::V1_17::Element::Block], conversions: { attributes: PandocObjectFilters::V1_17::Element::Attr } }],
|
31
|
+
["RawBlock", :format, :value, { include: [PandocObjectFilters::V1_17::Element::Block] }],
|
32
|
+
["BlockQuote", :elements, { include: [PandocObjectFilters::V1_17::Element::Block, PandocObjectFilters::V1_17::Element::Enum] }],
|
33
|
+
["OrderedList", :attributes, :elements, { include: [PandocObjectFilters::V1_17::Element::Block, PandocObjectFilters::V1_17::Element::Enum] }],
|
34
|
+
["BulletList", :elements, { include: [PandocObjectFilters::V1_17::Element::Block, PandocObjectFilters::V1_17::Element::Enum] }],
|
35
|
+
["DefinitionList", :elements, { include: [PandocObjectFilters::V1_17::Element::Block, PandocObjectFilters::V1_17::Element::Enum] }],
|
36
|
+
["Header", :level, :attributes, :elements, { include: [PandocObjectFilters::V1_17::Element::Block, PandocObjectFilters::V1_17::Element::Enum], conversions: { attributes: PandocObjectFilters::V1_17::Element::Attr } }],
|
37
|
+
["HorizontalRule", { include: [PandocObjectFilters::V1_17::Element::Block, PandocObjectFilters::V1_17::Element::Leaf] }],
|
38
|
+
["Table", :captions, :alignments, :widths, :headers, :rows, { include: [PandocObjectFilters::V1_17::Element::Block] }],
|
39
|
+
["Div", :attributes, :elements, { include: [PandocObjectFilters::V1_17::Element::Block, PandocObjectFilters::V1_17::Element::Enum], conversions: { attributes: PandocObjectFilters::V1_17::Element::Attr } }],
|
40
|
+
["Null", { include: [PandocObjectFilters::V1_17::Element::Block, PandocObjectFilters::V1_17::Element::Leaf] }],
|
41
|
+
["Str", :value, { include: [PandocObjectFilters::V1_17::Element::Inline] }],
|
42
|
+
["Emph", :elements, { include: [PandocObjectFilters::V1_17::Element::Inline, PandocObjectFilters::V1_17::Element::Enum] }],
|
43
|
+
["Strong", :elements, { include: [PandocObjectFilters::V1_17::Element::Inline, PandocObjectFilters::V1_17::Element::Enum] }],
|
44
|
+
["Strikeout", :elements, { include: [PandocObjectFilters::V1_17::Element::Inline, PandocObjectFilters::V1_17::Element::Enum] }],
|
45
|
+
["Superscript", :elements, { include: [PandocObjectFilters::V1_17::Element::Inline, PandocObjectFilters::V1_17::Element::Enum] }],
|
46
|
+
["Subscript", :elements, { include: [PandocObjectFilters::V1_17::Element::Inline, PandocObjectFilters::V1_17::Element::Enum] }],
|
47
|
+
["SmallCaps", :elements, { include: [PandocObjectFilters::V1_17::Element::Inline, PandocObjectFilters::V1_17::Element::Enum] }],
|
48
|
+
["Quoted", :type, :elements, { include: [PandocObjectFilters::V1_17::Element::Inline, PandocObjectFilters::V1_17::Element::Enum] }],
|
49
|
+
["Cite", :citations, :elements, { include: [PandocObjectFilters::V1_17::Element::Inline, PandocObjectFilters::V1_17::Element::Enum] }],
|
50
|
+
["Code", :attributes, :value, { include: [PandocObjectFilters::V1_17::Element::Inline], conversions: { attributes: PandocObjectFilters::V1_17::Element::Attr } }],
|
51
|
+
["Space", { include: [PandocObjectFilters::V1_17::Element::Inline, PandocObjectFilters::V1_17::Element::Leaf] }],
|
52
|
+
["SoftBreak", { include: [PandocObjectFilters::V1_17::Element::Inline, PandocObjectFilters::V1_17::Element::Leaf] }],
|
53
|
+
["LineBreak", { include: [PandocObjectFilters::V1_17::Element::Inline, PandocObjectFilters::V1_17::Element::Leaf] }],
|
54
|
+
["Math", :type, :value, { include: [PandocObjectFilters::V1_17::Element::Inline] }],
|
55
|
+
["RawInline", :format, :value, { include: [PandocObjectFilters::V1_17::Element::Inline] }],
|
56
|
+
["Link", :attributes, :elements, :target, { include: [PandocObjectFilters::V1_17::Element::Inline, PandocObjectFilters::V1_17::Element::Enum], conversions: { attributes: PandocObjectFilters::V1_17::Element::Attr, target: PandocObjectFilters::V1_17::Element::Target } }],
|
57
|
+
["Image", :attributes, :elements, :target, { include: [PandocObjectFilters::V1_17::Element::Inline, PandocObjectFilters::V1_17::Element::Enum], conversions: { attributes: PandocObjectFilters::V1_17::Element::Attr, target: PandocObjectFilters::V1_17::Element::Target } }],
|
58
|
+
["Note", :elements, { include: [PandocObjectFilters::V1_17::Element::Inline, PandocObjectFilters::V1_17::Element::Enum] }],
|
59
|
+
["Span", :attributes, :elements, { include: [PandocObjectFilters::V1_17::Element::Inline, PandocObjectFilters::V1_17::Element::Enum], conversions: { attributes: PandocObjectFilters::V1_17::Element::Attr } }]
|
60
|
+
# rubocop:enable Metrics/LineLength
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "pandoc_object_filters"
|
2
|
+
|
3
|
+
module PandocObjectFilters
|
4
|
+
module V1_17
|
5
|
+
module Element
|
6
|
+
class Document < PandocObjectFilters::V1_17::Element::Base
|
7
|
+
include PandocObjectFilters::V1_16::Element::Document::Behavior
|
8
|
+
attr_reader :pandoc_api_version
|
9
|
+
|
10
|
+
def initialize(ast)
|
11
|
+
object = PandocObjectFilters::Element.to_object(ast)
|
12
|
+
meta_object = PandocObjectFilters::Element.to_object(object["meta"])
|
13
|
+
@meta = PandocObjectFilters::Element::Meta.new(meta_object)
|
14
|
+
@contents = object["blocks"]
|
15
|
+
@pandoc_api_version = object["pandoc-api-version"]
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_ast
|
19
|
+
{
|
20
|
+
"blocks" => PandocObjectFilters::Element.to_ast(contents),
|
21
|
+
"meta" => PandocObjectFilters::Element.to_ast(meta),
|
22
|
+
"pandoc-api-version" => pandoc_api_version
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "pandoc_object_filters"
|
2
|
+
|
3
|
+
module PandocObjectFilters
|
4
|
+
module V1_17
|
5
|
+
module Element
|
6
|
+
class Meta < PandocObjectFilters::V1_17::Element::Base
|
7
|
+
include PandocObjectFilters::V1_17::Element::Enum
|
8
|
+
alias elements contents
|
9
|
+
|
10
|
+
def initialize(contents = {})
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_ast
|
15
|
+
PandocObjectFilters::Element.to_ast(contents)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pandoc_object_filters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Virata-Stone
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -96,18 +96,33 @@ files:
|
|
96
96
|
- examples/metavars-sample.md
|
97
97
|
- examples/metavars.rb
|
98
98
|
- lib/pandoc_object_filters.rb
|
99
|
-
- lib/pandoc_object_filters/
|
100
|
-
- lib/pandoc_object_filters/element/attr.rb
|
101
|
-
- lib/pandoc_object_filters/element/base.rb
|
102
|
-
- lib/pandoc_object_filters/element/base_element.rb
|
103
|
-
- lib/pandoc_object_filters/element/block.rb
|
104
|
-
- lib/pandoc_object_filters/element/document.rb
|
105
|
-
- lib/pandoc_object_filters/element/enum.rb
|
106
|
-
- lib/pandoc_object_filters/element/inline.rb
|
107
|
-
- lib/pandoc_object_filters/element/meta.rb
|
108
|
-
- lib/pandoc_object_filters/element/meta_value.rb
|
109
|
-
- lib/pandoc_object_filters/element/target.rb
|
99
|
+
- lib/pandoc_object_filters/element_helper.rb
|
110
100
|
- lib/pandoc_object_filters/filter.rb
|
101
|
+
- lib/pandoc_object_filters/v1_16.rb
|
102
|
+
- lib/pandoc_object_filters/v1_16/element.rb
|
103
|
+
- lib/pandoc_object_filters/v1_16/element/attr.rb
|
104
|
+
- lib/pandoc_object_filters/v1_16/element/base.rb
|
105
|
+
- lib/pandoc_object_filters/v1_16/element/base_element.rb
|
106
|
+
- lib/pandoc_object_filters/v1_16/element/block.rb
|
107
|
+
- lib/pandoc_object_filters/v1_16/element/document.rb
|
108
|
+
- lib/pandoc_object_filters/v1_16/element/enum.rb
|
109
|
+
- lib/pandoc_object_filters/v1_16/element/inline.rb
|
110
|
+
- lib/pandoc_object_filters/v1_16/element/meta.rb
|
111
|
+
- lib/pandoc_object_filters/v1_16/element/meta_value.rb
|
112
|
+
- lib/pandoc_object_filters/v1_16/element/target.rb
|
113
|
+
- lib/pandoc_object_filters/v1_17.rb
|
114
|
+
- lib/pandoc_object_filters/v1_17/element.rb
|
115
|
+
- lib/pandoc_object_filters/v1_17/element/attr.rb
|
116
|
+
- lib/pandoc_object_filters/v1_17/element/base.rb
|
117
|
+
- lib/pandoc_object_filters/v1_17/element/base_element.rb
|
118
|
+
- lib/pandoc_object_filters/v1_17/element/block.rb
|
119
|
+
- lib/pandoc_object_filters/v1_17/element/document.rb
|
120
|
+
- lib/pandoc_object_filters/v1_17/element/enum.rb
|
121
|
+
- lib/pandoc_object_filters/v1_17/element/inline.rb
|
122
|
+
- lib/pandoc_object_filters/v1_17/element/leaf.rb
|
123
|
+
- lib/pandoc_object_filters/v1_17/element/meta.rb
|
124
|
+
- lib/pandoc_object_filters/v1_17/element/meta_value.rb
|
125
|
+
- lib/pandoc_object_filters/v1_17/element/target.rb
|
111
126
|
- lib/pandoc_object_filters/version.rb
|
112
127
|
- lib/pandoc_object_filters/walker.rb
|
113
128
|
- pandoc_object_filters.gemspec
|
@@ -131,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
146
|
version: '0'
|
132
147
|
requirements: []
|
133
148
|
rubyforge_project:
|
134
|
-
rubygems_version: 2.
|
149
|
+
rubygems_version: 2.5.1
|
135
150
|
signing_key:
|
136
151
|
specification_version: 4
|
137
152
|
summary: A library for object based pandoc filters.
|
@@ -1,135 +0,0 @@
|
|
1
|
-
require "pandoc_object_filters"
|
2
|
-
|
3
|
-
module PandocObjectFilters
|
4
|
-
module Element
|
5
|
-
autoload :Attr, "pandoc_object_filters/element/attr"
|
6
|
-
autoload :Base, "pandoc_object_filters/element/base"
|
7
|
-
autoload :BaseElement, "pandoc_object_filters/element/base_element"
|
8
|
-
autoload :Block, "pandoc_object_filters/element/block"
|
9
|
-
autoload :Document, "pandoc_object_filters/element/document"
|
10
|
-
autoload :Enum, "pandoc_object_filters/element/enum"
|
11
|
-
autoload :Inline, "pandoc_object_filters/element/inline"
|
12
|
-
autoload :Meta, "pandoc_object_filters/element/meta"
|
13
|
-
autoload :MetaValue, "pandoc_object_filters/element/meta_value"
|
14
|
-
autoload :Target, "pandoc_object_filters/element/target"
|
15
|
-
|
16
|
-
def self.to_ast(object)
|
17
|
-
if object.respond_to?(:to_ast)
|
18
|
-
object.to_ast
|
19
|
-
elsif object.is_a?(Array)
|
20
|
-
object.map { |x| to_ast(x) }
|
21
|
-
elsif object.is_a?(Hash)
|
22
|
-
result = {}
|
23
|
-
object.each { |key, value| result[key] = to_ast(value) }
|
24
|
-
result
|
25
|
-
else
|
26
|
-
object
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.to_object(object)
|
31
|
-
if object.is_a?(Array)
|
32
|
-
object.map { |x| to_object(x) }
|
33
|
-
elsif object.is_a?(Hash) && object.include?("t") && object.include?("c")
|
34
|
-
raise "Unknown type: #{object['t']}" unless PandocObjectFilters::Element.const_defined?(object["t"])
|
35
|
-
type = PandocObjectFilters::Element.const_get(object["t"])
|
36
|
-
raise "Invalid type: #{object['t']}" unless type < PandocObjectFilters::Element::BaseElement
|
37
|
-
type.new(to_object(object["c"]))
|
38
|
-
elsif object.is_a?(Hash) && object.include?("unMeta")
|
39
|
-
PandocObjectFilters::Element::Meta.new(to_object(object["unMeta"]))
|
40
|
-
elsif object.is_a?(Hash)
|
41
|
-
result = {}
|
42
|
-
object.each { |key, value| result[key] = to_object(value) }
|
43
|
-
result
|
44
|
-
else
|
45
|
-
object
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def self.walk(object, &block)
|
50
|
-
PandocObjectFilters::Walker.new(object, &block).walk
|
51
|
-
end
|
52
|
-
|
53
|
-
def self.walk!(object, &block)
|
54
|
-
PandocObjectFilters::Walker.new(object, &block).walk!
|
55
|
-
end
|
56
|
-
|
57
|
-
# rubocop:disable Metrics/LineLength
|
58
|
-
[["MetaMap", :elements, { include: [PandocObjectFilters::Element::MetaValue, PandocObjectFilters::Element::Enum] }],
|
59
|
-
["MetaList", :elements, { include: [PandocObjectFilters::Element::MetaValue, PandocObjectFilters::Element::Enum] }],
|
60
|
-
["MetaBool", :value, { include: [PandocObjectFilters::Element::MetaValue] }],
|
61
|
-
["MetaString", :value, { include: [PandocObjectFilters::Element::MetaValue] }],
|
62
|
-
["MetaInlines", :elements, { include: [PandocObjectFilters::Element::MetaValue, PandocObjectFilters::Element::Enum] }],
|
63
|
-
["MetaBlocks", :elements, { include: [PandocObjectFilters::Element::MetaValue, PandocObjectFilters::Element::Enum] }],
|
64
|
-
["Plain", :elements, { include: [PandocObjectFilters::Element::Block, PandocObjectFilters::Element::Enum] }],
|
65
|
-
["Para", :elements, { include: [PandocObjectFilters::Element::Block, PandocObjectFilters::Element::Enum] }],
|
66
|
-
["CodeBlock", :attributes, :value, { include: [PandocObjectFilters::Element::Block], conversions: { attributes: PandocObjectFilters::Element::Attr } }],
|
67
|
-
["RawBlock", :format, :value, { include: [PandocObjectFilters::Element::Block] }],
|
68
|
-
["BlockQuote", :elements, { include: [PandocObjectFilters::Element::Block, PandocObjectFilters::Element::Enum] }],
|
69
|
-
["OrderedList", :attributes, :elements, { include: [PandocObjectFilters::Element::Block, PandocObjectFilters::Element::Enum] }],
|
70
|
-
["BulletList", :elements, { include: [PandocObjectFilters::Element::Block, PandocObjectFilters::Element::Enum] }],
|
71
|
-
["DefinitionList", :elements, { include: [PandocObjectFilters::Element::Block, PandocObjectFilters::Element::Enum] }],
|
72
|
-
["Header", :level, :attributes, :elements, { include: [PandocObjectFilters::Element::Block, PandocObjectFilters::Element::Enum], conversions: { attributes: PandocObjectFilters::Element::Attr } }],
|
73
|
-
["HorizontalRule", { include: [PandocObjectFilters::Element::Block] }],
|
74
|
-
["Table", :captions, :alignments, :widths, :headers, :rows, { include: [PandocObjectFilters::Element::Block] }],
|
75
|
-
["Div", :attributes, :elements, { include: [PandocObjectFilters::Element::Block, PandocObjectFilters::Element::Enum], conversions: { attributes: PandocObjectFilters::Element::Attr } }],
|
76
|
-
["Null", { include: [PandocObjectFilters::Element::Block] }],
|
77
|
-
["Str", :value, { include: [PandocObjectFilters::Element::Inline] }],
|
78
|
-
["Emph", :elements, { include: [PandocObjectFilters::Element::Inline, PandocObjectFilters::Element::Enum] }],
|
79
|
-
["Strong", :elements, { include: [PandocObjectFilters::Element::Inline, PandocObjectFilters::Element::Enum] }],
|
80
|
-
["Strikeout", :elements, { include: [PandocObjectFilters::Element::Inline, PandocObjectFilters::Element::Enum] }],
|
81
|
-
["Superscript", :elements, { include: [PandocObjectFilters::Element::Inline, PandocObjectFilters::Element::Enum] }],
|
82
|
-
["Subscript", :elements, { include: [PandocObjectFilters::Element::Inline, PandocObjectFilters::Element::Enum] }],
|
83
|
-
["SmallCaps", :elements, { include: [PandocObjectFilters::Element::Inline, PandocObjectFilters::Element::Enum] }],
|
84
|
-
["Quoted", :type, :elements, { include: [PandocObjectFilters::Element::Inline, PandocObjectFilters::Element::Enum] }],
|
85
|
-
["Cite", :citations, :elements, { include: [PandocObjectFilters::Element::Inline, PandocObjectFilters::Element::Enum] }],
|
86
|
-
["Code", :attributes, :value, { include: [PandocObjectFilters::Element::Inline], conversions: { attributes: PandocObjectFilters::Element::Attr } }],
|
87
|
-
["Space", { include: [PandocObjectFilters::Element::Inline] }],
|
88
|
-
["SoftBreak", { include: [PandocObjectFilters::Element::Inline] }],
|
89
|
-
["LineBreak", { include: [PandocObjectFilters::Element::Inline] }],
|
90
|
-
["Math", :type, :value, { include: [PandocObjectFilters::Element::Inline] }],
|
91
|
-
["RawInline", :format, :value, { include: [PandocObjectFilters::Element::Inline] }],
|
92
|
-
["Link", :attributes, :elements, :target, { include: [PandocObjectFilters::Element::Inline, PandocObjectFilters::Element::Enum], conversions: { attributes: PandocObjectFilters::Element::Attr, target: PandocObjectFilters::Element::Target } }],
|
93
|
-
["Image", :attributes, :elements, :target, { include: [PandocObjectFilters::Element::Inline, PandocObjectFilters::Element::Enum], conversions: { attributes: PandocObjectFilters::Element::Attr, target: PandocObjectFilters::Element::Target } }],
|
94
|
-
["Note", :elements, { include: [PandocObjectFilters::Element::Inline, PandocObjectFilters::Element::Enum] }],
|
95
|
-
["Span", :attributes, :elements, { include: [PandocObjectFilters::Element::Inline, PandocObjectFilters::Element::Enum], conversions: { attributes: PandocObjectFilters::Element::Attr } }]].each do |name, *params|
|
96
|
-
# rubocop:enable Metrics/LineLength
|
97
|
-
name.freeze
|
98
|
-
|
99
|
-
options =
|
100
|
-
if params.last.is_a?(Hash)
|
101
|
-
params.pop
|
102
|
-
else
|
103
|
-
{}
|
104
|
-
end
|
105
|
-
|
106
|
-
const_set(name, Class.new(PandocObjectFilters::Element::BaseElement) do
|
107
|
-
(options[:include] || []).each { |mod| include mod }
|
108
|
-
|
109
|
-
if params.size == 1
|
110
|
-
contents_attr params.first
|
111
|
-
else
|
112
|
-
params.each_with_index { |param, index| contents_attr param, index }
|
113
|
-
end
|
114
|
-
|
115
|
-
define_method(:element_name) { name }
|
116
|
-
|
117
|
-
if options[:conversions]
|
118
|
-
private
|
119
|
-
|
120
|
-
define_method(:convert_contents) do
|
121
|
-
@contents = @contents.map.with_index do |x, index|
|
122
|
-
convert_to_type = options[:conversions][params[index]]
|
123
|
-
|
124
|
-
if convert_to_type && !x.is_a?(convert_to_type)
|
125
|
-
convert_to_type.new(x)
|
126
|
-
else
|
127
|
-
x
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end)
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require "pandoc_object_filters"
|
2
|
-
|
3
|
-
module PandocObjectFilters
|
4
|
-
module Element
|
5
|
-
class Attr < PandocObjectFilters::Element::Base
|
6
|
-
contents_attr :identifier, 0
|
7
|
-
contents_attr :classes, 1
|
8
|
-
contents_attr :key_values, 2
|
9
|
-
|
10
|
-
def self.build(options = {})
|
11
|
-
id = options.fetch(:identifier, "")
|
12
|
-
classes = options.fetch(:classes, [])
|
13
|
-
key_values = options.fetch(:key_values, [])
|
14
|
-
|
15
|
-
key_values = key_values.to_a if key_values.is_a?(Hash)
|
16
|
-
|
17
|
-
new([id, classes, key_values])
|
18
|
-
end
|
19
|
-
|
20
|
-
def [](key)
|
21
|
-
# NOTE: While this pseudo Hash implementations are inefficient, they
|
22
|
-
# guarantee any changes to key_values will be honored, which would be
|
23
|
-
# difficult if the key_values were cached in a Hash
|
24
|
-
result = key_values.find { |pair| pair.first == key } || []
|
25
|
-
result[1]
|
26
|
-
end
|
27
|
-
|
28
|
-
def []=(key, value)
|
29
|
-
found = key_values.find { |pair| pair.first == key }
|
30
|
-
|
31
|
-
if found
|
32
|
-
found[1] = value
|
33
|
-
else
|
34
|
-
key_values << [key, value]
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def include?(key)
|
39
|
-
!!key_values.find { |pair| pair.first == key }
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
require "pandoc_object_filters"
|
2
|
-
|
3
|
-
module PandocObjectFilters
|
4
|
-
module Element
|
5
|
-
class Base
|
6
|
-
attr_accessor :contents
|
7
|
-
|
8
|
-
def self.contents_attr(name, index = nil)
|
9
|
-
if index
|
10
|
-
define_method(name) { contents[index] }
|
11
|
-
define_method("#{name}=") { |value| contents[index] = value }
|
12
|
-
else
|
13
|
-
define_method(name) { contents }
|
14
|
-
define_method("#{name}=") { |value| @contents = value }
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def initialize(contents = [])
|
19
|
-
@contents = contents
|
20
|
-
convert_contents if respond_to?(:convert_contents, true)
|
21
|
-
end
|
22
|
-
|
23
|
-
def to_ast
|
24
|
-
PandocObjectFilters::Element.to_ast(contents)
|
25
|
-
end
|
26
|
-
|
27
|
-
def inspect
|
28
|
-
to_ast.inspect
|
29
|
-
end
|
30
|
-
|
31
|
-
def ==(other)
|
32
|
-
self.class == other.class && contents == other.contents
|
33
|
-
end
|
34
|
-
|
35
|
-
def walk(&block)
|
36
|
-
PandocObjectFilters::Element.walk(self, &block)
|
37
|
-
end
|
38
|
-
|
39
|
-
def walk!(&block)
|
40
|
-
PandocObjectFilters::Element.walk!(self, &block)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require "pandoc_object_filters"
|
2
|
-
|
3
|
-
module PandocObjectFilters
|
4
|
-
module Element
|
5
|
-
class Document < PandocObjectFilters::Element::Base
|
6
|
-
attr_reader :meta
|
7
|
-
|
8
|
-
def initialize(ast)
|
9
|
-
object = PandocObjectFilters::Element.to_object(ast)
|
10
|
-
@meta = object[0]
|
11
|
-
@contents = object[1]
|
12
|
-
end
|
13
|
-
|
14
|
-
def to_ast
|
15
|
-
[meta.to_ast, PandocObjectFilters::Element.to_ast(contents)]
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require "pandoc_object_filters"
|
2
|
-
|
3
|
-
module PandocObjectFilters
|
4
|
-
module Element
|
5
|
-
class Meta < PandocObjectFilters::Element::Base
|
6
|
-
include PandocObjectFilters::Element::Enum
|
7
|
-
alias elements contents
|
8
|
-
|
9
|
-
def initialize(contents = {})
|
10
|
-
super
|
11
|
-
end
|
12
|
-
|
13
|
-
def to_ast
|
14
|
-
{ "unMeta" => PandocObjectFilters::Element.to_ast(contents) }
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|