Module:Sandbox/Wnt/ColorAlphabet

This module colors each letter depending on which one it is the first parameter/the function is "letter", if it is "blank" it does produce colors, but converts …

Module:Sandbox/Wnt/ColorAlphabet

 ---- This module is supposed to apply Green-Armytage's standard for a "color alphabet" to letters in a string of input text.
 ---- {{#invoke:Sandbox/Wnt/ColorAlphabet|blank|whatever}} for blank, 
 ---- {{#invoke:Sandbox/Wnt/ColorAlphabet|letter|whatever}} for colored letters
 
local getArgs = require('Module:Arguments').getArgs
local p = {}

function p._main(text, lookupfile, nowiki, blank)
   local debuglog=""
   local lookup = {}
   lookup.file = lookupfile
   lookup.data = mw.loadData(lookup.file)
   debuglog = debuglog..tostring(lookup.data)..table.concat(lookup.data)..lookup.data[7] -- debug
   if not(lookup.data) then return "error: failed to open lookup file" .. tostring(lookup.file) end
   local x=0
   repeat
       x=x+1
       i=lookup.data[x*3-2]
       j=lookup.data[x*3-1]
       k=lookup.data[x*3]
       -- debuglog=debuglog..tostring(i)..tostring(j)..tostring(k)
       if not (i and j and k) then break end
      lookup[i]=j .. (blank or i) .. k -- create the lookup table of what letters are supposed to be transliterated to.  If blank == " " then spaces, not letters go in the middle
   until false
   lookup["["]="";lookup["]"]="" -- don't include these in output
   local wikistart={};wikiend={}
   local s=0;local e=0
   repeat
       s,e=mw.ustring.find(text,"%[%[[^%[%]]-%]%]",e)
       if (not(s) or not(e)) then break end
       wikistart[s]=mw.text.trim(mw.ustring.sub(text,s+2,e-2))
       wikiend[e]=true
   until false
   local prowl=mw.ustring.gmatch(text,"(.)")
   local output=""
   local wl=1
   position=0
   repeat
      local letter=prowl()
      if not(letter) then break end
      position=position+1
      if wikistart[position] then output=output..'<div style="position:relative;display:inline-block;"><div style="position:absolute;display:inline-block;top:-20px;left:0px;clip:rect(0px,'..3*mw.ustring.len(wikistart[position])..'px,20px,0px);overflow:hidden;">[[File:Transparent600.gif|link=http://en.wikipedia.org/wiki/' ..wikistart[position].. ']]</div></div>' end
      if wikiend[position] then output=output.."" end
      output=output..(lookup[letter] or letter) -- unicode letters will never all be looked up, handle punctuation the same
   until false
   output='<div style="position:relative;display:inline-block;">'..output..'</div>'
   if nowiki then output='<nowiki>'..output..'</nowiki>'; output=output..debuglog end
   return output
end

 -- common code with all relevant args
function p.main(args, blank)
   local text = args[1] or ""
   local nowiki = args.nowiki or nil
   local lookupfile = args.lookup or "Module:Sandbox/Wnt/ColorAlphabet/lookup"
   return p._main(text, lookupfile, nowiki, blank)
end
   
 -- entry for colorizing letters
function p.letter(frame)
    local args = getArgs(frame)
    return frame:preprocess(p.main(args, nil))
end

 -- entry for replacing letters with colored nonbreaking spaces
function p.blank(frame)
	local args = getArgs(frame)
    return frame:preprocess(p.main(args, "&nbsp;"))
end

return p

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.