Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Humanipedia
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Module:Word count
Module
Discussion
English
Read
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
local p = {} local yn = require("Module:Yesno") local pv = require("Module:If preview") local pvWarning = pv._warning --[[ Formats the word count, etc. while showing/hiding the count ]]-- function p._main(str, limit) local strout = "" limit = limit or math.huge local count = 0 local phrases = mw.text.split(str, "%s") local separators = {} for match in mw.ustring.gmatch(str, "%s") do table.insert(separators, match) end for k,v in pairs(phrases) do if (count < limit) then strout = strout .. v .. (separators[k] ~= nil and separators[k] or "") end if v ~= "" then count = count + 1 end end return {str = str, trimmedstr = strout, count = count} end function p.main(frame) local args = require("Module:Arguments").getArgs(frame) local str = args[1] or '' local limit = tonumber(args['limit']) or tonumber(args[2]) or math.huge local result = p._main(str, limit) mw.logObject(result) local out = '' if (yn(args['showcount'] or false) and not mw.isSubsting()) or frame:preprocess('{{REVISIONID}}') == "" then --always show in preview if limit == math.huge then out = out .. 'Word count: ' .. result['count'] .. '<br/>' elseif 0 <= result['count'] and result['count'] < limit / 2 then out = out .. 'Word count: <span class="wordcount-good">' .. result['count'] .. '</span>/' .. limit .. '<br>' elseif limit / 2 <= result['count'] and result['count'] < limit then out = out .. 'Word count: <span class="wordcount-okay">' .. result['count'] .. '</span>/' .. limit .. '<br>' else out = out .. 'Word count: <span class="wordcount-bad">' .. result['count'] .. '</span>/' .. limit .. '<br>' end end if yn(args['trim']) and result['count'] > limit then out = out .. pvWarning({"Word count limit of " .. limit .. " exceeded by " .. (result['count'] - limit) .. " words. Additional text will be ignored."}) end local res = (yn(args['trim']) and result['trimmedstr'] or str) out = out .. (args['prepend'] or '') .. res .. (args['append'] or '') if mw.isSubsting() then if args['unsubst'] then local f = frame:getParent() local title = f:getTitle().text or "#invoke:Word count|main" local preout = '{{' .. title .. "\n" for k,v in pairs(args) do if k == args['unsubst'] or tonumber(k) == tonumber(args['unsubst'] or '0') then preout = preout .. '|' .. k .. '=' .. res .. "\n" else preout = preout .. '|' .. k .. '=' .. v end end return preout .. '}}' end return out end return frame:extensionTag("templatestyles", "", {src = "Module:Word_count/styles.css"}) .. out end return p
Summary:
Please note that all contributions to Humanipedia may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Humanipedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Sandbox other
(
edit
)
Template:Template link
(
edit
)
Template:Tl
(
edit
)
Template:Uses TemplateStyles
(
edit
)
Module:String
(
edit
)
Module:Word count/doc
(
edit
)