paru 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/paru/error.rb +4 -0
- data/lib/paru/filter.rb +77 -68
- data/lib/paru/filter/alignment.rb +12 -0
- data/lib/paru/filter/ast_manipulation.rb +43 -0
- data/lib/paru/filter/attr.rb +40 -0
- data/lib/paru/filter/block.rb +11 -0
- data/lib/paru/filter/block_quote.rb +11 -0
- data/lib/paru/filter/bullet_list.rb +8 -0
- data/lib/paru/filter/citation.rb +29 -0
- data/lib/paru/filter/cite.rb +25 -0
- data/lib/paru/filter/code.rb +30 -0
- data/lib/paru/filter/code_block.rb +26 -0
- data/lib/paru/filter/definition_list.rb +19 -0
- data/lib/paru/filter/definition_list_item.rb +22 -0
- data/lib/paru/filter/div.rb +25 -0
- data/lib/paru/filter/document.rb +47 -0
- data/lib/paru/filter/emph.rb +8 -0
- data/lib/paru/filter/header.rb +28 -0
- data/lib/paru/filter/horizontal_rule.rb +11 -0
- data/lib/paru/filter/image.rb +9 -0
- data/lib/paru/filter/inline.rb +19 -0
- data/lib/paru/filter/line_break.rb +16 -0
- data/lib/paru/filter/link.rb +27 -0
- data/lib/paru/filter/list.rb +22 -0
- data/lib/paru/filter/list_attributes.rb +24 -0
- data/lib/paru/filter/markdown.rb +52 -0
- data/lib/paru/filter/math.rb +51 -0
- data/lib/paru/filter/meta.rb +24 -0
- data/lib/paru/filter/meta_blocks.rb +13 -0
- data/lib/paru/filter/meta_bool.rb +9 -0
- data/lib/paru/filter/meta_inlines.rb +13 -0
- data/lib/paru/filter/meta_list.rb +9 -0
- data/lib/paru/filter/meta_map.rb +37 -0
- data/lib/paru/filter/meta_string.rb +9 -0
- data/lib/paru/filter/meta_value.rb +20 -0
- data/lib/paru/filter/node.rb +149 -0
- data/lib/paru/filter/note.rb +17 -0
- data/lib/paru/filter/null.rb +11 -0
- data/lib/paru/filter/ordered_list.rb +23 -0
- data/lib/paru/filter/para.rb +16 -0
- data/lib/paru/filter/plain.rb +15 -0
- data/lib/paru/filter/quoted.rb +23 -0
- data/lib/paru/filter/raw_block.rb +25 -0
- data/lib/paru/filter/raw_inline.rb +30 -0
- data/lib/paru/filter/small_caps.rb +9 -0
- data/lib/paru/filter/soft_break.rb +16 -0
- data/lib/paru/filter/space.rb +15 -0
- data/lib/paru/filter/span.rb +23 -0
- data/lib/paru/filter/str.rb +23 -0
- data/lib/paru/filter/strikeout.rb +9 -0
- data/lib/paru/filter/string.rb +9 -0
- data/lib/paru/filter/subscript.rb +9 -0
- data/lib/paru/filter/superscript.rb +9 -0
- data/lib/paru/filter/table.rb +34 -0
- data/lib/paru/filter/table_row.rb +18 -0
- data/lib/paru/filter/target.rb +19 -0
- data/lib/paru/pandoc_options.yaml +4 -2
- data/lib/paru/selector.rb +151 -0
- metadata +60 -4
@@ -0,0 +1,25 @@
|
|
1
|
+
module Paru
|
2
|
+
module PandocFilter
|
3
|
+
require_relative "./block"
|
4
|
+
require_relative "./attr"
|
5
|
+
|
6
|
+
class Div < Block
|
7
|
+
def initialize contents
|
8
|
+
@attr = Attr.new contents[0]
|
9
|
+
super contents[1]
|
10
|
+
end
|
11
|
+
|
12
|
+
def ast_contents
|
13
|
+
[
|
14
|
+
@attr.to_ast,
|
15
|
+
super
|
16
|
+
]
|
17
|
+
end
|
18
|
+
|
19
|
+
def has_block?
|
20
|
+
true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Paru
|
2
|
+
module PandocFilter
|
3
|
+
|
4
|
+
require 'json'
|
5
|
+
require_relative "./node"
|
6
|
+
require_relative "./plain"
|
7
|
+
require_relative "./meta"
|
8
|
+
|
9
|
+
class Document < Node
|
10
|
+
|
11
|
+
attr_reader :meta
|
12
|
+
|
13
|
+
def self.fragment node_list
|
14
|
+
meta = Hash.new
|
15
|
+
meta["unMeta"] = Hash.new
|
16
|
+
|
17
|
+
if node_list.any? {|n| n.is_block?}
|
18
|
+
new_doc = Document.new meta, []
|
19
|
+
new_doc.children = node_list
|
20
|
+
else
|
21
|
+
node = PandocFilter::Plain.new []
|
22
|
+
node.children = node_list
|
23
|
+
new_doc = Document.new meta, [node.to_ast]
|
24
|
+
end
|
25
|
+
|
26
|
+
new_doc
|
27
|
+
end
|
28
|
+
|
29
|
+
def initialize(meta, contents)
|
30
|
+
@meta = Meta.new meta
|
31
|
+
super contents
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_ast
|
35
|
+
[
|
36
|
+
@meta.to_ast,
|
37
|
+
ast_contents
|
38
|
+
]
|
39
|
+
end
|
40
|
+
|
41
|
+
def to_json
|
42
|
+
to_ast.to_json
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Paru
|
2
|
+
module PandocFilter
|
3
|
+
require_relative "./block"
|
4
|
+
require_relative "./attr"
|
5
|
+
|
6
|
+
class Header < Block
|
7
|
+
attr_accessor :level, :attr
|
8
|
+
|
9
|
+
def initialize contents
|
10
|
+
@level = contents[0]
|
11
|
+
@attr = Attr.new contents[1]
|
12
|
+
super contents[2], true
|
13
|
+
end
|
14
|
+
|
15
|
+
def ast_contents
|
16
|
+
[
|
17
|
+
@level,
|
18
|
+
@attr.to_ast,
|
19
|
+
super
|
20
|
+
]
|
21
|
+
end
|
22
|
+
|
23
|
+
def has_inline?
|
24
|
+
true
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Paru
|
2
|
+
module PandocFilter
|
3
|
+
|
4
|
+
require_relative "./inline"
|
5
|
+
require_relative "./attr"
|
6
|
+
require_relative "./target"
|
7
|
+
|
8
|
+
class Link < Inline
|
9
|
+
attr_accessor :attr, :target
|
10
|
+
|
11
|
+
def initialize contents
|
12
|
+
@attr = Attr.new contents[0]
|
13
|
+
super contents[1]
|
14
|
+
@target = Target.new contents[2]
|
15
|
+
end
|
16
|
+
|
17
|
+
def ast_contents
|
18
|
+
[
|
19
|
+
@attr.to_ast,
|
20
|
+
super,
|
21
|
+
@target.to_ast
|
22
|
+
]
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Paru
|
2
|
+
module PandocFilter
|
3
|
+
require_relative "./block"
|
4
|
+
|
5
|
+
class List < Block
|
6
|
+
def initialize contents
|
7
|
+
super []
|
8
|
+
contents.each do |item|
|
9
|
+
@children.push Block.new item
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def ast_contents
|
14
|
+
@children.map {|child| child.ast_contents}
|
15
|
+
end
|
16
|
+
|
17
|
+
def has_block?
|
18
|
+
true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Paru
|
2
|
+
module PandocFilter
|
3
|
+
class ListAttributes
|
4
|
+
|
5
|
+
STYLES = ["DefaultStyle", "Example", "Decimal", "LowerRoman", "UpperRoman", "LowerAlpha", "UpperAlpha"]
|
6
|
+
DELIMS = ["DefaultDelim", "Period", "OneParen", "TwoParens"]
|
7
|
+
|
8
|
+
attr_accessor :start, :number_style, :number_delim
|
9
|
+
def initialize attributes
|
10
|
+
@start = attributes[0]
|
11
|
+
@number_style = attributes[1]
|
12
|
+
@number_delim = attributes[2]
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_ast
|
16
|
+
[
|
17
|
+
@start,
|
18
|
+
@number_style,
|
19
|
+
@number_delim
|
20
|
+
]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Paru
|
2
|
+
module PandocFilter
|
3
|
+
module Markdown
|
4
|
+
|
5
|
+
require_relative "../pandoc"
|
6
|
+
require_relative "./document"
|
7
|
+
|
8
|
+
AST2MARKDOWN = Paru::Pandoc.new do
|
9
|
+
from "json"
|
10
|
+
to "markdown"
|
11
|
+
end
|
12
|
+
|
13
|
+
MARKDOWN2JSON = Paru::Pandoc.new do
|
14
|
+
from "markdown"
|
15
|
+
to "json"
|
16
|
+
end
|
17
|
+
|
18
|
+
def outer_markdown
|
19
|
+
temp_doc = PandocFilter::Document.fragment [self]
|
20
|
+
AST2MARKDOWN << temp_doc.to_json
|
21
|
+
end
|
22
|
+
|
23
|
+
def inner_markdown
|
24
|
+
temp_doc = PandocFilter::Document.fragment @children
|
25
|
+
AST2MARKDOWN << temp_doc.to_json
|
26
|
+
end
|
27
|
+
|
28
|
+
def inner_markdown= markdown
|
29
|
+
if has_string?
|
30
|
+
@string = markdown
|
31
|
+
else
|
32
|
+
if markdown.empty?
|
33
|
+
@children = []
|
34
|
+
else
|
35
|
+
json = MARKDOWN2JSON << markdown
|
36
|
+
meta, contents = JSON.parse json
|
37
|
+
temp_doc = PandocFilter::Document.new meta, contents
|
38
|
+
temp_doc.children.each {|c| c.parent = @parent}
|
39
|
+
|
40
|
+
if has_inline?
|
41
|
+
@children = temp_doc.children[0].children
|
42
|
+
elsif has_block?
|
43
|
+
@children = temp_doc.children
|
44
|
+
else
|
45
|
+
# Unknown; what to do here?
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Paru
|
2
|
+
module PandocFilter
|
3
|
+
require_relative "./inline"
|
4
|
+
|
5
|
+
class Math < Inline
|
6
|
+
attr_accessor :math_type, :string
|
7
|
+
|
8
|
+
def initialize contents
|
9
|
+
@math_type = contents[0]
|
10
|
+
@string = contents[1]
|
11
|
+
end
|
12
|
+
|
13
|
+
def inline?
|
14
|
+
"InlineMath" == @math_type[t]
|
15
|
+
end
|
16
|
+
|
17
|
+
def inline!
|
18
|
+
@math_type = {
|
19
|
+
"t" => "InlineMath",
|
20
|
+
"c" => []
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def display?
|
25
|
+
"DisplayMath" == @math_type[t]
|
26
|
+
end
|
27
|
+
|
28
|
+
def display!
|
29
|
+
@math_type = {
|
30
|
+
"t" => "DisplayMath",
|
31
|
+
"c" => []
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
def ast_contents
|
36
|
+
[
|
37
|
+
@math_type,
|
38
|
+
@string
|
39
|
+
]
|
40
|
+
end
|
41
|
+
|
42
|
+
def has_string?
|
43
|
+
true
|
44
|
+
end
|
45
|
+
|
46
|
+
def has_inline?
|
47
|
+
false
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Paru
|
2
|
+
module PandocFilter
|
3
|
+
require_relative "./meta_map"
|
4
|
+
|
5
|
+
class Meta < MetaMap
|
6
|
+
include Enumerable
|
7
|
+
|
8
|
+
def initialize contents
|
9
|
+
super contents["unMeta"]
|
10
|
+
end
|
11
|
+
|
12
|
+
def ast_type
|
13
|
+
"unMeta"
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_ast
|
17
|
+
{
|
18
|
+
"unMeta" => ast_contents
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Paru
|
2
|
+
module PandocFilter
|
3
|
+
|
4
|
+
require_relative "./node"
|
5
|
+
|
6
|
+
class MetaMap < Node
|
7
|
+
|
8
|
+
def initialize contents
|
9
|
+
@children = Hash.new
|
10
|
+
|
11
|
+
if contents.is_a? Hash
|
12
|
+
contents.each_pair do |key, value|
|
13
|
+
if PandocFilter.const_defined? value["t"]
|
14
|
+
@children[key] = PandocFilter.const_get(value["t"]).new value["c"]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def [](key)
|
21
|
+
if @children.key_exists?
|
22
|
+
@children[key]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
def ast_contents
|
28
|
+
ast = Hash.new
|
29
|
+
@children.each_pair do |key, value|
|
30
|
+
ast[key] = value.to_ast
|
31
|
+
end
|
32
|
+
ast
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|