@@ -340,6 +340,8 @@ class KeywordDoc(SourceEntity):
340
340
default = None , compare = False , repr = False , hash = False
341
341
)
342
342
343
+ parent : Optional [LibraryDoc ] = None
344
+
343
345
def __str__ (self ) -> str :
344
346
return f"{ self .name } ({ ', ' .join (str (arg ) for arg in self .args )} )"
345
347
@@ -394,7 +396,7 @@ def range(self) -> Range:
394
396
),
395
397
)
396
398
397
- def to_markdown (self , add_signature : bool = True , header_level : int = 0 , add_type : bool = True ) -> str :
399
+ def to_markdown (self , add_signature : bool = True , header_level : int = 2 , add_type : bool = True ) -> str :
398
400
result = ""
399
401
400
402
if add_signature :
@@ -417,10 +419,10 @@ def to_markdown(self, add_signature: bool = True, header_level: int = 0, add_typ
417
419
418
420
def _get_signature (self , header_level : int , add_type : bool = True ) -> str :
419
421
if add_type :
420
- result = f"#{ '#' * header_level } { 'Library' if self .is_initializer else 'Keyword' } *{ self .name } *"
422
+ result = f"#{ '#' * header_level } { 'Library' if self .is_initializer else 'Keyword' } *{ self .name } *\n "
421
423
else :
422
424
if not self .is_initializer :
423
- result = f"\n \n #{ '#' * header_level } { self .name } "
425
+ result = f"\n \n #{ '#' * header_level } { self .name } \n "
424
426
else :
425
427
result = ""
426
428
@@ -575,7 +577,7 @@ class ModuleSpec:
575
577
@dataclass
576
578
class LibraryDoc :
577
579
name : str = ""
578
- doc : str = ""
580
+ doc : str = field ( default = "" , compare = False )
579
581
version : str = ""
580
582
type : str = "LIBRARY"
581
583
scope : str = "TEST"
@@ -592,6 +594,21 @@ class LibraryDoc:
592
594
stdout : Optional [str ] = field (default = None , compare = False )
593
595
has_listener : Optional [bool ] = None
594
596
597
+ @single_call
598
+ def __hash__ (self ) -> int :
599
+ return hash (
600
+ (
601
+ self .name ,
602
+ self .source ,
603
+ self .line_no ,
604
+ self .end_line_no ,
605
+ self .version ,
606
+ self .type ,
607
+ self .scope ,
608
+ self .doc_format ,
609
+ )
610
+ )
611
+
595
612
@property
596
613
def is_deprecated (self ) -> bool :
597
614
return DEPRECATED_PATTERN .match (self .doc ) is not None
@@ -612,17 +629,19 @@ def range(self) -> Range:
612
629
),
613
630
)
614
631
615
- def to_markdown (self , add_signature : bool = True , only_doc : bool = True ) -> str :
632
+ def to_markdown (self , add_signature : bool = True , only_doc : bool = True , header_level : int = 2 ) -> str :
616
633
with io .StringIO (newline = "\n " ) as result :
617
634
618
635
def write_lines (* args : str ) -> None :
619
636
result .writelines (i + "\n " for i in args )
620
637
621
638
if add_signature and any (v for v in self .inits .values () if v .args ):
622
639
for i in self .inits .values ():
623
- write_lines (i .to_markdown (), "" , "---" )
640
+ write_lines (i .to_markdown (header_level = header_level ), "" , "---" )
624
641
625
- write_lines (f"# { (self .type .capitalize ()) if self .type else 'Unknown' } *{ self .name } *" , "" , "" )
642
+ write_lines (
643
+ f"#{ '#' * header_level } { (self .type .capitalize ()) if self .type else 'Unknown' } *{ self .name } *" , "" , ""
644
+ )
626
645
627
646
if self .version or self .scope :
628
647
write_lines (
@@ -639,7 +658,7 @@ def write_lines(*args: str) -> None:
639
658
640
659
if self .doc :
641
660
642
- write_lines ("## Introduction" , "" )
661
+ write_lines (f "##{ '#' * header_level } Introduction" , "" )
643
662
644
663
if self .doc_format == ROBOT_DOC_FORMAT :
645
664
doc = MarkDownFormatter ().format (self .doc )
@@ -655,7 +674,7 @@ def write_lines(*args: str) -> None:
655
674
result .write (self .doc )
656
675
657
676
if not only_doc :
658
- result .write (self ._get_doc_for_keywords ())
677
+ result .write (self ._get_doc_for_keywords (header_level = header_level ))
659
678
660
679
return self ._link_inline_links (result .getvalue ())
661
680
@@ -680,23 +699,23 @@ def source_or_origin(self) -> Optional[str]:
680
699
re .VERBOSE ,
681
700
)
682
701
683
- _headers : ClassVar [re .Pattern ] = re .compile (r"^(#{2,5 })\s+(\S.*)$" , re .MULTILINE ) # type: ignore
702
+ _headers : ClassVar [re .Pattern ] = re .compile (r"^(#{2,9 })\s+(\S.*)$" , re .MULTILINE ) # type: ignore
684
703
685
704
def _link_inline_links (self , text : str ) -> str :
686
705
headers = [v .group (2 ) for v in self ._headers .finditer (text )]
687
706
688
707
def repl (m : re .Match ) -> str : # type: ignore
689
708
if m .group (2 ) in headers :
690
- return f"[{ str (m .group (2 ))} ](#{ str (m .group (2 )).lower ().replace (' ' , '-' )} )"
709
+ return f"[{ str (m .group (2 ))} ](\\ #{ str (m .group (2 )).lower ().replace (' ' , '-' )} )"
691
710
return str (m .group (0 ))
692
711
693
712
return str (self ._inline_link .sub (repl , text ))
694
713
695
- def _get_doc_for_keywords (self ) -> str :
714
+ def _get_doc_for_keywords (self , header_level : int = 2 ) -> str :
696
715
result = ""
697
716
if any (v for v in self .inits .values () if v .args ):
698
717
result += "\n ---\n \n "
699
- result += "\n ## Importing\n \n "
718
+ result += f "\n ##{ '#' * header_level } Importing\n \n "
700
719
701
720
first = True
702
721
@@ -709,7 +728,7 @@ def _get_doc_for_keywords(self) -> str:
709
728
710
729
if self .keywords :
711
730
result += "\n ---\n \n "
712
- result += "\n ## Keywords\n \n "
731
+ result += f "\n ##{ '#' * header_level } Keywords\n \n "
713
732
714
733
first = True
715
734
@@ -718,7 +737,7 @@ def _get_doc_for_keywords(self) -> str:
718
737
result += "\n ---\n "
719
738
first = False
720
739
721
- result += "\n " + kw .to_markdown (header_level = 2 , add_type = False )
740
+ result += "\n " + kw .to_markdown (header_level = header_level , add_type = False )
722
741
return result
723
742
724
743
def _add_toc (self , doc : str , only_doc : bool = True ) -> str :
@@ -1102,6 +1121,21 @@ def find_library(
1102
1121
)[0 ]
1103
1122
1104
1123
1124
+ def get_robot_library_html_doc_str (name : str , working_dir : str = "." , base_dir : str = "." ) -> str :
1125
+ from robot .libdocpkg import LibraryDocumentation
1126
+ from robot .libdocpkg .htmlwriter import LibdocHtmlWriter
1127
+
1128
+ _update_env (working_dir )
1129
+
1130
+ robot_libdoc = LibraryDocumentation (name )
1131
+ robot_libdoc .convert_docs_to_html ()
1132
+ with io .StringIO () as output :
1133
+ writer = LibdocHtmlWriter ()
1134
+ writer .write (robot_libdoc , output )
1135
+
1136
+ return output .getvalue ()
1137
+
1138
+
1105
1139
def get_library_doc (
1106
1140
name : str ,
1107
1141
args : Optional [Tuple [Any , ...]] = None ,
@@ -1278,6 +1312,7 @@ def get_test_library(
1278
1312
doc_format = str (lib .doc_format ) or ROBOT_DOC_FORMAT ,
1279
1313
is_initializer = True ,
1280
1314
arguments = ArgumentSpec .from_robot_argument_spec (kw [1 ].arguments ),
1315
+ parent = libdoc ,
1281
1316
)
1282
1317
for kw in [
1283
1318
(KeywordDocBuilder ().build_keyword (k ), k ) for k in [KeywordWrapper (lib .init , source )]
@@ -1326,6 +1361,7 @@ def get_test_library(
1326
1361
arguments = ArgumentSpec .from_robot_argument_spec (kw [1 ].arguments )
1327
1362
if not kw [1 ].is_error_handler
1328
1363
else None ,
1364
+ parent = libdoc ,
1329
1365
)
1330
1366
for kw in [
1331
1367
(KeywordDocBuilder ().build_keyword (k ), k )
0 commit comments