Class: Tocer::Transformers::Link

Inherits:
Object
  • Object
show all
Defined in:
lib/tocer/transformers/link.rb

Overview

Transforms a Markdown header (embedded link) into a table of contents link.

Instance Method Summary collapse

Constructor Details

#initialize(text, parser: Parsers::Header) ⇒ Link

Returns a new instance of Link.



12
13
14
# File 'lib/tocer/transformers/link.rb', line 12

def initialize text, parser: Parsers::Header
  @parser = parser.new text
end

Instance Method Details

#call(url_suffix: "") ⇒ Object



20
# File 'lib/tocer/transformers/link.rb', line 20

def call(url_suffix: "") = "#{indented_bullet}[#{label}](##{computed_url url_suffix})"

#labelObject



16
# File 'lib/tocer/transformers/link.rb', line 16

def label = parser.content.gsub(embedded_link, embedded_link_label)

#urlObject



18
# File 'lib/tocer/transformers/link.rb', line 18

def url = label.downcase.gsub(/\s/, "-").gsub(/[^\w-]+/, "")