Class: Keepachangelog::MarkdownParser

Inherits:
Parser
  • Object
show all
Defined in:
lib/keepachangelog/parser/markdown.rb

Overview

Parser for Markdown content

Instance Attribute Summary

Attributes inherited from Parser

#parsed_content

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Parser

#initialize, #to_json, #to_md, #to_s, #to_yaml

Constructor Details

This class inherits a constructor from Keepachangelog::Parser

Class Method Details

.load(filename = nil) ⇒ Object

Parse a file with markdown content


10
11
12
13
14
15
# File 'lib/keepachangelog/parser/markdown.rb', line 10

def self.load(filename = nil)
  filename ||= 'CHANGELOG.md'
  p = new
  p.parse File.open(filename, &:read)
  p
end

.parse(content = '') ⇒ Object

Parse raw markdown content


5
6
7
# File 'lib/keepachangelog/parser/markdown.rb', line 5

def self.parse(content = '')
  new.parse(content)
end

Instance Method Details

#parse(content) ⇒ Object


17
18
19
20
21
22
23
24
25
26
27
# File 'lib/keepachangelog/parser/markdown.rb', line 17

def parse(content)
  content = "\n" + content.strip + "\n"
  anchors = extract_anchors! content
  sections = content.split(/\n\s*## /)
  parse_meta anchors, sections[0]
  versions = sections[1..-1]
  parsed_content['versions'] = versions.map do |v|
    parse_version v, anchors
  end.to_h
  parsed_content
end