PHP 8.2.31
Preview: to_label.rb Size: 1.89 KB
//proc/thread-self/root/opt/alt/ruby40/share/gems/gems/rdoc-7.0.4/lib/rdoc/markup/to_label.rb

# frozen_string_literal: true
require 'cgi/escape'
require 'cgi/util' unless defined?(CGI::EscapeExt)

##
# Creates HTML-safe labels suitable for use in id attributes.  Tidylinks are
# converted to their link part and cross-reference links have the suppression
# marks removed (\\SomeClass is converted to SomeClass).

class RDoc::Markup::ToLabel < RDoc::Markup::Formatter

  attr_reader :res # :nodoc:

  ##
  # Creates a new formatter that will output HTML-safe labels

  def initialize(markup = nil)
    super nil, markup

    @markup.add_regexp_handling RDoc::CrossReference::CROSSREF_REGEXP, :CROSSREF
    @markup.add_regexp_handling(/(((\{.*?\})|\b\S+?)\[\S+?\])/, :TIDYLINK)

    add_tag :BOLD, '', ''
    add_tag :TT,   '', ''
    add_tag :EM,   '', ''

    @res = []
  end

  ##
  # Converts +text+ to an HTML-safe label

  def convert(text)
    label = convert_flow @am.flow text

    CGI.escape(label).gsub('%', '-').sub(/^-/, '')
  end

  ##
  # Converts the CROSSREF +target+ to plain text, removing the suppression
  # marker, if any

  def handle_regexp_CROSSREF(target)
    text = target.text

    text.sub(/^\\/, '')
  end

  ##
  # Converts the TIDYLINK +target+ to just the text part

  def handle_regexp_TIDYLINK(target)
    text = target.text

    return text unless text =~ /\{(.*?)\}\[(.*?)\]/ or text =~ /(\S+)\[(.*?)\]/

    $1
  end

  alias accept_blank_line         ignore
  alias accept_block_quote        ignore
  alias accept_heading            ignore
  alias accept_list_end           ignore
  alias accept_list_item_end      ignore
  alias accept_list_item_start    ignore
  alias accept_list_start         ignore
  alias accept_paragraph          ignore
  alias accept_raw                ignore
  alias accept_rule               ignore
  alias accept_verbatim           ignore
  alias end_accepting             ignore
  alias handle_regexp_HARD_BREAK  ignore
  alias start_accepting           ignore

end

Directory Contents

Dirs: 0 × Files: 35

Name Size Perms Modified Actions
1.25 KB lrw-r--r-- 2026-05-21 12:15:23
Edit Download
10.05 KB lrw-r--r-- 2026-05-21 12:15:23
Edit Download
423 B lrw-r--r-- 2026-05-21 12:15:23
Edit Download
671 B lrw-r--r-- 2026-05-21 12:15:23
Edit Download
551 B lrw-r--r-- 2026-05-21 12:15:23
Edit Download
252 B lrw-r--r-- 2026-05-21 12:15:23
Edit Download
3.16 KB lrw-r--r-- 2026-05-21 12:15:23
Edit Download
529 B lrw-r--r-- 2026-05-21 12:15:23
Edit Download
5.63 KB lrw-r--r-- 2026-05-21 12:15:23
Edit Download
671 B lrw-r--r-- 2026-05-21 12:15:23
Edit Download
2.40 KB lrw-r--r-- 2026-05-21 12:15:23
Edit Download
831 B lrw-r--r-- 2026-05-21 12:15:23
Edit Download
909 B lrw-r--r-- 2026-05-21 12:15:23
Edit Download
1.82 KB lrw-r--r-- 2026-05-21 12:15:23
Edit Download
1.72 KB lrw-r--r-- 2026-05-21 12:15:23
Edit Download
494 B lrw-r--r-- 2026-05-21 12:15:23
Edit Download
14.50 KB lrw-r--r-- 2026-05-21 12:15:23
Edit Download
10.08 KB lrw-r--r-- 2026-05-21 12:15:23
Edit Download
1.35 KB lrw-r--r-- 2026-05-21 12:15:23
Edit Download
717 B lrw-r--r-- 2026-05-21 12:15:23
Edit Download
316 B lrw-r--r-- 2026-05-21 12:15:23
Edit Download
1.51 KB lrw-r--r-- 2026-05-21 12:15:23
Edit Download
2.13 KB lrw-r--r-- 2026-05-21 12:15:23
Edit Download
2.34 KB lrw-r--r-- 2026-05-21 12:15:23
Edit Download
14.06 KB lrw-r--r-- 2026-05-21 12:15:23
Edit Download
7.17 KB lrw-r--r-- 2026-05-21 12:15:23
Edit Download
5.52 KB lrw-r--r-- 2026-05-21 12:15:23
Edit Download
1.13 KB lrw-r--r-- 2026-05-21 12:15:23
Edit Download
1.89 KB lrw-r--r-- 2026-05-21 12:15:23
Edit Download
3.65 KB lrw-r--r-- 2026-05-21 12:15:23
Edit Download
7.11 KB lrw-r--r-- 2026-05-21 12:15:23
Edit Download
1.72 KB lrw-r--r-- 2026-05-21 12:15:23
Edit Download
1.14 KB lrw-r--r-- 2026-05-21 12:15:23
Edit Download
2.29 KB lrw-r--r-- 2026-05-21 12:15:23
Edit Download
1.29 KB lrw-r--r-- 2026-05-21 12:15:23
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).