Class: Marko::Parser::Topic

Inherits:
Object
  • Object
show all
Defined in:
lib/marko/parser/topic.rb

Overview

Topic parser

Instance Method Summary collapse

Constructor Details

#initializeTopic

Returns a new instance of Topic.



9
10
11
# File 'lib/marko/parser/topic.rb', line 9

def initialize
   = .new
end

Instance Method Details

#parse(markup) ⇒ Model::Topic

Parameters:

Returns:



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/marko/parser/topic.rb', line 15

def parse(markup)
  text = markup.content
  first = text.lines.first
  match = first.match(/\W+(.*)/)
  title = match[1]&.strip || ''

  rest = text.lines.drop(1).join
  match = rest.match(/^({{([\s\S]*?)}})?(.*)?$/m)
   = match[2]&.strip || ''
  content  = match[3]&.strip || ''
   = .parse()

  Model::Topic.new(title, content,
    **{markup: markup}.merge())
end