Path: blob/main/shared/lib/InterDocumentReferencesMacro/extension.rb
18086 views
require 'asciidoctor/extensions' unless RUBY_ENGINE == 'opal'12include ::Asciidoctor34class InterDocumentReferencesMacro < Asciidoctor::Extensions::InlineMacroProcessor5use_dsl67# Macro to handle cross references to different files in the same book.8named :crossref910def process parent, target, attrs11anchor = attrs[1]12text = attrs[2]1314if text.nil? || text.empty?15warn "Crossref '#{anchor}' needs a description."16end1718doc = parent.document1920if doc.backend == 'html5'21if doc.attributes['book'] == "true"22if doc.attributes['isonline'] == "1"23(create_anchor parent, text, type: :link, target: %(./##{anchor})).render24else25(create_anchor parent, text, type: :link, target: %(./index.html##{anchor})).render26end27else28if doc.attributes['isonline'] == "1"29(create_anchor parent, text, type: :link, target: %(../#{target}/##{anchor})).render30else31(create_anchor parent, text, type: :link, target: %(../#{target}/index.html##{anchor})).render32end33end34else35xref_attrs = { 'refid' => anchor }36xref_node = create_anchor parent, text, type: :xref, target: target, attributes: xref_attrs37# Return the node38xref_node39end40end # process4142end # class43444546