Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python
- # BBEdit Text Filter
- # find all html links, and add /" target="_blank" rel="noopener noreferrer"/ to them
- # to ensure the link opens in a new window when clicked
- # Written by Phil Stokes
- import re
- from sys import stdin, stdout
- def filter(txt):
- # constants
- attr = '" target="_blank" rel="noopener noreferrer'
- ptrn = '(<a href.+?(?=">))'
- # copy the text
- str = txt
- str = re.sub((ptrn), r'\1'+attr, txt)
- str2 = re.sub(r'<', r'<', str)
- str = re.sub(r'>', r'>', str2)
- return str
- if __name__ == "__main__":
- text = stdin.read()
- stdout.write(filter(text))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement