Skip to content

Commit b3f0228

Browse files
joewlambethjlambeth
andauthored
Add CWD for OpenAPI links (#73)
Co-authored-by: jlambeth <joseph.w.lambeth1@aexp.com>
1 parent a01f62c commit b3f0228

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

neoteroi/mkdocs/oad/__init__.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
neoteroi.mkdocs.oad
1010
"""
1111

12+
from pathlib import Path
1213
import re
1314

1415
from mkdocs.config.config_options import Type
@@ -25,22 +26,27 @@ class MkDocsOpenAPIDocumentationPlugin(BasePlugin):
2526
def _get_style(self) -> str:
2627
return "MKDOCS" if self.config.get("use_pymdownx", False) else "MARKDOWN"
2728

28-
def _replacer(self, match) -> str:
29-
source = match.group(1).strip("'\"")
30-
data = read_from_source(source)
29+
def _replacer(self, cwd):
30+
def replace(match) -> str:
31+
source = match.group(1).strip("'\"")
3132

32-
handler = OpenAPIV3DocumentationHandler(
33-
data, style=self._get_style(), source=source
34-
)
35-
return handler.write()
33+
data = read_from_source(source, cwd)
3634

37-
def on_page_markdown(self, markdown, *args, **kwargs):
35+
handler = OpenAPIV3DocumentationHandler(
36+
data, style=self._get_style(), source=source
37+
)
38+
return handler.write()
39+
40+
return replace
41+
42+
def on_page_markdown(self, markdown, page, *args, **kwargs):
3843
"""
3944
Replaces the tag [OAD(...)] in markdown with markdown generated from an
4045
OpenAPI Documentation, using essentials-openapi
4146
4247
https://github.com/Neoteroi/essentials-openapi
4348
"""
4449
if "[OAD(" in markdown:
45-
return self.rx.sub(self._replacer, markdown)
50+
cwd = (Path(page.file.src_dir) / page.file.src_path).parent
51+
return self.rx.sub(self._replacer(cwd), markdown)
4652
return markdown

0 commit comments

Comments
 (0)