Edge Rewrite
// HTMLRewriter · presentation

This page was redesigned at the edge.

Cloudflare fetched the original article and streamed it through HTMLRewriter to apply an entirely new visual system without rebuilding the source page.

// request.cf · coarse context

A page that knows where it met you.

Only coarse request metadata is shown. This demo does not display or persist visitor IP addresses.

Country
US
Cloudflare location
CMH
Connection
HTTP/2
Language
Not provided

Ray ID: a22cff5bef0aeddd

Jump to content

Module:Sandbox/teaktl17

From Wikipedia, the free encyclopedia

--[[
Sandbox of User:teaktl17
]]--

require ('strict')

local getArgs = require('Module:Arguments').getArgs
local p = {}

local prefs = {
-- stereo specifiers
	['cis'] = true,
	['trans'] = true,
	['syn'] = true,
	['anti'] = true,
	['endo'] = true,
	['exo'] = true,
	['meso'] = true,
	['sn'] = true,
-- arene substitution patters		
	['ortho'] = true,
	['o'] = true,
	['meta'] = true,
	['m'] = true,
	['para'] = true,
	['p'] = true,
-- traditional:	sec-, s-, tert-, t-
	['sec'] = true,
	['s'] = true,
	['tert'] = true,
	['t'] = true,
-- historical: n- for normal, i- for iso
	['n'] = true,
	['i'] = true
}

function p.format(in_str)
	local out = in_str or ''
	local i -- position in 'out' string to analyze
	local function insert2(s, e, on, a_off)
		local off = a_off or on
		out = out:sub(1, s - 1) .. on .. out:sub(s, e) .. off .. out:sub(e + 1)
		i = e + 1 + #on + #off
	end
	i = 1
	repeat
		local s, e -- start and end position in 'out' string
		local found -- pattern is matched
		local function find3(pat, lit)
			s, e = out:find(pat, i, lit)
			found = not not (s and e) 
			return found
		end
		-- small for D-, L-, DL-, etc.
		if find3('^[DL]+%-') then
			e = e - 1
		end
		if not found then
			if find3('%-[DL]+%-') then
				s = s + 1
				e = e - 1
			end
		end
		if found then
			insert2(s, e, '<small>', '</small>')
		else
			-- italic for 
			--     Stereo specifiers: R/S, E/Z, etc.
			local function find4(pair)
				local before = '%' .. pair:sub(1,1)
				local after = '%' .. pair:sub(2,2)
				local pat = before .. '%d*%l?[RSrsEZ]' .. after
				if find3(pat) then
					s = e - 1
					e = e - 1
					insert2(s, e, "''")
				end
			end
			find4('()')
			if not found then
				find4('(,')
				if found then
					repeat
						find4(',,')
					until not found
					find4(',)')
				end
			end
			if not found then
				mw.log("prefs", i, out:sub(i))
				local function test_pr()
					local str = out:sub(s, e)
					if prefs[str] then
						mw.log(i, out:sub(i))
						insert2(s, e, "''")
						mw.log(i, out:sub(i))
					else
						i = e
					end
				end
				if i == 1 and find3("^%l+[-,]") then
					e = e - 1
					test_pr()
				end
				if not found and find3("%A%l+[-,]") then
					s = s + 1
					e = e - 1
					test_pr()
				end
			end
		end
	until not found
	return out
end

function p._main(args)
	local in_str = args[1] or ''
	return p.format(in_str)
end

function p.main(frame)
    local args = getArgs(frame)
    return p._main(args)
end

return p