@@ -161,12 +161,12 @@ def extract_macros(code: str) -> tuple[list[Macro], str]:
161161 return macros , "\n " .join (extracted )
162162
163163
164- class InOut (Enum ):
164+ class InOut (str , Enum ):
165165 """Enumeration for parameter direction."""
166166
167- UNSPECIFIED = 0
168- IN = 1
169- OUT = 2
167+ UNSPECIFIED = "unspecified"
168+ IN = "in"
169+ OUT = "out"
170170
171171
172172@dataclass
@@ -320,13 +320,13 @@ class CodeDoc:
320320 typedefs : dict [str , DocType ]
321321
322322
323- class TypeDecl (Enum ):
323+ class TypeDecl (str , Enum ):
324324 """Enumeration for type declarations."""
325325
326- NORMAL = 0
327- POINTER = 1
328- ARRAY = 2
329- FUNCTION = 3
326+ NORMAL = "normal"
327+ POINTER = "pointer"
328+ ARRAY = "array"
329+ FUNCTION = "function"
330330
331331
332332@dataclass
@@ -413,6 +413,18 @@ def tp_ref_to_str(ref: TypeRef, qualname: str) -> str:
413413 return f"{ ret } (*{ qualname } )({ ', ' .join (params )} )"
414414
415415
416+ def typedef_to_str (decl : DocType ) -> str :
417+ """Convert a typedef to a string.
418+
419+ Parameters:
420+ decl: The typedef to convert.
421+
422+ Returns:
423+ The string representation of the typedef.
424+ """
425+ return tp_ref_to_str (decl .tp , decl .name )
426+
427+
416428def desc (doc : Docstring | None ) -> str :
417429 """Get the description from a docstring.
418430
@@ -441,9 +453,9 @@ def lookup_type_html(data: CodeDoc, tp: TypeRef, *, name: str | None = None) ->
441453 """
442454 tp_str = ""
443455
444- for name , doctype in data .typedefs .items ():
456+ for type_name , doctype in data .typedefs .items ():
445457 if doctype .tp == tp :
446- tp_str = f'<a href="#type-{ name } ">{ name } </a>'
458+ tp_str = f'<a href="#type-{ type_name } ">{ type_name } </a>'
447459
448460 return f'<code>{ tp_str or tp_ref_to_str (tp , name or "unknown" )} </code>'
449461
@@ -469,6 +481,8 @@ class CHandler(BaseHandler):
469481 default_config : ClassVar [dict ] = {
470482 "show_root_heading" : False ,
471483 "show_root_toc_entry" : True ,
484+ "show_symbol_type_heading" : True ,
485+ "show_symbol_type_toc_entry" : True ,
472486 "heading_level" : 2 ,
473487 }
474488 """The default configuration options.
@@ -480,7 +494,7 @@ class CHandler(BaseHandler):
480494 **`heading_level`** | `int` | The initial heading level to use. | `2`
481495 """
482496
483- def collect (self , identifier : str , config : MutableMapping [str , Any ]) -> CollectorItem : # noqa: ARG002
497+ def collect (self , identifier : str , config : MutableMapping [str , Any ]) -> CollectorItem :
484498 """Collect data given an identifier and selection configuration.
485499
486500 In the implementation, you typically call a subprocess that returns JSON, and load that JSON again into
@@ -496,6 +510,9 @@ def collect(self, identifier: str, config: MutableMapping[str, Any]) -> Collecto
496510 Returns:
497511 Anything you want, as long as you can feed it to the `render` method.
498512 """
513+ if config .get ("fallback" , False ):
514+ raise CollectionError ("Not loading additional headers during fallback" )
515+
499516 source = Path (identifier ).read_text (encoding = "utf-8" )
500517 comments_list , source = extract_comments (source )
501518 macros_list , source = extract_macros (source )
@@ -573,7 +590,7 @@ def collect(self, identifier: str, config: MutableMapping[str, Any]) -> Collecto
573590 # def get_templates_dir(self, handler: str | None = None) -> Path:
574591 # return Path.cwd()
575592
576- def render (self , data : CodeDoc , config : Mapping [str , Any ]) -> str : # noqa: ARG002
593+ def render (self , data : CodeDoc , config : Mapping [str , Any ]) -> str :
577594 """Render a template using provided data and configuration options.
578595
579596 Parameters:
@@ -584,13 +601,15 @@ def render(self, data: CodeDoc, config: Mapping[str, Any]) -> str: # noqa: ARG0
584601 Returns:
585602 The rendered template as HTML.
586603 """
587- # final_config = {**self.default_config, **config}
588- # heading_level = final_config["heading_level"]
589- # template = self.env.get_template(f"{data...}.html.jinja")
590- # return template.render(
591- # **{"config": final_config, data...: data, "heading_level": heading_level, "root": True},
592- # )
593- raise PluginError ("Implement me!" )
604+ final_config = {** self .default_config , ** config }
605+ heading_level = final_config ["heading_level" ]
606+ template = self .env .get_template ("header.html.jinja" )
607+ return template .render (
608+ config = final_config ,
609+ header = data ,
610+ heading_level = heading_level ,
611+ root = True ,
612+ )
594613
595614 def update_env (self , md : Markdown , config : dict ) -> None :
596615 """Update the Jinja environment with any custom settings/filters/options for this handler.
@@ -604,6 +623,9 @@ def update_env(self, md: Markdown, config: dict) -> None:
604623 self .env .trim_blocks = True
605624 self .env .lstrip_blocks = True
606625 self .env .keep_trailing_newline = False
626+ self .env .filters ["typedef_to_str" ] = typedef_to_str
627+ self .env .filters ["lookup_type_html" ] = lookup_type_html
628+ self .env .filters ["zip" ] = zip
607629
608630
609631def get_handler (
0 commit comments