spec.linkprefix or "", indepCity, spec.linksuffix or "")
local name = format("%s%s%s",
spec[modulenameprefix] or spec.nameprefix or "",
indepCity,
spec[modulenamesuffix] or spec.namesuffix or "")
indepCityText = format("%s%s%s",
spec[modulearticle] or spec.article or "",
spec[moduleprefix] or spec.prefix or "",
link, name)
else
-- TODO transition
warnings.indep_city = "Spec for indep_city parameter undefined in road data module"
local cityLink -- Wikilink for independent city
if primaryTopic then
cityLink = format('%s', indepCity)
else
-- Specialize independent city to the region.
cityLink = format('%s', indepCity, region, indepCity)
end
indepCityText = "City of " .. cityLink
end
end
if indepCityText then
return {region = regionText, indep_city = indepCityText, warnings = warnings}
end  
-- First-level subdivision, e.g., county
-- Name of the type of subdivision, e.g., "County" and "Parish"
local sub1name = args.sub1name -- TODO transition
local sub1Text
if args.sub1_special then
sub1Text = args.sub1_special -- Overrides `sub1` argument.
elseif args.sub1 then
local sub1 = args.sub1
local article
local link = sub1
local name = sub1
-- Type of first-level subdivision area, as a form of disambiguation
local sub1area = args.sub1area
if sub1area then
local sub1areaSpec = locations.sub1areas and locations.sub1areas[sub1area]
if sub1areaSpec then
article = sub1areaSpec[modulearticle] or sub1areaSpec.article or ""
link = format("%s%s%s",
sub1areaSpec.linkprefix or "", link, sub1areaSpec.linksuffix or "")
name = format("%s%s%s",
group and "" or sub1areaSpec[modulenameprefix] or sub1areaSpec.nameprefix or "",
name,
group and "" or sub1areaSpec[modulenamesuffix] or sub1areaSpec.namesuffix or "")
else
-- TODO report error
local errMsg = util.err(format("Undefined sub1area: %s", sub1area))
name = format("%s%s", name, errMsg)
end
end
if locations.sub1 then
local spec = locations.sub1
-- Prepend and append text from spec.
link = format("%s%s%s",
spec.linkprefix or "", link, spec.linksuffix or "")
name = format("%s%s%s",
spec[modulenameprefix] or spec.nameprefix or "",
name,
spec[modulenamesuffix] or spec.namesuffix or "")
sub1Text = format("%s%s", article or "", link, name)
else
-- TODO transition
warnings.sub1 = "Spec for sub1 parameter undefined in road data module"
-- Add type (if specified) to wikilink for first-level subdivision.
local sub1Link = sub1name and trim(format("%s %s", sub1, sub1name)) or sub1
local sub1Name = module == "jcttop" and sub1Link or sub1
if primaryTopic then
sub1Text = format('%s', sub1Link, sub1Name)
else
-- Specialize first-level subdivision, with type added, to the region.
sub1Text = format('%s', sub1Link, region, sub1Name)
end
end
end  
-- Second-level subdivision, e.g., city and town
local sub2Text
if args.sub2_special then
sub2Text = args.sub2_special -- Overrides `sub2` argument.
elseif args.sub2 then
local sub2 = args.sub2
if sub2 == "" then
sub2Text = "&#8203;" -- Zero-width space
elseif sub2 == "&nbsp;" then
-- TODO transition
warnings.sub2 = "&nbsp; argument for sub2 parameter is deprecated"
sub2Text = "&#8203;" -- Zero-width space
elseif primaryTopic then
-- TODO transition
sub2Text = format("%s", sub2)
else
local article
local link = sub2
local name = sub2
-- Type of area, e.g., city and village, as a form of disambiguation
local sub2area = args.sub2area --TODO transition or args.area
if sub2area then
local sub2areaSpec = locations.sub2areas and locations.sub2areas[sub2area]
if not sub2areaSpec then
-- TODO transition
warnings.sub2 =
format("Spec for area parameter '%s' undefined in road data module", sub2area)
local sub2areas = { -- table of different area types
city = {
linksuffix = " (city)",
jcttoparticle = "the ",
nameprefix = "City of "
},
town = {
linksuffix = " (town)",
jcttoparticle = "the ",
nameprefix = "Town of "
},
village = {
linksuffix = " (village)",
jcttoparticle = "the ",
nameprefix = "Village of "
},
community = {
linksuffix = " (community)",
jcttoparticle = "the ",
nameprefix = "Community of "
},
CDP = {
linksuffix = " (CDP)",
jcttoparticle = "the ",
nameprefix = "Community of "
},
hamlet = {
linksuffix = " (hamlet)",
jcttoparticle = "the ",
nameprefix = "Hamlet of "
},
["unorganized territory"] = {
linksuffix = " (unorganized territory)",
jcttoparticle = "the ",
nameprefix = "Unorganized Territory of "
},
township = {
linksuffix = " Township",
namesuffix = " Township",
}
}
sub2areaSpec = sub2areas[sub2area]
end
if sub2areaSpec then
article = sub2areaSpec[modulearticle] or sub2areaSpec.article or ""
link = format("%s%s%s",
sub2areaSpec.linkprefix or "", link, sub2areaSpec.linksuffix or "")
name = format("%s%s%s",
group and "" or sub2areaSpec[modulenameprefix] or sub2areaSpec.nameprefix or "",
name,
group and "" or sub2areaSpec[modulenamesuffix] or sub2areaSpec.namesuffix or "")
else
-- TODO report error
local errMsg = util.err(format("Undefined sub2area: %s", sub2area))
name = format("%s%s", name, errMsg)
end
end
if locations.sub2 then
local spec = locations.sub2
-- Prepend and append text from spec.
link = format("%s%s%s",
spec.linkprefix or "", link, spec.linksuffix or "")
name = format("%s%s%s",
spec[modulenameprefix] or spec.nameprefix or "",
name,
spec[modulenamesuffix] or spec.namesuffix or "")
else
-- TODO transition
warnings.sub2 = "Spec for sub2 parameter undefined in road data module"
-- Some second-level subdivisions are not unique in a given region.
-- `sub1dab` is the first-level subdivision to be used for disambiguation.
local sub1dab = args.sub1dab
if sub1dab then
sub1dab = sub1name and trim(format("%s %s", sub1dab, sub1name)) or sub1dab
link = format("%s, %s", link, sub1dab)
end
link = format("%s, %s", link, region) -- Add region to wikilink
end
sub2Text = format("%s%s", article or "", link, name)
end
end
return {region = regionText, sub1 = sub1Text, sub2 = sub2Text, warnings = warnings}
end  
return p