Spiderjjr45 (talk | contribs) (Created page with "local p = {} function p.count(frame) -- Get the content of the current article local content = mw.title.getCurrentTitle():getContent() -- Check if content is not nil if content == nil then return "Article content not available" end -- Count the words local _, wordCount = string.gsub(content, "%S+", "") -- Return the word count return tostring(wordCount) .. " words" end return p") |
Spiderjjr45 (talk | contribs) No edit summary Tag: Reverted |
||
Line 1: | Line 1: | ||
-- Module:WordCount |
|||
local p = {} |
local p = {} |
||
Line 9: | Line 10: | ||
return "Article content not available" |
return "Article content not available" |
||
end |
end |
||
-- Remove comments and some special formatting |
|||
content = content:gsub("<!%-%-.-%-%->", "") -- Remove HTML comments |
|||
content = content:gsub("%-%-%[=%[.-%]%=%]", "") -- Remove Lua long comments |
|||
content = content:gsub("%-%-.*", "") -- Remove single line comments |
|||
content = content:gsub("%[%[File:.-|%[%[Image:.-|%[%[Media:.-", "") -- Remove file, image, media |
|||
content = content:gsub("%[%[.-|", "") -- Remove wiki links label |
|||
content = content:gsub("%[%[", ""):gsub("%]%]", "") -- Remove wiki link brackets |
|||
content = content:gsub("{{.-}}", "") -- Remove template calls |
|||
-- Replace HTML entities |
|||
content = mw.text.unstrip(content) |
|||
content = mw.text.decode(content) |
|||
-- Count the words |
-- Count the words |
Revision as of 18:33, 24 January 2024
Documentation for this module may be created at Module:Wordcount/doc
-- Module:WordCount local p = {} function p.count(frame) -- Get the content of the current article local content = mw.title.getCurrentTitle():getContent() -- Check if content is not nil if content == nil then return "Article content not available" end -- Remove comments and some special formatting content = content:gsub("<!%-%-.-%-%->", "") -- Remove HTML comments content = content:gsub("%-%-%[=%[.-%]%=%]", "") -- Remove Lua long comments content = content:gsub("%-%-.*", "") -- Remove single line comments content = content:gsub("%[%[File:.-|%[%[Image:.-|%[%[Media:.-", "") -- Remove file, image, media content = content:gsub("%[%[.-|", "") -- Remove wiki links label content = content:gsub("%[%[", ""):gsub("%]%]", "") -- Remove wiki link brackets content = content:gsub("{{.-}}", "") -- Remove template calls -- Replace HTML entities content = mw.text.unstrip(content) content = mw.text.decode(content) -- Count the words local _, wordCount = string.gsub(content, "%S+", "") -- Return the word count return tostring(wordCount) .. " words" end return p