99neoteroi.mkdocs.oad
1010"""
1111
12+ from pathlib import Path
1213import re
1314
1415from 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