1818
1919if TYPE_CHECKING :
2020 from sphinx .application import Sphinx
21+ from sphinx .util import logging
2122
2223__title__ = 'sphinxnotes-isso'
2324__license__ = 'BSD' ,
3637 'isso_avatar_fg' , 'isso_vote' , 'isso_vote_levels' ,
3738 'isso_feed' ]
3839
40+ logger = logging .getLogger (__name__ )
41+
3942def ext_config_to_isso_config (key :str , value :Any ) -> Tuple [str ,str ]:
4043 assert key in CONFIG_ITEMS
4144 key = 'data-' + key .replace ('_' , '-' )
@@ -55,8 +58,11 @@ def visit(self, node):
5558 kwargs = {
5659 'data-isso-id' : node ['thread-id' ],
5760 }
61+ if node .get ('thread-title' ):
62+ kwargs ['data-title' ] = node ['thread-title' ]
5863 self .body .append (self .starttag (node , 'section' , '' , ** kwargs ))
5964
65+
6066 @staticmethod
6167 def depart (self , _ ):
6268 self .body .append ('</section>' )
@@ -66,7 +72,8 @@ class IssoDirective(Directive):
6672 """Isso ".. isso::" rst directive."""
6773
6874 option_spec = {
69- 'id' : directives .unchanged
75+ 'id' : directives .unchanged ,
76+ 'title' : directives .unchanged ,
7077 }
7178
7279 def run (self ):
@@ -77,11 +84,23 @@ def run(self):
7784
7885 node = IssoNode ()
7986 node ['ids' ] = ['isso-thread' ]
80- node ['thread-id' ] = self .options .get ('id' ) or \
81- '/' + self .state .document .settings .env .docname
87+ if self .options .get ('id' ):
88+ thread_id = self .options .get ('id' )
89+ if not thread_id .startswith ('/' ):
90+ logger .warning ('isso thread-id should starts with slash' , location = node )
91+ node ['thread-id' ] = thread_id
92+ else :
93+ node ['thread-id' ] = '/' + self .state .document .settings .env .docname
94+ if self .options .get ('title' ):
95+ node ['thread-title' ] = self .options .get ('title' )
96+ else :
97+ title = self .state .document .next_node (nodes .title )
98+ if title :
99+ node ['thread-title' ] = title .astext ()
82100
83101 return [node ]
84102
103+
85104def on_html_page_context (app :Sphinx , pagename :str , templatename :str , context ,
86105 doctree :nodes .document ) -> None :
87106 """Called when the HTML builder has created a context dictionary to render a template with.
0 commit comments