Created
June 15, 2021 15:45
-
-
Save Tiryoh/41bccca5ef7f954ffed9f1829dc2dcc6 to your computer and use it in GitHub Desktop.
A shell script to add target="_blank" option to link in Markdown text
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
#!/usr/bin/env bash | |
set -eu | |
# (C) 2021 Daisuke Sato | |
# Released under the MIT License | |
# https://tiryoh.mit-license.org/2021 | |
SRC_DIR=$(cd $(dirname ${BASH_SOURCE:-$0}); pwd) | |
# there is no Negative Lookahead in sed | |
# https | |
find . -name "*.md" | xargs sed -i -e 's#\([^\!]\)\[\(.*\)\](\(https://.*\))\([^\{]\)#\1[\2](\3){target=_blank rel=noopener}\4#g' | |
find . -name "*.md" | xargs sed -i -e 's#\([^\!]\)\[\(.*\)\](\(https://.*\))$#\1[\2](\3){target=_blank rel=noopener}#g' | |
find . -name "*.md" | xargs sed -i -e 's#^\[\(.*\)\](\(https://.*\))\([^\{]\)#[\1](\2){target=_blank rel=noopener}\3#g' | |
# http | |
find . -name "*.md" | xargs sed -i -e 's#\([^\!]\)\[\(.*\)\](\(http://.*\))\([^\{]\)#\1[\2](\3){target=_blank rel=noopener}\4#g' | |
find . -name "*.md" | xargs sed -i -e 's#\([^\!]\)\[\(.*\)\](\(http://.*\))$#\1[\2](\3){target=_blank rel=noopener}#g' | |
find . -name "*.md" | xargs sed -i -e 's#^\[\(.*\)\](\(http://.*\))\([^\{]\)#[\1](\2){target=_blank rel=noopener}\3#g' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment