-
-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add extlinks + external links open in new tab
- Loading branch information
Showing
5 changed files
with
72 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from sphinx.util.docutils import is_html5_writer_available | ||
from sphinx.writers.html import HTMLTranslator | ||
from sphinx.writers.html5 import HTML5Translator | ||
|
||
|
||
class PatchedHTMLTranslator( | ||
HTML5Translator if is_html5_writer_available() else HTMLTranslator | ||
): | ||
def starttag(self, node, tagname, *args, **attrs): | ||
if ( | ||
tagname == "a" | ||
and "target" not in attrs | ||
and ( | ||
"external" in attrs.get("class", "") | ||
or "external" in attrs.get("classes", []) | ||
) | ||
): | ||
attrs["target"] = "_blank" | ||
attrs["ref"] = "noopener noreferrer" | ||
return super().starttag(node, tagname, *args, **attrs) | ||
|
||
|
||
def setup(app): | ||
app.set_translator("html", PatchedHTMLTranslator) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters