local html_t = {};
local style_added = '';
local wrapper_tag = tag; -- <tag> gets modified so save a copy for use when/if we create a wrapper span or div  
if text:match ('^%*') then
table.insert (html_t, '&#42;'); -- move proto language text prefix outside of italic markup if any; use numeric entity because plain splat confuses MediaWiki
text = text:gsub ('^%*', ''); -- remove the splat from the text
end  
if 'span' == tag then -- default html tag for inline content
if 'italic' == style then -- but if italic
tag = 'i'; -- change to <i> tags
end
else -- must be div so go
text = div_markup_add (text, style); -- handle implied <p>, implied <p> with <i>, and list markup (*;:#) with <i>
end  
table.insert (html_t, table.concat ({'<', tag})); -- open the <i>, <span>, or <div> html tag
code = code:gsub ('%-x%-.*', ''); -- strip private use subtag from code tag because meaningless outside of wikipedia
table.insert (html_t, table.concat ({' lang="', code, '\"'})); -- add language attribute  
if (rtl or unicode.is_rtl(text)) and ('ltr' == this_wiki_lang_dir) then -- text is -to- on a -to- wiki
table.insert (html_t, ' dir="rtl"'); -- add direction attribute for -to- languages
elseif not (rtl or unicode.is_rtl(text)) and ('rtl' == this_wiki_lang_dir) then -- text is -to- on a -to- wiki
table.insert (html_t, ' dir="ltr"'); -- add direction attribute for -to- languages
end  
if 'normal' == style then -- when |italic=no
table.insert (html_t, ' style=\"font-style: normal;'); -- override external markup, if any
style_added = '\"'; -- remember that style attribute added and is not yet closed
end  
if is_set (size) then -- when |size=<something>
if is_set (style_added) then
table.insert (html_t, table.concat ({' font-size: ', size, ';'})); -- add when style attribute already inserted
else
table.insert (html_t, table.concat ({' style=\"font-size: ', size, ';'})); -- create style attribute
style_added = '\"'; -- remember that style attribute added and is not yet closed
end
end  
table.insert (html_t, table.concat ({style_added, '>'})); -- close the opening html tag
table.insert (html_t, text); -- insert the text  
table.insert (html_t, table.concat ({'</', tag, '>'})); -- close the 'text' <i>, <span>, or <div> html tag  
if is_set (language) then -- create a <title_text> string for the title= attribute in a wrapper span or div
local title_text;
if 'zxx' == code then -- special case for this tag 'no linguistic content'
title_text = substitute ('$1 $2', {language, cfg.make_text_html_t.zxx}); -- not a language so don't use 'language' in title text
elseif mw.ustring.find (language, 'languages', 1, true) then
title_text = substitute ('$1 $2', {language, cfg.make_text_html_t.collective}); -- for collective languages
else
title_text = substitute ('$1-$2', {language, cfg.make_text_html_t.individual}); -- for individual languages
end  
return title_wrapper_make (title_text, table.concat (html_t), wrapper_tag);
else
return table.concat (html_t);
end
end  
--[=[-------------------------< M A K E _ C A T E G O R Y >----------------------------------------------------  
For individual language, <language>, returns:  
For English:  
For ISO 639-2 collective languages (and for 639-1 bh):  
]=]  
local function make_category (code, language_name, nocat, name_get)
if ((0 ~= namespace) or nocat) and not name_get then -- only categorize in article space
return ''; -- return empty string for concatenation
end  
if mw.ustring.find (language_name, 'languages', 1, true) then
return substitute ('$1 $2', {cfg.make_category_t.collective_cat, language_name});
end  
if this_wiki_lang_tag == code then
return substitute ('$1 $2 $3-$4', { -- unique category name for the local language
cfg.make_category_t.cat_prefix,
cfg.make_category_t.explicit_cat,
language_name,
cfg.make_category_t.cat_postfix,
});
else
return substitute ('$1 $2-$3', { -- category for individual languages
cfg.make_category_t.cat_prefix,
language_name,
cfg.make_category_t.cat_postfix,
});
end
end  
--script= is not used in for this purpose; instead it uses |code. Because language scripts
are listed in the switches they are included in the data tables. The script parameter is introduced
at . If |script= is set, this function uses it in preference to code.  
To avoid confusion, in this module and the templates that use it, the transliteration script parameter is renamed
to be |translit-script= (in this function, tscript).  
This function is used by both lang_xx and transl
lang_xx always provides code, language_name, and translit; may provide tscript; never provides style
transl always provides language_name, translit, and one of code or tscript, never both; always provides style  
For , style only applies when a language code is provided.  
local function make_translit (code, language_name, translit, std, tscript, style, engvar)
local title_t = lang_data.translit_title_table; -- table of transliteration standards and the language codes and scripts that apply to those standards
local title_text = ''; -- tool tip text for title= attribute  
std = std and std:lower; -- lower case for table indexing  
if not is_set (std) and not is_set (tscript) then -- when neither standard nor script specified
title_text = language_name; -- write a generic tool tip
if not mw.ustring.find (language_name, 'languages', 1, true) then -- collective language names (plural 'languages' is part of the name)
title_text = substitute ('$1-$2', {title_text, cfg.misc_text_t.language}); -- skip this text (individual and macro languages only)
end
title_text = substitute ('$1 $2', {title_text, mw.ustring.lower (cfg.engvar_t[engvar]['romanisz_lc'])}); -- finish the tool tip; use romanization when neither script nor standard supplied  
elseif is_set (std) and is_set (tscript) then -- when both are specified
if title_t[std] then -- and if standard is legitimate
if title_t[std][tscript] then -- and if script for that standard is legitimate
if script_table[tscript] then
title_text = substitute ('$1$2 ($3 $4) $5', { -- add the appropriate text to the tool tip
title_text,
title_t[std][tscript:lower],
script_table[tscript],
cfg.make_translit_t.script,
cfg.make_translit_t.transliteration,
});
else
title_text = title_text .. title_t[std]['default']; -- use the default if script not in std table; TODO: maint cat? error message because script not found for this standard?
end
else
title_text = title_text .. title_t[std]['default']; -- use the default if script not in std table; TODO: maint cat? error message because script not found for this standard?
end
else
return ''; -- invalid standard, setup for error message
end  
elseif is_set (std) then -- translit-script not set, use language code
if not title_t[std] then return ''; end -- invalid standard, setup for error message  
if title_t[std][code] then -- if language code is in the table (transl may not provide a language code)
title_text = substitute ('$1$2 ($3 $4) $5', { -- add the appropriate text to the tool tip
title_text,
title_t[std][code:lower],
language_name,
cfg.misc_text_t.language,
cfg.make_translit_t.transliteration,
});
else -- code doesn't match
title_text = title_text .. title_t[std]['default']; -- so use the standard's default
end  
else -- here if translit-script set but translit-std not set
if title_t['no_std'][tscript] then
title_text = title_text .. title_t['no_std'][tscript]; -- use translit-script if set
elseif title_t['no_std'][code] then
title_text = title_text .. title_t['no_std'][code]; -- use language code
else
if is_set (tscript) then
title_text = substitute ('$1$2-$3 $4', { -- write a script tool tip
title_text,
language_name,
cfg.make_translit_t.script,
cfg.make_translit_t.transliteration,
});  
elseif is_set (code) then
if not mw.ustring.find (language_name, 'languages', 1, true) then -- collective language names (plural 'languages' is part of the name)
title_text = substitute ('$1-$2', { -- skip this text (individual and macro languages only)
title_text,
cfg.misc_text_t.language,
});
end