Module: YARD::Markdown::ArefHelper

Defined in:
lib/yard/markdown/aref_helper.rb

Overview

Computes anchor ids that match the generated Markdown headings.

Class Method Summary collapse

Class Method Details

.anchor_component(value) ⇒ String

Encodes a value so it can be embedded safely in an HTML anchor id.

Parameters:

  • value (Object)

    Raw anchor fragment to encode.

Returns:

  • (String)

    Anchor-safe identifier fragment.



13
14
15
16
17
# File 'lib/yard/markdown/aref_helper.rb', line 13

def self.anchor_component(value)
  value.to_s.each_char.map do |char|
    char.match?(/[A-Za-z0-9_-]/) ? char : format("-%X", char.ord)
  end.join
end

.aref(object) ⇒ String

Returns the primary anchor id for a documented object.

Parameters:

  • object (YARD::CodeObjects::Base)

    Object being rendered.

Returns:

  • (String)

    Anchor id for the object's heading.



23
24
25
# File 'lib/yard/markdown/aref_helper.rb', line 23

def self.aref(object)
  aref_for(object, object.type, object.name)
end