diff options
author | Aki <please@ignore.pl> | 2020-08-08 00:40:28 +0200 |
---|---|---|
committer | Aki <please@ignore.pl> | 2020-08-08 00:40:28 +0200 |
commit | 1869fac40e4a35975f2e3713d37589225ae4866e (patch) | |
tree | b25a3fa5bf9098d45af98bcc1b4f47dd3fa7080a | |
parent | e2e3244eee4429aef9a2fd158beeccdd5bac0b9b (diff) | |
download | browse-1869fac40e4a35975f2e3713d37589225ae4866e.zip browse-1869fac40e4a35975f2e3713d37589225ae4866e.tar.gz browse-1869fac40e4a35975f2e3713d37589225ae4866e.tar.bz2 |
Extended and moved out address resolution
-rwxr-xr-x | viewhtml | 24 |
1 files changed, 13 insertions, 11 deletions
@@ -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 |