Class: Paru::PandocFilter::Header

Inherits:
Block
  • Object
show all
Includes:
InnerMarkdown
Defined in:
lib/paru/filter/header.rb

Overview

A Header node has a level, an attribute object and the contents of the header as a list on Inline nodes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(contents) ⇒ Header

Create a new Header node

Parameters:

  • contents (Array)

    an array with the level, attribute, and the header contents



42
43
44
45
46
# File 'lib/paru/filter/header.rb', line 42

def initialize(contents)
    @level = contents[0]
    @attr = Attr.new contents[1]
    super contents[2], true
end

Instance Attribute Details

#attrAttr

Returns:



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/paru/filter/header.rb', line 33

class Header < Block
    include InnerMarkdown

    attr_accessor :level, :attr

    # Create a new Header node
    #
    # @param contents [Array] an array with the level, attribute, and
    #   the header contents
    def initialize(contents)
        @level = contents[0]
        @attr = Attr.new contents[1]
        super contents[2], true
    end

    # Create an AST representation of this Header node
    def ast_contents()
        [
            @level,
            @attr.to_ast,
            super
        ]
    end

    # Has this Header node inline contents?
    #
    # @return [Boolean] true
    def has_inline?
        true
    end
end

#levelInteger

Returns:

  • (Integer)


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/paru/filter/header.rb', line 33

class Header < Block
    include InnerMarkdown

    attr_accessor :level, :attr

    # Create a new Header node
    #
    # @param contents [Array] an array with the level, attribute, and
    #   the header contents
    def initialize(contents)
        @level = contents[0]
        @attr = Attr.new contents[1]
        super contents[2], true
    end

    # Create an AST representation of this Header node
    def ast_contents()
        [
            @level,
            @attr.to_ast,
            super
        ]
    end

    # Has this Header node inline contents?
    #
    # @return [Boolean] true
    def has_inline?
        true
    end
end

Instance Method Details

#ast_contentsObject

Create an AST representation of this Header node



49
50
51
52
53
54
55
# File 'lib/paru/filter/header.rb', line 49

def ast_contents()
    [
        @level,
        @attr.to_ast,
        super
    ]
end

#has_inline?Boolean

Has this Header node inline contents?

Returns:

  • (Boolean)

    true



60
61
62
# File 'lib/paru/filter/header.rb', line 60

def has_inline?
    true
end

#inner_markdownString Originally defined in module InnerMarkdown

Get the markdown representation of this Node's children.

Examples:

Replace all occurrences of “hello” by “world” in all paragraphs

Paru::Filter.run do
    with "Para" do |p|
        p.inner_markdown = p.inner_markdown.gsub "hello", "world"
    end
end         

Returns:

  • (String)

    the inner markdown representation of this Node

#inner_markdown=(markdown) ⇒ Object Originally defined in module InnerMarkdown

Replace this Node's children with the Nodes represented by the markdown string

Examples:

Replace all occurrences of “hello” by “world” in all paragraphs

Paru::Filter.run do
    with "Para" do |p|
        p.inner_markdown = p.inner_markdown.gsub "hello", "world"
    end
end         

Parameters:

  • markdown (String)

    the markdown string to replace this Node's children