Module:Interlinear: Difference between revisions

no edit summary
No edit summary
No edit summary
 
(2 intermediate revisions by the same user not shown)
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 90: Line 105:
local function help_link (anchor)
local function help_link (anchor)
if anchor then
if anchor then
return " ([[w:" .. conf.ErrorHelpLocation .. "#" .. anchor .. "|help]])"
return " ([[" .. conf.ErrorHelpLocation .. "#" .. anchor .. "|help]])"
else return "" end
else return "" end
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("messagebox")
div:addClass("interlinear-preview-warning")
:css("margin", "inherit")
: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 282: 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 314: Line 332:
end
end
if glossing_type == "wikilink" and wikilink
if glossing_type == "wikilink" and wikilink
then gloss_node:wikitext("[[w:", wikilink, "|" , gloss, "]]")
then gloss_node:wikitext("[[", wikilink, "|" , gloss, "]]")
else gloss_node:wikitext(gloss) end
else gloss_node:wikitext(gloss) end
if source ~= "local" and displaying_messages then -- logging gloss lookups:
if source ~= "local" and displaying_messages then -- logging gloss lookups:
Line 518: 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:preprocess('{{#section:{{FULLPAGENAME}}|list-of-glossing-abbreviations}}')
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 589: Line 607:
line[1].class = line[1].class .. " uchen"
line[1].class = line[1].class .. " uchen"
line[1].attr.style = line[1].attr.style .. "font-size:1.25em; word-wrap:break-word;"
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
end
end
Line 823: Line 847:
end_div:attr("style", conf.style.EndDiv)
end_div:attr("style", conf.style.EndDiv)
div:newline()
div:newline()
return tostring(div) .. msg:print_warnings()
local temp_track = ""
if last_line == 2
then temp_track = "[[Category:Pages with interlinear glosses using two unnamed parameters]]"
end
if last_line > 3 and template_name ~= 'Template:Fs interlinear'
then  temp_track = "[[Category:Pages with interlinear glosses using more than three unnamed parameters]]"
end
return tostring(div) .. temp_track .. msg:print_warnings()
end
end


return p
return p