Module:InfoboxImage

From WikiMD's Wellness Encyclopedia

Revision as of 05:55, 11 December 2024 by Prab (talk | contribs)

local p = {}

function p.renderImage(frame)

   -- Get the arguments passed to the module
   local args = frame:getParent().args
   -- Extract image-related arguments
   local image = args["image"] or ""
   local width = args["width"] or "250px" -- Default width if not provided
   local caption = args["caption"] or ""
   -- Validate if an image is provided
   if image == "" then
       return "" -- Return nothing if no image is provided
   end
   -- Build the image HTML for WikiMD.com
   local imageHtml = string.format(

"

\n" ..
       "    <img src='https://www.wikimd.com/wiki/images/%s' alt='%s' style='width:%s;' />\n" ..
"

",

       mw.text.encode(image),
       mw.text.encode(caption),
       mw.text.encode(width)
   )
   -- Add caption if provided
   if caption ~= "" then
       imageHtml = imageHtml .. string.format(

"

%s

",

           mw.text.encode(caption)
       )
   end
   return imageHtml

end

return p