• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2020-2023 The Khronos Group Inc.
2#
3# SPDX-License-Identifier: Apache-2.0
4
5require 'asciidoctor/extensions' unless RUBY_ENGINE == 'opal'
6
7include ::Asciidoctor
8
9class VUIDExpanderTreeprocessor < Extensions::Treeprocessor
10  def process document
11    # Find all list items inside Valid Usage sidebar blocks
12    document.find_by(context: :sidebar).each do |sidebar|
13      # Get sidebar title from instance variable to avoid side-effects from substitutions
14      if sidebar.title? and sidebar.instance_variable_get(:@title).start_with? "Valid Usage"
15        sidebar.find_by(context: :list_item) do |item|
16            # Get item text directly from instance variable to avoid inline substitutions
17            original_text = item.instance_variable_get(:@text)
18            # Find VUID anchor and append with matching VUID-styled text and line break
19            item.text = original_text.gsub(/(\[\[(VUID-[^\]]*)\]\])/, "\\1 [vuid]#\\2# +\n")
20        end
21      end
22    end
23    nil
24  end
25end
26
27Extensions.register do
28  treeprocessor VUIDExpanderTreeprocessor
29end
30