@@ -144,6 +144,8 @@ class _ButtonDirective(SphinxDirective):
144144 "click-parent" : directives .flag ,
145145 "tooltip" : directives .unchanged_required ,
146146 "shadow" : directives .flag ,
147+ # ref button only
148+ "ref-type" : make_choice (["any" , "ref" , "doc" , "myst" ]),
147149 "class" : directives .class_option ,
148150 }
149151
@@ -174,13 +176,16 @@ def run(self) -> List[nodes.Node]:
174176 self .set_source_info (node )
175177 if "tooltip" in self .options :
176178 node ["reftitle" ] = self .options ["tooltip" ] # TODO escape HTML
179+
177180 if self .content :
178181 textnodes , _ = self .state .inline_text (
179182 "\n " .join (self .content ), self .lineno + self .content_offset
180183 )
181- node .extend (textnodes )
184+ content = nodes .inline ("" , "" )
185+ content .extend (textnodes )
182186 else :
183- node += nodes .inline (target , target )
187+ content = nodes .inline (target , target )
188+ node .append (content )
184189
185190 if "expand" in self .options :
186191 grid_container = nodes .inline (classes = ["sd-d-grid" ])
@@ -217,13 +222,14 @@ def create_ref_node(
217222 self , rawtext : str , target : str , explicit_title : bool , classes : List [str ]
218223 ) -> nodes .Node :
219224 """Create the reference node."""
225+ ref_type = self .options .get ("ref-type" , "any" )
220226 options = {
221227 # TODO the presence of classes raises an error if the link cannot be found
222228 "classes" : classes ,
223229 "reftarget" : target ,
224230 "refdoc" : self .env .docname ,
225- "refdomain" : "" ,
226- "reftype" : "any" , # TODO allow for variable ref type
231+ "refdomain" : "std" if ref_type in { "ref" , "doc" } else " " ,
232+ "reftype" : ref_type ,
227233 "refexplicit" : explicit_title ,
228234 "refwarn" : True ,
229235 }
0 commit comments