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)