Module:Jcon
local p = {}
 local getArgs = require(&quot;Module:Arguments&quot;).getArgs
 local data = mw.loadData('Module:Jcon/data')
 local miscTable = data.miscTable
 local typeTable = data.typeTable
 local divisionTable = data.divisionTable
 local pictureTable = data.pictureTable
 
 --[[ 
           R E T U R N P I C T U R E
           Return the picture of text 
 ]]--
 
 local function returnPicture(frame,Type,args,division)
 	if not pictureTable[division] then -- Return nothing if region doen't have pictures
 		return &quot;&quot;
 	end
 	
 	local export = pictureTable[division][1]..args[2]..pictureTable[division][2] or &quot;&quot; -- Set picture
 	
 	if args[2] == &quot;52&quot; and division == &quot;Simcoe&quot; then -- Picture exceptions                           
 		export = &quot;Simcoe county road 52.png&quot;
 	elseif args[2] == &quot;407ETR&quot; and division == &quot;Highway&quot; then
 		export = &quot;Highway407crest.png&quot;
 	elseif args[2] == &quot;QEW&quot; and division == &quot;Highway&quot; then
 		export = &quot;Ontario QEW crown.svg&quot;
 	else
 		routenumber = string.gsub(args[2],&quot;%D&quot;,&quot;&quot;)
 		if tonumber(routenumber) == nil then
 			return &quot;&quot; -- Return nothing if there's no route number
 		elseif tonumber(routenumber) &gt;= 500 and division == &quot;Highway&quot; then -- If highway is secondary
 			export = &quot;Ontario Highway &quot;..args[2]..&quot;.svg&quot;
 		end
 	end
 	if export == &quot;&quot; or nil then return &quot;&quot; end -- Return nothing if export is nothing
 	if frame:callParserFunction('#ifexist', 'Media:' .. export, '1') ~= '' then -- Set picture sizes
 		if args[&quot;size&quot;] then                                                    
 			return table.concat({&quot;[[File:&quot;,export,&quot;|alt=|link=|&quot;,args[&quot;size&quot;],&quot;]]&quot;})
 		elseif args[2] == &quot;407ETR&quot; then
 			return table.concat({&quot;[[File:&quot;,export,&quot;|alt=|link=|24px]]&quot;})
 		elseif division == &quot;Kawartha Lakes&quot; then
 			return table.concat({&quot;[[File:&quot;,export,&quot;|alt=|link=|21px]]&quot;})	
 		else
 			return table.concat({&quot;[[File:&quot;,export,&quot;|alt=|link=|x20px]]&quot;})
 		end
 	else
 		return &quot;&quot; -- Retrun nothing if the picture doesn't exist
 	end
 end
 
 --[[
           R E T U R N T E X T 
           Returns the text/link 
 ]]--
 
 local function returnText(frame,Type,args,division,showred)
 	local export; -- Link
 	local display; -- Display (if different from link)
 		if args[2] == &quot;407ETR&quot; then -- Exception
 			export = &quot;Ontario Highway&quot;..&quot; &quot;..&quot;407&quot;
 			display = &quot;Highway&quot;..&quot; &quot;..&quot;407&quot;
 		elseif args[2] == &quot;QEW&quot; then -- Exception
 			export = &quot;Queen Elizabeth Way&quot;
 		elseif Type == &quot;Highway&quot; then -- Highways
 			export = &quot;Ontario Highway&quot;..&quot; &quot;..args[2]
 			display = &quot;Highway&quot;..&quot; &quot;..args[2]
 		elseif division == &quot;Kawartha Lakes&quot; then 
 			export =&quot;Kawartha Lakes&quot; ..&quot; &quot;..&quot;Road&quot;..&quot; &quot;..args[2]
 			display = Type..&quot; &quot;..&quot;Road&quot;..&quot; &quot;..args[2]
 		elseif Type == &quot;County Highway&quot; or Type == &quot;Regional Highway&quot; then
 			export = division..&quot; &quot;..args[2]
 			display = Type..&quot; &quot;..args[2]
 		else
 			export = division..&quot; &quot;..Type..&quot; &quot;..&quot;Road&quot;..&quot; &quot;..args[2]
 			display = Type..&quot; &quot;..&quot;Road&quot;..&quot; &quot;..args[2]
 		end
 		if (frame:callParserFunction('#ifexist',export, '1') ~= '' or showred) and not args[&quot;nolink&quot;] then 
 			if display then
 				export =  &quot;[[&quot;..export..&quot;|&quot;..display..&quot;]]&quot; -- Show display
 			else
 				export = &quot;[[&quot;..export..&quot;]]&quot; -- Show export
 			end
 			
 			return export
 		elseif display then
 			return display
 		else
 			return export
 		end
 end
 
 --[[
            R E T U R N P L A C E 
            Add name/link for a city/town
 ]]--
 
 local function returnPlace(frame,export,place,after,showred)
 	local preExport
 	if frame:callParserFunction('#ifexist',place..&quot;, Ontario&quot;, '1') ~= '' or showred then
 		preExport = &quot;[[&quot;..place..&quot;, Ontario|&quot;..place..&quot;]]&quot;
 	else
 		preExport = place
 	end
 	if after == true then
 		return export..&quot;, &quot;..preExport
 	else
 		return export..&quot; – &quot;..preExport
 	end
 end
 
 --[[
            P . J C O N
            Return final picture(s)/text(s)
 ]]--
 
 function p.jcon (frame)
 	local args = getArgs(frame)
 	args[1] = args[1] or &quot;&quot; -- Unnil args[1]
 	local Remove = {&quot;regional&quot;,&quot;region&quot;,&quot;county&quot;,&quot;country&quot;,
 		&quot;municipality of&quot;,&quot;city of&quot;,&quot;^ &quot;,&quot; $&quot;} -- Stuff to remove from lowercase input
 	for _,v in ipairs(Remove) do
 		args[1] = mw.ustring.gsub(args[1]:lower(),v,'')
 	end
 	args[2] = args[2] or &quot;&quot;
 	local division = divisionTable[args[1]:lower()] or args[1]
 	local Type = typeTable[division]
 	local export = &quot;&quot;
 	if miscTable[args[1]:lower()] or miscTable[args[2]:lower()] then
 		return miscTable[args[1]:lower()] or miscTable[args[2]:lower()]
 	end
 	if not typeTable[division] then -- Region not in typeTable
 		return &quot;&amp;#8203;&quot;
 	end
 	if args[2] == &quot;&quot; then -- Need args[2] after this point
 		return &quot;&amp;#8203;&quot;
 	end
 	if args[&quot;ot&quot;] then -- If output should only be text
 		args[&quot;nosh&quot;] = &quot;yes&quot;
 		args[&quot;nolink&quot;] = &quot;yes&quot;
 	end
 	args[&quot;2A&quot;] = args[2] -- road1 is args[2]
 	if args[&quot;con&quot;] then args[&quot;2B&quot;] = args[&quot;con&quot;] end -- road 2 is args[&quot;con&quot;]
 	if args[&quot;con2&quot;] then args[&quot;2C&quot;] = args[&quot;con2&quot;] end -- road 3 is args[&quot;con2&quot;]
 	-- [[ G E T   P I C T U R E ]] --
 	if not args[&quot;nosh&quot;] then -- If allowed to add shield
 			args[2] = args[&quot;2A&quot;] -- Set args[2] to road 1
 			picture = returnPicture(frame,Type,args,division) -- Return picture of road 1
 		if args[&quot;con&quot;] then
 			args[2] = args[&quot;2B&quot;] -- Set args[2] to road 2
 			picture = picture..&quot;&amp;nbsp;&quot;..returnPicture(frame,Type,args,division) -- Return picture of road 2
 		end
 		if args[&quot;con2&quot;] then
 			args[2] = args[&quot;2C&quot;] -- Set args[2] to road 3
 			picture = picture..&quot;&amp;nbsp;&quot;..returnPicture(frame,Type,args,division) -- Return picture of road 3
 		end
 		if picture ~= &quot;&quot; and not args[&quot;pic aft&quot;] then -- If a picture was returned and picture goes first
 			picture = picture..&quot;&amp;nbsp;&quot; -- Add a space
 		end
 	end
 	-- [[ A D D   P I C T U R E ]] (If it goes before) --
 	if not args[&quot;pic aft&quot;] and picture then -- If picure goes first
 		export = picture
 	end
 	-- [[ A D D   T E X T ]] --
 	if not args[&quot;notext&quot;] then -- If allowed to show text
 		args[2] = args[&quot;2A&quot;]
 		export = export..returnText(frame,Type,args,division,args['showred']) 
 		if args[&quot;con&quot;] then
 			args[2] = args[&quot;2B&quot;]
 			export = export..&quot;&amp;nbsp;&quot;..&quot;/&quot;..&quot; &quot;..returnText(frame,Type,args,division,args['showred'])
 		end
 		if args[&quot;con2&quot;] then
 			args[2] = args[&quot;2C&quot;]
 			export = export..&quot;&amp;nbsp;&quot;..&quot;/&quot;..&quot; &quot;..returnText(frame,Type,args,division,args['showred'])
 		end
 	end
 	if args[&quot;dir&quot;] then -- Direction
 		export = export..&quot; &quot;..args[&quot;dir&quot;]
 		if args[&quot;condir&quot;] then
 			export=export..&quot;/&quot;..args[&quot;condir&quot;]
 		end
 	end
 	if args[3] then -- Name (argument 3)
 		export = export..&quot; (&quot;..args[3]..&quot;)&quot;
 	end
 	if args[&quot;city&quot;] then -- City 1
 		export = returnPlace(frame,export,args[&quot;city&quot;],false,args['showred'])
 	elseif args[&quot;town&quot;] then -- Or town 1
 		export = returnPlace(frame,export,args[&quot;town&quot;],false,args['showred'])
 	end
 	if args[&quot;city2&quot;] then -- City 1
 		export = returnPlace(frame,export,args[&quot;city2&quot;],true,args['showred'])
 	elseif args[&quot;town2&quot;] then -- Or town 1
 		export = returnPlace(frame,export,args[&quot;town2&quot;],true,args['showred'])
 	end
 	-- [[ A D D   P I C T U R E ]] (If it goes after) --
 	if args[&quot;pic aft&quot;] and picture then
 		export = export..&quot;&amp;nbsp;&quot;..picture
 	end
 	return export
 end
 
 --[[
            P . S U P P O R T E D 
            Return all supported &quot;regions&quot; in a list format
 ]]--
 
 function p.supported (frame)
 	local export = &quot;'''Note: All inputs are converted to lowercase'''&lt;br /&gt;&lt;u&gt;'''Supported 'Regions':'''&lt;/u&gt;&quot; -- Add header
 	local supportedTable = {} -- Used to store all regional tables
 	local index = {} -- Used to sort alphabetically
 	for correct,_ in pairs(typeTable) do -- Create tables for each region
 		supportedTable[correct] = {correct}
 	end 
 	for improper,proper in pairs(divisionTable) do -- Add improper to regional tables
 		if supportedTable[proper] then
 			table.insert(supportedTable[proper],improper)
 		else
 			mw.log(proper..&quot; doesn't have a type specified&quot;) -- Log regions that do not have a type
 			supportedTable[proper] = {proper,improper} -- Create table
 		end
 	end
     for correct,_ in pairs(supportedTable) do  -- Add keys to sortable index
     	table.insert(index,correct) 
     end
     table.sort(index) -- Sort index
     for _,correct in ipairs(index) do -- Go over each proper region
     	for _,name in ipairs(supportedTable[correct]) do -- Go over each region name
     		table.sort(supportedTable[correct])
     		if name == correct then -- Add to list if proper name
     			export = export..&quot;&lt;br /&gt;• &quot;..name
     		else -- Add to list if improper name
     			export = export..&quot;&lt;br /&gt;&quot;..&quot;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&quot;..&quot;• &quot;..name
     		end
     	end
     end
     export = export..&quot;&lt;br /&gt;&lt;u&gt;'''Supported MTO signs:'''&lt;/u&gt;&quot; -- Add MTO header
     for k,v in pairs(miscTable) do -- Add MTO signs
 		export = export..&quot;&lt;br /&gt;• &quot;..k
 	end
 	return export -- Return list
 end
 
 --[[
            Return Output
            End of module
 ]]--