view core/src/luan/modules/Html.luan @ 563:195a64f948f2

remove SimplyHTML
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 24 Jun 2015 16:57:18 -0600
parents 92c3d22745b8
children a3c1e11fb6aa
line wrap: on
line source

java()
local HtmlLuan = require "java:luan.modules.HtmlLuan"

local M = {}

M.encode = HtmlLuan.encode
M.parse = HtmlLuan.parse
M.to_string = HtmlLuan.to_string



-- extras

local Luan = require "luan:Luan"
local ipairs = Luan.ipairs
local type = Luan.type
local Io = require "luan:Io"
local URLEncoder = require "java:java.net.URLEncoder"

function M.url_encode(s)
	return URLEncoder.encode(s,"UTF-8")
end

function M.process_url_tags(html)
	for i, v in ipairs(html) do
		if type(v) == "table" and v.type == "tag" then
			if v.name == "url" then
				local url = v.attributes.url or html[i+1]
				v.name = "a"
				v.attributes.url = nil
				v.attributes.href = url
			elseif v.name == "/url" then
				v.name = "/a"
			end
		end
	end
end

function M.add_nofollow(html)
	for i, v in ipairs(html) do
		if type(v) == "table" and v.type == "tag" and v.name == "a" then
			v.attributes.rel = "nofollow"
		end
	end
end


return M