Documentation for this module may be created at Մոդուլ:Պիես/doc

local p={}
   
function teatro(verso)
	if string.match(verso,"%+") ~=nil then
		local parti={}
		local ind=0
		parti=mw.text.split(verso,"%+")
		if parti[1] ~= "" then
			parti[1]='<span style="margin-left:0;  position:absolute; left:0; font-variant:small-caps">'..parti[1]..'</span>'
		end
		ind=string.match(parti[2],"^%d+")
		if ind~=nil then
			parti[2]=mw.text.trim(string.gsub(parti[2],ind,"",1))
			ind='<span style="letter-spacing:'..ind..'em;">&nbsp;</span>'
			parti[2]=ind..parti[2]
			
		end
		verso=parti[1]..parti[2]

	end
	return verso.."<br/>\n"
end	
function p.poem (frame)
    frame=frame:getParent()
    local testo=frame.args[1]
    local nvc=frame.args["R"]
    if nvc==nil then 
        nvc=1
    end
    local view=frame.args["V"]
    if view==nil then 
        view=false
    end
    if string.sub(testo,1,1)=="\n" then
    	testo=string.sub(testo,2,#testo)
    end
    if string.sub(testo,-1)=="\n" then
    	testo=string.sub(testo,1,#testo-1)
    end
    local versi=mw.text.split( testo, '\n')
    local verso=""
    local spazi=""
    testo='<div class="poem" style="position:relative; margin-left:0; padding-left:6em"><p>'
    nr=1
	while versi[nr]~=nil do
        verso=teatro(versi[nr])
        -- gestione spazi in  testa
        spazi=string.match(verso,"^ +")
        if spazi~=nil then
        	 verso=string.gsub(verso,spazi,string.rep("&nbsp;",#spazi))
        end
        testo=testo..verso
		nr=nr+1
    end
    
    testo=testo.."</p></div>"
    testo=string.gsub(testo,"<br>%n</p>","</p>")
    return testo
end
return p