Add simple handling of html tags

This commit is contained in:
Konstantin Nazarov 2021-07-25 16:48:52 +00:00
parent ebd74283ee
commit a2a7d97cb1
Signed by: knazarov
GPG key ID: 4CFE0A42FA409C22
2 changed files with 30 additions and 0 deletions

View file

@ -171,6 +171,25 @@ function escape_char(char) {
return char;
}
function extract_html_tag(str, i, sstr) {
sstr=substr(str, i, length(str) - i + 1);
if (match(sstr, /^<\/[a-zA-Z][a-zA-Z0-9]*>/))
return substr(str, i, RLENGTH) ;
if (match(sstr, /^<[a-zA-Z][a-zA-Z0-9]*( *[a-zA-Z][a-zA-Z0-9]* *= *"[^"]*")* *>/))
return substr(str, i, RLENGTH);
return "";
}
function is_html_tag(str, i, sstr) {
if (extract_html_tag(str, i) == "")
return 0;
return 1;
}
function parse_line(str, result, end, i) {
#print "block '" str "'"
result = ""
@ -204,6 +223,11 @@ function parse_line(str, result, end, i) {
end = find(str, "`", i+1);
}
else if (is_html_tag(str, i)) {
tag = extract_html_tag(str, i);
result = result tag;
i = i + length(tag) - 1;
}
else {
if (substr(str, i, 1) == "\n") {
if (length(result) > 0)

View file

@ -301,5 +301,11 @@ foo&bar
<p>2 &gt; 1</p>
EOF
check <<-"EOF"
foo <a href="" ></a> bar
---
<p>foo <a href="" ></a> bar</p>
EOF
echo
echo "All tests passed"