45,342
edits
(Created page with "local p = {} local data = mw.loadData( 'Module:Interlinear/data' ) local gloss_override = {} -- for custom gloss abbreviations local getArgs = require('Module:Arguments').getA...") |
No edit summary |
||
(7 intermediate revisions by the same user not shown) | |||
Line 20: | Line 20: | ||
GlossAbbrBoundary = "-.,;:<>‹›/\\~+=%?%s%[%]()%_\127'", | GlossAbbrBoundary = "-.,;:<>‹›/\\~+=%?%s%[%]()%_\127'", | ||
GlossExcludeTable = {I = true,}, --strings not be treated as glossing abbreviations | GlossExcludeTable = {I = true,}, --strings not be treated as glossing abbreviations | ||
GlossExcludePattern = '[0-9][0-9]+', | GlossExcludePattern = '^[0-9][0-9]+$', -- excludes strings consisting entirely of digits | ||
GlossSmallCapsExclude = "^[AOPS]$", -- glossing abbreviations matching this pattern will not be rendered in small caps | GlossSmallCapsExclude = "^[AOPS]$", -- glossing abbreviations matching this pattern will not be rendered in small caps | ||
GlossingType = "label", -- if set to "label" gloss abbreviations are formatted as an <abbr> with the "label" appearing in a tooltip | GlossingType = "label", -- if set to "label" gloss abbreviations are formatted as an <abbr> with the "label" appearing in a tooltip | ||
Line 57: | Line 57: | ||
ErrorMessage = "error", | ErrorMessage = "error", | ||
} | } | ||
--------------------- | |||
-- Section transclusion | |||
--------------------- | |||
local page_content = nil -- lazy initilization | |||
local function get_section(frame, section_name) | |||
if page_content == nil then | |||
local current_title = mw.title.getCurrentTitle() | |||
page_content = current_title:getContent() | |||
end | |||
if page_content then | |||
if mw.ustring.find(page_content, section_name, 1, true) then | |||
return frame:preprocess('{{#section:{{FULLPAGENAME}}|' .. section_name .. '}}') | |||
end | |||
end | |||
return '' | |||
end | |||
--------------------- | --------------------- | ||
-- Sundry small functions | -- Sundry small functions | ||
Line 78: | Line 93: | ||
local function tone_sup(str) | local function tone_sup(str) | ||
return mw.ustring.gsub(str, "([^%p%s0-9])([0-9])", "%1<sup>%2</sup>") | return mw.ustring.gsub(str, "([^%p%s0-9])([0-9]+)", "%1<sup>%2</sup>") | ||
end | end | ||
Line 206: | Line 221: | ||
if displaying_messages and (next(self.gloss_messages) or next(self.warnings)) then | if displaying_messages and (next(self.gloss_messages) or next(self.warnings)) then | ||
local div = mw.html.create("div") | local div = mw.html.create("div") | ||
div:addClass(" | div:addClass("interlinear-preview-warning") | ||
: | :cssText('border: 1px solid #a2a9b1; background-color: #f8f9fa; width: 80%; padding: 0.2em;') | ||
:wikitext("<i>This message box is shown only in preview:</i>") | :wikitext("<i>This message box is shown only in preview:</i>") | ||
:newline() | :newline() | ||
Line 231: | Line 246: | ||
--------------------- | --------------------- | ||
local function gloss_lookup(a, label, wikilink) | local function gloss_lookup(a, label, wikilink) | ||
local _label, _wikilink, _lookup = nil, nil, nil | local _label, _wikilink, _lookup, source = nil, nil, nil, nil | ||
if gloss_override[a] then _lookup = gloss_override[a] | if gloss_override[a] then | ||
_lookup = gloss_override[a] | |||
source = "local" | |||
elseif data.abbreviations[a] then _lookup = data.abbreviations[a] end | elseif data.abbreviations[a] then _lookup = data.abbreviations[a] end | ||
if _lookup and _lookup.expansion ~= "" then | if _lookup and _lookup.expansion ~= "" then | ||
Line 272: | Line 289: | ||
if not label then label = _label end | if not label then label = _label end | ||
if not wikilink then wikilink = _wikilink end | if not wikilink then wikilink = _wikilink end | ||
return label, wikilink | return label, wikilink, source | ||
end | end | ||
Line 280: | Line 297: | ||
--------------------- | --------------------- | ||
local function format_gloss(gloss, label, wikilink) | local function format_gloss(gloss, label, wikilink) | ||
if string.sub(gloss,1,3) == "000" then -- checks for a common component of exposed strip markers (see [[:mw:Strip marker]]) | |||
return gloss | |||
end | |||
local gloss2 = mw.ustring.gsub(gloss,"<.->","") -- remove any html fluff | local gloss2 = mw.ustring.gsub(gloss,"<.->","") -- remove any html fluff | ||
gloss2 = mw.ustring.gsub(gloss2, "%'%'+", "") -- remove wiki bold/italic formatting | gloss2 = mw.ustring.gsub(gloss2, "%'%'+", "") -- remove wiki bold/italic formatting | ||
Line 288: | Line 308: | ||
then | then | ||
if glossing_type ~= "no abbr" | if glossing_type ~= "no abbr" | ||
then label, wikilink = gloss_lookup(gloss2, label, wikilink) | then label, wikilink, source = gloss_lookup(gloss2, label, wikilink) | ||
end | end | ||
end | end | ||
Line 305: | Line 325: | ||
else abbr_label = wikilink end | else abbr_label = wikilink end | ||
gloss_node:attr("title", abbr_label) | gloss_node:attr("title", abbr_label) | ||
if data.abbreviations[gloss2] then | if source ~= "local" and data.abbreviations[gloss2] then | ||
if data.abbreviations[gloss2].ambiguous then | if data.abbreviations[gloss2].ambiguous then | ||
gloss_node:addClass(conf.class.GlossAbbrAmb) | gloss_node:addClass(conf.class.GlossAbbrAmb) | ||
Line 314: | Line 334: | ||
then gloss_node:wikitext("[[", wikilink, "|" , gloss, "]]") | then gloss_node:wikitext("[[", wikilink, "|" , gloss, "]]") | ||
else gloss_node:wikitext(gloss) end | else gloss_node:wikitext(gloss) end | ||
if displaying_messages then -- logging gloss lookups: | if source ~= "local" and displaying_messages then -- logging gloss lookups: | ||
local message = "" | local message = "" | ||
if label then | if label then | ||
Line 491: | Line 511: | ||
args.italics2 = args.italics2 or "yes" | args.italics2 = args.italics2 or "yes" | ||
args.glossing3 = args.glossing3 or "yes" | args.glossing3 = args.glossing3 or "yes" | ||
if args.lang and not args.lang2 then args.lang2 = args.lang .."-Latn" end | |||
if args.transl and not args.transl2 then args.transl2 = args.transl end | if args.transl and not args.transl2 then args.transl2 = args.transl end | ||
if_auto_translit = true | if_auto_translit = true | ||
Line 515: | Line 536: | ||
end | end | ||
--this looks for a list of glossing abbreviations on the page that transcludes the template: | --this looks for a list of glossing abbreviations on the page that transcludes the template: | ||
local _ablist_section = frame | local _ablist_section = get_section(frame, 'list-of-glossing-abbreviations') | ||
if _ablist_section and _ablist_section ~= "" then | if _ablist_section and _ablist_section ~= "" then | ||
local _a = mw.ustring.gsub(_ablist_section, '</?div [^\n]*>', '') -- strips off the div tags | local _a = mw.ustring.gsub(_ablist_section, '</?div [^\n]*>', '') -- strips off the div tags | ||
Line 521: | Line 542: | ||
end | end | ||
--and this looks looks for a list of abbreviations set within the template: | --and this looks looks for a list of abbreviations set within the template: | ||
local _ablist = args.abbreviations | local _ablist = args.abbreviations | ||
if _ablist and _ablist ~= "" | |||
then set_custom_glosses(_ablist) end | |||
local _ablist = args.ablist | |||
if _ablist and _ablist ~= "" | if _ablist and _ablist ~= "" | ||
then set_custom_glosses(_ablist) end | then set_custom_glosses(_ablist) end | ||
Line 578: | Line 602: | ||
end | end | ||
line[i].attr.lang = line[i].lang | line[i].attr.lang = line[i].lang | ||
--the following emulates the behaviour of {{Bo-textonly}} (see Template talk:Fs interlinear#Tibetan): | |||
if template_name == 'Template:Fs interlinear' then | |||
if _lang == "bo" and i == 1 then | |||
line[1].class = line[1].class .. " uchen" | |||
line[1].attr.style = line[1].attr.style .. "font-size:1.25em; word-wrap:break-word;" | |||
end | |||
end | |||
--the following emulates the behaviour of {{Spell-nv}}: | |||
if template_name == 'Template:Interlinear' then | |||
if _lang == "nv" and i == 1 then | |||
line[1].attr.style = line[1].attr.style .. "font-family: Aboriginal Sans, DejaVu Sans, Calibri, Arial Unicode MS, sans-serif;" | |||
end | |||
end | |||
if yesno(args["italics" .. i]) then | if yesno(args["italics" .. i]) then |