Class: Asciidoctor::Html::CrefInlineMacro

Inherits:
Extensions::InlineMacroProcessor
  • Object
show all
Defined in:
lib/asciidoctor/html/cref_inline_macro.rb

Overview

Allow cross references between documents by creating a suitable ERB inline ruby string:

cref:example.adoc#element-id[]

> <a href=“example.html#element-id”><%= refs.dig(“example”, “element-id”) %></a>

cref:example.adoc[]

> <a href=“example.html”><%= refs.dig(“example”, “chapref”) %></a>

cref:example.adoc

> <a href=“example.html”>here</a>

Instance Method Summary collapse

Instance Method Details

#process(parent, target, attrs) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/asciidoctor/html/cref_inline_macro.rb', line 25

def process(parent, target, attrs)
  path_tag = target.split "#"
  path = path_tag.first
  tag = path_tag.size > 1 ? path_tag[1] : "chapref"
  doc_key = Pathname(path).sub_ext ""
  text = attrs["text"] || %(<%= refs.dig("#{doc_key}", "#{tag}") || "[#{doc_key}][#{tag}]" %>)
  hash_tag = path_tag.size > 1 ? "##{path_tag[1]}" : ""
  href = "#{Pathname(path).sub_ext ".html"}#{hash_tag}"
  create_anchor parent, text, type: :link, target: href
end