Class: Tocer::Transformers::Text

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

Overview

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Text.



12
13
14
# File 'lib/tocer/transformers/text.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/text.rb', line 20

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

#labelObject



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

def label = parser.content

#urlObject



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

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