Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
cpppathinc: prefix_path as a list of prefix path
  • Loading branch information
nplanelcisco committed Apr 28, 2025
commit 221b9e104c94612d7250d22d118d9f8e0115f2f0
7 changes: 5 additions & 2 deletions elixir/filters/cpppathinc.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ def keep_cpppathinc(m):
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'/%s/{ w }' % self.prefix_path
return f'<a href="{ ctx.get_absolute_source_url(path) }">{ w }</a>'
for p in self.prefix_path:
path = f'/%s/{ w }' % p
if ctx.query.query('exist', ctx.tag, path):
return f'<a href="{ ctx.get_absolute_source_url(path) }">{ w }</a>'
return w

return re.sub('__KEEPCPPPATHINC__([A-J]+)', replace_cpppathinc, html, flags=re.MULTILINE)

2 changes: 1 addition & 1 deletion elixir/filters/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
],
'vpp': [
*default_filters,
(CppPathIncFilter, {"prefix_path": 'src'}),
(CppPathIncFilter, {"prefix_path": ['src', 'src/plugins']}),
MakefileFileFilter,
],
'zephyr': [
Expand Down
4 changes: 2 additions & 2 deletions elixir/filters/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ class FilterContext:
# up to the filter, but it's important to be careful to not break formatting.
# The second part runs on HTML, replacing markings left by the first part with HTML code.
# path_exceptions: list of regexes, disables filter if path of the filtered file matches a regex from the list
# prefix_path: will be used to replace the prefix path during the untransform_formatted_code step
# prefix_path: a list of paths, will be used to replace the prefix path during the untransform_formatted_code step
class Filter:
def __init__(self, path_exceptions: List[str] = [], prefix_path: str = "include"):
def __init__(self, path_exceptions: List[str] = [], prefix_path: List[str] = ["include"]):
self.path_exceptions = path_exceptions
self.prefix_path = prefix_path

Expand Down