Spiderjjr45 (talk | contribs) No edit summary Tag: Reverted |
Spiderjjr45 (talk | contribs) No edit summary |
||
(6 intermediate revisions by the same user not shown) | |||
Line 10: | Line 10: | ||
return "Article content not available" |
return "Article content not available" |
||
end |
end |
||
⚫ | |||
content = mw.text.unstrip(content) -- Unstrip markers |
|||
content = mw.text.killMarkers(content) -- Remove markers left after unstrip |
|||
content = mw.text.decode(content) -- Decode HTML entities |
|||
-- Remove comments and some special formatting |
-- Remove comments and some special formatting |
||
content = content:gsub(" |
content = content:gsub("%[%[.-|", "") -- Remove wiki links labellink brackets |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
content = content:gsub("%[%[", ""):gsub("%]%]", "") -- Remove wiki link brackets |
|||
content = content:gsub("{{.-}}", "") -- Remove template calls |
content = content:gsub("{{.-}}", "") -- Remove template calls |
||
⚫ | |||
⚫ | |||
⚫ | |||
content = |
content = content:gsub("====", "") -- Remove level 4 headers |
||
content = |
content = content:gsub("===", "") -- Remove level 3 headers |
||
⚫ | |||
⚫ | |||
-- Count the words |
-- Count the words |
Latest revision as of 18:44, 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 -- Replace HTML entities content = mw.text.unstrip(content) -- Unstrip markers content = mw.text.killMarkers(content) -- Remove markers left after unstrip content = mw.text.decode(content) -- Decode HTML entities -- Remove comments and some special formatting content = content:gsub("%[%[.-|", "") -- Remove wiki links labellink brackets content = content:gsub("{{.-}}", "") -- Remove template calls content = content:gsub("======", "") -- Remove level 6 headers content = content:gsub("=====", "") -- Remove level 5 headers content = content:gsub("====", "") -- Remove level 4 headers content = content:gsub("===", "") -- Remove level 3 headers content = content:gsub("==", "") -- Remove level 2 headers content = content:gsub("=", "") -- Remove level 1 headers headers -- Count the words local _, wordCount = string.gsub(content, "%S+", "") -- Return the word count return tostring(wordCount) .. " words" end return p