From a0e24444f4dc7e59fefb4a018648ac05dd0de3da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Noco=C5=84?= Date: Wed, 11 Mar 2026 11:26:27 +0100 Subject: [PATCH 1/2] Added remove_indent --- main.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index af2a37be87..147a48bef5 100644 --- a/main.py +++ b/main.py @@ -29,11 +29,12 @@ def define_env(env): """ @env.macro - def include_file(filename, start_line=0, end_line=None, glue=''): + def include_file(filename, start_line=0, end_line=None, glue='', remove_indent=False): """ Include a file, optionally indicating start_line and end_line (start counting from 0) optionally set a glue string to lead every string except the first one (can be used for indent) + optionally remove common leading whitespace from all lines (remove_indent=True) The path is relative to the top directory of the documentation project. """ @@ -41,6 +42,13 @@ def include_file(filename, start_line=0, end_line=None, glue=''): with open(full_filename, 'r') as f: lines = f.readlines() line_range = lines[start_line:end_line] + + if remove_indent: + non_empty = [l for l in line_range if l.strip()] + if non_empty: + indent = min(len(l) - len(l.lstrip()) for l in non_empty) + line_range = [l[indent:] if l.strip() else l for l in line_range] + return glue.join(line_range) @env.macro From 0ba3c950752d4a3bc210946f6fb1f0aaf80746b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Noco=C5=84?= Date: Wed, 11 Mar 2026 11:31:10 +0100 Subject: [PATCH 2/2] Usage example --- docs/ai_actions/extend_ai_actions.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/ai_actions/extend_ai_actions.md b/docs/ai_actions/extend_ai_actions.md index 5674155151..4bbe4f198e 100644 --- a/docs/ai_actions/extend_ai_actions.md +++ b/docs/ai_actions/extend_ai_actions.md @@ -14,7 +14,7 @@ For example, you can create a handler that connects to a translation model and u You can execute AI Actions by using the [ActionServiceInterface](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ConnectorAi-ActionServiceInterface.html) service, as in the following example: ``` php -[[= include_file('code_samples/ai_actions/src/Command/AddMissingAltTextCommand.php', 86, 105) =]] +[[= include_file('code_samples/ai_actions/src/Command/AddMissingAltTextCommand.php', 86, 105, remove_indent=True) =]] ``` The `GenerateAltTextAction` is a built-in action that implements the [ActionInterface](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ConnectorAi-ActionInterface.html), takes an [Image](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ConnectorAi-Action-DataType-Image.html) as an input, and generates the alternative text in the response. @@ -77,7 +77,7 @@ See [Action Configuration Search Criteria reference](action_configuration_criter The following example creates a new Action Configuration: ``` php hl_lines="3 17" -[[= include_file('code_samples/ai_actions/src/Command/ActionConfigurationCreateCommand.php', 46, 63) =]] +[[= include_file('code_samples/ai_actions/src/Command/ActionConfigurationCreateCommand.php', 46, 63, remove_indent=True) =]] ``` Actions Configurations are tied to a specific Action Type and are translatable. @@ -88,7 +88,7 @@ Reuse existing Action Configurations to simplify the execution of AI Actions. You can pass one directly to the `ActionServiceInterface::execute()` method: ``` php hl_lines="7-8" -[[= include_file('code_samples/ai_actions/src/Command/ActionConfigurationCreateCommand.php', 64, 72) =]] +[[= include_file('code_samples/ai_actions/src/Command/ActionConfigurationCreateCommand.php', 64, 72, remove_indent=True) =]] ``` The passed Action Configuration is only taken into account if the Action Context was not passed to the Action directly using the [ActionInterface::setActionContext()](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ConnectorAi-ActionInterface.html#method_hasActionContext) method.