paru 0.1.0 → 0.2.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.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/lib/paru.rb +2 -2
  3. data/lib/paru/error.rb +2 -2
  4. data/lib/paru/filter.rb +69 -70
  5. data/lib/paru/filter/alignment.rb +7 -7
  6. data/lib/paru/filter/ast_manipulation.rb +39 -39
  7. data/lib/paru/filter/attr.rb +30 -32
  8. data/lib/paru/filter/block.rb +7 -7
  9. data/lib/paru/filter/block_quote.rb +8 -7
  10. data/lib/paru/filter/bullet_list.rb +6 -5
  11. data/lib/paru/filter/citation.rb +23 -23
  12. data/lib/paru/filter/cite.rb +19 -18
  13. data/lib/paru/filter/code.rb +23 -22
  14. data/lib/paru/filter/code_block.rb +20 -19
  15. data/lib/paru/filter/definition_list.rb +14 -13
  16. data/lib/paru/filter/definition_list_item.rb +17 -17
  17. data/lib/paru/filter/div.rb +19 -18
  18. data/lib/paru/filter/document.rb +56 -42
  19. data/lib/paru/filter/emph.rb +5 -4
  20. data/lib/paru/filter/empty_block.rb +17 -0
  21. data/lib/paru/filter/empty_inline.rb +21 -0
  22. data/lib/paru/filter/header.rb +22 -21
  23. data/lib/paru/filter/horizontal_rule.rb +5 -7
  24. data/lib/paru/filter/image.rb +10 -4
  25. data/lib/paru/filter/line_block.rb +9 -0
  26. data/lib/paru/filter/line_break.rb +5 -12
  27. data/lib/paru/filter/link.rb +21 -20
  28. data/lib/paru/filter/list.rb +16 -16
  29. data/lib/paru/filter/list_attributes.rb +31 -18
  30. data/lib/paru/filter/markdown.rb +62 -42
  31. data/lib/paru/filter/math.rb +46 -48
  32. data/lib/paru/filter/meta.rb +15 -16
  33. data/lib/paru/filter/meta_blocks.rb +8 -7
  34. data/lib/paru/filter/meta_bool.rb +5 -4
  35. data/lib/paru/filter/meta_inlines.rb +9 -8
  36. data/lib/paru/filter/meta_list.rb +5 -4
  37. data/lib/paru/filter/meta_map.rb +30 -29
  38. data/lib/paru/filter/meta_string.rb +5 -4
  39. data/lib/paru/filter/meta_value.rb +13 -11
  40. data/lib/paru/filter/node.rb +125 -122
  41. data/lib/paru/filter/note.rb +19 -11
  42. data/lib/paru/filter/null.rb +5 -7
  43. data/lib/paru/filter/ordered_list.rb +18 -17
  44. data/lib/paru/filter/para.rb +12 -11
  45. data/lib/paru/filter/plain.rb +11 -10
  46. data/lib/paru/filter/quoted.rb +17 -16
  47. data/lib/paru/filter/raw_block.rb +18 -18
  48. data/lib/paru/filter/raw_inline.rb +21 -21
  49. data/lib/paru/filter/small_caps.rb +5 -4
  50. data/lib/paru/filter/soft_break.rb +5 -12
  51. data/lib/paru/filter/space.rb +5 -11
  52. data/lib/paru/filter/span.rb +17 -16
  53. data/lib/paru/filter/str.rb +17 -16
  54. data/lib/paru/filter/strikeout.rb +5 -4
  55. data/lib/paru/filter/strong.rb +10 -0
  56. data/lib/paru/filter/subscript.rb +5 -4
  57. data/lib/paru/filter/superscript.rb +5 -4
  58. data/lib/paru/filter/table.rb +28 -27
  59. data/lib/paru/filter/table_row.rb +13 -13
  60. data/lib/paru/filter/target.rb +14 -14
  61. data/lib/paru/filter/version.rb +19 -0
  62. data/lib/paru/pandoc.rb +18 -13
  63. data/lib/paru/pandoc_options.yaml +14 -1
  64. data/lib/paru/selector.rb +152 -148
  65. metadata +9 -5
  66. data/lib/paru/filter/string.rb +0 -9
@@ -1,25 +1,26 @@
1
+ # Cite [Citation] [Inline]
1
2
  module Paru
2
- module PandocFilter
3
- require_relative "./inline"
3
+ module PandocFilter
4
+ require_relative "./inline"
4
5
 
5
- class Cite < Inline
6
- attr_accessor :citations
6
+ class Cite < Inline
7
+ attr_accessor :citations
7
8
 
8
- def initialize contents
9
- @citations = []
10
- contents[0].each do |citation|
11
- @citations.push Citation.new(citation)
12
- end
13
- super contents[1]
14
- end
15
-
16
- def ast_contents
17
- [
18
- @citations.map {|citation| citation.to_ast},
19
- super
20
- ]
21
- end
9
+ def initialize contents
10
+ @citations = []
11
+ contents[0].each do |citation|
12
+ @citations.push Citation.new(citation)
22
13
  end
14
+ super contents[1]
15
+ end
16
+
17
+ def ast_contents
18
+ [
19
+ @citations.map {|citation| citation.to_ast},
20
+ super
21
+ ]
22
+ end
23
23
  end
24
+ end
24
25
  end
25
26
 
@@ -1,30 +1,31 @@
1
+ # Code Attr String
1
2
  module Paru
2
- module PandocFilter
3
- require_relative "./inline"
4
- require_relative "./attr"
3
+ module PandocFilter
4
+ require_relative "./inline"
5
+ require_relative "./attr"
5
6
 
6
- class Code < Inline
7
- attr_accessor :attr, :string
7
+ class Code < Inline
8
+ attr_accessor :attr, :string
8
9
 
9
- def initialize contents
10
- @attr = Attr.new contents[0]
11
- @string = contents[1]
12
- end
10
+ def initialize contents
11
+ @attr = Attr.new contents[0]
12
+ @string = contents[1]
13
+ end
13
14
 
14
- def ast_contents
15
- [
16
- @attr.to_ast,
17
- @string
18
- ]
19
- end
15
+ def ast_contents
16
+ [
17
+ @attr.to_ast,
18
+ @string
19
+ ]
20
+ end
20
21
 
21
- def has_string?
22
- true
23
- end
22
+ def has_string?
23
+ true
24
+ end
24
25
 
25
- def has_inline?
26
- false
27
- end
28
- end
26
+ def has_inline?
27
+ false
28
+ end
29
29
  end
30
+ end
30
31
  end
@@ -1,26 +1,27 @@
1
+ # CodeBlock Attr String
1
2
  module Paru
2
- module PandocFilter
3
- require_relative "./block"
4
- require_relative "./attr"
3
+ module PandocFilter
4
+ require_relative "./block"
5
+ require_relative "./attr"
5
6
 
6
- class CodeBlock < Block
7
- attr_accessor :attr, :string
7
+ class CodeBlock < Block
8
+ attr_accessor :attr, :string
8
9
 
9
- def initialize(contents)
10
- @attr = Attr.new contents[0]
11
- @string = contents[1]
12
- end
10
+ def initialize(contents)
11
+ @attr = Attr.new contents[0]
12
+ @string = contents[1]
13
+ end
13
14
 
14
- def ast_contents
15
- [
16
- @attr.to_ast,
17
- @string
18
- ]
19
- end
15
+ def ast_contents
16
+ [
17
+ @attr.to_ast,
18
+ @string
19
+ ]
20
+ end
20
21
 
21
- def has_string?
22
- true
23
- end
24
- end
22
+ def has_string?
23
+ true
24
+ end
25
25
  end
26
+ end
26
27
  end
@@ -1,19 +1,20 @@
1
+ # DefinitionList [([Inline], [[Block]])]
1
2
  module Paru
2
- module PandocFilter
3
- require_relative "./block"
3
+ module PandocFilter
4
+ require_relative "./block"
4
5
 
5
- class DefinitionList < Block
6
- def initialize contents
7
- super []
8
- contents.each do |item|
9
- @children.push DefinitionListItem.new item
10
- end
11
- end
6
+ class DefinitionList < Block
7
+ def initialize contents
8
+ super []
9
+ contents.each do |item|
10
+ @children.push DefinitionListItem.new item
11
+ end
12
+ end
12
13
 
13
- def ast_contents
14
- @children.map {|child| child.to_ast}
15
- end
14
+ def ast_contents
15
+ @children.map {|child| child.to_ast}
16
+ end
16
17
 
17
- end
18
18
  end
19
+ end
19
20
  end
@@ -1,22 +1,22 @@
1
1
  module Paru
2
- module PandocFilter
3
- require_relative "./block"
4
- require_relative "./list"
5
- require_relative "./inline"
2
+ module PandocFilter
3
+ require_relative "./block"
4
+ require_relative "./list"
5
+ require_relative "./inline"
6
6
 
7
- class DefinitionListItem < Block
8
- attr_accessor :term, :definition
9
- def initialize item
10
- @term = Block.new item[0]
11
- @definition = List.new item[1]
12
- end
7
+ class DefinitionListItem < Block
8
+ attr_accessor :term, :definition
9
+ def initialize item
10
+ @term = Block.new item[0]
11
+ @definition = List.new item[1]
12
+ end
13
13
 
14
- def to_ast
15
- [
16
- @term.ast_contents,
17
- @definition.ast_contents
18
- ]
19
- end
20
- end
14
+ def to_ast
15
+ [
16
+ @term.ast_contents,
17
+ @definition.ast_contents
18
+ ]
19
+ end
21
20
  end
21
+ end
22
22
  end
@@ -1,25 +1,26 @@
1
+ # Div Attr [Block]
1
2
  module Paru
2
- module PandocFilter
3
- require_relative "./block"
4
- require_relative "./attr"
3
+ module PandocFilter
4
+ require_relative "./block"
5
+ require_relative "./attr"
5
6
 
6
- class Div < Block
7
- def initialize contents
8
- @attr = Attr.new contents[0]
9
- super contents[1]
10
- end
7
+ class Div < Block
8
+ def initialize contents
9
+ @attr = Attr.new contents[0]
10
+ super contents[1]
11
+ end
11
12
 
12
- def ast_contents
13
- [
14
- @attr.to_ast,
15
- super
16
- ]
17
- end
13
+ def ast_contents
14
+ [
15
+ @attr.to_ast,
16
+ super
17
+ ]
18
+ end
18
19
 
19
- def has_block?
20
- true
21
- end
22
- end
20
+ def has_block?
21
+ true
22
+ end
23
23
  end
24
+ end
24
25
  end
25
26
 
@@ -1,47 +1,61 @@
1
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
2
+ module PandocFilter
44
3
 
4
+ require "json"
5
+ require_relative "./node"
6
+ require_relative "./plain"
7
+ require_relative "./meta"
8
+ require_relative "./version"
9
+
10
+ VERSION = "pandoc-api-version"
11
+ META = "meta"
12
+ BLOCKS = "blocks"
13
+
14
+ CURRENT_PANDOC_VERSION = [1, 17, 4]
15
+
16
+ class Document < Node
17
+
18
+ attr_reader :meta
19
+
20
+ def self.from_JSON json
21
+ doc = JSON.parse json
22
+ version, metadata, contents = doc.values_at(VERSION, META, BLOCKS)
23
+ PandocFilter::Document.new version, metadata, contents
24
+ end
25
+
26
+ def self.fragment node_list
27
+ meta = Hash.new
28
+
29
+ if node_list.any? {|n| n.is_block?}
30
+ new_doc = Document.new CURRENT_PANDOC_VERSION, meta, []
31
+ new_doc.children = node_list
32
+ else
33
+ node = PandocFilter::Plain.new []
34
+ node.children = node_list
35
+ new_doc = Document.new CURRENT_PANDOC_VERSION, meta, [node.to_ast]
45
36
  end
37
+
38
+ new_doc
39
+ end
40
+
41
+ def initialize(version, meta, contents)
42
+ @version = Version.new version
43
+ @meta = Meta.new meta
44
+ super contents
45
+ end
46
+
47
+ def to_ast
48
+ {
49
+ VERSION => @version.to_ast,
50
+ META => @meta.to_ast,
51
+ BLOCKS => ast_contents
52
+ }
53
+ end
54
+
55
+ def to_json
56
+ to_ast.to_json
57
+ end
58
+
46
59
  end
60
+ end
47
61
  end
@@ -1,8 +1,9 @@
1
+ # Emph [Inline]
1
2
  module Paru
2
- module PandocFilter
3
- require_relative "./inline"
3
+ module PandocFilter
4
+ require_relative "./inline"
4
5
 
5
- class Emph < Inline
6
- end
6
+ class Emph < Inline
7
7
  end
8
+ end
8
9
  end
@@ -0,0 +1,17 @@
1
+ module Paru
2
+ module PandocFilter
3
+ require_relative "./block"
4
+
5
+ class EmptyBlock < Block
6
+ def initialize _
7
+ super []
8
+ end
9
+
10
+ def to_ast
11
+ {
12
+ "t" => ast_type
13
+ }
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,21 @@
1
+ module Paru
2
+ module PandocFilter
3
+ require_relative "./inline"
4
+
5
+ class EmptyInline < Inline
6
+ def initialize _
7
+ super []
8
+ end
9
+
10
+ def has_inline?
11
+ false
12
+ end
13
+
14
+ def to_ast
15
+ {
16
+ "t" => ast_type
17
+ }
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,28 +1,29 @@
1
+ # Header Int Attr [Inline]
1
2
  module Paru
2
- module PandocFilter
3
- require_relative "./block"
4
- require_relative "./attr"
3
+ module PandocFilter
4
+ require_relative "./block"
5
+ require_relative "./attr"
5
6
 
6
- class Header < Block
7
- attr_accessor :level, :attr
7
+ class Header < Block
8
+ attr_accessor :level, :attr
8
9
 
9
- def initialize contents
10
- @level = contents[0]
11
- @attr = Attr.new contents[1]
12
- super contents[2], true
13
- end
10
+ def initialize contents
11
+ @level = contents[0]
12
+ @attr = Attr.new contents[1]
13
+ super contents[2], true
14
+ end
14
15
 
15
- def ast_contents
16
- [
17
- @level,
18
- @attr.to_ast,
19
- super
20
- ]
21
- end
16
+ def ast_contents
17
+ [
18
+ @level,
19
+ @attr.to_ast,
20
+ super
21
+ ]
22
+ end
22
23
 
23
- def has_inline?
24
- true
25
- end
26
- end
24
+ def has_inline?
25
+ true
26
+ end
27
27
  end
28
+ end
28
29
  end