include "scanstri.s7i";
const set of string: voidHtmlElements is {
"area", "base", "br", "col", "command", "embed", "hr", "img",
"input", "keygen", "link", "meta", "param", "source", "wbr"};
const func string: getValueOfHtmlAttribute (in var string: tag, in string: attribute) is func
result
var string: attrValue is "";
local
var string: symbol is "";
begin
repeat
symbol := getSymbolInXmlTag(tag);
until symbol = attribute or symbol = "";
if symbol = attribute then
symbol := getSymbolInXmlTag(tag);
if symbol = "=" then
attrValue := getHtmlAttributeValue(tag);
end if;
end if;
end func;
const func array string: getHtmlLinks (in string: html) is func
result
var array string: htmlLinks is 0 times "";
local
var integer: startPos is 0;
var integer: endPos is 0;
var string: rawLink is "";
var string: symbol is "";
var string: linkDest is "";
begin
startPos := pos(html, "<a ");
while startPos <> 0 do
endPos := pos(html, ">", startPos + 3);
if endPos <> 0 then
rawLink := html[startPos + 3 .. pred(endPos)];
linkDest := getValueOfHtmlAttribute(rawLink, "href");
if linkDest <> "" then
htmlLinks &:= linkDest;
end if;
startPos := pos(html, "<a ", succ(endPos));
else
startPos := 0;
end if;
end while;
end func;