Skip to main content
shorter
Source Link
Syntax
  • 111
  • 4

Lua - 340340 335

a,b=f='(%w+)'a={},b={}for l in io.lines(arg[2])do i=l:sub(1,1)t=i=='#'and a or b
k,v=l:match'match(%w+)f..' {(.-)}'t[k]=v')t[k]=v end
for l in io.lines(arg[1])do
c=''g='class="(.-)"'f='(%w+)'h='style="'l=l"'h='style="'l=l:gsub('id="(%w+)"''id='..f,function(v)l:gsub(g,function(e)c=e:gsub(f,b)end)return h..a[v]..c..'"'end)l=l:gsub(g,function(e)return #c<1 and h..e:gsub(f,b)..'"'end)print(l)end

**Usage:** execute from the command line `lua script.lua input.html input.css`

Lua - 340

a,b={},{}for l in io.lines(arg[2])do i=l:sub(1,1)t=i=='#'and a or b
k,v=l:match'(%w+) {(.-)}'t[k]=v end
for l in io.lines(arg[1])do
c=''g='class="(.-)"'f='(%w+)'h='style="'l=l:gsub('id="(%w+)"',function(v)l:gsub(g,function(e)c=e:gsub(f,b)end)return h..a[v]..c..'"'end)l=l:gsub(g,function(e)return #c<1 and h..e:gsub(f,b)..'"'end)print(l)end

**Usage:** execute from the command line `lua script.lua input.html input.css`

Lua - 340 335

f='(%w+)'a={}b={}for l in io.lines(arg[2])do i=l:sub(1,1)t=i=='#'and a or b
k,v=l:match(f..' {(.-)}')t[k]=v end
for l in io.lines(arg[1])do
c=''g='class="(.-)"'h='style="'l=l:gsub('id='..f,function(v)l:gsub(g,function(e)c=e:gsub(f,b)end)return h..a[v]..c..'"'end)l=l:gsub(g,function(e)return #c<1 and h..e:gsub(f,b)..'"'end)print(l)end

**Usage:** execute from the command line `lua script.lua input.html input.css`
Source Link
Syntax
  • 111
  • 4

Lua - 340

a,b={},{}for l in io.lines(arg[2])do i=l:sub(1,1)t=i=='#'and a or b
k,v=l:match'(%w+) {(.-)}'t[k]=v end
for l in io.lines(arg[1])do
c=''g='class="(.-)"'f='(%w+)'h='style="'l=l:gsub('id="(%w+)"',function(v)l:gsub(g,function(e)c=e:gsub(f,b)end)return h..a[v]..c..'"'end)l=l:gsub(g,function(e)return #c<1 and h..e:gsub(f,b)..'"'end)print(l)end

**Usage:** execute from the command line `lua script.lua input.html input.css`