From 1869fac40e4a35975f2e3713d37589225ae4866e Mon Sep 17 00:00:00 2001 From: Aki Date: Sat, 8 Aug 2020 00:40:28 +0200 Subject: Extended and moved out address resolution --- viewhtml | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'viewhtml') 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 -- cgit v1.1