Jump to content
Toggle menu
  • 8 articles
  • 75 files
  • 7 users
  • 37.8K edits
Neodyland Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Suppress categories: Difference between revisions

From Neodyland Wiki
Copy from w:en:Module:Suppress categories. Attribution: User:Mr. Stradivarius.
 
mNo edit summary
Line 8: Line 8:
-- the function returns the blank string. If not, the input
-- the function returns the blank string. If not, the input
-- is returned with no changes.
-- is returned with no changes.
local function processCategory( all, submatch )
localprocessCategory( all, submatch )
     local beforePipe = mw.ustring.match( submatch, '^(.-)[%s_]*|[%s_]*.-$' )
     local beforePipe = mw.ustring.match( submatch, '^(.-)[%s_]*|[%s_]*.-$' )
     beforePipe = beforePipe or submatch
     beforePipe = beforePipe
    if mw.ustring.match( beforePipe, '[%[%]<>{}%c\n]' ) then
 
        return all
    else
        return ''
    end
end


-- Preprocess the content if we aren't being called from #invoke,
-- Preprocess the content if we aren't being called from #invoke,
-- and pass it to gsub to remove valid category links.
-- and pass it to gsub to remove valid category links.
local function suppress( content, isPreprocessed )
localsuppress( content, isPreprocessed )
     if not isPreprocessed then
     if not isPreprocessed then
         content = mw.getCurrentFrame():preprocess( content )
         content = mw.getCurrentFrame (content )
     end
     end
     content = mw.ustring.gsub(
      
        content,
        '(%[%[[%s_]*[cC][aA][tT][eE][gG][oO][rR][yY][%s_]*:[%s_]*(.-)[%s_]*%]%])',
        processCategory
    )
    return content
end


-- Get the content to suppress categories from, and find
-- Get the content to suppress categories from, and find
-- whether the content has already been preprocessed. (If the
-- whether the content has already been preprocessed. (If the
-- module is called from #invoke, it has been preprocessed already.)
-- module is called from #invoke, it has been preprocessed already.)
function p.main( frame )
p.main( frame )
     local content, isPreprocessed
     local content, isPreprocessed
     if frame == mw.getCurrentFrame() then
     if frame == mw.getCurrentFrame() then
         content = frame:getParent().args[1]
         content = frame:getParent()
        if frame.args[1] then
             content = frame.args[1]
             content = frame.args[1]
        end
    end
         isPreprocessed = true
         isPreprocessed = true
    else
 
         content = frame
         content = frame
         isPreprocessed = false
         isPreprocessed = false
    end
    return suppress( content, isPreprocessed )
end
return p

Revision as of 16:14, 18 March 2024

Module documentation[ create · purge ]
This documentation is transcluded from Module:Suppress categories/doc.
-- This is a simple module to strip categories from wikitext. It does
-- not support nested links or magic words like __TOC__, etc. Even so,
-- it should still handle most categories.

local p = {}

-- Detects if a category link is valid or not. If it is valid,
-- the function returns the blank string. If not, the input
-- is returned with no changes.
localprocessCategory( all, submatch )
    local beforePipe = mw.ustring.match( submatch, '^(.-)[%s_]*|[%s_]*.-$' )
    beforePipe = beforePipe
  
 

-- Preprocess the content if we aren't being called from #invoke,
-- and pass it to gsub to remove valid category links.
localsuppress( content, isPreprocessed )
    if not isPreprocessed then
        content = mw.getCurrentFrame (content )
    end
    

-- Get the content to suppress categories from, and find
-- whether the content has already been preprocessed. (If the
-- module is called from #invoke, it has been preprocessed already.)
 p.main( frame )
    local content, isPreprocessed
    if frame == mw.getCurrentFrame() then
        content = frame:getParent()
            content = frame.args[1]
    end
        isPreprocessed = true
  
        content = frame
        isPreprocessed = false
Cookies help us deliver our services. By using our services, you agree to our use of cookies.