1e5c31af7Sopenharmony_ci# Copyright 2021-2024 The Khronos Group Inc. 2e5c31af7Sopenharmony_ci# 3e5c31af7Sopenharmony_ci# SPDX-License-Identifier: Apache-2.0 4e5c31af7Sopenharmony_ci 5e5c31af7Sopenharmony_cirequire 'asciidoctor/extensions' unless RUBY_ENGINE == 'opal' 6e5c31af7Sopenharmony_ci 7e5c31af7Sopenharmony_ciinclude Asciidoctor 8e5c31af7Sopenharmony_ci 9e5c31af7Sopenharmony_ciclass ExistsIncludeProcessor < Extensions::IncludeProcessor 10e5c31af7Sopenharmony_ci def handles? target 11e5c31af7Sopenharmony_ci # Only handle files which do not exist 12e5c31af7Sopenharmony_ci # This relies on the full absolute path to every include file being 13e5c31af7Sopenharmony_ci # given, since relative directory information exists only in the 14e5c31af7Sopenharmony_ci # process method. 15e5c31af7Sopenharmony_ci 16e5c31af7Sopenharmony_ci not File.exist? target 17e5c31af7Sopenharmony_ci end 18e5c31af7Sopenharmony_ci 19e5c31af7Sopenharmony_ci def process doc, reader, target, attributes 20e5c31af7Sopenharmony_ci # If we reach this point, we have been asked to include a file which 21e5c31af7Sopenharmony_ci # does not exist. Do nothing, instead of raising an error. 22e5c31af7Sopenharmony_ci 23e5c31af7Sopenharmony_ci reader 24e5c31af7Sopenharmony_ci end 25e5c31af7Sopenharmony_ciend 26e5c31af7Sopenharmony_ci 27e5c31af7Sopenharmony_ciExtensions.register do 28e5c31af7Sopenharmony_ci include_processor ExistsIncludeProcessor 29e5c31af7Sopenharmony_ciend 30e5c31af7Sopenharmony_ci 31