Class: Marko::Parser::Topic
- Inherits:
-
Object
- Object
- Marko::Parser::Topic
- Defined in:
- lib/marko/parser/topic.rb
Overview
Topic parser
Instance Method Summary collapse
-
#initialize ⇒ Topic
constructor
A new instance of Topic.
- #parse(markup) ⇒ Model::Topic
Constructor Details
#initialize ⇒ Topic
Returns a new instance of Topic.
9 10 11 |
# File 'lib/marko/parser/topic.rb', line 9 def initialize = Metadata.new end |
Instance Method Details
#parse(markup) ⇒ Model::Topic
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 |