summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick White <git@njw.name>2014-04-05 12:28:19 -0400
committerNick White <git@njw.name>2014-04-05 12:28:19 -0400
commit580d588d7225ee3c229fc41f17711ec915875729 (patch)
treebebb66fc7bafa6319d05285b6dbb67a3310ddd6d
parentd24c552d9988ccab56297ba23926010d82b28ba5 (diff)
downloadtkread-580d588d7225ee3c229fc41f17711ec915875729.tar.bz2
tkread-580d588d7225ee3c229fc41f17711ec915875729.zip
Handle image 'title' tags, as used by pandoc
-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]
}