"Wordpress Tools" by JohnLBevan
Rating:









(0 votes)
| Name: | Wordpress Tools |
|---|---|
| Uploaded By: | JohnLBevan |
| Date Created: | June 29, 2010 5:06 p.m. |
| Date Modified: | June 29, 2010 5:06 p.m. |
| Description: | Provides HTML character escaping, allowing you to easily publish your code to your blog without manually running multiple replace statements. Also inserts CODE and PRE tags to ensure formatting is maintained once published. |
| Num Views: | 514 |
| Num Downloads: | 137 |
Contents
# ########################################################### #
# created: 2010-06-29
# developer: JohnLBevan (http://developer42.wordpress.com)
# description: Provides HTML character escaping, allowing
# you to easily publish your code to your blog
# without manually running multiple replace
# statements. Also inserts CODE and PRE tags
# to ensure formatting is maintained once
# published.
#
# modified: 2010-06-29
# by: JohnLBevan
import pn
import scintilla
import re, string
import cgi #provides escaping ootb for <>&
from pypn.decorators import script
@script("Prepare For Press", "Wordpress") #puts in the required tags and escapes your code as required
def PrepForPress():
editor = scintilla.Scintilla(pn.CurrentDoc())
data = editor.GetText(editor.Length+1)
content = cgi.escape(data)
content = "<code><pre>\r\n" + content + "\r\n</pre></code>"
UpdateDocument(editor,content)
@script("Escape Characters for HTML", "Wordpress") #replaces html special chars with their code equivs
def EscapeCharacters():
editor = scintilla.Scintilla(pn.CurrentDoc())
data = editor.GetText(editor.Length+1)
content = cgi.escape(data)
UpdateDocument(editor,content)
@script("Unescape Characters for HTML", "Wordpress") #just because I like things to be symmetrical
def UnescapeCharacters():
editor = scintilla.Scintilla(pn.CurrentDoc())
data = editor.GetText(editor.Length+1)
content = (data).replace("<", "<").replace(">", ">").replace("&", "&")
UpdateDocument(editor, content)
def UpdateDocument(editor, content): #standard doc update code
editor.BeginUndoAction()
editor.ClearAll()
editor.AddText(len(content), content)
editor.EndUndoAction()