wiki:CoDiFy

Version 1 (modified by chriz, 8 years ago) (diff)

Migrated from old trac wiki

# Select any text, press Ctrl-Shift-C and it will be surrounded with <code></code> HTML tags.
# Without a selection, an empty <code></code> pair is inserted.
# Install: Put the source below into "WikidPad/user_extensions/codify.py"
# and restart WikidPad.
# Extremely heavily inspired by the URLifyFile plugin.

import urllib, string
WIKIDPAD_PLUGIN = (("MenuFunctions",1),)
def describeMenuItems(wiki):
	global nextNumber
	return ((codify, "Codify selection\tCtrl-Shift-C", "Codify selection"),)

def codify(wiki, evt):
	text = wiki.getActiveEditor().GetSelectedText()
	editor = wiki.getActiveEditor()
	editor.ReplaceSelection("<code>")
	bytePos = editor.GetCurrentPos()
	temp = string.strip(text)
	if len(temp) == 0:
		editor.AddText("</code>")
		editor.GotoPos(bytePos)
	else:
		editor.AddText(text + "</code>")	


Note: You might want to surround "codified" block with "<<pre", ">>" tags , too.