Module: RDoc::Generator::Markdown::CrossrefExtension

Defined in:
lib/rdoc/generator/markdown/crossref.rb

Overview

Prevents RDoc from linking to code objects omitted from Markdown output.

Instance Method Summary collapse

Instance Method Details

Renders a cross-reference only when its owning object is emitted.

Parameters:

  • name (String, nil)

    Cross-reference target.

  • text (String)

    Visible link text.

  • code (Boolean) (defaults to: true)

    Whether to format code objects as code.

  • rdoc_ref (Boolean) (defaults to: false)

    Whether the target uses the rdoc-ref scheme.

Returns:

  • (String)

    HTML link or unlinked text.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rdoc/generator/markdown/crossref.rb', line 27

def link(name, text, code = true, rdoc_ref: false)
  return super unless @markdown_cross_reference

  ref = @markdown_cross_reference.resolve(name) if name
  return super unless RDoc::CodeObject === ref

  context = ref
  context = context.parent until RDoc::ClassModule === context || RDoc::TopLevel === context
  return super if @markdown_output_object_ids.include?(context.object_id)

  return text if RDoc::TopLevel === ref || !code

  "<code>#{text}</code>"
end

#with_markdown_cross_references(cross_reference, output_object_ids) ⇒ Object

Applies Markdown cross-reference state while rendering a description.

Parameters:

  • cross_reference (RDoc::CrossReference)

    Resolver scoped to the formatter.

  • output_object_ids (Set<Integer>)

    Object IDs emitted by the generator.

Returns:

  • (Object)

    Value returned by the block.



11
12
13
14
15
16
17
# File 'lib/rdoc/generator/markdown/crossref.rb', line 11

def with_markdown_cross_references(cross_reference, output_object_ids)
  @markdown_cross_reference = cross_reference
  @markdown_output_object_ids = output_object_ids
  yield
ensure
  @markdown_cross_reference = nil
end