Module:Clade/example

local p = {}

function p.example(frame)
	
	local params = mw.getCurrentFrame():getParent().args
		-- build HTML table
	local exampleTable = mw.html.create('table')
	exampleTable:addClass('wikitable')
	local align = params['align'] or 'center'
	if align == 'center' then
		exampleTable:css('margin-left', 'auto')
		exampleTable:css('margin-right','auto')
	elseif align == 'right' then
		exampleTable:css('float',align)
	end
	
	local columns = {'description','code','output','comment'}
	--local headers = {'Description','Code','Output','Comment'}
    -- create header row and add requested headers
    local row = exampleTable:tag('tr')
    local headerText
    for k,v in pairs(columns) do
		if params[v] then 
			if params[v]~='' then headerText=params[v]  else headerText = firstToUpper(v) end
			row:tag('th'):wikitext(headerText) 
	    end
    end

	-- now deal with the data rows
	local i=0
	while i<10 do
		i=i+1 
		local moreRows = false
		for k,v in pairs(columns) do
			if params[v..i] then moreRows = true end
		end
		if not moreRows then break end
			
		row = exampleTable:tag('tr')
		for k,v in pairs(columns) do
			if params[v] then
				if params[v] then 
					if v=="code" and isNoWikiStripMarker(params['code'..i]) then
						local nowikiOutput = mw.text.unstripNoWiki(params["code"..i])
						local parsedNowikiOutput = frame:preprocess ('<syntaxhighlight lang="wikitext">' .. nowikiOutput .. '</syntaxhighlight>')
						row:tag('td'):css('text-align', 'left')
						            --:wikitext('\n' .. frame:callParserFunction( '#tag:pre', nowikiOutput ) ) -- wrap with <pre>
						            :wikitext('\n' .. parsedNowikiOutput )                                     -- use syntaxhighlight
					elseif v=="output" and isNoWikiStripMarker(params['code'..i]) then
						local nowikiOutput = mw.text.unstripNoWiki(params["code"..i])
						local parsedOutput = frame:preprocess (nowikiOutput)
						row:tag('td'):css('text-align', 'left'):wikitext('\n' .. parsedOutput) 
					else
						row:tag('td'):css('text-align', 'left'):wikitext('\n' ..params[v..i]) 
					end
				else
					row:tag('td')
				end
			end
		end
    end

	return tostring(exampleTable)
end
function isNoWikiStripMarker(str)
	return string.match (str, '^%s*\127[^\127]*UNIQ%-%-nowiki%-%x%x%x%x%x%x%x%x%-QINU[^\127]*\127%s*$') 
end

function firstToUpper(str)
    return (str:gsub("^%l", string.upper))
end


function p.templateStyle( frame, src )
   return frame:extensionTag( 'templatestyles', '', { src = src } );
end

-- this must be at 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.