Class: HParser::Block::Quote

Inherits:
Object
  • Object
show all
Includes:
Collectable, Indent, Hatena, Html, Inline, Latex, Text, Util
Defined in:
lib/hparser/block/quote.rb,
lib/hparser/html.rb,
lib/hparser/text.rb,
lib/hparser/latex.rb,
lib/hparser/hatena.rb

Overview

Quote parser.

Defined Under Namespace

Classes: QuoteUrl

Constant Summary collapse

@@start_pattern =
/^>(.*)>\s*$/
@@end_pattern =
/^<<\s*$/
@@blocks =
Concat.new(Or.new(*HParser::Parser.default_parser),
Skip.new(Empty))

Constants included from Html

Html::ESCAPE_TABLE

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Hatena

#to_hatena

Methods included from Indent

#_to_text_, #to_text

Methods included from Text

#to_text

Methods included from Html

#escape, #to_html

Constructor Details

#initialize(items, url = nil) ⇒ Quote

Returns a new instance of Quote.



31
32
33
34
# File 'lib/hparser/block/quote.rb', line 31

def initialize(items, url = nil)
  @items = items
  @url = url
end

Instance Attribute Details

#itemsObject (readonly)

Returns the value of attribute items.



30
31
32
# File 'lib/hparser/block/quote.rb', line 30

def items
  @items
end

#urlObject (readonly)

Returns the value of attribute url.



30
31
32
# File 'lib/hparser/block/quote.rb', line 30

def url
  @url
end

Class Method Details

.parse(scanner, context, inlines) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/hparser/block/quote.rb', line 17

def self.parse(scanner,context,inlines)
  if scanner.scan(@@start_pattern)
    url = Url.parse(StringScanner.new "[#{scanner.matched_pattern[1]}]")

    items = []
    until scanner.scan(@@end_pattern)
      break unless scanner.match? /.*/
      items << @@blocks.parse(scanner,context,inlines)[0]
    end
    self.new(items, url)
  end
end

Instance Method Details

#==(o) ⇒ Object



36
37
38
# File 'lib/hparser/block/quote.rb', line 36

def ==(o)
  o and self.class == o.class and self.items == o.items and @url == o.url
end

#hatena_contentObject



54
55
56
# File 'lib/hparser/hatena.rb', line 54

def hatena_content
  @items
end

#hatena_filter(c) ⇒ Object



57
58
59
# File 'lib/hparser/hatena.rb', line 57

def hatena_filter c
  ">>\n"+c+"\n<<"
end

#latex_contentObject



111
112
113
# File 'lib/hparser/latex.rb', line 111

def latex_content
  @items
end

#text_contentObject



66
67
68
# File 'lib/hparser/text.rb', line 66

def text_content
  @items
end

#to_latexObject



106
107
108
109
# File 'lib/hparser/latex.rb', line 106

def to_latex
  content = super
  %Q[\\begin{quotation}\n#{content}\n\\end{quotation}\n]
end