diff --git a/CHANGES b/CHANGES index 74f3fb8b55..8bf13ed6d2 100644 --- a/CHANGES +++ b/CHANGES @@ -136,6 +136,7 @@ Bugs fixed * #2485: autosummary crashes with multiple source_suffix values * #1734: Could not translate the caption of toctree directive * Could not translate the content of meta directive (ref: #1734) +* #2550: external links are opened in help viewer Documentation ------------- diff --git a/sphinx/builders/htmlhelp.py b/sphinx/builders/htmlhelp.py index cdb51b2c60..ecc752b606 100644 --- a/sphinx/builders/htmlhelp.py +++ b/sphinx/builders/htmlhelp.py @@ -198,6 +198,14 @@ class HTMLHelpBuilder(StandaloneHTMLBuilder): def handle_finish(self): self.build_hhx(self.outdir, self.config.htmlhelp_basename) + def write_doc(self, docname, doctree): + for node in doctree.traverse(nodes.reference): + # add ``target=_blank`` attributes to external links + if node.get('internal') is None and 'refuri' in node: + node['target'] = '_blank' + + StandaloneHTMLBuilder.write_doc(self, docname, doctree) + def build_hhx(self, outdir, outname): self.info('dumping stopword list...') with self.open_file(outdir, outname+'.stp') as f: diff --git a/sphinx/writers/html.py b/sphinx/writers/html.py index 324f8132a2..e15a18ab73 100644 --- a/sphinx/writers/html.py +++ b/sphinx/writers/html.py @@ -213,6 +213,8 @@ class HTMLTranslator(BaseTranslator): atts['class'] += ' image-reference' if 'reftitle' in node: atts['title'] = node['reftitle'] + if 'target' in node: + atts['target'] = node['target'] self.body.append(self.starttag(node, 'a', '', **atts)) if node.get('secnumber'):