From cb818fe4a7f6aa2af6b7d7543228662e4fb5115d Mon Sep 17 00:00:00 2001 From: Nicolas PLANEL Date: Mon, 17 Mar 2025 17:35:31 +0100 Subject: [PATCH] filter: allow customising prefix_path (default is "include") MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit VPP will need this. Signed-off-by: Nicolas PLANEL Signed-off-by: Nicolas PLANEL Signed-off-by: Théo Lebrun --- elixir/filters/cpppathinc.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/elixir/filters/cpppathinc.py b/elixir/filters/cpppathinc.py index 6d3c48c..940b5e2 100755 --- a/elixir/filters/cpppathinc.py +++ b/elixir/filters/cpppathinc.py @@ -1,4 +1,5 @@ import re +from typing import List from .utils import Filter, FilterContext, encode_number, decode_number, extension_matches # Filters for cpp includes like these: @@ -8,8 +9,11 @@ from .utils import Filter, FilterContext, encode_number, decode_number, extensio # If we make references to other projects, we could # end up with links to headers which are outside the project # Example: u-boot/v2023.10/source/env/embedded.c#L16 +# prefix_path: a list of paths, will be used to replace the prefix path during the +# untransform_formatted_code step class CppPathIncFilter(Filter): - def __init__(self, *args, **kwargs): + def __init__(self, prefix_path: List[str] = ["include"], *args, **kwargs): + self.prefix_path = prefix_path super().__init__(*args, **kwargs) self.cpppathinc = [] @@ -35,8 +39,11 @@ class CppPathIncFilter(Filter): def untransform_formatted_code(self, ctx: FilterContext, html: str) -> str: def replace_cpppathinc(m): w = self.cpppathinc[decode_number(m.group(1)) - 1] - path = f'/include/{ w }' - return f'{ w }' + for p in self.prefix_path: + path = f"/{p}/{w}" + if ctx.query.file_exists(ctx.tag, path): + return f'{ w }' + return w return re.sub('__KEEPCPPPATHINC__([A-J]+)', replace_cpppathinc, html, flags=re.MULTILINE)