1
+ from typing import Any , Dict , Iterable , Sequence , Tuple
1
2
from urllib .parse import urljoin
2
3
import docutils .nodes as nodes
3
4
import string
4
5
from html .parser import HTMLParser
5
-
6
+ import sphinx
7
+ from sphinx .application import Sphinx
6
8
7
9
DEFAULT_DESCRIPTION_LENGTH = 200
8
10
@@ -18,13 +20,13 @@ def __init__(self):
18
20
self .text_outside_tags = ""
19
21
self .level = 0
20
22
21
- def handle_starttag (self , tag , attrs ):
23
+ def handle_starttag (self , tag , attrs ) -> None :
22
24
self .level += 1
23
25
24
- def handle_endtag (self , tag ):
26
+ def handle_endtag (self , tag ) -> None :
25
27
self .level -= 1
26
28
27
- def handle_data (self , data ):
29
+ def handle_data (self , data ) -> None :
28
30
self .text += data
29
31
if self .level == 0 :
30
32
self .text_outside_tags += data
@@ -34,7 +36,7 @@ class OGMetadataCreatorVisitor(nodes.NodeVisitor):
34
36
Finds the title and creates a description from a doctree
35
37
"""
36
38
37
- def __init__ (self , desc_len , known_titles = None , document = None ):
39
+ def __init__ (self , desc_len : int , known_titles : Iterable [ str ] = None , document : nodes . document = None ):
38
40
39
41
# Hack to prevent requirement for the doctree to be passed in.
40
42
# It's only used by doctree.walk(...) to print debug messages.
@@ -135,7 +137,7 @@ def make_tag(property: str, content: str) -> str:
135
137
return f'<meta property="{ property } " content="{ content } " />\n '
136
138
137
139
138
- def get_tags (context , doctree , config ) :
140
+ def get_tags (context : Dict [ str , Any ], doctree : nodes . document , config : Dict [ str , Any ]) -> str :
139
141
140
142
# Set length of description
141
143
try :
@@ -185,12 +187,12 @@ def get_tags(context, doctree, config):
185
187
return tags
186
188
187
189
188
- def html_page_context (app , pagename , templatename , context , doctree ) :
190
+ def html_page_context (app : Sphinx , pagename : str , templatename : str , context : Dict [ str , Any ], doctree : nodes . document ) -> None :
189
191
if doctree :
190
192
context ['metatags' ] += get_tags (context , doctree , app .config )
191
193
192
194
193
- def setup (app ) :
195
+ def setup (app : Sphinx ) -> Dict [ str , Any ] :
194
196
app .add_config_value ("ogp_site_url" , None , "html" )
195
197
app .add_config_value ("ogp_description_length" , DEFAULT_DESCRIPTION_LENGTH , "html" )
196
198
app .add_config_value ("ogp_image" , None , "html" )
0 commit comments