Module: YARD::Markdown::AnchorComponentHelper

Included in:
ArefHelper
Defined in:
lib/yard/markdown/anchor_component_helper.rb

Overview

Builds anchor-safe identifier fragments from arbitrary values.

Instance Method Summary collapse

Instance 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/anchor_component_helper.rb', line 13

def 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