1# Copyright 2023 The Khronos Group, Inc.
2# SPDX-License-Identifier: Apache-2.0
3
4# Rewrite VUID anchors with 'href' attributes so they can be selected in a
5# browser.
6
7require 'asciidoctor/extensions' unless RUBY_ENGINE == 'opal'
8
9include ::Asciidoctor
10
11class AnchorLinkPostprocessor < Asciidoctor::Extensions::Postprocessor
12  def process document, output
13    content = (document.attr 'copyright') || 'Copyright Acme, Inc.'
14    if document.basebackend? 'html'
15      output = output.gsub(/<a id="(VUID\-[\w\-:]+)">/, '<a id="\1" href="#\1">')
16    end
17    output
18  end
19end
20
21Asciidoctor::Extensions.register do
22  postprocessor AnchorLinkPostprocessor
23end
24