summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xtkread22
1 files changed, 22 insertions, 0 deletions
diff --git a/tkread b/tkread
index 34472b1..f4c6039 100755
--- a/tkread
+++ b/tkread
@@ -90,6 +90,14 @@ proc indexmovechar {str moveby} {
return $linenum.[expr $charnum $moveby]
}
+# Moves line part of a text widget index (linenum.charnum)
+proc indexmoveline {str moveby} {
+ set dotindex [string first . $str]
+ set charnum [string range $str [expr $dotindex + 1] end]
+ set linenum [string range $str 0 [expr $dotindex - 1]]
+ return [expr $linenum $moveby].$charnum
+}
+
# TODO: move each section into their own procedures
proc markup {widget} {
global fontfamily
@@ -117,6 +125,15 @@ proc markup {widget} {
set alt [$widget get $altstart $altend]
set src [$widget get $srcstart $srcend]
+ # sometimes "title" tags are encoded after a space following the source, enclosed in ""
+ set imgtitlestart [string first " " $src]
+ if {$imgtitlestart != -1} {
+ set imgtitle [string trim [string range $src $imgtitlestart end] {" }]
+ set src [string range $src 0 [expr $imgtitlestart - 1] ]
+ } else {
+ set imgtitle ""
+ }
+
$widget delete [indexmovechar $altstart "- 2"] [indexmovechar $srcend "+ 1"]
set insertion [indexmovechar $altstart "- 2"]
set localfile [file tail $src]
@@ -129,6 +146,11 @@ proc markup {widget} {
set cur [indexmovechar $insertion "+ [string length $alt]"]
}
+ set insertion [indexmoveline $insertion "+ 1"]
+ if {[string length $imgtitle] != 0} {
+ $widget insert $insertion "${imgtitle}\n"
+ }
+
set cur [$widget search {![} $cur end]
}