12,564
edits
TheNightAvl (talk | contribs) No edit summary |
TheNightAvl (talk | contribs) No edit summary |
||
| Line 10: | Line 10: | ||
local gloss = args[1] | local gloss = args[1] | ||
local gloss_keys = {} | local gloss_keys = {} | ||
for glosslet in gloss:gmatch("[^" .. delimiters .. "]+") do | for glosslet in gloss:gmatch("[^" .. delimiters .. "]+") do -- split the string into chunks by delimiters | ||
if glosslet:match("^[%d%u]+$") then | if glosslet:match("^[%d%u]+$") then --[[ match chunks which are valid glosses (i.e. only contain capital letters and numbers) | ||
local gloss_code = glosslet:lower() | This method means that you can use capital letters in semantic glosses, such as when you need to gloss proper nouns, | ||
local glosslet_format = gloss_code:gsub("(%d+)", "<small>%1</small>") | without the capitalisation being mistaken for grammatical glossing. Be wary of glossing acronyms, as “USA”, for example, | ||
will still be parsed as a grammatical gloss on its own. | |||
]]-- | |||
local gloss_code = glosslet:lower() -- decapitalise grammatical glosses for correct display under small caps | |||
local glosslet_format = gloss_code:gsub("(%d+)", "<small>%1</small>") -- make numbers small too, as they are unaffected by small caps | |||
local l_gloss = m_data.aliases[gloss_code] | |||
if l_gloss then -- check valid gloss (does not necessarily check for standardised glossing practices, just whatever is in form of/data) | |||
local l = m_data.labels[l_gloss] | local l = m_data.labels[l_gloss] | ||
if l then l_gloss = type(l.glossary) == "string" and l.glossary or l.label end | if l then l_gloss = type(l.glossary) == "string" and l.glossary or l.label end -- check if label has glossary text and update | ||
glosslet_format = frame:expandTemplate{title = "hover", args = {glosslet_format, l_gloss, noline = args.noline or (args.style == nil and l and args.nolinks == nil), style = args.style}} --[[ format hover text (I spent ages agonising over the logic in excel for the conditions of this system, so here it is) | |||
glosslet_format = frame:expandTemplate{title = "hover", args = {glosslet_format, l_gloss, noline = args.noline or (args.style == nil and l and args.nolinks == nil), style = args.style}} | LINKS ENABLED? IN GLOSSARY? (L) NOLINK=1 STYLE NOLINE=1 LINE DISPLAYED? FINAL BOOLEAN FOR NO LINE | ||
✓ ✓ × × × × TRUE | |||
✓ × × × × ✓ FALSE | |||
× ✓ ✓ × × ✓ FALSE | |||
× × ✓ × × ✓ FALSE | |||
✓ ✓ × ✓ × ✓ FALSE | |||
✓ × × ✓ × ✓ FALSE | |||
× ✓ ✓ ✓ × ✓ FALSE | |||
× × ✓ ✓ × ✓ FALSE | |||
✓ ✓ × × ✓ × TRUE | |||
✓ × × × ✓ × TRUE | |||
× ✓ ✓ × ✓ × TRUE | |||
× × ✓ × ✓ × TRUE | |||
-]] | |||
if l and args.nolinks == nil then glosslet_format = "[[Appendix:Glossary#" .. l_gloss .. "|" .. glosslet_format .. "]]" end | if l and args.nolinks == nil then glosslet_format = "[[Appendix:Glossary#" .. l_gloss .. "|" .. glosslet_format .. "]]" end | ||
-- format links (hover and links MUST be in this order) | -- format links (hover and links MUST be done in this order for the gloss' hover texts to override the links') | ||
end | end | ||
gloss_keys[glosslet] = '<span style="font-variant: small-caps">' .. glosslet_format .. '</span>' | gloss_keys[glosslet] = '<span style="font-variant: small-caps">' .. glosslet_format .. '</span>' | ||