Module:Glossary

--[[

This module provides helper functions for Template:Glossary_entry. Created by Pyrrhus for me-pedia.org November 2019

]]

local gloss = {}

--[[ tooltipCleanse: (adapted from Module:String.replace)

This function allows one to cleanse pre-processed, pre-HTML wikitext for use as a tooltip text. It removes: 1) strip markers of the form '"`UNIQ--ref-00000001-QINU`"'  2) all other strip markers, except for strip markers 3) tracking categories of the form 'Category:tracking_category', with brackets  4) superscripts, such as citation needed, of the form ...

It also protects double quotation marks so that the tooltip can be specified in a construct.

What is "pre-processed, pre-HTML wikitext", you ask? I'm not sure. It might be "parsed, but not HTML rendered". Again, I'm really not sure.

Usage:

]] function gloss.tooltipCleanse( frame ) local my_args = gloss._getParameters( frame.args, {'source'} ) local source_str = my_args['source'] or '' local trackPattern = '%[%Cc]ategory:[^%*%]%]'

local supPattern = "<sup.+ " if source_str == '' then return source_str end

-- remove all strip markers, including -- (except strip markers) source_str = mw.text.unstrip( source_str )

-- remove superscripts such as citation needed source_str = mw.ustring.gsub( source_str, supPattern, '' )

-- remove tracking categories source_str = mw.ustring.gsub( source_str, trackPattern, '' )

-- protect double quotes source_str = mw.ustring.gsub( source_str, "\"", '&#34;' )

return source_str end

-- hostname: This function returns the hostname for a URL function gloss.hostname( frame ) local new_args = gloss._getParameters( frame.args, {'url'} ) local myUrl = new_args['url'] or '' local myUrlObject = mw.uri.new( myUrl ) return myUrlObject["host"] end

-- _getParameters: (copied from Module:String) Helper function that populates the argument list given that user may need to use a mix of named and unnamed parameters. This is relevant because named parameters are not identical to unnamed parameters due to string trimming, and when dealing with strings we sometimes want to either preserve or remove that whitespace depending on the application. function gloss._getParameters( frame_args, arg_list ) local new_args = {} local index = 1 local value

for _, arg in ipairs( arg_list ) do		value = frame_args[arg] if value == nil then value = frame_args[index] index = index + 1 end new_args[arg] = value end

return new_args end

return gloss