Anchorify - butscher/WikidPad GitHub Wiki

Anchorify

Select any text, press Ctrl-Shift-Z and it will be surrounded with <a href=""></a> HTML tags. If the selection starts with "http", it is interpreted as URL, else as a word.

Added by Bobby Digital on Thu Aug 2 03:31:16 2007.

# Select any text, press Ctrl-Shift-Z and it will be surrounded with <a href=""></a> HTML tags.
# Without a selection, an empty <a href=""></a> pair is inserted.
# If the selection starts with "http", it is interpreted as URL, else as a word.
# Install: Put the source below into "WikidPad/user_extensions/anchorify.py"
# and restart WikidPad.
# mod of codify plugin; Extremely heavily inspired by the URLifyFile plugin.

WIKIDPAD_PLUGIN = (("MenuFunctions",1),)
def describeMenuItems(wiki):
	return ((anchorify, "Anchorify selection\tCtrl-Shift-Z", "Anchorify selection"),)

def anchorify(wiki, evt):
	text = wiki.getActiveEditor().GetSelectedText()
	editor = wiki.getActiveEditor()
	if text.find("http") != 0:
		editor.ReplaceSelection("<a href=\"\" target=\"_blank\">")
		bytePos = editor.GetCurrentPos()
		temp = text.strip()
		if len(temp) == 0:
			editor.AddText("</a>")
			editor.GotoPos(bytePos)
		else:
			editor.AddText(text + "</a>")
	else:
		editor.ReplaceSelection("<a href=\"")
		bytePos = editor.GetCurrentPos()
		temp = text.strip()
		if len(temp) == 0:
			editor.AddText("\" target=\"_blank\"></a>")
			editor.GotoPos(bytePos)
		else:
			editor.AddText(text + "\" target=\"_blank\"></a>")
⚠️ **GitHub.com Fallback** ⚠️