Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-doc
Path: blob/main/shared/lib/InterDocumentReferencesMacro/extension.rb
18086 views
1
require 'asciidoctor/extensions' unless RUBY_ENGINE == 'opal'
2
3
include ::Asciidoctor
4
5
class InterDocumentReferencesMacro < Asciidoctor::Extensions::InlineMacroProcessor
6
use_dsl
7
8
# Macro to handle cross references to different files in the same book.
9
named :crossref
10
11
def process parent, target, attrs
12
anchor = attrs[1]
13
text = attrs[2]
14
15
if text.nil? || text.empty?
16
warn "Crossref '#{anchor}' needs a description."
17
end
18
19
doc = parent.document
20
21
if doc.backend == 'html5'
22
if doc.attributes['book'] == "true"
23
if doc.attributes['isonline'] == "1"
24
(create_anchor parent, text, type: :link, target: %(./##{anchor})).render
25
else
26
(create_anchor parent, text, type: :link, target: %(./index.html##{anchor})).render
27
end
28
else
29
if doc.attributes['isonline'] == "1"
30
(create_anchor parent, text, type: :link, target: %(../#{target}/##{anchor})).render
31
else
32
(create_anchor parent, text, type: :link, target: %(../#{target}/index.html##{anchor})).render
33
end
34
end
35
else
36
xref_attrs = { 'refid' => anchor }
37
xref_node = create_anchor parent, text, type: :xref, target: target, attributes: xref_attrs
38
# Return the node
39
xref_node
40
end
41
end # process
42
43
end # class
44
45
46