WordCountInsertion - butscher/WikidPad GitHub Wiki

import os, urllib
import wx

''' 
A Insertion plugin for WikidPad to count the words on the page 

Written by Eric Tolman ([email protected])
'''
WIKIDPAD_PLUGIN = (("InsertionByKey", 1),)

def describeInsertionKeys(ver, app):
	"""
	Adds a word count insertion.
	
	Examples
	[:wordcount:]			Outputs the word count
	
	"""
	return ((u"wordcount", ("wikidpad_language",), WordCountHandler),)


class WordCountHandler:
	"""
	Class fulfilling the "insertion by key" protocol.
	"""
	def __init__(self, app):
		self.app = app

	def taskStart(self, exporter, exportType):
		pass

	def taskEnd(self):
		pass

	def createContent(self, exporter, exportType, insToken):
		wiki = exporter.mainControl
		editor = wiki.getActiveEditor()
		text = editor.GetText()
		return str(len(text.split(None)))

	def getExtraFeatures(self):
		return ()
⚠️ **GitHub.com Fallback** ⚠️