From 580d588d7225ee3c229fc41f17711ec915875729 Mon Sep 17 00:00:00 2001 From: Nick White Date: Sat, 5 Apr 2014 12:28:19 -0400 Subject: Handle image 'title' tags, as used by pandoc --- tkread | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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] } -- cgit v1.2.3