summaryrefslogtreecommitdiff
path: root/viewhtml
diff options
context:
space:
mode:
Diffstat (limited to 'viewhtml')
-rwxr-xr-xviewhtml24
1 files changed, 13 insertions, 11 deletions
diff --git a/viewhtml b/viewhtml
index 7303da2..44d0f39 100755
--- a/viewhtml
+++ b/viewhtml
@@ -39,24 +39,26 @@ set html [read $file]
close $file
set output [gumbo::parse $html]
-proc click {w x y} {
+proc makeAddress {address} {
global baseAddress
- set range [$w tag prevrange href [$w index @$x,$y]]
- set address [eval $w get $range]
-
- # TODO: Handle external base address nicely
- # TODO: Handle /-prefixed addresses
- if {0 == [regexp {^https?.*} $address]} {
- exec "./browse" "$baseAddress$address"
+ if {1 == [regexp {^https?.*} $address]} {
+ return "$address"
+ } elseif {1 == [regexp {^/.*} $address]} {
+ return "[regsub {(https?://[^/]+)/.*} $baseAddress {\1}]$address"
} else {
- exec "./browse" $address
+ return "$baseAddress$address"
}
}
+proc click {w x y} {
+ set range [$w tag prevrange href [$w index @$x,$y]]
+ set address [eval $w get $range]
+ exec "./browse" [makeAddress $address]
+}
+
proc displayNode {node tagList} {
# TODO: Avoid using global variables.
global w
- global baseAddress
set type [gumbo::node_get_type $node]
if {$type == $gumbo::GUMBO_NODE_ELEMENT} {
@@ -69,7 +71,7 @@ proc displayNode {node tagList} {
} elseif {$tag == "img"} {
$w insert end "\n"
set lattr [array get $attributes]
- set path "$baseAddress[lindex $lattr [expr [lsearch -exact $lattr src] + 1]]"
+ set path [makeAddress [lindex $lattr [expr [lsearch -exact $lattr src] + 1]]]
set localPath [lindex [split [exec ./phttp $path] { }] 2]
image create photo $path -file $localPath
$w image create end -image $path