filter: allow customising prefix_path (default is "include")
VPP will need this. Signed-off-by: Nicolas PLANEL <nplanel@cisco.com> Signed-off-by: Nicolas PLANEL <nplanel@gmail.com> Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
This commit is contained in:
parent
f1b2c52450
commit
cb818fe4a7
1 changed files with 10 additions and 3 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
import re
|
import re
|
||||||
|
from typing import List
|
||||||
from .utils import Filter, FilterContext, encode_number, decode_number, extension_matches
|
from .utils import Filter, FilterContext, encode_number, decode_number, extension_matches
|
||||||
|
|
||||||
# Filters for cpp includes like these:
|
# 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
|
# If we make references to other projects, we could
|
||||||
# end up with links to headers which are outside the project
|
# end up with links to headers which are outside the project
|
||||||
# Example: u-boot/v2023.10/source/env/embedded.c#L16
|
# 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):
|
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)
|
super().__init__(*args, **kwargs)
|
||||||
self.cpppathinc = []
|
self.cpppathinc = []
|
||||||
|
|
||||||
|
|
@ -35,8 +39,11 @@ class CppPathIncFilter(Filter):
|
||||||
def untransform_formatted_code(self, ctx: FilterContext, html: str) -> str:
|
def untransform_formatted_code(self, ctx: FilterContext, html: str) -> str:
|
||||||
def replace_cpppathinc(m):
|
def replace_cpppathinc(m):
|
||||||
w = self.cpppathinc[decode_number(m.group(1)) - 1]
|
w = self.cpppathinc[decode_number(m.group(1)) - 1]
|
||||||
path = f'/include/{ w }'
|
for p in self.prefix_path:
|
||||||
return f'<a href="{ ctx.get_absolute_source_url(path) }">{ w }</a>'
|
path = f"/{p}/{w}"
|
||||||
|
if ctx.query.file_exists(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)
|
return re.sub('__KEEPCPPPATHINC__([A-J]+)', replace_cpppathinc, html, flags=re.MULTILINE)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue