Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-doc
Path: blob/main/shared/lib/CrossDocumentReferencesMacro/extension.rb
18086 views
1
require 'asciidoctor/extensions' unless RUBY_ENGINE == 'opal'
2
3
include ::Asciidoctor
4
5
class CrossDocumentReferencesMacro < Asciidoctor::Extensions::InlineMacroProcessor
6
use_dsl
7
8
# Macro to handle cross references to a different book.
9
named :extref
10
name_positional_attributes 'attributes'
11
12
def process parent, target, attrs
13
destination = target
14
text = attrs[1]
15
anchor = ""
16
17
unless attrs[2].nil?
18
anchor = "#" + attrs[2]
19
end
20
21
doc = parent.document
22
23
if doc.attributes['isonline'] == "1"
24
(create_anchor parent, text, type: :link, target: %(#{destination}#{anchor})).render
25
else
26
if doc.attributes['doctype'] == "book"
27
(create_anchor parent, text, type: :link, target: %(../#{destination}/index.html#{anchor})).render
28
else
29
(create_anchor parent, text, type: :link, target: %(#{destination}/index.html#{anchor})).render
30
end
31
end
32
33
end
34
end
35
36