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,11 +1,9 @@
1
+ # HorizontalRule
1
2
  module Paru
2
- module PandocFilter
3
- require_relative "./block"
3
+ module PandocFilter
4
+ require_relative "./empty_block"
4
5
 
5
- class HorizontalRule < Block
6
- def initialize contents
7
- super []
8
- end
9
- end
6
+ class HorizontalRule < EmptyBlock
10
7
  end
8
+ end
11
9
  end
@@ -1,9 +1,15 @@
1
+ # Image Attr [Inline] Target
1
2
  module Paru
2
- module PandocFilter
3
+ module PandocFilter
3
4
 
4
- require_relative "./link"
5
+ require_relative "./link"
5
6
 
6
- class Image < Link
7
- end
7
+ class Image < Link
8
+ # Although Image is defined to be inline, probably because in HTML it
9
+ # can be an inline element, often it acts like a block element.
10
+ def can_act_as_both_block_and_inline?
11
+ true
12
+ end
8
13
  end
14
+ end
9
15
  end
@@ -0,0 +1,9 @@
1
+ # LineBlock [[Inline]]
2
+ module Paru
3
+ module PandocFilter
4
+ require_relative "./list.rb"
5
+
6
+ class LineBlock < List
7
+ end
8
+ end
9
+ end
@@ -1,16 +1,9 @@
1
+ # LineBreak
1
2
  module Paru
2
- module PandocFilter
3
- require_relative "./inline"
3
+ module PandocFilter
4
+ require_relative "./empty_inline"
4
5
 
5
- class LineBreak < Inline
6
- def initialize contents
7
- super []
8
- end
9
-
10
- def has_inline?
11
- false
12
- end
13
- end
6
+ class LineBreak < EmptyInline
14
7
  end
8
+ end
15
9
  end
16
-
@@ -1,27 +1,28 @@
1
+ # Link Attr [Inline] Target
1
2
  module Paru
2
- module PandocFilter
3
+ module PandocFilter
3
4
 
4
- require_relative "./inline"
5
- require_relative "./attr"
6
- require_relative "./target"
5
+ require_relative "./inline"
6
+ require_relative "./attr"
7
+ require_relative "./target"
7
8
 
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
9
+ class Link < Inline
10
+ attr_accessor :attr, :target
16
11
 
17
- def ast_contents
18
- [
19
- @attr.to_ast,
20
- super,
21
- @target.to_ast
22
- ]
23
- end
12
+ def initialize contents
13
+ @attr = Attr.new contents[0]
14
+ super contents[1]
15
+ @target = Target.new contents[2]
16
+ end
17
+
18
+ def ast_contents
19
+ [
20
+ @attr.to_ast,
21
+ super,
22
+ @target.to_ast
23
+ ]
24
+ end
24
25
 
25
- end
26
26
  end
27
+ end
27
28
  end
@@ -1,22 +1,22 @@
1
1
  module Paru
2
- module PandocFilter
3
- require_relative "./block"
2
+ module PandocFilter
3
+ require_relative "./block"
4
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
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
12
 
13
- def ast_contents
14
- @children.map {|child| child.ast_contents}
15
- end
13
+ def ast_contents
14
+ @children.map {|child| child.ast_contents}
15
+ end
16
16
 
17
- def has_block?
18
- true
19
- end
20
- end
17
+ def has_block?
18
+ true
19
+ end
21
20
  end
21
+ end
22
22
  end
@@ -1,24 +1,37 @@
1
1
  module Paru
2
- module PandocFilter
3
- class ListAttributes
2
+ module PandocFilter
3
+ class ListAttributes
4
4
 
5
- STYLES = ["DefaultStyle", "Example", "Decimal", "LowerRoman", "UpperRoman", "LowerAlpha", "UpperAlpha"]
6
- DELIMS = ["DefaultDelim", "Period", "OneParen", "TwoParens"]
5
+ STYLES = [
6
+ "DefaultStyle",
7
+ "Example",
8
+ "Decimal",
9
+ "LowerRoman",
10
+ "UpperRoman",
11
+ "LowerAlpha",
12
+ "UpperAlpha"
13
+ ]
14
+ DELIMS = [
15
+ "DefaultDelim",
16
+ "Period",
17
+ "OneParen",
18
+ "TwoParens"
19
+ ]
7
20
 
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
21
+ attr_accessor :start, :number_style, :number_delim
22
+ def initialize attributes
23
+ @start = attributes[0]
24
+ @number_style = attributes[1]
25
+ @number_delim = attributes[2]
26
+ end
14
27
 
15
- def to_ast
16
- [
17
- @start,
18
- @number_style,
19
- @number_delim
20
- ]
21
- end
22
- end
28
+ def to_ast
29
+ [
30
+ @start,
31
+ @number_style,
32
+ @number_delim
33
+ ]
34
+ end
23
35
  end
36
+ end
24
37
  end
@@ -1,52 +1,72 @@
1
1
  module Paru
2
- module PandocFilter
3
- module Markdown
2
+ module PandocFilter
3
+ module Markdown
4
4
 
5
- require_relative "../pandoc"
6
- require_relative "./document"
5
+ require_relative "../pandoc"
6
+ require_relative "./document"
7
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
8
+ AST2MARKDOWN = Paru::Pandoc.new do
9
+ from "json"
10
+ to "markdown"
11
+ end
17
12
 
18
- def outer_markdown
19
- temp_doc = PandocFilter::Document.fragment [self]
20
- AST2MARKDOWN << temp_doc.to_json
21
- end
13
+ MARKDOWN2JSON = Paru::Pandoc.new do
14
+ from "markdown"
15
+ to "json"
16
+ end
22
17
 
23
- def inner_markdown
24
- temp_doc = PandocFilter::Document.fragment @children
25
- AST2MARKDOWN << temp_doc.to_json
26
- end
18
+ def outer_markdown
19
+ temp_doc = PandocFilter::Document.fragment [self]
20
+ AST2MARKDOWN << temp_doc.to_json
21
+ end
22
+
23
+ def outer_markdown= markdown
24
+ json = MARKDOWN2JSON << markdown
25
+ temp_doc = PandocFilter::Document.from_JSON json
26
+
27
+ if not has_parent? or is_root?
28
+ @children = temp_doc.children
29
+ else
30
+ # replace current node by new nodes
31
+ # There is a difference between inline and block nodes
32
+ current_index = parent.find_index self
33
+ index = current_index
34
+ temp_doc.each do |child|
35
+ index += 1
36
+ parent.insert index, child
37
+ end
38
+ # Remove the original node
39
+ parent.remove_at current_index
40
+ end
41
+
42
+ end
43
+
44
+ def inner_markdown
45
+ temp_doc = PandocFilter::Document.fragment @children
46
+ AST2MARKDOWN << temp_doc.to_json
47
+ end
48
+
49
+ def inner_markdown= markdown
50
+ if has_string?
51
+ @string = markdown
52
+ else
53
+ if markdown.empty?
54
+ @children = []
55
+ else
56
+ json = MARKDOWN2JSON << markdown
57
+ temp_doc = PandocFilter::Document.from_JSON json
58
+ temp_doc.children.each {|c| c.parent = @parent}
27
59
 
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
60
+ if has_inline?
61
+ @children = temp_doc.children[0].children
62
+ elsif has_block?
63
+ @children = temp_doc.children
64
+ else
65
+ # Unknown; what to do here?
49
66
  end
67
+ end
50
68
  end
69
+ end
51
70
  end
71
+ end
52
72
  end
@@ -1,51 +1,49 @@
1
+ # Math MathType String
1
2
  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
3
+ module PandocFilter
4
+ require_relative "./inline"
5
+
6
+ class Math < Inline
7
+ attr_accessor :math_type, :string
8
+
9
+ def initialize contents
10
+ @math_type, @string = contents
11
+ end
12
+
13
+ def inline?
14
+ "InlineMath" == @math_type[t]
15
+ end
16
+
17
+ def inline!
18
+ @math_type = {
19
+ "t" => "InlineMath"
20
+ }
21
+ end
22
+
23
+ def display?
24
+ "DisplayMath" == @math_type[t]
25
+ end
26
+
27
+ def display!
28
+ @math_type = {
29
+ "t" => "DisplayMath"
30
+ }
31
+ end
32
+
33
+ def ast_contents
34
+ [
35
+ @math_type,
36
+ @string
37
+ ]
38
+ end
39
+
40
+ def has_string?
41
+ true
42
+ end
43
+
44
+ def has_inline?
45
+ false
46
+ end
50
47
  end
48
+ end
51
49
  end
@@ -1,24 +1,23 @@
1
+ # Meta is a MetaMap
1
2
  module Paru
2
- module PandocFilter
3
- require_relative "./meta_map"
3
+ module PandocFilter
4
+ require_relative "./meta_map"
4
5
 
5
- class Meta < MetaMap
6
- include Enumerable
6
+ class Meta < MetaMap
7
+ include Enumerable
7
8
 
8
- def initialize contents
9
- super contents["unMeta"]
10
- end
9
+ def initialize contents
10
+ super contents
11
+ end
11
12
 
12
- def ast_type
13
- "unMeta"
14
- end
13
+ def ast_type
14
+ "meta"
15
+ end
15
16
 
16
- def to_ast
17
- {
18
- "unMeta" => ast_contents
19
- }
20
- end
17
+ def to_ast
18
+ ast_contents
19
+ end
21
20
 
22
- end
23
21
  end
22
+ end
24
23
  end